本文整理汇总了Java中org.netbeans.api.java.classpath.ClassPath.findResource方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPath.findResource方法的具体用法?Java ClassPath.findResource怎么用?Java ClassPath.findResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.classpath.ClassPath
的用法示例。
在下文中一共展示了ClassPath.findResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isValid
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@Override
public boolean isValid() {
if (!super.isValid()) {
return false;
}
for (String tool : PlatformConvertor.IMPORTANT_TOOLS) {
if (findTool(tool) == null) {
return false;
}
}
Boolean valid = bootValidCache.get();
if (valid == null) {
final ClassPath boot = getBootstrapLibraries();
if (!bootValidListens.get() && bootValidListens.compareAndSet(false, true)) {
boot.addPropertyChangeListener(this);
}
valid = boot.findResource("java/lang/Object.class") != null; //NOI18N
bootValidCache.set(valid);
}
return valid;
}
示例2: getFile
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@CheckForNull
public static FileObject getFile(
@NonNull final ElementHandle<TypeElement> toResolve,
@NonNull final ClasspathInfo cpInfo) {
FileObject res = SourceUtils.getFile(toResolve, cpInfo);
if (res == null) {
final ClassPath cp = ClassPathSupport.createProxyClassPath(
cpInfo.getClassPath(ClasspathInfo.PathKind.BOOT),
cpInfo.getClassPath(ClasspathInfo.PathKind.COMPILE));
res = cp.findResource(String.format(
"%s.%s", //NOI18N
toResolve.getBinaryName().replace('.', '/'), //NOI18N
CLASS_EXTENSION));
}
return res;
}
示例3: getLibraryVersion
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static String getLibraryVersion(Library library, String className) {
List<URL> urls = library.getContent("classpath"); // NOI18N
ClassPath cp = createClassPath(urls);
try {
FileObject resource = cp.findResource(className.replace('.', '/') + ".class"); //NOI18N
if (resource==null) {
return null;
}
FileObject ownerRoot = cp.findOwnerRoot(resource);
if (ownerRoot !=null) { //NOI18N
if (ownerRoot.getFileSystem() instanceof JarFileSystem) {
JarFileSystem jarFileSystem = (JarFileSystem) ownerRoot.getFileSystem();
return getImplementationVersion(jarFileSystem);
}
}
} catch (FileStateInvalidException e) {
Exceptions.printStackTrace(e);
}
return null;
}
示例4: isBeanValidationSupported
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
boolean isBeanValidationSupported() {
if (project == null) {
return false;
}
final String notNullAnnotation = "javax.validation.constraints.NotNull"; //NOI18N
Sources sources=ProjectUtils.getSources(project);
SourceGroup groups[]=sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if(groups == null || groups.length<1){
return false;
}
SourceGroup firstGroup=groups[0];
FileObject fo=firstGroup.getRootFolder();
ClassPath compile=ClassPath.getClassPath(fo, ClassPath.COMPILE);
if (compile == null) {
return false;
}
return compile.findResource(notNullAnnotation.replace('.', '/')+".class")!=null;//NOI18N
}
示例5: findOwnerRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@CheckForNull
private static FileObject findOwnerRoot(
@NonNull final String className,
@NonNull final String[] extensions,
@NonNull final ClassPath... binCps) {
final String binaryResource = FileObjects.convertPackage2Folder(className);
final ClassPath merged = ClassPathSupport.createProxyClassPath(binCps);
for (String ext : extensions) {
final FileObject res = merged.findResource(String.format(
"%s.%s", //NOI18N
binaryResource,
ext));
if (res != null) {
return merged.findOwnerRoot(res);
}
}
return null;
}
示例6: findUnitTestInTestRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Copied from JUnit module implementation in 4.1 and modified
*/
private static FileObject findUnitTestInTestRoot(ClassPath cp, FileObject selectedFO, URL testRoot) {
ClassPath testClassPath = null;
if (testRoot == null) { //no tests, use sources instead
testClassPath = cp;
} else {
try {
List<PathResourceImplementation> cpItems = new ArrayList<PathResourceImplementation>();
cpItems.add(ClassPathSupport.createResource(testRoot));
testClassPath = ClassPathSupport.createClassPath(cpItems);
} catch (IllegalArgumentException ex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
testClassPath = cp;
}
}
String testName = getTestName(cp, selectedFO);
return testClassPath.findResource(testName + ".java"); // NOI18N
}
示例7: findUnitTestInTestRoot
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static FileObject findUnitTestInTestRoot(ClassPath cp, FileObject selectedFO, URL testRoot) {
ClassPath testClassPath = null;
if (testRoot == null) { //no tests, use sources instead
testClassPath = cp;
} else {
try {
List<PathResourceImplementation> cpItems
= new ArrayList<PathResourceImplementation>();
cpItems.add(ClassPathSupport.createResource(testRoot));
testClassPath = ClassPathSupport.createClassPath(cpItems);
} catch (IllegalArgumentException ex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
testClassPath = cp;
}
}
String testName = getTestName(cp, selectedFO);
return testClassPath.findResource(testName+".java");
}
示例8: supportsModules
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static boolean supportsModules(
@NonNull final ClassPath boot,
@NonNull final ClassPath compile,
@NonNull final ClassPath src) {
if (boot.findResource("java/util/zip/CRC32C.class") != null) { //NOI18N
return true;
}
if (compile.findResource("java/util/zip/CRC32C.class") != null) { //NOI18N
return true;
}
return src.findResource("java/util/zip/CRC32C.java") != null; //NOI18N
}
示例9: classifyModules
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private List<Map<String,List<File>>> classifyModules(
@NonNull final Collection<? extends String> toClassify,
@NonNull final Set<? super File> moduleInfosToListenOn,
@NonNull final Collection<? super ClassPath> cpsToListenOn) {
final Map<String,List<File>> mods = new HashMap<>();
final Map<String,List<File>> ptchs = new HashMap<>();
final Map<String,List<File>> invd = new HashMap<>();
for (String modName : toClassify) {
ClassPath cp = testModules.getModuleSources(modName);
if (cp == null) {
invd.put(modName, Collections.emptyList());
continue;
}
final Map<String,List<File>> into;
FileObject modInfo;
if ((modInfo = cp.findResource(MODULE_INFO)) != null && modInfo.isData()) {
into = mods;
} else if (sourceModules.getModuleNames().contains(modName)) {
into = ptchs;
} else {
into = invd;
}
final List<File> files = cp.entries().stream()
.map((e) -> FileUtil.archiveOrDirForURL(e.getURL()))
.filter((f) -> f != null)
.collect(Collectors.toList());
into.put(modName, files);
files.stream()
.map((f) -> new File(f, MODULE_INFO))
.forEach(moduleInfosToListenOn::add);
cpsToListenOn.add(cp);
}
return Arrays.asList(mods, ptchs, invd);
}
示例10: valid
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public boolean valid(WizardDescriptor wizard) {
SourceGroup[] groups = SourceGroups.getJavaSourceGroups(project);
if (groups.length > 0) {
ClassPath compileCP = ClassPath.getClassPath(groups[0].getRootFolder(), ClassPath.COMPILE);
if (compileCP==null || compileCP.findResource("javax/persistence/Entity.class") == null) { // NOI18N
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class, "ERR_NoPersistenceProvider"));
return false;
}
}
if (!ProviderUtil.isValidServerInstanceOrNone(project)){
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class,"ERR_MissingServer")); //NOI18N
return false;
}
if (!entityClosure.isModelReady()) {
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class, "scanning-in-progress"));
return false;
}
if (listSelected.getModel().getSize() == 0) {
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class, "MSG_NoEntityClassesSelected"));
return false;
}
if (entityClosure.isEjbModuleInvolved()) {
wizard.putProperty(WizardDescriptor.PROP_WARNING_MESSAGE, NbBundle.getMessage(PersistenceClientEntitySelectionVisual.class, "WARN_DetectedEntitiesFromEjbModule"));
return true;
}
wizard.putProperty(WizardDescriptor.PROP_WARNING_MESSAGE, " "); //NOI18N
wizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, " "); //NOI18N
return true;
}
示例11: findSourceRootOf
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private FileObject findSourceRootOf(FileObject[] roots, String resName) {
for (FileObject root : roots) {
ClassPath resCP = ClassPath.getClassPath(root, ClassPath.SOURCE);
if (resCP != null) {
FileObject res = resCP.findResource(resName);
if (res != null) {
return res;
}
}
}
return null;
}
示例12: doFindModuleUsages
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public static Map<URL, Collection<ClassPath>> doFindModuleUsages(FileObject projectArtifact, Collection<URL> locations) {
Project p = FileOwnerQuery.getOwner(projectArtifact);
if (p == null) {
return Collections.emptyMap();
}
Map<String, URL> modLocations = new HashMap<>();
for (URL u : locations) {
String n = SourceUtils.getModuleName(u, true);
if (n != null) {
modLocations.put(n, u);
}
}
Map<URL, Collection<ClassPath>> resultMap = new HashMap<>();
Set seenCP = new HashSet<>();
for (SourceGroup g : ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
FileObject r = g.getRootFolder();
ClassPath src = ClassPath.getClassPath(r, ClassPath.SOURCE);
if (!seenCP.add(Arrays.asList(src.getRoots()))) {
continue;
}
if (src.findResource("module-info.java") == null) {
continue;
}
JavaSource js = JavaSource.forFileObject(r);
if (js != null) {
try {
js.runUserActionTask(new S(src, modLocations, resultMap), true);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return resultMap;
}
示例13: ensureJPA
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Ensure that the compile class path has the Java Persistence API present. Checks
* whether JPA is already present in the compile class path and if not, tries to
* find an appropriate JPA library and add it to the compile class path.
*
* @return true if the compile class path contained or could be made to contain
* the Java Persistence API.
*/
private boolean ensureJPA() {
for (ClassPath classPath : compile) {
if (classPath.findResource("javax/persistence/Entity.class") != null) { // NOI18N
return true;
}
}
ClassPath jpaClassPath = findJPALibrary();
if (jpaClassPath != null) {
compile.add(jpaClassPath);
return true;
}
return false;
}
示例14: isEnable
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static boolean isEnable(FileObject fileObject, TypeElement typeElement) {
Project project = FileOwnerQuery.getOwner(fileObject);
if (project == null) {
return false;
}
if(ElementKind.INTERFACE == typeElement.getKind())return false;
DataObject dObj = null;
try {
dObj = DataObject.find(fileObject);
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
if(dObj == null) {
return false;
}
// Enable it only if the EntityManager is in the project classpath
// This check was motivated by issue 139333 - The Use Entity Manager action
// breaks from left to right if the javax.persistence.EntityManager class is missing
FileObject target = dObj.getCookie(DataObject.class).getPrimaryFile();
ClassPath cp = ClassPath.getClassPath(target, ClassPath.COMPILE);
if(cp == null) {
return false;
}
if(PersistenceScope.getPersistenceScope(target) == null){
return false;
}
FileObject entityMgrRes = cp.findResource("javax/persistence/EntityManager.class"); // NOI18N
if (entityMgrRes != null) {
return true;
} else {
return false;
}
}
示例15: isOnClassPath
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public static boolean isOnClassPath(FileObject fileInProject, String className) {
String resourceName = className.replace('.', '/') + ".class"; // NOI18N
ClassPath classPath = ClassPath.getClassPath(fileInProject, ClassPath.COMPILE);
if (classPath == null)
return false;
return classPath.findResource(resourceName) != null;
}