2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api;
23 import com.opencsv.CSVWriter;
26 import java.io.FileWriter;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.List;
31 import java.util.Scanner;
33 //Generate excel file, include all validation issues errors in jtosca
34 //the error java code, the line number and file name for each error.
35 public class GetValidationIssues {
37 public static CSVWriter fileWriter = null;
38 public static List<String[]> data = new ArrayList<>();
40 public static void main(String[] args) {
41 System.out.println("GetAllValidationIssues - path to project files Directory is " + Arrays.toString(args));
42 File jtoscaFiles = new File(args[0] + "\\jtosca\\src\\main\\java\\org\\onap\\sdc\\toscaparser\\api");
45 printFiles(jtoscaFiles);
46 fileWriter = new CSVWriter(new FileWriter(args[1] + "\\JToscaValidationIssues_" + System.currentTimeMillis() + ".csv"), '\t');
47 fileWriter.writeNext(new String[]{"Error Message", "Class Name", "Line No."}, false);
48 fileWriter.writeAll(data, false);
49 } catch (IOException e) {
55 } catch (IOException e) {
56 System.out.println("Error while flushing/closing fileWriter !!!");
62 private static void printFiles(File dir) {
63 if (dir != null && dir.exists()) {
64 for (File file : dir.listFiles()) {
65 if (file.isDirectory())
68 Scanner scanner = null;
70 scanner = new Scanner(file);
73 while (scanner.hasNextLine()) {
74 String line = scanner.nextLine();
76 if (line.startsWith("/*python"))
79 if (!line.trim().startsWith("//") && !line.trim().startsWith("#") && line.contains("ThreadLocalsHolder.getCollector().appendValidationIssue")) {
80 String errMsg = line.trim();
81 if (!errMsg.contains(";")) {
82 String nextLine = null;
83 while (scanner.hasNextLine() && (nextLine == null || !nextLine.contains(";"))) {
84 nextLine = scanner.nextLine();
85 errMsg += nextLine.trim();
89 data.add(new String[]{errMsg, file.getName(), String.valueOf(lineNum)});
92 } catch (IOException e) {