summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java')
-rw-r--r--openecomp-be/tools/compile-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/BuildState.java72
1 files changed, 61 insertions, 11 deletions
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 ead6e7b755..1ce60a636c 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
@@ -28,9 +28,13 @@ import static org.openecomp.sdc.onboarding.Constants.RESOURCE_BUILD_DATA;
import static org.openecomp.sdc.onboarding.Constants.SKIP_MAIN_SOURCE_COMPILE;
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.nio.file.Paths;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -39,36 +43,59 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
public class BuildState {
+ private static final String SHUTDOWN_TIME = "shutdownTime";
+
private static Map<String, Map> compileDataStore = new HashMap<>();
private static Map<String, Object> moduleBuildData = new HashMap<>();
private static Map<String, Object> resourceBuildData = new HashMap<>();
private static Map<String, Artifact> artifacts = new HashMap<>();
private static Set<String> executeTestsIfDependsOnStore = new HashSet<>();
private static Set<String> pmdExecutedInRun = new HashSet<>();
+ private static File stateFileLocation =
+ new File(Paths.get(System.getProperties().getProperty("java.io.tmpdir")).toFile(), "compileState.dat");
private static File compileStateFile;
private MavenProject project;
private String compileStateFilePath;
+ private static Log logger;
static {
initializeStore();
Optional<HashMap> masterStore = readState("compile.dat", HashMap.class);
compileDataStore = masterStore.isPresent() ? masterStore.get() : compileDataStore;
+ if (stateFileLocation.exists()) {
+ HashMap dat = loadState(stateFileLocation);
+ if (swapStates((HashMap<?, ?>) compileDataStore, dat)) {
+ compileDataStore = dat;
+ }
+ }
+ }
+
+ private static void setLogger(Log log) {
+ logger = log;
}
- void init() {
+ void init(Log log) {
+ setLogger(log);
artifacts.clear();
for (Artifact artifact : project.getArtifacts()) {
if (artifact.isSnapshot() && JAR.equals(artifact.getType())) {
artifacts.put(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact);
}
}
- compileStateFile =
- getCompileStateFile(compileStateFilePath.substring(0, compileStateFilePath.indexOf('/')), project);
+ if (compileStateFile == null) {
+ setCompileStateFile(
+ getCompileStateFile(compileStateFilePath.substring(0, compileStateFilePath.indexOf('/')), project));
+ }
+ }
+
+ private static void setCompileStateFile(File file) {
+ compileStateFile = file;
}
static void initializeStore() {
@@ -124,12 +151,13 @@ public class BuildState {
Long lastTime = Long.class.cast(compileDataStore.get(FULL_BUILD_DATA).put(moduleCoordinates, buildTime));
try {
if (lastTime == null || !lastTime.equals(buildTime)) {
- if (!project.getProperties().containsKey(SKIP_MAIN_SOURCE_COMPILE)) {
+ boolean skipMainCompile = project.getProperties().containsKey(SKIP_MAIN_SOURCE_COMPILE);
+ if (!skipMainCompile) {
writeCompileState();
}
}
} catch (IOException ignored) {
- // ignored. No need to handle. System will take care.
+ logger.debug(ignored);
}
}
@@ -140,7 +168,7 @@ public class BuildState {
compileDataStore.get(FULL_RESOURCE_BUILD_DATA).put(moduleCoordinates, buildTime);
writeCompileState();
} catch (IOException ignored) {
- // ignored. No need to handle. System will take care.
+ logger.debug(ignored);
}
}
}
@@ -182,7 +210,7 @@ public class BuildState {
ObjectOutputStream ois = new ObjectOutputStream(fos)) {
ois.writeObject(dataToSave);
} catch (IOException ignored) {
- //ignored. do nothing. system will take care.
+ logger.debug(ignored);
}
}
}
@@ -209,10 +237,11 @@ public class BuildState {
boolean isCompileMust(String moduleCoordinates, Collection<String> dependencies) {
for (String d : dependencies) {
if (artifacts.containsKey(d) && JAR.equals(artifacts.get(d).getType())) {
- if (artifacts.get(d).getVersion().equals(project.getVersion()) && getBuildTime(d) == 0) {
- System.out.println(ANSI_YELLOW + "[WARNING:]" + "You have module[" + d
- + "] not locally compiled even once, please compile your project once daily from root to have reliable build results."
- + ANSI_COLOR_RESET);
+ boolean versionEqual = artifacts.get(d).getVersion().equals(project.getVersion());
+ if (versionEqual && getBuildTime(d) == 0) {
+ logger.warn(ANSI_YELLOW + "[WARNING:]" + "You have module[" + d
+ + "] not locally compiled even once, please compile your project once daily from root to have reliable build results."
+ + ANSI_COLOR_RESET);
return true;
}
}
@@ -248,4 +277,25 @@ public class BuildState {
return false;
}
+ private static HashMap loadState(File file) {
+ try (InputStream is = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(is)) {
+ return HashMap.class.cast(ois.readObject());
+ } catch (Exception e) {
+ logger.debug(e);
+ return new HashMap<>();
+ }
+ }
+
+ 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;
+ if (repoBuildNumber != lastBuildNumber) {
+ return false;
+ }
+ return Long.compare(repoTime, lastTime) < 0;
+ }
+
+
}