Merge pull request #522 from neeuq/master
Fix #510 ResourceUtils read resource from jar.
This commit is contained in:
commit
d85b77022e
|
|
@ -19,7 +19,7 @@
|
|||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.Reader;
|
||||
import java.util.Map;
|
||||
import org.skywalking.apm.collector.core.config.ConfigLoader;
|
||||
import org.skywalking.apm.collector.core.framework.DefineException;
|
||||
|
|
@ -39,8 +39,8 @@ public class ModuleConfigLoader implements ConfigLoader<Map<String, Map>> {
|
|||
Yaml yaml = new Yaml();
|
||||
try {
|
||||
try {
|
||||
FileReader applicationFileReader = ResourceUtils.read("application.yml");
|
||||
return (Map<String, Map>)yaml.load(applicationFileReader);
|
||||
Reader applicationReader = ResourceUtils.read("application.yml");
|
||||
return (Map<String, Map>)yaml.load(applicationReader);
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.info("Could not found application.yml file, use default");
|
||||
return (Map<String, Map>)yaml.load(ResourceUtils.read("application-default.yml"));
|
||||
|
|
|
|||
|
|
@ -18,9 +18,10 @@
|
|||
|
||||
package org.skywalking.apm.collector.core.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
|
|
@ -28,12 +29,12 @@ import java.net.URL;
|
|||
*/
|
||||
public class ResourceUtils {
|
||||
|
||||
public static FileReader read(String fileName) throws FileNotFoundException {
|
||||
public static Reader read(String fileName) throws FileNotFoundException {
|
||||
URL url = ResourceUtils.class.getClassLoader().getResource(fileName);
|
||||
if (url == null) {
|
||||
throw new FileNotFoundException("file not found: " + fileName);
|
||||
}
|
||||
File file = new File(ResourceUtils.class.getClassLoader().getResource(fileName).getFile());
|
||||
return new FileReader(file);
|
||||
InputStream inputStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName);
|
||||
return new InputStreamReader(inputStream);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.module;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.skywalking.apm.collector.core.framework.DefineException;
|
||||
|
||||
/**
|
||||
* @author neeuq
|
||||
*/
|
||||
public class ModuleConfigLoaderTestCase {
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@Test
|
||||
public void testLoad() throws DefineException {
|
||||
ModuleConfigLoader configLoader = new ModuleConfigLoader();
|
||||
Map<String, Map> configuration = configLoader.load();
|
||||
Assert.assertNotNull(configuration.get("cluster"));
|
||||
Assert.assertNotNull(configuration.get("cluster").get("zookeeper"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2017, OpenSkywalking Organization All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Project repository: https://github.com/OpenSkywalking/skywalking
|
||||
*/
|
||||
|
||||
package org.skywalking.apm.collector.core.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.skywalking.apm.collector.core.util.ResourceUtils;
|
||||
|
||||
/**
|
||||
* @author neeuq
|
||||
*/
|
||||
public class ResourceUtilsTestCase {
|
||||
|
||||
@Test
|
||||
public void testRead() throws IOException {
|
||||
Reader reader = ResourceUtils.read("application.yml");
|
||||
Assert.assertNotNull(reader);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue