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.Collections;
25 import java.util.HashSet;
27 import java.util.function.Predicate;
29 public class NonConfigResource {
31 private static final Set<URL> urls = Collections.synchronizedSet(new HashSet<>());
32 private static final Set<File> files = Collections.synchronizedSet(new HashSet<>());
34 public static void add(URL url) {
38 public static Path locate(String resource) {
40 if (resource != null) {
41 File file = new File(resource);
43 return Paths.get(resource);
45 for (File availableFile : files) {
46 if (availableFile.getAbsolutePath().endsWith(resource) && availableFile.exists()) {
47 return Paths.get(availableFile.getAbsolutePath());
50 if (System.getProperty("node.config.location") != null) {
51 Path path = locate(new File(System.getProperty("node.config.location")), resource);
56 if (System.getProperty("config.location") != null) {
57 Path path = locate(new File(System.getProperty("config.location")), resource);
62 for (URL url : urls) {
63 if (url.getFile().endsWith(resource)) {
64 return Paths.get(url.toURI());
68 } catch (Exception exception) {
69 exception.printStackTrace();
74 private static Path locate(File root, String resource) {
76 Collection<File> filesystemResources = ConfigurationUtils.getAllFiles(root, true, false);
77 Predicate<File> f1 = ConfigurationUtils::isConfig;
78 for (File file : filesystemResources) {
81 if (file.getAbsolutePath().endsWith(resource)) {
82 return Paths.get(file.getAbsolutePath());
90 public static void add(File file) {