Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support HTTP proxy #64

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/org/jfrog/buildinfo/ArtifactoryMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Proxy;
import org.jfrog.build.extractor.ci.BuildInfoFields;
import org.jfrog.build.extractor.clientConfiguration.ArtifactoryClientConfiguration;
import org.jfrog.build.extractor.clientConfiguration.ClientProperties;
Expand Down Expand Up @@ -61,10 +62,14 @@ public class ArtifactoryMojo extends AbstractMojo {
@Parameter
Config.Resolver resolver = new Config.Resolver();

@Parameter
Config.Proxy proxy = new Config.Proxy();

@Override
public void execute() {
if (session.getRequest().getData().putIfAbsent("configured", Boolean.TRUE) == null) {
replaceVariables();
setupProxy();
enforceResolution();
enforceDeployment();
}
Expand All @@ -78,6 +83,20 @@ private void replaceVariables() {
deployProperties.replaceAll((key, value) -> Utils.parseInput(value));
}

/**
* Set up proxy from settings.xml, if not provided.
*/
private void setupProxy() {
if (this.proxy.getHost() != null) {
return;
}
Proxy proxy = session.getSettings().getActiveProxy();
this.proxy.setHost(proxy.getHost());
this.proxy.setPort(proxy.getPort());
this.proxy.setUsername(proxy.getUsername());
this.proxy.setPassword(proxy.getPassword());
}

/**
* Enforce resolution from Artifactory repositories if there is a 'resolver' configuration.
*/
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jfrog/buildinfo/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ public static class BuildInfo {
@Delegate(types = {ArtifactoryClientConfiguration.BuildInfoHandler.class, PrefixPropertyHandler.class})
ArtifactoryClientConfiguration.BuildInfoHandler delegate = CLIENT_CONFIGURATION.info;
}

/**
* Represents the 'proxy' configuration in the pom.xml.
*/
public static class Proxy {
@Delegate(types = {ArtifactoryClientConfiguration.ProxyHandler.class, PrefixPropertyHandler.class})
ArtifactoryClientConfiguration.ProxyHandler delegate = CLIENT_CONFIGURATION.proxy;
}
}
10 changes: 10 additions & 0 deletions src/test/java/org/jfrog/buildinfo/ArtifactoryMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public void testBuildInfoConfiguration() {
assertTrue(buildInfo.getBuildStarted().startsWith("2020-01-01T00:00:00.000"));
}

public void testProxyConfiguration() {
Config.Proxy configProxy = mojo.proxy;
assertNotNull(configProxy);
ArtifactoryClientConfiguration.ProxyHandler proxyHandler = configProxy.delegate;
assertEquals("proxy.jfrog.io", proxyHandler.getHost());
assertEquals(Integer.valueOf(8888), proxyHandler.getPort());
assertEquals("proxyUser", proxyHandler.getUsername());
assertEquals("proxyPassword", proxyHandler.getPassword());
}

public void testDeployProperties() {
// Test input deploy properties
Map<String, String> deployProperties = mojo.deployProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ private void fillMojoFromConfiguration(Xpp3Dom configuration) throws JsonProcess
mojo.buildInfo = objectMapper.readValue(configuration.getChild("buildInfo").toString(), Config.BuildInfo.class);
mojo.publisher = objectMapper.readValue(configuration.getChild("publisher").toString(), Config.Publisher.class);
mojo.resolver = objectMapper.readValue(configuration.getChild("resolver").toString(), Config.Resolver.class);
mojo.proxy = objectMapper.readValue(configuration.getChild("proxy").toString(), Config.Proxy.class);
Log log = new MavenLogger();
mojo.setLog(log);
mojo.repositoryListener = new RepositoryListener(new PlexusLogger(log));
}
}
}
6 changes: 6 additions & 0 deletions src/test/resources/unit-tests-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
<agentVersion>2</agentVersion>
<buildRetentionMaxDays>5</buildRetentionMaxDays>
</buildInfo>
<proxy>
<host>proxy.jfrog.io</host>
<port>8888</port>
<username>proxyUser</username>
<password>proxyPassword</password>
</proxy>
</configuration>
</execution>
</executions>
Expand Down