diff options
Diffstat (limited to 'openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java')
-rw-r--r-- | openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java index 067517504c..22ba506c48 100644 --- a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java +++ b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on a "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.openecomp.sdc.onboarding.util; import java.io.File; @@ -16,12 +32,15 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; +import org.apache.maven.settings.Proxy; @Mojo(name = "init-artifact-helper", threadSafe = true, defaultPhase = LifecyclePhase.PRE_CLEAN, requiresDependencyResolution = ResolutionScope.NONE) public class InitializationHelperMojo extends AbstractMojo { private static final String SKIP_GET = "skipGet"; + private static final String HTTP = "http"; + private static final String HTTPS = "https"; @Parameter(defaultValue = "${session}") private MavenSession session; @@ -42,10 +61,11 @@ public class InitializationHelperMojo extends AbstractMojo { @Parameter private ArtifactHelper artifactHelper; + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (System.getProperties().containsKey(SKIP_GET)) { project.getProperties() - .setProperty(SKIP_GET, Boolean.valueOf(System.getProperties().containsKey(SKIP_GET)).toString()); + .setProperty(SKIP_GET, Boolean.toString(System.getProperties().containsKey(SKIP_GET))); return; } else { File orgFile = new File( @@ -67,9 +87,10 @@ public class InitializationHelperMojo extends AbstractMojo { String buildNumber = null; for (ArtifactRepository repo : list) { try { - String content = artifactHelper.getContents( - new URL(repo.getUrl() + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version - + "/maven-metadata.xml")); + URL url = new URL(repo.getUrl() + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version + + "/maven-metadata.xml"); + setProxy(url); + String content = artifactHelper.getContents(url); Matcher m = timestampPattern.matcher(content); if (m.find()) { timestamp = m.group(1); @@ -79,10 +100,31 @@ public class InitializationHelperMojo extends AbstractMojo { buildNumber = m.group(1); } } catch (IOException e) { - continue; + getLog().debug(e); + } + if (timestamp != null && buildNumber != null) { + return timestamp + "-" + buildNumber; } } - return timestamp != null && buildNumber != null ? timestamp + "-" + buildNumber : version; + return version; + } + + private void setProxy(URL url) { + if (url.getProtocol().equalsIgnoreCase(HTTP)) { + setProperties("http.proxyHost", "http.proxyPort", "http.nonProxyHosts", HTTP); + } else if (url.getProtocol().equalsIgnoreCase(HTTPS)) { + setProperties("https.proxyHost", "https.proxyPort", "https.nonProxyHosts", HTTPS); + } } + private void setProperties(String proxyHostProperty, String proxyPortProperty, String nonProxyHostsProperty, + String protocol) { + for (Proxy proxy : session.getSettings().getProxies()) { + if (proxy.isActive() && proxy.getProtocol().equalsIgnoreCase(protocol)) { + System.setProperty(proxyHostProperty, proxy.getHost()); + System.setProperty(proxyPortProperty, String.valueOf(proxy.getPort())); + System.setProperty(nonProxyHostsProperty, proxy.getNonProxyHosts()); + } + } + } } |