当前位置: 首页>>代码示例>>Java>>正文


Java ClasspathHelper.forClass方法代码示例

本文整理汇总了Java中org.reflections.util.ClasspathHelper.forClass方法的典型用法代码示例。如果您正苦于以下问题:Java ClasspathHelper.forClass方法的具体用法?Java ClasspathHelper.forClass怎么用?Java ClasspathHelper.forClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.reflections.util.ClasspathHelper的用法示例。


在下文中一共展示了ClasspathHelper.forClass方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deriveBuild

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Derives the OpenGamma build from the classpath and dependencies.
 * 
 * @return the build, null if not known
 */
public static String deriveBuild() {
  URL url = ClasspathHelper.forClass(VersionUtils.class, VersionUtils.class.getClassLoader());
  if (url != null && url.toString().contains(".jar")) {
    try {
      final String part = ClasspathHelper.cleanPath(url);
      try (JarFile myJar = new JarFile(part)) {
        final Manifest manifest = myJar.getManifest();
        if (manifest != null) {
          Attributes attributes = manifest.getMainAttributes();
          if (attributes != null) {
            if (attributes.getValue(IMPLEMENTATION_BUILD) != null) {
              return attributes.getValue(IMPLEMENTATION_BUILD);
            }
          }
        }
      }
    } catch (Exception ex) {
      s_logger.warn(ex.getMessage(), ex);
    }
  }
  return null;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:28,代码来源:VersionUtils.java

示例2: deriveBuildId

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Derives the OpenGamma build ID from the classpath and dependencies.
 * <p>
 * This ID is derived from the CI server.
 * 
 * @return the build ID, null if not known
 */
public static String deriveBuildId() {
  URL url = ClasspathHelper.forClass(VersionUtils.class, VersionUtils.class.getClassLoader());
  if (url != null && url.toString().contains(".jar")) {
    try {
      final String part = ClasspathHelper.cleanPath(url);
      try (JarFile myJar = new JarFile(part)) {
        final Manifest manifest = myJar.getManifest();
        if (manifest != null) {
          Attributes attributes = manifest.getMainAttributes();
          if (attributes != null) {
            if (attributes.getValue(IMPLEMENTATION_BUILD_ID) != null) {
              return attributes.getValue(IMPLEMENTATION_BUILD_ID);
            }
          }
        }
      }
    } catch (Exception ex) {
      s_logger.warn(ex.getMessage(), ex);
    }
  }
  return null;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:30,代码来源:VersionUtils.java

示例3: vfsFromDirWithinAJarUrl

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
@Test
  public void vfsFromDirWithinAJarUrl() throws MalformedURLException {
  	URL directoryInJarUrl = ClasspathHelper.forClass(String.class);
      assertTrue(directoryInJarUrl.toString().startsWith("jar:file:"));
      assertTrue(directoryInJarUrl.toString().contains(".jar!"));
      
      String directoryInJarPath = directoryInJarUrl.toExternalForm().replaceFirst("jar:", "");
      int start = directoryInJarPath.indexOf(":") + 1;
int end = directoryInJarPath.indexOf(".jar!") + 4;
String expectedJarFile = directoryInJarPath.substring(start, end);
      
      Vfs.Dir dir = Vfs.fromURL(new URL(directoryInJarPath));

      assertEquals(ZipDir.class, dir.getClass());
      assertEquals(expectedJarFile, dir.getPath());
  }
 
开发者ID:ronmamo,项目名称:reflections,代码行数:17,代码来源:VfsTest.java

示例4: deriveVersion

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Derives the OpenGamma version from the classpath and dependencies.
 * 
 * @return the version, null if not known
 */
public static String deriveVersion() {
  URL url = ClasspathHelper.forClass(VersionUtils.class, VersionUtils.class.getClassLoader());
  if (url != null && url.toString().contains(".jar")) {
    try {
      final String part = ClasspathHelper.cleanPath(url);
      try (JarFile myJar = new JarFile(part)) {
        final Manifest manifest = myJar.getManifest();
        if (manifest != null) {
          Attributes attributes = manifest.getMainAttributes();
          if (attributes != null) {
            if (attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION) != null) {
              return attributes.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
            }
            if (attributes.getValue(Attributes.Name.SPECIFICATION_VERSION) != null) {
              return attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
            }
          }
        }
      }
    } catch (Exception ex) {
      s_logger.warn(ex.getMessage(), ex);
    }
  } else {
    List<DependencyInfo> dependencies = ClasspathUtils.getDependencies();
    for (DependencyInfo dependency : dependencies) {
      if ("og-util".equals(dependency.getArtifactId())) {
        return dependency.getVersion();
      }
    }
  }
  return null;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:38,代码来源:VersionUtils.java

示例5: addSubtypesOf

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Add all subtypes of the given class
 * @param baseClass
 */
protected void addSubtypesOf(Class baseClass) {
    Reflections reflections = new Reflections(ClasspathHelper.forClass(baseClass), new SubTypesScanner(false));
    Set<Class<?>> classes = reflections.getSubTypesOf(baseClass);

    System.out.println("type names size: " + classes.size());
    classes.forEach(this::addClass);
}
 
开发者ID:nedap,项目名称:archie,代码行数:12,代码来源:ModelInfoLookup.java

示例6: GUIWriter

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
public GUIWriter(GUI gui)throws JAXBException, ClassNotFoundException, IOException{
    this.gui = gui;
    Reflections reflections = new Reflections ("jada.ngeditor.model",ClasspathHelper.forClass(GElement.class), 
                         new SubTypesScanner(false), new TypeAnnotationsScanner());
    Set<Class<?>> setXmlRoot = reflections.getTypesAnnotatedWith(XmlRootElement.class);
    Class[] classes = setXmlRoot.toArray(new Class[0]);
    
    JAXBContext jc = JAXBContext.newInstance("jada.ngeditor.model:jada.ngeditor.model.elements:jada.ngeditor.model.elements.specials:jada.ngeditor.model.elements.effects",this.getClass().getClassLoader());       
   
    m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd");
}
 
开发者ID:relu91,项目名称:niftyeditor,代码行数:14,代码来源:GUIWriter.java

示例7: configure

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Prepares an Eclipse plugin to be used with LOGICOBJECTS
 * @param plugin
 */
public static void configure(Plugin plugin) {
	//enabling javassist to work correctly in Eclipse
	ClassPool classPool = ClassPool.getDefault();
	classPool.appendClassPath(new LoaderClassPath(plugin.getClass().getClassLoader()));
	LogicObjects.getDefault().getContext().getLogicObjectFactory().setClassPool(classPool);
	
	Vfs.addDefaultURLTypes(new BundleUrlType(plugin.getBundle()));  //enabling the Reflections filters to work in Eclipse
	
	String pathLogicFiles = null;
	URL urlPlugin = ClasspathHelper.forClass(plugin.getClass());
	/**
	 * adding all the classes in the plugin to the search path
	 * This line has to be after the call to Vfs.addDefaultURLTypes(...)
	 */
	LogicObjects.getDefault().getContext().addSearchUrl(urlPlugin);
	try {
		pathLogicFiles = FileLocator.toFileURL(urlPlugin).getPath();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	/**
	 * move to the directory where the plugin is deployed
	 * This code uses the bootstrap engine since this engine will not trigger the loading of Logtalk
	 * After we have moved to the location of the plugin files we can load logtalk afterwards
	 */
	//LogicEngine.getBootstrapEngine().cd(pathLogicFiles); TODO verify that this is not needed anymore (it should work without this since all the logic files are copied to a tmp directory)
	

}
 
开发者ID:java-prolog-connectivity,项目名称:logicobjects,代码行数:34,代码来源:EclipsePluginConfigurator.java

示例8: loadDependencies

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
public boolean loadDependencies(LogicClass logicObjectClass) {
	if(isClassLoaded(logicObjectClass.getWrappedClass()))
		return true;
	Package pakkage = logicObjectClass.getWrappedClass().getPackage();
	boolean packageLoaded = true;
	if(!isPackageLoaded(pakkage)) {
		URL url = ClasspathHelper.forClass(logicObjectClass.getWrappedClass());
		packageLoaded = simpleLoadPackage(pakkage, url);
	}
	return packageLoaded && simpleLoadClass(logicObjectClass);
}
 
开发者ID:java-prolog-connectivity,项目名称:logicobjects,代码行数:12,代码来源:LogicDependenciesLoader.java

示例9: findAllGElements

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
public static  Set<Class<? extends GElement>> findAllGElements(){
     Reflections reflections = new Reflections ("jada.ngeditor.model",ClasspathHelper.forClass(GElement.class), 
    new SubTypesScanner(false));
        Set<Class<? extends GElement>> subTypesOf = reflections.getSubTypesOf(GElement.class);
        return subTypesOf;
}
 
开发者ID:relu91,项目名称:niftyeditor,代码行数:7,代码来源:ClassUtils.java

示例10: simpleLoadClass

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
public boolean simpleLoadClass(LogicClass logicObjectClass) {
	boolean prologResult;
	boolean logtalkResult;
	AbstractPrologEngineDriver engineConfig = LogicObjects.getLogicEngineConfiguration(logicObjectClass.getWrappedClass());
	PrologUtil logicUtil = new PrologUtil(engineConfig);
	LogicResourcePathAdapter resourceAdapter = new LogicResourcePathAdapter(engineConfig, ClasspathHelper.forClass(logicObjectClass.getWrappedClass()), resourceManager);
	
	//LOADING PROLOG MODULES
	List<String> descriptorModules = logicObjectClass.getLogicObjectDescriptor().modules(); //modules defined in the descriptor (e.g., with the LObject annotation)
	List<String> allModulesNames = new ArrayList<>();
	allModulesNames.addAll(descriptorModules); 
	
	if(logicObjectClass.getLogicObjectDescriptor().automaticImport()) {
		List<String> defaultModules = getDefaultPrologResources(logicObjectClass);  //modules defined by convention (Prolog files in the same package than the class and with the same id + Prolog extension)
		allModulesNames.addAll(defaultModules);
	}
	
	List<LogicResource> allModules = PrologResource.asPrologResources(allModulesNames);

	List<AbstractTerm> moduleTerms = new ArrayList<AbstractTerm>();
	resourceAdapter.adapt(allModules, moduleTerms);
	
	prologResult = logicUtil.ensureLoaded(moduleTerms); //loading prolog modules
	if(!prologResult)
		logger.warn("Impossible to load Prolog files from class: " + logicObjectClass.getSimpleName() + ". List of resources: " + allModules);
	
	//LOADING LOGTALK OBJECTS
	List<String> descriptorImports = logicObjectClass.getLogicObjectDescriptor().imports();
	
	List<String> allImportsNames = new ArrayList<>();
	allImportsNames.addAll(descriptorImports);

	if(logicObjectClass.getLogicObjectDescriptor().automaticImport()) {
		List<String> defaultImports = getDefaultLogtalkResources(logicObjectClass);   //Logtalk files defined by convention (in the same package than the class and with the same id + Logtalk extension)
		allImportsNames.addAll(defaultImports);
	}
	
	List<LogicResource> allImports = LogtalkResource.asLogtalkResources(allImportsNames);
	
	List<AbstractTerm> importTerms = new ArrayList<AbstractTerm>();
	resourceAdapter.adapt(allImports, importTerms);
	
	
	logtalkResult = logicUtil.logtalkLoad(importTerms); //loading Logtalk objects
	if(!logtalkResult)
		logger.warn("Impossible to load Logtalk files from class: " + logicObjectClass.getSimpleName() + ". List of resources: " + allImports);
	
	List<LogicResource> allResources = new ArrayList<>();
	allResources.addAll(allModules);
	allResources.addAll(allImports);
	rememberLoadedClass(logicObjectClass.getWrappedClass(), allResources);
	
	return prologResult && logtalkResult;
}
 
开发者ID:java-prolog-connectivity,项目名称:logicobjects,代码行数:55,代码来源:LogicDependenciesLoader.java

示例11: testFindResources

import org.reflections.util.ClasspathHelper; //导入方法依赖的package包/类
/**
 * Test for finding resources with a given id
 * (Currently) does not work if the resources are in a jar.
 * it is commented out so maven will not complain in the automated unit tests execution in the 'installation' phase (where the project is zipped in a jar)
 */

@Test
public void testFindResources() {
	URL urlLogicObjects = ClasspathHelper.forClass(PrologEngine.class);
	Reflections reflections = new Reflections(new ConfigurationBuilder()
       //.setUrls(ClasspathHelper.forPackage("org.logicobjects"))
	.setUrls(urlLogicObjects)
       .setScanners(new ResourcesScanner()));
	
	
	Predicate<String> predicate = new Predicate<String>() {
		  public boolean apply(String string) {
			    //return string.matches(".*\\.properties");
			  boolean matches = string.matches(".*\\.lgt");
			  return matches;

		  }
	};

	/*
	 * WARNING: the getResources method answers resources RELATIVE paths (relatives to the classpath from where they were found)
	 * If a file is created with this path (like with: new File(relativePath)) the path of such File object will be the current execution path + the relative path
	 * If the current execution path is not the base directory of the relative paths, this could lead to files having absolute paths pointing to non existing resources
	 */
	Set<String> propertiesFiles = reflections.getResources(predicate);  //in case a complex predicate is needed
	//Set<String> propertiesFiles = reflections.getResources(Pattern.compile(".*\\.properties")); //in case the condition is just based on the id of the file
	
	System.out.println("URL Logic Objects: " + urlLogicObjects);
	System.out.println("Protocol: "+urlLogicObjects.getProtocol());
	System.out.println("File: "+urlLogicObjects.getFile());
	//System.out.println("Execution Path: "  + System.getProperty("user.dir"));
	//System.out.println("Number of property files: " + propertiesFiles.size());
	for(String propertyFile : propertiesFiles) {
		System.out.println(propertyFile);
	}
	
	//Dir dir = Vfs.fromURL(urlLogicObjects);
	try {
		URL url = new URL(urlLogicObjects, "org/jpc/examples/metro/line.lgt");
		System.out.println("URL:" + url);
		System.out.println(url.openStream().available());
		
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
	
}
 
开发者ID:java-prolog-connectivity,项目名称:logicobjects,代码行数:53,代码来源:TestReflections.java


注:本文中的org.reflections.util.ClasspathHelper.forClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。