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


Java ClassPath.findResource方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:J2SEPlatformImpl.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Utils.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:SpringUtilities.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:EntityClassesPanel.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ProjectRunnerImpl.java

示例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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:ProjectUtilities.java

示例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");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:OpenTestAction.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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ModuleClassPaths.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:MultiModuleUnitTestsCompilerOptionsQueryImpl.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:PersistenceClientEntitySelectionVisual.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:CustomIconEditor.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:DefaultProjectModulesModifier.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:JPAClassPathHelper.java

示例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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:UseEntityManagerCodeGenerator.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ClassPathUtils.java


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