Skip to content

Commit

Permalink
JENKINS-50293 Repository Connector Plugin does not use Jenkins config…
Browse files Browse the repository at this point in the history
…ured proxy correctly (#33)
  • Loading branch information
butchyyyy authored and jgangemi committed May 18, 2018
1 parent a6f7866 commit 8851b74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
Expand Up @@ -70,6 +70,7 @@ public class Aether {

private final List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();
private final RepositorySystem repositorySystem;
private final RepositorySystemSession session;
private final LocalRepository localRepository;
private final PrintStream logger;
private final boolean extendedLogging;
Expand All @@ -86,8 +87,9 @@ public Aether(Collection<Repository> remoteRepositories, File localRepository) {
public Aether(Collection<Repository> remoteRepositories, File localRepository, PrintStream logger, boolean extendedLogging,
String snapshotUpdatePolicy, String snapshotChecksumPolicy, String releaseUpdatePolicy, String releaseChecksumPolicy) {
this.logger = logger;
this.repositorySystem = newManualSystem();
this.localRepository = new LocalRepository(localRepository);
this.repositorySystem = newManualSystem();
this.session = newSession();
this.extendedLogging = extendedLogging;
this.releaseUpdatePolicy = releaseUpdatePolicy;
this.releaseChecksumPolicy = releaseChecksumPolicy;
Expand All @@ -101,6 +103,7 @@ public Aether(File localRepository, PrintStream logger, boolean extendedLogging)
this.localRepository = new LocalRepository(localRepository);
this.extendedLogging = extendedLogging;
this.repositorySystem = newManualSystem();
this.session = newSession();
}

private void initRemoteRepos(Collection<Repository> remoteRepositories) {
Expand Down Expand Up @@ -129,6 +132,9 @@ private void initRemoteRepos(Collection<Repository> remoteRepositories) {
// @see org.sonatype.aether.impl.internal.DefaultMetadataResolver#getEnabledSourceRepositories(org.sonatype.aether.repository.RemoteRepository, org.sonatype.aether.metadata.Metadata.Nature)
repoObj.setMirroredRepositories(resolveMirrors(repoObj));
}
if (session.getProxySelector() != null) {
repoObj.setProxy(session.getProxySelector().getProxy(repoObj));
}
repositories.add(repoObj);
}
}
Expand All @@ -153,7 +159,7 @@ private void addProxySelectorIfNecessary(DefaultRepositorySystemSession reposito
}
}

public String convertHudsonNonProxyToJavaNonProxy(String hudsonNonProxy) {
public static String convertHudsonNonProxyToJavaNonProxy(String hudsonNonProxy) {
if (StringUtils.isEmpty(hudsonNonProxy)) {
return "";
}
Expand Down Expand Up @@ -206,7 +212,6 @@ private RepositorySystemSession newSession() {

public AetherResult resolve(String groupId, String artifactId, String classifier, String extension, String version)
throws DependencyCollectionException, DependencyResolutionException {
RepositorySystemSession session = newSession();
Dependency dependency = new Dependency(new DefaultArtifact(groupId, artifactId, classifier, extension, version), "provided");

CollectRequest collectRequest = new CollectRequest(dependency, repositories);
Expand All @@ -226,7 +231,6 @@ public AetherResult resolve(String groupId, String artifactId, String classifier

public VersionRangeResultWithLatest resolveVersions(String groupId, String artifactId)
throws VersionRangeResolutionException {
RepositorySystemSession session = newSession();
Artifact artifact = new DefaultArtifact(groupId, artifactId, null, null, "[0,)");

VersionRangeRequest rangeRequest = new VersionRangeRequest();
Expand All @@ -237,17 +241,13 @@ public VersionRangeResultWithLatest resolveVersions(String groupId, String artif
}

public void install(Artifact artifact, Artifact pom) throws InstallationException {
RepositorySystemSession session = newSession();

InstallRequest installRequest = new InstallRequest();
installRequest.addArtifact(artifact).addArtifact(pom);

repositorySystem.install(session, installRequest);
}

public void deploy(Repository repository, Artifact artifact, Artifact pom) throws DeploymentException {
RepositorySystemSession session = newSession();

RemoteRepository repoObj = new RemoteRepository(repository.getId(), repository.getType(), repository.getUrl());
repoObj.setRepositoryManager(repository.isRepositoryManager());
final String user = repository.getUser();
Expand Down
@@ -1,31 +1,22 @@
package org.jvnet.hudson.plugins.repositoryconnector.aether;

import org.junit.Before;
import org.junit.Test;

import java.io.File;

import static org.junit.Assert.assertEquals;

public class AetherTest {

private Aether sut;

@Before
public void setup() {
sut = new Aether(new File("jenkinstest"), System.out, false);
}

@Test
public void convertGivenNonHttpProxySettings() throws Exception {

String result = sut.convertHudsonNonProxyToJavaNonProxy("localhost\n*.google.com\n\napple.com");
String result = Aether.convertHudsonNonProxyToJavaNonProxy("localhost\n*.google.com\n\napple.com");

assertEquals("New lines should be replaced", result, "localhost|*.google.com|apple.com");
}

@Test
public void convertGivenNullNonHttpProxySettings() throws Exception {
assertEquals("New lines should be replaced", sut.convertHudsonNonProxyToJavaNonProxy(null), "");
assertEquals("New lines should be replaced", Aether.convertHudsonNonProxyToJavaNonProxy(null), "");
}

}

0 comments on commit 8851b74

Please sign in to comment.