2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
14 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 package org.onap.ccsdk.sli.core.sli;
26 import static java.nio.file.FileVisitResult.CONTINUE;
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;
36 public class SvcLogicCrawler extends SimpleFileVisitor<Path> {
38 private List<Path> xmlGraphPathList;
39 private List<Path> activationFilePathList;
41 public SvcLogicCrawler() {
42 xmlGraphPathList = new ArrayList<>();
43 activationFilePathList = new ArrayList<>();
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);
54 else if (fileName.endsWith(".versions")) {
55 activationFilePathList.add(file);
63 public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
68 public FileVisitResult visitFileFailed(Path file, IOException exc) {
69 System.err.println("Couldn't visitFile");
70 System.err.println(exc.getMessage());
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;
85 public List<Path> getGraphPaths() {
86 return this.xmlGraphPathList;
89 public List<Path> getActivationPaths() {
90 return this.activationFilePathList;