diff options
author | Gautam Shah <gautams@amdocs.com> | 2018-06-05 18:50:13 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-06-06 06:27:18 +0000 |
commit | 719e3bb7d4f6b31c178abaeff9b8124ce7703662 (patch) | |
tree | db69388be45dfb58c781f78c9907ae1b4ca2d9ed /openecomp-be/tools/compile-helper-plugin/src | |
parent | 16ecda5c6ebb673636e7c74e5501f9f2c8ae00b0 (diff) |
Onboarding backend build optimization.
Enhancing Test RUN/NO-RUN Logic, adding identifiers for local build state repo
Change-Id: Ie0a541f216c16ddc40605111981d7a2fa045c39d
Issue-ID: SDC-1189
Signed-off-by: GAUTAMS <gautams@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/compile-helper-plugin/src')
5 files changed, 59 insertions, 24 deletions
diff --git a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildHelper.java b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildHelper.java index 8f20f221d9..d9767fdd1d 100644 --- a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildHelper.java +++ b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildHelper.java @@ -19,7 +19,9 @@ package org.openecomp.sdc.onboarding; import static org.openecomp.sdc.onboarding.Constants.CHECKSUM; import static org.openecomp.sdc.onboarding.Constants.COLON; import static org.openecomp.sdc.onboarding.Constants.DOT; +import static org.openecomp.sdc.onboarding.Constants.JAR; import static org.openecomp.sdc.onboarding.Constants.JAVA_EXT; +import static org.openecomp.sdc.onboarding.Constants.SHA1; import static org.openecomp.sdc.onboarding.Constants.UNICORN; import java.io.ByteArrayInputStream; @@ -67,14 +69,26 @@ class BuildHelper { } try { signature = new String(fetchSnapshotSignature(snapshotFile, version)); + if (version.equals(signature)) { + signature = getSHA1For(snapshotFile, Paths.get(snapshotFile.getParentFile().getAbsolutePath(), + moduleCoordinate.substring(moduleCoordinate.indexOf(':') + 1) + "-" + version + DOT + JAR + DOT + + SHA1).toFile()); + } store.put(key, signature); return signature; - } catch (IOException ioe) { + } catch (IOException | NoSuchAlgorithmException e) { return version; } } + private static String getSHA1For(File file, File signatureFile) throws IOException, NoSuchAlgorithmException { + if (signatureFile.exists()) { + return new String(Files.readAllBytes(signatureFile.toPath())); + } + return getSourceChecksum(Files.readAllBytes(file.toPath()), SHA1); + } + static long getChecksum(File file, String fileType) { try { return readSources(file, fileType).hashCode(); @@ -84,8 +98,12 @@ class BuildHelper { } static String getSourceChecksum(String data, String hashType) throws NoSuchAlgorithmException { + return getSourceChecksum(data.getBytes(), hashType); + } + + static String getSourceChecksum(byte[] data, String hashType) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(hashType); - md.update(data.getBytes()); + md.update(data); byte[] hashBytes = md.digest(); StringBuilder buffer = new StringBuilder(); @@ -197,7 +215,7 @@ class BuildHelper { JarInputStream jis = new JarInputStream(bais)) { JarEntry entry = null; while ((entry = jis.getNextJarEntry()) != null) { - if (entry.getName().equals(UNICORN + DOT + CHECKSUM)) { + if (entry.getName().endsWith(UNICORN + DOT + CHECKSUM)) { byte[] sigStore = new byte[1024]; return new String(sigStore, 0, jis.read(sigStore, 0, 1024)).getBytes(); } diff --git a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java index 68557a9609..c8177989a5 100644 --- a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java +++ b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java @@ -48,6 +48,7 @@ import org.apache.maven.project.MavenProject; public class BuildState { private static final String SHUTDOWN_TIME = "shutdownTime"; + private static final String VERSION = "version"; private static Map<String, Map> compileDataStore = new HashMap<>(); private static Map<String, Object> moduleBuildData = new HashMap<>(); @@ -66,6 +67,11 @@ public class BuildState { initializeStore(); Optional<HashMap> masterStore = readState("compile.dat", HashMap.class); compileDataStore = masterStore.isPresent() ? masterStore.get() : compileDataStore; + String version = String.class.cast(compileDataStore.get(VERSION)); + if (version != null) { + stateFileLocation = new File(Paths.get(System.getProperties().getProperty("java.io.tmpdir")).toFile(), + "compileState.dat-" + version); + } if (stateFileLocation.exists()) { HashMap dat = loadState(stateFileLocation); if (swapStates((HashMap<?, ?>) compileDataStore, dat)) { @@ -282,11 +288,16 @@ public class BuildState { private static boolean swapStates(HashMap repo, HashMap last) { Long repoTime = repo.get(SHUTDOWN_TIME) == null ? 0 : (Long) repo.get(SHUTDOWN_TIME); Long lastTime = last.get(SHUTDOWN_TIME) == null ? 0 : (Long) last.get(SHUTDOWN_TIME); - long repoBuildNumber = repoTime / 1000; - long lastBuildNumber = lastTime / 1000; + String repoVersion = repo.get(VERSION) == null ? "" : (String) repo.get(VERSION); + String lastVersion = last.get(VERSION) == null ? "" : (String) last.get(VERSION); + long repoBuildNumber = repoTime % 1000; + long lastBuildNumber = lastTime % 1000; if (repoBuildNumber != lastBuildNumber) { return false; } + if (!repoVersion.equals(lastVersion)) { + return false; + } return Long.compare(repoTime, lastTime) < 0; } diff --git a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/Constants.java b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/Constants.java index 195b356377..c6603a7497 100644 --- a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/Constants.java +++ b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/Constants.java @@ -21,22 +21,26 @@ public class Constants { public static final String UNICORN = "unicorn"; public static final String EMPTY_STRING = ""; - public static final String PREFIX = System.getProperties().contains(UNICORN) ? EMPTY_STRING : UNICORN; public static final String JACOCO_SKIP = "jacoco.skip"; + public static final String JACOCO_BUILD = Boolean.toString( + System.getProperties().containsKey(JACOCO_SKIP) && Boolean.FALSE.equals(Boolean.valueOf( + System.getProperties().getProperty(JACOCO_SKIP)))); + public static final String JACOCO = Boolean.valueOf(JACOCO_BUILD) ? UNICORN : EMPTY_STRING; + public static final String PREFIX = System.getProperties().contains(UNICORN) ? EMPTY_STRING : UNICORN; public static final String FORK_COUNT = "fork.count"; public static final String FORK_MODE = "fork.mode"; public static final String SKIP_PMD = "skipPMD"; public static final String JAVA_EXT = ".java"; public static final String ANY_EXT = "*"; - public static final String SKIP_TEST_RUN = PREFIX + "skipTestRun"; + public static final String SKIP_TEST_RUN = PREFIX + JACOCO + "skipTestRun"; public static final String SKIP_TESTS = "skipTests"; public static final String MAIN = "main"; public static final String TEST = "test"; public static final String RESOURCES_CHANGED = "resourcesChanged"; public static final String ANSI_YELLOW = "\u001B[43m"; public static final String ANSI_COLOR_RESET = "\u001B[0m"; - public static final String SKIP_MAIN_SOURCE_COMPILE = PREFIX + "skipMainSourceCompile"; - public static final String SKIP_TEST_SOURCE_COMPILE = PREFIX + "skipTestSourceCompile"; + public static final String SKIP_MAIN_SOURCE_COMPILE = PREFIX + JACOCO + "skipMainSourceCompile"; + public static final String SKIP_TEST_SOURCE_COMPILE = PREFIX + JACOCO + "skipTestSourceCompile"; public static final String MAIN_CHECKSUM = "mainChecksum"; public static final String CHECKSUM = "checksum"; public static final String TEST_CHECKSUM = "testChecksum"; @@ -60,8 +64,8 @@ public class Constants { public static final String RESOURCE_WITH_TEST_ONLY = "resourceWithTestOnly"; public static final String INSTRUMENT_ONLY = "instrumentOnly"; public static final String TEST_ONLY = "testOnly"; - public static final String SKIP_RESOURCE_COLLECTION = PREFIX + "skipResourceCollection"; - public static final String SKIP_INSTALL = PREFIX + "skipInstall"; + public static final String SKIP_RESOURCE_COLLECTION = PREFIX + JACOCO + "skipResourceCollection"; + public static final String SKIP_INSTALL = PREFIX + JACOCO + "skipInstall"; private Constants() { diff --git a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/InitializationHelperMojo.java b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/InitializationHelperMojo.java index 6c1d2be28e..552ae6ada1 100644 --- a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/InitializationHelperMojo.java +++ b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/InitializationHelperMojo.java @@ -18,7 +18,8 @@ package org.openecomp.sdc.onboarding; import static org.openecomp.sdc.onboarding.Constants.FORK_COUNT; import static org.openecomp.sdc.onboarding.Constants.FORK_MODE; -import static org.openecomp.sdc.onboarding.Constants.JACOCO_SKIP; +import static org.openecomp.sdc.onboarding.Constants.JACOCO; +import static org.openecomp.sdc.onboarding.Constants.JACOCO_BUILD; import static org.openecomp.sdc.onboarding.Constants.PREFIX; import static org.openecomp.sdc.onboarding.Constants.SKIP_PMD; import static org.openecomp.sdc.onboarding.Constants.UNICORN; @@ -45,15 +46,13 @@ public class InitializationHelperMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { - if (PREFIX == UNICORN) { + if (PREFIX == UNICORN || JACOCO == UNICORN) { System.getProperties().setProperty(UNICORN, Boolean.TRUE.toString()); } if (project.getPackaging().equals(excludePackaging)) { return; } - project.getProperties().setProperty("skipGet", Boolean.FALSE.toString()); - if (System.getProperties().containsKey(JACOCO_SKIP) && Boolean.FALSE.equals(Boolean.valueOf( - System.getProperties().getProperty(JACOCO_SKIP)))) { + if (Boolean.valueOf(JACOCO_BUILD)) { project.getProperties().setProperty(FORK_COUNT, "1"); project.getProperties().setProperty(FORK_MODE, "once"); } else { diff --git a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/PreCompileHelperMojo.java b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/PreCompileHelperMojo.java index e97b172b84..3b51398bc7 100644 --- a/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/PreCompileHelperMojo.java +++ b/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/PreCompileHelperMojo.java @@ -349,16 +349,19 @@ public class PreCompileHelperMojo extends AbstractMojo { return moduleBuildData; } for (Artifact dependency : project.getArtifacts()) { - String version = dependency.isSnapshot() ? getSnapshotSignature(dependency.getFile(), - dependency.getGroupId() + COLON + dependency.getArtifactId(), dependency.getVersion()) : - dependency.getVersion(); - if (excludeDependencies.contains(dependency.getScope())) { - HashMap.class.cast(moduleBuildData.get(TEST)) + if (JAR.equals(dependency.getType())) { + String version = dependency.isSnapshot() || dependency.getFile().getName().contains("SNAPSHOT") ? + getSnapshotSignature(dependency.getFile(), + dependency.getGroupId() + COLON + dependency.getArtifactId(), + dependency.getVersion()) : dependency.getVersion(); + if (excludeDependencies.contains(dependency.getScope())) { + HashMap.class.cast(moduleBuildData.get(TEST)) + .put(dependency.getGroupId() + COLON + dependency.getArtifactId(), version); + continue; + } + HashMap.class.cast(moduleBuildData.get(MAIN)) .put(dependency.getGroupId() + COLON + dependency.getArtifactId(), version); - continue; } - HashMap.class.cast(moduleBuildData.get(MAIN)) - .put(dependency.getGroupId() + COLON + dependency.getArtifactId(), version); } return moduleBuildData; } |