List of usage examples for org.springframework.util ClassUtils classPackageAsResourcePath
public static String classPackageAsResourcePath(@Nullable Class<?> clazz)
From source file:com.taobao.itest.listener.ResourceLocationProcessingUtil.java
public static String[] modifyLocations(Class<?> clazz, String... locations) { String[] modifiedLocations = new String[locations.length]; for (int i = 0; i < locations.length; i++) { String path = locations[i]; if (path.startsWith("/")) { modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path; } else if (!ResourcePatternUtils.isUrl(path)) { modifiedLocations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + "/" + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + path); } else {//from w ww .java2s.c om modifiedLocations[i] = StringUtils.cleanPath(path); } } return modifiedLocations; }
From source file:com.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java
/** * Generates the default classpath resource location based on the supplied * class./* w w w .j a v a2 s . c o m*/ * <p> * For example, if the supplied class is <code>com.example.MyTest</code>, * the generated location will be a string with a value of * "classpath:/com/example/<code><suffix></code>", where * <code><suffix></code> is the value of the * {@link #getResourceName() resource name} string. * <p> * Subclasses can override this method to implement a different * <em>default location generation</em> strategy. * * @param clazz * the class for which the default locations are to be generated * @return an array of default application context resource locations * @see #getResourceSuffix() */ private String generateDefaultLocation(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); return ResourceUtils.CLASSPATH_URL_PREFIX + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + getResourceName()); }
From source file:com.excilys.ebi.utils.spring.log.logback.test.LogbackConfigurerTestExecutionListener.java
/** * Generate a modified version of the supplied location and returns it. * <p>/*from w w w.j av a 2s. c om*/ * A plain path, e.g. "context.xml", will be treated as a * classpath resource from the same package in which the specified class is * defined. A path starting with a slash is treated as a fully qualified * class path location, e.g.: "/com/example/whatever/foo.xml". A * path which references a URL (e.g., a path prefixed with * {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:}, * {@link ResourceUtils#FILE_URL_PREFIX file:}, <code>http:</code>, etc.) * will be added to the results unchanged. * <p> * Subclasses can override this method to implement a different * <em>location modification</em> strategy. * * @param clazz * the class with which the locations are associated * @param locations * the resource location to be modified * @return the modified application context resource location */ protected String modifyLocation(Class<?> clazz, String location) { String modifiedLocation = null; if (location.startsWith("/")) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + location; } else if (!ResourcePatternUtils.isUrl(location)) { modifiedLocation = ResourceUtils.CLASSPATH_URL_PREFIX + StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + "/" + location); } else { modifiedLocation = StringUtils.cleanPath(location); } return modifiedLocation; }
From source file:org.apache.servicemix.platform.testing.support.SmxPlatform.java
/** * Loads Felix config.properties./*from w w w.j av a 2 s . c om*/ * * <strong>Note</strong> the current implementation uses Felix's Main class * to resolve placeholders as opposed to loading the properties manually * (through JDK's Properties class or Spring's PropertiesFactoryBean). * * @return */ // TODO: this method should be removed once Felix 1.0.2 is released private Properties getFelixConfiguration() { String location = "/".concat(ClassUtils.classPackageAsResourcePath(getClass())).concat("/") .concat(FELIX_CONF_FILE); URL url = getClass().getResource(location); if (url == null) throw new RuntimeException("cannot find felix configuration properties file:" + location); // used with Main System.getProperties().setProperty(FELIX_CONFIG_PROPERTY, url.toExternalForm()); // load config.properties (use Felix's Main for resolving placeholders) Properties props = new Properties(); InputStream is = null; try { is = url.openConnection().getInputStream(); props.load(is); is.close(); } catch (FileNotFoundException ex) { // Ignore file not found. } catch (Exception ex) { System.err.println("Main: Error loading system properties from " + url); System.err.println("Main: " + ex); try { if (is != null) is.close(); } catch (IOException ex2) { // Nothing we can do. } return null; } // Perform variable substitution for system properties. for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); props.setProperty(name, substVars(props.getProperty(name), name, null, props)); } return props; }
From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java
/** * Eliminate 'special' packages (java.*, test framework internal and the * class declaring package)//from w w w. j a v a2 s . com * * @param rawImports * @return */ private Collection eliminateSpecialPackages(String[] rawImports) { String currentPckg = ClassUtils.classPackageAsResourcePath(getClass()).replace('/', '.'); Set filteredImports = new LinkedHashSet(rawImports.length); Set eliminatedImports = new LinkedHashSet(4); for (int i = 0; i < rawImports.length; i++) { String pckg = rawImports[i]; if (!(pckg.startsWith("java.") || pckg.startsWith("org.eclipse.gemini.blueprint.test.internal") || pckg.equals(currentPckg))) filteredImports.add(pckg); else eliminatedImports.add(pckg); } if (!eliminatedImports.isEmpty() && logger.isTraceEnabled()) logger.trace("Eliminated special packages " + eliminatedImports); return filteredImports; }