+/*
+ * 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;
@Parameter
private ArtifactHelper artifactHelper;
+ @Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (!project.getProperties().containsKey("resolvedVersion")) {
return;
}
boolean isSnapshot = version.contains("SNAPSHOT");
List<ArtifactRepository> 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);
}
}
copyTargetArtifact(directory, list[0]);
}
} catch (IOException | NoSuchAlgorithmException e) {
- throw new MojoFailureException(e.getMessage());
+ throw new MojoFailureException(e.getMessage(), e);
}
}
}
- private boolean copyResolvedArtifact(List<ArtifactRepository> list, String resolvedVersion){
+ private boolean copyResolvedArtifact(List<ArtifactRepository> list, String resolvedVersion) {
for (ArtifactRepository repo : list) {
try {
writeContents(
+ ".jar"));
return true;
} catch (IOException e) {
- getLog().warn(e);
+ getLog().debug(e);
}
}
return false;
+/*
+ * 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;
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;
@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(
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);
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());
+ }
+ }
+ }
}