use of io.tesla.aether.Repository in project druid by druid-io.
the class PullDependencies method getAetherClient.
@SuppressForbidden(reason = "System#out")
private DefaultTeslaAether getAetherClient() {
/*
DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying. We choose to disable that
unless debug logging is turned on. "Disabling" it, however, is kinda bass-ackwards. We copy out a reference
to the current System.out, and set System.out to a noop output stream. Then after DefaultTeslaAether has pulled
The reference we swap things back.
This has implications for other things that are running in parallel to this. Namely, if anything else also grabs
a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
to nothingness. Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
alongside anything else that's grabbing System.out. But who knows.
*/
final List<String> remoteUriList = new ArrayList<>();
if (!noDefaultRemoteRepositories) {
remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
}
remoteUriList.addAll(remoteRepositories);
List<Repository> remoteRepositories = new ArrayList<>();
for (String uri : remoteUriList) {
try {
URI u = new URI(uri);
Repository r = new Repository(uri);
if (u.getUserInfo() != null) {
String[] auth = u.getUserInfo().split(":", 2);
if (auth.length == 2) {
r.setUsername(auth[0]);
r.setPassword(auth[1]);
} else {
log.warn("Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]", u.getUserInfo(), uri);
}
}
remoteRepositories.add(r);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
if (log.isTraceEnabled() || log.isDebugEnabled()) {
return createTeslaAether(remoteRepositories);
}
PrintStream oldOut = System.out;
try {
System.setOut(new PrintStream(new OutputStream() {
@Override
public void write(int b) {
}
@Override
public void write(byte[] b) {
}
@Override
public void write(byte[] b, int off, int len) {
}
}, false, StringUtils.UTF8_STRING));
return createTeslaAether(remoteRepositories);
} catch (UnsupportedEncodingException e) {
// should never happen
throw new IllegalStateException(e);
} finally {
System.setOut(oldOut);
}
}
use of io.tesla.aether.Repository in project druid by druid-io.
the class PullDependencies method getAetherClient.
private DefaultTeslaAether getAetherClient() {
/*
DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying. We choose to disable that
unless debug logging is turned on. "Disabling" it, however, is kinda bass-ackwards. We copy out a reference
to the current System.out, and set System.out to a noop output stream. Then after DefaultTeslaAether has pulled
The reference we swap things back.
This has implications for other things that are running in parallel to this. Namely, if anything else also grabs
a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
to nothingness. Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
alongside anything else that's grabbing System.out. But who knows.
*/
final List<String> remoteUriList = Lists.newArrayList();
if (!noDefaultRemoteRepositories) {
remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
}
remoteUriList.addAll(remoteRepositories);
List<Repository> remoteRepositories = Lists.newArrayList();
for (String uri : remoteUriList) {
try {
URI u = new URI(uri);
Repository r = new Repository(uri);
if (u.getUserInfo() != null) {
String[] auth = u.getUserInfo().split(":", 2);
if (auth.length == 2) {
r.setUsername(auth[0]);
r.setPassword(auth[1]);
} else {
log.warn("Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]", u.getUserInfo(), uri);
}
}
remoteRepositories.add(r);
} catch (URISyntaxException e) {
throw Throwables.propagate(e);
}
}
if (log.isTraceEnabled() || log.isDebugEnabled()) {
return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
}
PrintStream oldOut = System.out;
try {
System.setOut(new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
}
@Override
public void write(byte[] b) throws IOException {
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
}
}, false, StringUtils.UTF8_STRING));
return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
} catch (UnsupportedEncodingException e) {
// should never happen
throw new IllegalStateException(e);
} finally {
System.setOut(oldOut);
}
}
use of io.tesla.aether.Repository in project druid by druid-io.
the class PullDependencies method createTeslaAether.
private DefaultTeslaAether createTeslaAether(List<Repository> remoteRepositories) {
if (!useProxy) {
return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[0]));
}
if (!StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTP) && !StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTPS)) {
throw new IllegalArgumentException("invalid proxy type: " + proxyType);
}
RepositorySystemSession repositorySystemSession = new RepositorySystemSessionProvider(new File(localRepository)).get();
List<RemoteRepository> rl = remoteRepositories.stream().map(r -> {
RemoteRepository.Builder builder = new RemoteRepository.Builder(r.getId(), "default", r.getUrl());
if (r.getUsername() != null && r.getPassword() != null) {
Authentication auth = new AuthenticationBuilder().addUsername(r.getUsername()).addPassword(r.getPassword()).build();
builder.setAuthentication(auth);
}
final Authentication proxyAuth;
if (Strings.isNullOrEmpty(proxyUsername)) {
proxyAuth = null;
} else {
proxyAuth = new AuthenticationBuilder().addUsername(proxyUsername).addPassword(proxyPassword).build();
}
builder.setProxy(new Proxy(proxyType, proxyHost, proxyPort, proxyAuth));
return builder.build();
}).collect(Collectors.toList());
return new DefaultTeslaAether(rl, repositorySystemSession);
}
Aggregations