Replace artifact folder ONBOARDED_PACKAGE in CSAR
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / CsarToscaTester.java
index afdfa43..be337ba 100644 (file)
@@ -1,70 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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 an "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.
+ * ============LICENSE_END=========================================================
+ */
+
 package org.openecomp.sdc.ci.tests.utils;
 
-import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
-import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
-import org.openecomp.sdc.tosca.parser.impl.SdcTypes;
-import org.openecomp.sdc.toscaparser.api.Group;
-import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-import org.openecomp.sdc.toscaparser.api.elements.Metadata;
-import org.openecomp.sdc.toscaparser.api.parameters.Input;
-import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
+import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.onap.sdc.toscaparser.api.Group;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+import org.onap.sdc.toscaparser.api.parameters.Input;
 
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 public class CsarToscaTester {
-       public static void main(String[] args) throws Exception {
-               System.out.println("CsarToscaParser - path to CSAR's Directory is " + Arrays.toString(args));
-               SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
-
-               File folder = new File(args[0]);
-               File[] listOfFiles = folder.listFiles();
-               Date now = new Date();
-               SimpleDateFormat dateFormat = new SimpleDateFormat("d-MM-y-HH_mm_ss");
-               String time = dateFormat.format(now);
-               String csarsDir = args[1] + "/csar-reports-" + time;
-               File dir = new File(csarsDir);
-               dir.mkdir();
-
-
-               for (File file : listOfFiles) {
-                       if (file.isFile()) {  
-                               System.out.println("File  " + file.getAbsolutePath());
-                               String name = file.getName();
-                               String currentCsarDir = csarsDir+"/"+name+"-"+time;
-                               dir = new File(currentCsarDir);
-                               dir.mkdir();
-                               try {
-                                       processCsar(factory, file);
-                               } catch (SdcToscaParserException e){
-                                       System.out.println("SdcToscaParserException caught. Code: "+e.getCode()+", message: "+ e.getMessage());
-                               }
-                               List<String> notAnalyzedReport = ThreadLocalsHolder.getCollector().getNotAnalyzedExceptionsReport();
-                               System.out.println("NOT ANALYZED during CSAR parsing are: " + (notAnalyzedReport != null ? notAnalyzedReport.toString() : "none"));
-                               List<String> warningsReport = ThreadLocalsHolder.getCollector().getWarningsReport();
-                               //System.out.println("WARNINGS during CSAR parsing are: " + (warningsReport != null ? warningsReport.toString() : "none"));
-                               List<String> criticalsReport = ThreadLocalsHolder.getCollector().getCriticalsReport();
-                               System.out.println("CRITICALS during CSAR parsing are: " + (criticalsReport != null ? criticalsReport.toString() : "none"));
-
-                               try {
-                                       generateReport(time, name, currentCsarDir, criticalsReport, "critical");
-                                       generateReport(time, name, currentCsarDir, warningsReport, "warning");
-                                       generateReport(time, name, currentCsarDir, notAnalyzedReport, "notAnalyzed");
-
-                               } catch (IOException ex) {
-                                       ex.printStackTrace();
-                               }
-                       }
-
-               }               
-       }
 
        public static void processCsar(SdcToscaParserFactory factory, File file) throws SdcToscaParserException {
                ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());
@@ -127,7 +98,8 @@ public class CsarToscaTester {
        private static void generateReport(String time, String name, String currentCsarDir, List<String> criticalsReport, String type)
                        throws IOException {
                FileWriter fw;
-               fw = new FileWriter(new File(currentCsarDir + "/" + criticalsReport.size() + "-"+type+"-" + name +"-"+time + ".txt"));
+               try (FileWriter fileWriter = fw = new FileWriter(new File(currentCsarDir + "/" + criticalsReport.size() + "-" + type + "-" + name + "-" + time + ".txt"))) {
+               }
                for (String exception : criticalsReport) {
                        fw.write(exception);
                        fw.write("\r\n");