org.netbeans.api.java.classpath.ClassPath.findResource()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中org.netbeans.api.java.classpath.ClassPath.findResource()方法的一些代码示例,展示了ClassPath.findResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClassPath.findResource()方法的具体详情如下:
包路径:org.netbeans.api.java.classpath.ClassPath
类名称:ClassPath
方法名:findResource

ClassPath.findResource介绍

暂无

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-junit-ant

public FileObject find(String filename) {
  return classpath.findResource(filename);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf

/**
 * Whether the given classpath contains support for Facelets.
 *
 * @param cp examined classpath
 * @return {@code true} if the facelets classes are present on the classpath, {@code false} otherwise
 */
public static boolean isFaceletsPresent(ClassPath cp) {
  if (cp == null) {
    return false;
  }
  return cp.findResource(JSFUtils.MYFACES_SPECIFIC_CLASS.replace('.', '/') + ".class") != null || //NOI18N
      cp.findResource("com/sun/facelets/Facelet.class") != null || //NOI18N
      cp.findResource("com/sun/faces/facelets/Facelet.class") != null || // NOI18N
      cp.findResource("javax/faces/view/facelets/FaceletContext.class") != null; //NOI18N
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spring-beans

private static boolean containsClass(ClassPath classPath, String className) {
  String classRelativePath = className.replace('.', '/') + ".class"; //NOI18N
  return classPath.findResource(classRelativePath) != null;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base

private static boolean hasResource(
  @NonNull String resourceBase,
  @NullAllowed ClassPath boot,
  @NullAllowed ClassPath compile,
  @NullAllowed ClassPath source) {
  final String resourceClass = String.format("%s.class", resourceBase);
  final String resourceJava = String.format("%s.java", resourceBase);
  if (boot != null && boot.findResource(resourceClass) == null) { //NOI18N
    if (source != null && source.findResource(resourceJava) == null) {   //NOI18N
      if (compile == null || compile.findResource(resourceClass) == null) { // NOI18N
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans

static boolean hasResource(SourceGroup group , String classPathType, String fqn){
  ClassPath classPath = ClassPath.getClassPath(group.getRootFolder(), classPathType);
  String path = fqn.replace('.', '/');
  if ( ClassPath.SOURCE.equals( classPathType ) ){
    path = path+".java";                    // NOI18N
  }
  else {
    path = path+".class";                   // NOI18N
  }
  if (classPath == null) {
    return false;
  }
  
  return classPath.findResource(path) != null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

private void selectClasspathResource(Matcher m) {
  String resource = m.group(1) + m.group(4);
  int lineNumber = Integer.parseInt(m.group(5));
  org.netbeans.api.java.classpath.ClassPath cp = ClassPathSupport.createClassPath(GlobalPathRegistry.getDefault().getSourceRoots().toArray(new FileObject[0]));
  FileObject source = cp.findResource(resource);
  if (source != null) {
    doOpen(source, lineNumber);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

private void selectStackTrace(Matcher m) {
  String pkg = m.group(2);
  String filename = m.group(3);
  String resource = pkg.replace('.', '/') + filename;
  int lineNumber = Integer.parseInt(m.group(4));
  org.netbeans.api.java.classpath.ClassPath cp = ClassPathSupport.createClassPath(GlobalPathRegistry.getDefault().getSourceRoots().toArray(new FileObject[0]));
  FileObject source = cp.findResource(resource);
  if (source != null) {
    doOpen(source, lineNumber);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-swingapp

/**
 * Checks whether the project of given file uses Swing Application Framework,
 * i.e. whether the framework is on project classpath. Does not check if
 * there is an Application subclass (the project can be just a library).
 * @param fileInProject some source file contained in the project
 * @return true if the project of given file uses app framework
 */
static boolean isFrameworkLibAvailable(FileObject fileInProject) {
  ClassPath cp = ClassPath.getClassPath(fileInProject, ClassPath.EXECUTE);
  return cp != null && cp.findResource(APPLICATION_RESOURCE_NAME) != null
      && projectCanUseFramework(fileInProject);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-core

private static boolean isJSF22(WebModule wm) {
  ClassPath classpath = ClassPath.getClassPath(wm.getDocumentBase(), ClassPath.COMPILE);
  return classpath != null && classpath.findResource("javax/faces/flow/Flow.class") != null; //NOI18N
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project

private @CheckForNull FileObject findBundle(FileObject javaFile) {
  ClassPath cp = ClassPath.getClassPath(javaFile, ClassPath.SOURCE);
  if (cp == null) {
    return null;
  }
  String name = cp.getResourceName(javaFile);
  if (name != null) {
    int index = name.lastIndexOf('/');
    name = name.substring(0, index) + "/Bundle.properties"; //NOI18N
    return cp.findResource(name);
  }
  return null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-core

private static boolean isJSF20(WebModule wm) {
  ClassPath classpath = ClassPath.getClassPath(wm.getDocumentBase(), ClassPath.COMPILE);
  return classpath != null && classpath.findResource("javax/faces/application/ProjectStage.class") != null; //NOI18N
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor

private URL getSourceFile(String name) {
    // this is slightly faster then original implementation
    FileObject fo = path.findResource(name.replace('.', '/') + config.getDefaultScriptExtension());
    if (fo == null || fo.isFolder()) {
      return null;
    }
    return URLMapper.findURL(fo, URLMapper.EXTERNAL);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-swingapp

static DesignResourceMap getAppDesignResourceMap(Project project) {
  String appClassName = AppFrameworkSupport.getApplicationClassName(project);
  if (appClassName != null) {
    String bundleName = getBundleName(appClassName);
    ClassPath cp = AppFrameworkSupport.getSourcePath(project);
    FileObject fo = cp.findResource(appClassName.replace('.', '/') + ".java"); // NOI18N
    return new DesignResourceMap(null, cp.getClassLoader(true), fo,
        new String[] { bundleName }, DesignResourceMap.APP_LEVEL);
  }
  return null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-junit-ui

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");
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-websvc-restapi

protected void addJerseySpringJar() throws IOException {
  FileObject srcRoot = MiscUtilities.findSourceRoot(getProject());
  if (srcRoot != null) {
    ClassPath cp = ClassPath.getClassPath(srcRoot, ClassPath.COMPILE);
    if (cp ==null ||cp.findResource(
        "com/sun/jersey/api/spring/Autowire.class") == null)        //NOI18N
    {
      File jerseyRoot = InstalledFileLocator.getDefault().locate(JERSEY_API_LOCATION, null, false);
      if (jerseyRoot != null && jerseyRoot.isDirectory()) {
        File[] jerseyJars = jerseyRoot.listFiles(new MiscPrivateUtilities.JerseyFilter(JERSEY_SPRING_JAR_PATTERN));
        if (jerseyJars != null && jerseyJars.length>0) {
          URL url = FileUtil.getArchiveRoot(jerseyJars[0].toURI().toURL());
          ProjectClassPathModifier.addRoots(new URL[] {url}, srcRoot, ClassPath.COMPILE);
        }
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-websvc-restapi

public static boolean hasResource(Project project, String resource) {
  SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
  if (sgs.length < 1) {
    return false;
  }
  FileObject sourceRoot = sgs[0].getRootFolder();
  ClassPath classPath = ClassPath.getClassPath(sourceRoot, ClassPath.COMPILE);
  if (classPath == null) {
    return false;
  }
  FileObject resourceFile = classPath.findResource(resource);
  if (resourceFile != null) {
    return true;
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans

private static boolean hasResource(Project project, String resource) {
  SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
  if (sgs.length < 1) {
    return false;
  }
  FileObject sourceRoot = sgs[0].getRootFolder();
  ClassPath classPath = ClassPath.getClassPath(sourceRoot, ClassPath.COMPILE);
  if (classPath == null) {
    return false;
  }
  FileObject resourceFile = classPath.findResource(resource);
  if (resourceFile != null) {
    return true;
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-project

private static @CheckForNull FileObject findFile(FileObject manifest, String path) {
  Project prj = FileOwnerQuery.getOwner(manifest);
  if (prj == null) {
    return null;
  }
  Sources srcs = ProjectUtils.getSources(prj);
  SourceGroup[] grps = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
  if (grps.length == 0)   // #143157: there needn't to be source group (yet)
    return null;
  ClassPath cp = ClassPath.getClassPath(grps[0].getRootFolder(), ClassPath.SOURCE);
  if (cp == null) {
    return null;
  }
  path = path.trim();
  return cp.findResource(path);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-junit-ant-ui

@Override
protected void projectOpened() {
  final ClassPath classPath = getTestClassPath(p);
  if (classPath != null) {
    if (classPath.findResource(JUNIT3_SPECIFIC) != null || 
        classPath.toString().contains("${libs.junit.classpath}")) {
      getJUnitProjectProblemsProvider(p).setProblem(ProjectProblem.createError(
        Bundle.Error_display_name_junit(), Bundle.Error_description_junit(),
        new JUnitProblemResolver(new UpdateToJUnit4Action(p, true), MISSING_JUNIT_BINARIES)));
    }
    if (classPath.findResource(JUNIT4_SPECIFIC) != null && classPath.findResource(HAMCREST_SPECIFIC) == null) {
      getJUnitProjectProblemsProvider(p).setProblem(ProjectProblem.createError(
        Bundle.Error_display_name_junit4(), Bundle.Error_description_junit4(),
        new JUnitProblemResolver(new UpdateToJUnit4Action(p, false), MISSING_JUNIT_BINARIES)));
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-spring-beans

private void refreshLocation(String fqn) {
  String cpBase = fqn.replace('.', '/'); //NOI18N
  ClassPath sourceCP = getHelper().getClasspathInfo().getClassPath(ClasspathInfo.PathKind.SOURCE);
  FileObject classFO = sourceCP.findResource(cpBase + ".java"); //NOI18N
  if (classFO == null) {
    ClassPath compileCP = getHelper().getClasspathInfo().getClassPath(ClasspathInfo.PathKind.COMPILE);
    classFO = searchForFile(compileCP, cpBase);
  }
  if (classFO != null) {
    location = new SpringAnnotatedBeanLocation(classFO);
  }
}

相关文章