diff options
author | Gautam Shah <gautams@amdocs.com> | 2018-06-06 16:02:45 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-08-10 07:51:32 +0000 |
commit | 7e0f45ab7839fda19459f790e0384c3a6c98e2bf (patch) | |
tree | fbafe7289b677f52990118d84a4818189214ca92 /openecomp-be/tools/artifact-copy-plugin/src/main | |
parent | 9de469a6617bd0e53829d032fc871fdbecf6f4b1 (diff) |
Onboarding backend build optimization.
Enhancing Logic for referring/not-referring local build state repo
Change-Id: Ic2f85b20aed45cda7011ed1facb8ee39fdf54919
Issue-ID: SDC-1189
Signed-off-by: GAUTAMS <gautams@amdocs.com>
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/artifact-copy-plugin/src/main')
2 files changed, 48 insertions, 38 deletions
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 index 59b3437beb..ce63a8d466 100644 --- 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 @@ -44,11 +44,11 @@ public class ArtifactHelper { private MavenProject project; private MavenSession session; - private static Map<String, byte[]> store = new HashMap<>(); - private static Set<String> terminalModuleCoordinates = new HashSet<>(); + private static final Map<String, byte[]> store = new HashMap<>(); + private static final Set<String> terminalModuleCoordinates = new HashSet<>(); private String unicornRoot = null; private static File unicornMetaLocation = null; - private File tempLocation = Paths.get(System.getProperties().getProperty("java.io.tmpdir")).toFile(); + private final File tempLocation = Paths.get(System.getProperties().getProperty("java.io.tmpdir")).toFile(); private static int snapshotBuildNumber = 0; private static final String HYPHEN = "-"; @@ -95,8 +95,8 @@ public class ArtifactHelper { } String getContents(URL path) throws IOException { - try (InputStream is = path.openStream(); Scanner scnr = new Scanner(is).useDelimiter("\\A")) { - return scnr.hasNext() ? scnr.next() : ""; + try (InputStream is = path.openStream(); Scanner scanner = new Scanner(is).useDelimiter("\\A")) { + return scanner.hasNext() ? scanner.next() : ""; } } @@ -105,11 +105,19 @@ public class ArtifactHelper { } void deleteAll(File f) { - if (!f.exists() && !f.isDirectory()) { + + if (!f.exists() || !f.isDirectory()) { + return; + } + + File[] fileList = f.listFiles(); + if (fileList == null) { return; } - for (File file : f.listFiles()) { - if (f.isFile()) { + + for (File file : fileList) { + + if (file.isFile()) { file.delete(); } } @@ -119,30 +127,32 @@ public class ArtifactHelper { return project.getGroupId() + ":" + project.getArtifactId(); } - private File getUnicornRootFile(String moduleCoordinate, MavenProject proj) { - return getStateFile(moduleCoordinate, proj, unicornRoot); + private File getUnicornRootFile(String moduleCoordinate, MavenProject mavenProject) { + return getStateFile(moduleCoordinate, mavenProject, unicornRoot); } - private File getStateFile(String moduleCoordinate, MavenProject proj, String filePath) { - return new File(getTopParentProject(moduleCoordinate, proj).getBasedir(), + 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 proj) { - if (getModuleCoordinate(proj).equals(moduleCoordinate) || proj.getParent() == null) { - return proj; + MavenProject getTopParentProject(String moduleCoordinate, MavenProject mavenProject) { + if (getModuleCoordinate(mavenProject).equals(moduleCoordinate) || mavenProject.getParent() == null) { + return mavenProject; } else { - return getTopParentProject(moduleCoordinate, proj.getParent()); + return getTopParentProject(moduleCoordinate, mavenProject.getParent()); } } void shutDown(MavenProject project) throws IOException, ClassNotFoundException { File file = new File(unicornMetaLocation, "compileState.dat"); - Map dataStore = null; + HashMap dataStore; if (isModuleTerminal(project) && file.exists()) { try (InputStream is = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(is)) { - dataStore = HashMap.class.cast(ois.readObject()); + 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)) { 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 57f4994a94..afe5d3e702 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 @@ -16,18 +16,6 @@ package org.openecomp.sdc.onboarding.util; -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; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -39,6 +27,17 @@ 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) @@ -66,12 +65,12 @@ public class InitializationHelperMojo extends AbstractMojo { private ArtifactHelper artifactHelper; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + public void execute() throws MojoExecutionException { if (System.getProperties().containsKey(UNICORN_INITIALIZED)) { try { artifactHelper.shutDown(project); } catch (IOException | ClassNotFoundException e) { - throw new MojoExecutionException("Unexpected Error Occured during shutdown activities", e); + throw new MojoExecutionException("Unexpected Error Occurred during shutdown activities", e); } return; } @@ -94,8 +93,6 @@ public class InitializationHelperMojo extends AbstractMojo { try { URL url = new URL(repo.getUrl() + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version + "/maven-metadata.xml"); - URL fallbackUrl = - new URL(repo.getUrl() + (groupId.replace('.', '/')) + '/' + artifactId + '/' + version + '/'); setProxy(url); String content = artifactHelper.getContents(url); Matcher m = timestampPattern.matcher(content); @@ -106,12 +103,15 @@ public class InitializationHelperMojo extends AbstractMojo { 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)); + ArtifactHelper.setSnapshotBuildNumber(Integer.parseInt(buildNumber) + 1); return timestamp + "-" + buildNumber; } } catch (IOException e) { @@ -188,12 +188,12 @@ public class InitializationHelperMojo extends AbstractMojo { ClassLoader cl = ClassLoader.getSystemClassLoader(); Class<?> clazz = cl.getClass(); - Method method = clazz.getSuperclass().getDeclaredMethod("addURL", new Class[] {URL.class}); + Method method = clazz.getSuperclass().getDeclaredMethod("addURL", URL.class); method.setAccessible(true); - method.invoke(cl, new Object[] {jar.toURI().toURL()}); + method.invoke(cl, jar.toURI().toURL()); } catch (Exception e) { - throw new MojoFailureException("Problem while loadig build-data", e); + throw new MojoFailureException("Problem while loading build-data", e); } } |