Merge "fixed sonar issue in SvcLogicExpression.java"
[ccsdk/sli/core.git] / sli / common / src / main / java / org / onap / ccsdk / sli / core / sli / SvcLogicCrawler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Modifications Copyright (C) 2018 IBM.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.ccsdk.sli.core.sli;
25
26 import static java.nio.file.FileVisitResult.CONTINUE;
27
28 import java.io.IOException;
29 import java.nio.file.FileVisitResult;
30 import java.nio.file.Path;
31 import java.nio.file.SimpleFileVisitor;
32 import java.nio.file.attribute.BasicFileAttributes;
33 import java.util.ArrayList;
34 import java.util.List;
35
36 public class SvcLogicCrawler extends SimpleFileVisitor<Path> {
37
38     private List<Path> xmlGraphPathList;
39     private List<Path> activationFilePathList;
40
41     public SvcLogicCrawler() {
42         xmlGraphPathList = new ArrayList<>();
43         activationFilePathList = new ArrayList<>();
44     }
45
46     @Override
47     public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
48         if (attr.isRegularFile()) {
49             String fileName = file.getFileName().toString();
50             if (!file.toString().contains(".git") && !fileName.equals("pom.xml") && !fileName.equals("assemble_zip.xml") && !fileName.equals("assemble_zip_less_config.xml") && !fileName.equals("descriptor.xml")) {
51                 if (fileName.endsWith(".xml")) {
52                     xmlGraphPathList.add(file);
53                 } 
54                 else if (fileName.endsWith(".versions")) {
55                     activationFilePathList.add(file);
56                 }
57             }
58         }
59         return CONTINUE;
60     }
61
62     @Override
63     public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
64         return CONTINUE;
65     }
66
67     @Override
68     public FileVisitResult visitFileFailed(Path file, IOException exc) {
69         System.err.println("Couldn't visitFile");
70         System.err.println(exc.getMessage());
71         return CONTINUE;
72     }
73
74     @Override
75     public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
76         String[] skipDirectories = {".git"};
77         for (String str : skipDirectories) {
78             if (dir.endsWith(str)) {
79                 return FileVisitResult.SKIP_SUBTREE;
80             }
81         }
82         return CONTINUE;
83     }
84
85     public List<Path> getGraphPaths() {
86         return this.xmlGraphPathList;
87     }
88
89     public List<Path> getActivationPaths() {
90         return this.activationFilePathList;
91     }
92 }