gnodet commented on code in PR #35:
URL:
https://github.com/apache/maven-build-cache-extension/pull/35#discussion_r1090762647
##########
src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java:
##########
@@ -81,11 +90,58 @@ public RemoteCacheRepositoryImpl(
RepositorySystemSession session =
mavenSession.getRepositorySession();
RemoteRepository repo = new RemoteRepository.Builder(
cacheConfig.getId(), "cache", cacheConfig.getUrl()
).build();
- RemoteRepository mirror = session.getMirrorSelector().getMirror(
repo );
- RemoteRepository repoOrMirror = mirror != null ? mirror : repo;
- Proxy proxy = session.getProxySelector().getProxy( repoOrMirror );
- Authentication auth =
session.getAuthenticationSelector().getAuthentication( repoOrMirror );
- RemoteRepository repository = new RemoteRepository.Builder(
repoOrMirror )
+ Map<String, String> env = System.getenv();
+
+ // if direct connectivity isn't forced, resolving through maven
settings
+ if ( !env.containsKey( MAVEN_BUILD_CACHE_DIRECT_CONNECT ) )
+ {
+ RemoteRepository mirror =
session.getMirrorSelector().getMirror( repo );
+ if ( mirror != null )
+ {
+ repo = mirror;
+ }
+ }
+
+ // if proxy is set by environment, use it
+ Proxy proxy;
+ if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_URL ) )
+ {
+ String proxyUrl = env.get( MAVEN_BUILD_CACHE_PROXY_URL );
+ LOGGER.debug( "Remote build cache proxy url overridden by
environment to {}", proxyUrl );
+ URI uri = URI.create( proxyUrl );
+ if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_USER ) )
Review Comment:
`&& env.containsKey( MAVEN_BUILD_CACHE_PASSWORD )` ? Or cleanly fail if
it's missing maybe.
##########
src/main/java/org/apache/maven/buildcache/RemoteCacheRepositoryImpl.java:
##########
@@ -81,11 +90,58 @@ public RemoteCacheRepositoryImpl(
RepositorySystemSession session =
mavenSession.getRepositorySession();
RemoteRepository repo = new RemoteRepository.Builder(
cacheConfig.getId(), "cache", cacheConfig.getUrl()
).build();
- RemoteRepository mirror = session.getMirrorSelector().getMirror(
repo );
- RemoteRepository repoOrMirror = mirror != null ? mirror : repo;
- Proxy proxy = session.getProxySelector().getProxy( repoOrMirror );
- Authentication auth =
session.getAuthenticationSelector().getAuthentication( repoOrMirror );
- RemoteRepository repository = new RemoteRepository.Builder(
repoOrMirror )
+ Map<String, String> env = System.getenv();
+
+ // if direct connectivity isn't forced, resolving through maven
settings
+ if ( !env.containsKey( MAVEN_BUILD_CACHE_DIRECT_CONNECT ) )
+ {
+ RemoteRepository mirror =
session.getMirrorSelector().getMirror( repo );
+ if ( mirror != null )
+ {
+ repo = mirror;
+ }
+ }
+
+ // if proxy is set by environment, use it
+ Proxy proxy;
+ if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_URL ) )
+ {
+ String proxyUrl = env.get( MAVEN_BUILD_CACHE_PROXY_URL );
+ LOGGER.debug( "Remote build cache proxy url overridden by
environment to {}", proxyUrl );
+ URI uri = URI.create( proxyUrl );
+ if ( env.containsKey( MAVEN_BUILD_CACHE_PROXY_USER ) )
+ {
+ LOGGER.debug( "Remote build cache proxy credentials
overridden by environment" );
+ Authentication proxyAuthentication = new
AuthenticationBuilder()
+ .addUsername( env.get(
MAVEN_BUILD_CACHE_PROXY_USER ) )
+ .addPassword( env.get(
MAVEN_BUILD_CACHE_PROXY_PASSWORD ) )
+ .build();
+ proxy = new Proxy( uri.getScheme(), uri.getHost(),
uri.getPort(), proxyAuthentication );
+ }
+ else
+ {
+ proxy = new Proxy( uri.getScheme(), uri.getHost(),
uri.getPort() );
+ }
+ }
+ else
+ {
+ proxy = session.getProxySelector().getProxy( repo );
+ }
+
+ Authentication auth;
+ if ( env.containsKey( MAVEN_BUILD_CACHE_USER ) )
Review Comment:
`&& env.containsKey( MAVEN_BUILD_CACHE_PASSWORD )` ? Or cleanly fail if
it's missing maybe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]