@Test(expected = IOException.class) public void loadProperties_classpath_missing() throws Exception { URI uri = new URI("classpath:MISSING-FILE.properties"); CommandLineUtil.loadProperties(uri, null); }
public static Properties loadProperties(URI path, ClassLoader loader) throws IOException { if (path == null) { throw new IllegalArgumentException("path must not be null"); } LOG.debug("Loading properties: {}", path); String scheme = path.getScheme(); if (scheme == null) { File file = new File(path.getPath()); LOG.debug("Loading properties from local path: {}", file); FileInputStream in = new FileInputStream(file); return loadProperties(path, in); } else if (scheme.equals(SCHEME_CLASSPATH)) { ClassLoader cl = loader == null ? ClassLoader.getSystemClassLoader() : loader; String rest = path.getSchemeSpecificPart(); LOG.debug("Loading properties from class path: {}", rest); InputStream in = cl.getResourceAsStream(rest); if (in == null) { throw new FileNotFoundException(MessageFormat.format( "Failed to load properties \"{0}\"", path.toString())); } return loadProperties(path, in); } else { URL url = path.toURL(); LOG.debug("Loading properties from URL: {}", url); InputStream in = url.openStream(); return loadProperties(path, in); } }
CommandLineUtil { public static Properties loadProperties(URI path, ClassLoader loader) throws IOException { if (path == null) { throw new IllegalArgumentException("path must not be null"); } LOG.debug("Loading properties: {}", path); String scheme = path.getScheme(); if (scheme == null) { File file = new File(path.getPath()); LOG.debug("Loading properties from local path: {}", file); FileInputStream in = new FileInputStream(file); return loadProperties(path, in); } else if (scheme.equals(SCHEME_CLASSPATH)) { ClassLoader cl = loader == null ? ClassLoader.getSystemClassLoader() : loader; String rest = path.getSchemeSpecificPart(); LOG.debug("Loading properties from class path: {}", rest); InputStream in = cl.getResourceAsStream(rest); if (in == null) { throw new FileNotFoundException(MessageFormat.format( "Failed to load properties \"{0}\"", path.toString())); } return loadProperties(path, in); } else { URL url = path.toURL(); LOG.debug("Loading properties from URL: {}", url); InputStream in = url.openStream(); return loadProperties(path, in); } } }
CommandLineUtil { public static Properties loadProperties(URI path, ClassLoader loader) throws IOException { if (path == null) { throw new IllegalArgumentException("path must not be null"); } LOG.debug("Loading properties: {}", path); String scheme = path.getScheme(); if (scheme == null) { File file = new File(path.getPath()); LOG.debug("Loading properties from local path: {}", file); FileInputStream in = new FileInputStream(file); return loadProperties(path, in); } else if (scheme.equals(SCHEME_CLASSPATH)) { ClassLoader cl = loader == null ? ClassLoader.getSystemClassLoader() : loader; String rest = path.getSchemeSpecificPart(); LOG.debug("Loading properties from class path: {}", rest); InputStream in = cl.getResourceAsStream(rest); if (in == null) { throw new FileNotFoundException(MessageFormat.format( "Failed to load properties \"{0}\"", path.toString())); } return loadProperties(path, in); } else { URL url = path.toURL(); LOG.debug("Loading properties from URL: {}", url); InputStream in = url.openStream(); return loadProperties(path, in); } } private  CommandLineUtil(); }
CommandLineUtil { public static Properties loadProperties(URI path, ClassLoader loader) throws IOException { if (path == null) { throw new IllegalArgumentException("path must not be null"); } LOG.debug("Loading properties: {}", path); String scheme = path.getScheme(); if (scheme == null) { File file = new File(path.getPath()); LOG.debug("Loading properties from local path: {}", file); FileInputStream in = new FileInputStream(file); return loadProperties(path, in); } else if (scheme.equals(SCHEME_CLASSPATH)) { ClassLoader cl = loader == null ? ClassLoader.getSystemClassLoader() : loader; String rest = path.getSchemeSpecificPart(); LOG.debug("Loading properties from class path: {}", rest); InputStream in = cl.getResourceAsStream(rest); if (in == null) { throw new FileNotFoundException(MessageFormat.format( "Failed to load properties \"{0}\"", path.toString())); } return loadProperties(path, in); } else { URL url = path.toURL(); LOG.debug("Loading properties from URL: {}", url); InputStream in = url.openStream(); return loadProperties(path, in); } } private  CommandLineUtil(); static void prepareRuntimeContext(); static void prepareLogContext(); static String toName(URI uri); static URI toUri(String path); static Properties loadProperties(URI path, ClassLoader loader); static List<File> parseFileList(String fileListOrNull); static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files); static ParameterList parseArguments(String arguments); }
CommandLineUtil { public static Properties loadProperties(URI path, ClassLoader loader) throws IOException { if (path == null) { throw new IllegalArgumentException("path must not be null"); } LOG.debug("Loading properties: {}", path); String scheme = path.getScheme(); if (scheme == null) { File file = new File(path.getPath()); LOG.debug("Loading properties from local path: {}", file); FileInputStream in = new FileInputStream(file); return loadProperties(path, in); } else if (scheme.equals(SCHEME_CLASSPATH)) { ClassLoader cl = loader == null ? ClassLoader.getSystemClassLoader() : loader; String rest = path.getSchemeSpecificPart(); LOG.debug("Loading properties from class path: {}", rest); InputStream in = cl.getResourceAsStream(rest); if (in == null) { throw new FileNotFoundException(MessageFormat.format( "Failed to load properties \"{0}\"", path.toString())); } return loadProperties(path, in); } else { URL url = path.toURL(); LOG.debug("Loading properties from URL: {}", url); InputStream in = url.openStream(); return loadProperties(path, in); } } private  CommandLineUtil(); static void prepareRuntimeContext(); static void prepareLogContext(); static String toName(URI uri); static URI toUri(String path); static Properties loadProperties(URI path, ClassLoader loader); static List<File> parseFileList(String fileListOrNull); static ClassLoader buildPluginLoader(ClassLoader parent, List<File> files); static ParameterList parseArguments(String arguments); static final String LOG_CONTEXT_PREFIX; static final String SCHEME_CLASSPATH; }