2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.config;
21 import java.nio.file.Path;
22 import java.nio.file.Paths;
23 import java.util.Collection;
24 import java.util.HashSet;
26 import java.util.function.Predicate;
28 public class NonConfigResource {
30 private static final Set<URL> urls = new HashSet<>();
31 private static final Set<File> files = new HashSet<>();
33 public static void add(URL url) {
37 public static Path locate(String resource) {
39 if (resource != null) {
40 File file = new File(resource);
42 return Paths.get(resource);
44 for (File availableFile : files) {
45 if (availableFile.getAbsolutePath().endsWith(resource) && availableFile.exists()) {
46 return Paths.get(availableFile.getAbsolutePath());
49 if (System.getProperty("node.config.location") != null) {
50 Path path = locate(new File(System.getProperty("node.config.location")), resource);
55 if (System.getProperty("config.location") != null) {
56 Path path = locate(new File(System.getProperty("config.location")), resource);
61 for (URL url : urls) {
62 if (url.getFile().endsWith(resource)) {
63 return Paths.get(url.toURI());
67 } catch (Exception exception) {
68 exception.printStackTrace();
73 private static Path locate(File root, String resource) {
75 Collection<File> filesystemResources = ConfigurationUtils.getAllFiles(root, true, false);
76 Predicate<File> f1 = ConfigurationUtils::isConfig;
77 for (File file : filesystemResources) {
80 if (file.getAbsolutePath().endsWith(resource)) {
81 return Paths.get(file.getAbsolutePath());
89 public static void add(File file) {