summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java
diff options
context:
space:
mode:
authorGautam Shah <gautams@amdocs.com>2018-06-01 08:38:32 +0530
committerGAUTAMS <gautams@amdocs.com>2018-06-04 13:53:51 +0530
commit03205dad582ffa5db54187f451b9a29d3d0af386 (patch)
tree21e67f2a40764fe1b1904e58cd775c0041528352 /openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java
parent06b1f35479a40194c6d84c38cc1215ae76b81ba6 (diff)
Fixing Merge Build issue and Sonar issues.
fixing build issue and Sonar issues. Change-Id: I4209b79ab2a3646839df50be4b58f8f230b6d710 Issue-ID: SDC-1189 Signed-off-by: GAUTAMS <gautams@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java')
-rw-r--r--openecomp-be/tools/artifact-copy-plugin/src/main/java/org/openecomp/sdc/onboarding/util/ArtifactHelper.java118
1 files changed, 108 insertions, 10 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 e7ad5dacb1..f51a8aae60 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
@@ -1,21 +1,68 @@
+/*
+ * 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.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+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 Map<String, byte[]> store = new HashMap<>();
+ private static 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 static int snapshotBuildNumber = 0;
+
+ 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<ArtifactRepository> getRepositories(boolean snapshotRepo) {
List<ArtifactRepository> list = new ArrayList<>();
@@ -33,24 +80,75 @@ public class ArtifactHelper {
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 scnr = new Scanner(is).useDelimiter("\\A")) {
return scnr.hasNext() ? scnr.next() : "";
}
}
- String getChecksum(String filePath, String hashType) throws NoSuchAlgorithmException, IOException {
- MessageDigest md = MessageDigest.getInstance(hashType);
- md.update(Files.readAllBytes(Paths.get(filePath)));
- byte[] hashBytes = md.digest();
+ void store(String artifactId, byte[] data) {
+ store.put(artifactId, data);
+ }
- StringBuffer buffer = new StringBuffer();
- for (byte hashByte : hashBytes) {
- buffer.append(Integer.toString((hashByte & 0xff) + 0x100, 16).substring(1));
+ void deleteAll(File f) {
+ if (!f.exists() && !f.isDirectory()) {
+ return;
}
- return buffer.toString();
+ for (File file : f.listFiles()) {
+ if (f.isFile()) {
+ file.delete();
+ }
+ }
+ }
+
+ String getModuleCoordinate(MavenProject project) {
+ return project.getGroupId() + ":" + project.getArtifactId();
+ }
+
+ private File getUnicornRootFile(String moduleCoordinate, MavenProject proj) {
+ return getStateFile(moduleCoordinate, proj, unicornRoot);
+ }
+
+ private File getStateFile(String moduleCoordinate, MavenProject proj, String filePath) {
+ return new File(getTopParentProject(moduleCoordinate, proj).getBasedir(),
+ filePath.substring(filePath.indexOf('/') + 1));
}
+ MavenProject getTopParentProject(String moduleCoordinate, MavenProject proj) {
+ if (getModuleCoordinate(proj).equals(moduleCoordinate) || proj.getParent() == null) {
+ return proj;
+ } else {
+ return getTopParentProject(moduleCoordinate, proj.getParent());
+ }
+ }
+
+ void shutDown(MavenProject project) throws IOException, ClassNotFoundException {
+ File file = new File(unicornMetaLocation, "compileState.dat");
+ Map dataStore = null;
+ if (isModuleTerminal(project) && file.exists()) {
+ try (InputStream is = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(is)) {
+ dataStore = HashMap.class.cast(ois.readObject());
+ dataStore.put("shutdownTime", (System.currentTimeMillis() / 1000) * 1000 + snapshotBuildNumber);
+ }
+ try (OutputStream os = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(os)) {
+ oos.writeObject(dataStore);
+ }
+ Files.copy(file.toPath(), Paths.get(tempLocation.getAbsolutePath(), file.getName()),
+ StandardCopyOption.REPLACE_EXISTING);
+ }
+ }
}