From: vempo Date: Mon, 5 Nov 2018 16:41:47 +0000 (+0200) Subject: Removed artifact-copy plugin X-Git-Tag: 1.3.3~15 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=f069fd4e35f20456f83767ca07d8a58b50ca4b59;p=sdc.git Removed artifact-copy plugin Change-Id: I2993bdc46693af1b48ed886718d17b835437740e Issue-ID: SDC-1861 Signed-off-by: vempo --- diff --git a/common/pom.xml b/common/pom.xml index 42274dd4c7..95f58b7403 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -48,29 +48,6 @@ ${java.target} - - org.openecomp.sdc.onboarding - artifact-copy-plugin - ${project.version} - - - - init-artifact-helper - calibrate-artifact-helper - - - - - org.openecomp.sdc - build-data-installer - ${project.version} - - ${project} - ${session} - org.openecomp.sdc:sdc-onboarding/target/build-data - - - org.openecomp.sdc.onboarding compile-helper-plugin diff --git a/onboarding/pom.xml b/onboarding/pom.xml index 23bbb82540..166a079c3a 100644 --- a/onboarding/pom.xml +++ b/onboarding/pom.xml @@ -14,11 +14,9 @@ - ../openecomp-be/tools/artifact-copy-plugin ../openecomp-be/tools/compile-helper-plugin ../common ../openecomp-be - ../openecomp-be/tools/build-data-installer ../openecomp-be/tools/snapshot-signature-plugin ../openecomp-ui diff --git a/openecomp-be/pom.xml b/openecomp-be/pom.xml index 234234ef15..356b0c5670 100644 --- a/openecomp-be/pom.xml +++ b/openecomp-be/pom.xml @@ -59,30 +59,6 @@ ${java.target} - - org.openecomp.sdc.onboarding - artifact-copy-plugin - ${project.version} - - - - init-artifact-helper - - calibrate-artifact-helper - - - - - org.openecomp.sdc - build-data-installer - ${project.version} - - ${project} - ${session} - org.openecomp.sdc:sdc-onboarding/target/build-data - - - org.openecomp.sdc.onboarding compile-helper-plugin diff --git a/openecomp-be/tools/artifact-copy-plugin/pom.xml b/openecomp-be/tools/artifact-copy-plugin/pom.xml deleted file mode 100644 index 1e35ac0c39..0000000000 --- a/openecomp-be/tools/artifact-copy-plugin/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - 4.0.0 - - org.openecomp.sdc.onboarding - artifact-copy-plugin - maven-plugin - - sdc-onboarding - org.openecomp.sdc - 1.3.3-SNAPSHOT - ../../../onboarding/pom.xml - - - classes/**/*.class - maven-status/** - true - - - - org.apache.maven - maven-core - ${maven-core.version} - - - org.apache.maven.plugin-tools - maven-plugin-annotations - ${maven-plugin-annotations.version} - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${maven-plugin-plugin.version} - - - - - \ No newline at end of file diff --git a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java deleted file mode 100644 index ce63a8d466..0000000000 --- a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * 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 java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.MavenProject; - -public class ArtifactHelper { - - private MavenProject project; - private MavenSession session; - private static final Map store = new HashMap<>(); - private static final Set terminalModuleCoordinates = new HashSet<>(); - private String unicornRoot = null; - private static File unicornMetaLocation = null; - private final File tempLocation = Paths.get(System.getProperties().getProperty("java.io.tmpdir")).toFile(); - private static int snapshotBuildNumber = 0; - private static final String HYPHEN = "-"; - - void init(String terminalModuleCoordinate) { - setUnicornMetaLocation(getUnicornRootFile(unicornRoot.substring(0, unicornRoot.indexOf('/')), project)); - setTerminalModuleCoordinates(session.getProjects().get(session.getProjects().size() - 1)); - terminalModuleCoordinates.add(terminalModuleCoordinate); - } - - private static void setUnicornMetaLocation(File file) { - unicornMetaLocation = file; - } - - static void setSnapshotBuildNumber(int number) { - snapshotBuildNumber = number; - } - - List getRepositories(boolean snapshotRepo) { - List list = new ArrayList<>(); - for (ArtifactRepository artRepo : project.getRemoteArtifactRepositories()) { - if (snapshotRepo) { - if (artRepo.getSnapshots().isEnabled()) { - list.add(artRepo); - } - } else { - if (artRepo.getReleases().isEnabled()) { - list.add(artRepo); - } - } - } - return list; - } - - private void setTerminalModuleCoordinates(MavenProject project) { - terminalModuleCoordinates.add(getModuleCoordinate(project)); - } - - private boolean isModuleTerminal(MavenProject project) { - return terminalModuleCoordinates.contains(getModuleCoordinate(project)); - } - - File getUnicornMetaLocation() { - return unicornMetaLocation; - } - - String getContents(URL path) throws IOException { - try (InputStream is = path.openStream(); Scanner scanner = new Scanner(is).useDelimiter("\\A")) { - return scanner.hasNext() ? scanner.next() : ""; - } - } - - void store(String artifactId, byte[] data) { - store.put(artifactId, data); - } - - void deleteAll(File f) { - - if (!f.exists() || !f.isDirectory()) { - return; - } - - File[] fileList = f.listFiles(); - if (fileList == null) { - return; - } - - for (File file : fileList) { - - if (file.isFile()) { - file.delete(); - } - } - } - - String getModuleCoordinate(MavenProject project) { - return project.getGroupId() + ":" + project.getArtifactId(); - } - - private File getUnicornRootFile(String moduleCoordinate, MavenProject mavenProject) { - return getStateFile(moduleCoordinate, mavenProject, unicornRoot); - } - - private File getStateFile(String moduleCoordinate, MavenProject mavenProject, String filePath) { - return new File(getTopParentProject(moduleCoordinate, mavenProject).getBasedir(), - filePath.substring(filePath.indexOf('/') + 1)); - } - - MavenProject getTopParentProject(String moduleCoordinate, MavenProject mavenProject) { - if (getModuleCoordinate(mavenProject).equals(moduleCoordinate) || mavenProject.getParent() == null) { - return mavenProject; - } else { - return getTopParentProject(moduleCoordinate, mavenProject.getParent()); - } - } - - void shutDown(MavenProject project) throws IOException, ClassNotFoundException { - File file = new File(unicornMetaLocation, "compileState.dat"); - HashMap dataStore; - if (isModuleTerminal(project) && file.exists()) { - try (InputStream is = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(is)) { - dataStore = (HashMap) ois.readObject(); - //noinspection unchecked - dataStore.put("shutdownTime", (System.currentTimeMillis() / 1000) * 1000 + snapshotBuildNumber); - //noinspection unchecked - dataStore.put("version", project.getVersion()); - } - try (OutputStream os = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(os)) { - oos.writeObject(dataStore); - } - Files.copy(file.toPath(), - Paths.get(tempLocation.getAbsolutePath(), file.getName() + HYPHEN + project.getVersion()), - StandardCopyOption.REPLACE_EXISTING); - } - } -} - - diff --git a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CalibrateArtifactPlugin.java b/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CalibrateArtifactPlugin.java deleted file mode 100644 index fa871c20c5..0000000000 --- a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/CalibrateArtifactPlugin.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.openecomp.sdc.onboarding.util; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.*; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; - -import java.io.File; -import java.io.IOException; - -@Mojo(name = "calibrate-artifact-helper", threadSafe = true, defaultPhase = LifecyclePhase.INSTALL, - requiresDependencyResolution = ResolutionScope.TEST) -public class CalibrateArtifactPlugin extends AbstractMojo { - - private static final String ARTIFACT_COPY_PATH = "artifactPathToCopy"; - - @Parameter(defaultValue = "${session}") - private MavenSession session; - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Component - private MavenProjectHelper projectHelper; - @Parameter - private String groupId; - @Parameter - private String artifactId; - @Parameter - private String version; - @Parameter - private String excludePackaging; - @Parameter - private ArtifactHelper artifactHelper; - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - if (project.getPackaging().equals(excludePackaging)) { - return; - } - if (project.getProperties().containsKey(ARTIFACT_COPY_PATH) - && project.getProperties().getProperty(ARTIFACT_COPY_PATH) != null) { - File f = new File(project.getProperties().getProperty(ARTIFACT_COPY_PATH)); - if (f.exists()) { - project.getArtifact().setFile(f); - } - } - try { - artifactHelper.shutDown(project); - } catch (IOException | ClassNotFoundException e) { - throw new MojoExecutionException("Unexpected Error Occured during shutdown activities", e); - } - } -} 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 deleted file mode 100644 index afe5d3e702..0000000000 --- a/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/InitializationHelperMojo.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * 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 java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -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 UNICORN_INITIALIZED = "unicorn_initialized"; - private static final String HTTP = "http"; - private static final String HTTPS = "https"; - private static final String SNAPSHOT = "SNAPSHOT"; - private static final String DOT = "."; - - @Parameter(defaultValue = "${session}") - private MavenSession session; - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Parameter - private String groupId; - @Parameter - private String artifactId; - @Parameter - private String version; - @Parameter - private String excludePackaging; - @Parameter - private ArtifactHelper artifactHelper; - - @Override - public void execute() throws MojoExecutionException { - if (System.getProperties().containsKey(UNICORN_INITIALIZED)) { - try { - artifactHelper.shutDown(project); - } catch (IOException | ClassNotFoundException e) { - throw new MojoExecutionException("Unexpected Error Occurred during shutdown activities", e); - } - return; - } - artifactHelper.init(groupId + ":" + artifactId); - artifactHelper.deleteAll(artifactHelper.getUnicornMetaLocation()); - String resolvedVersion = - getResolvedVersion(artifactHelper.getRepositories(version.contains(SNAPSHOT)), artifactId); - getLog().info(resolvedVersion.equals(version) ? "Unicorn Initialization Failed!!!" : - "Unicorn Initialization Completed Successfully!!!"); - System.getProperties().setProperty(UNICORN_INITIALIZED, Boolean.TRUE.toString()); - } - - private String getResolvedVersion(List list, String artifactId) { - Pattern timestampPattern = Pattern.compile(".*(.*).*"); - Pattern buildNumberPattern = Pattern.compile(".*(.*).*"); - - String timestamp = null; - String buildNumber = null; - for (ArtifactRepository repo : list) { - try { - 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); - } - m = buildNumberPattern.matcher(content); - if (m.find()) { - buildNumber = m.group(1); - } - - URL fallbackUrl = - new URL(repo.getUrl() + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version + '/'); - timestamp = verifyBuildTimestamp(buildNumber, timestamp, fallbackUrl); - if (timestamp != null && buildNumber != null) { - byte[] data = fetchContents(repo.getUrl(), artifactId, timestamp + "-" + buildNumber); - artifactHelper.store(artifactId, data); - getLog().info(artifactId + " Version to be copied is " + timestamp + "-" + buildNumber); - ArtifactHelper.setSnapshotBuildNumber(Integer.parseInt(buildNumber) + 1); - return timestamp + "-" + buildNumber; - } - } catch (IOException e) { - getLog().debug(e); - } - } - return version; - } - - private String verifyBuildTimestamp(String buildNumber, String timestamp, URL fallbackUrl) throws IOException { - if (buildNumber == null) { - return timestamp; - } - String buildPage = artifactHelper.getContents(fallbackUrl); - Pattern verifyPattern = Pattern.compile( - ".*" + artifactId + "-" + version.replace(SNAPSHOT, "") + "(.*)" + "-" + buildNumber + ".jar.*"); - Matcher m = verifyPattern.matcher(buildPage); - if (m.find()) { - String str = m.group(1); - if (!str.equals(timestamp)) { - return str; - } - } - return timestamp; - } - - private byte[] fetchContents(String repoUrl, String artifactId, String resolvedVersion) throws IOException { - File location = Paths.get(project.getBuild().getDirectory(), "build-data").toFile(); - location.mkdirs(); - File file = new File(location, artifactId + "-" + (version.equals(resolvedVersion) ? version : - version.replace(SNAPSHOT, resolvedVersion)) + DOT - + "jar"); - URL path = new URL(repoUrl + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version + '/' + artifactId - + "-" + (version.equals(resolvedVersion) ? version : - version.replace(SNAPSHOT, resolvedVersion)) + DOT + "jar"); - try (InputStream is = path.openStream()) { - Files.copy(is, file.toPath(), StandardCopyOption.REPLACE_EXISTING); - } - byte[] data = Files.readAllBytes(file.toPath()); - try { - addJarToClasspath(file); - } catch (Exception e) { - getLog().error("Error while feeding the build-data into system.", e); - } - - return data; - } - - 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)) { - if (proxy.getHost() != null && !proxy.getHost().trim().isEmpty()) { - System.setProperty(proxyHostProperty, proxy.getHost()); - System.setProperty(proxyPortProperty, String.valueOf(proxy.getPort())); - } - if (proxy.getNonProxyHosts() != null && !proxy.getNonProxyHosts().trim().isEmpty()) { - System.setProperty(nonProxyHostsProperty, proxy.getNonProxyHosts()); - } - } - } - } - - public void addJarToClasspath(File jar) throws MojoFailureException { - try { - ClassLoader cl = ClassLoader.getSystemClassLoader(); - Class clazz = cl.getClass(); - - Method method = clazz.getSuperclass().getDeclaredMethod("addURL", URL.class); - - method.setAccessible(true); - method.invoke(cl, jar.toURI().toURL()); - } catch (Exception e) { - throw new MojoFailureException("Problem while loading build-data", e); - } - } - -} diff --git a/openecomp-be/tools/build-data-installer/pom.xml b/openecomp-be/tools/build-data-installer/pom.xml deleted file mode 100644 index f69dad6be2..0000000000 --- a/openecomp-be/tools/build-data-installer/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - 4.0.0 - - build-data-installer - - - sdc-onboarding - org.openecomp.sdc - 1.3.3-SNAPSHOT - ../../../onboarding/pom.xml - - - - - org.openecomp.sdc.onboarding - artifact-copy-plugin - ${project.version} - - - - init-artifact-helper - calibrate-artifact-helper - - - - - org.openecomp.sdc - build-data-installer - ${project.version} - - ${project} - ${session} - org.openecomp.sdc:sdc-onboarding/target/build-data - - - - - - \ No newline at end of file