From 2d0b9a3ff4c381bc98993670803c14279f8168ee Mon Sep 17 00:00:00 2001 From: Gautam Shah Date: Tue, 29 May 2018 16:40:44 +0530 Subject: Adding Proxy settings for pulling PMD artifact. Proxy settings applied. Change-Id: I9c32894239c998a497a6b59e79b3c41dd7d5df14 Issue-ID: SDC-1189 Signed-off-by: GAUTAMS --- .../sdc/onboarding/util/CopyArtifactPlugin.java | 31 ++++++++++--- .../onboarding/util/InitializationHelperMojo.java | 54 +++++++++++++++++++--- 2 files changed, 72 insertions(+), 13 deletions(-) diff --git a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CopyArtifactPlugin.java b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CopyArtifactPlugin.java index 20b1a7c940..c89fdd2a4e 100644 --- a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CopyArtifactPlugin.java +++ b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CopyArtifactPlugin.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; @@ -43,18 +59,19 @@ public class CopyArtifactPlugin extends AbstractMojo { @Parameter private ArtifactHelper artifactHelper; + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (!project.getProperties().containsKey("resolvedVersion")) { return; } boolean isSnapshot = version.contains("SNAPSHOT"); List artRepoList = artifactHelper.getRepositories(isSnapshot); - String resolvedVersion = - project.getProperties().getProperty("resolvedVersion"); + String resolvedVersion = project.getProperties().getProperty("resolvedVersion"); try { if (!version.equals(resolvedVersion)) { - if(copyResolvedArtifact(artRepoList, resolvedVersion) && getLog().isInfoEnabled()){ - getLog().info("Data Artifact Copied with "+resolvedVersion); + boolean result = copyResolvedArtifact(artRepoList, resolvedVersion); + if (result && getLog().isInfoEnabled()) { + getLog().info("Data Artifact Copied with " + resolvedVersion); } } @@ -75,7 +92,7 @@ public class CopyArtifactPlugin extends AbstractMojo { copyTargetArtifact(directory, list[0]); } } catch (IOException | NoSuchAlgorithmException e) { - throw new MojoFailureException(e.getMessage()); + throw new MojoFailureException(e.getMessage(), e); } } @@ -100,7 +117,7 @@ public class CopyArtifactPlugin extends AbstractMojo { } - private boolean copyResolvedArtifact(List list, String resolvedVersion){ + private boolean copyResolvedArtifact(List list, String resolvedVersion) { for (ArtifactRepository repo : list) { try { writeContents( @@ -110,7 +127,7 @@ public class CopyArtifactPlugin extends AbstractMojo { + ".jar")); return true; } catch (IOException e) { - getLog().warn(e); + getLog().debug(e); } } return false; 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()); + } + } + } } -- cgit 1.2.3-korg