本文整理汇总了Java中org.netbeans.spi.java.classpath.ClassPathProvider.findClassPath方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPathProvider.findClassPath方法的具体用法?Java ClassPathProvider.findClassPath怎么用?Java ClassPathProvider.findClassPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.spi.java.classpath.ClassPathProvider
的用法示例。
在下文中一共展示了ClassPathProvider.findClassPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCycle
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testCycle () throws Exception {
GlobalPathRegistry regs = GlobalPathRegistry.getDefault();
Set<ClassPath> toCleanUp = regs.getPaths(ClassPath.COMPILE);
regs.unregister(ClassPath.COMPILE, toCleanUp.toArray(new ClassPath[toCleanUp.size()]));
toCleanUp = regs.getPaths(ClassPath.EXECUTE);
regs.unregister(ClassPath.EXECUTE, toCleanUp.toArray(new ClassPath[toCleanUp.size()]));
File wdf = getWorkDir();
FileObject wd = FileUtil.toFileObject(wdf);
FileObject root1 = wd.createFolder("root1");
FileObject root2 = wd.createFolder("root2");
ClassPathProvider cpp = new DefaultClassPathProvider ();
ClassPath dcp = cpp.findClassPath(root2, ClassPath.COMPILE);
ClassPath cp = ClassPathSupport.createClassPath(new FileObject[] {root1});
regs.register(ClassPath.COMPILE, new ClassPath[] {cp});
assertNotNull(dcp);
FileObject[] roots = dcp.getRoots();
assertEquals(1, roots.length);
assertEquals(root1, roots[0]);
regs.register(ClassPath.COMPILE, new ClassPath[] {dcp});
roots = dcp.getRoots();
assertEquals(1, roots.length);
}
示例2: findClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public ClassPath findClassPath(FileObject file, String type) {
Project p = FileOwnerQuery.getOwner(file);
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "findClassPath({0}, {1}) on project {2}", new Object[] {file, type, p});
}
if (p != null) {
ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
if (cpp != null) {
final ClassPath result = cpp.findClassPath(file, type);
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "findClassPath({0}, {1}) -> {2} from {3}", new Object[] {file, type, result, cpp});
}
return result;
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "cpp.findClassPath({0}, {1}) -> null", new Object[] {file, type});
}
return null;
}
} else {
return null;
}
}
示例3: testMissingEvents
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testMissingEvents() throws Exception {
InstanceContent ic = new InstanceContent();
Lookup lookup = new AbstractLookup(ic);
ProviderImpl defaultCP = new ProviderImpl();
final URL root1 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root1")));
final URL root2 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root2")));
final MutableCPImpl cpImpl = new MutableCPImpl(root1);
defaultCP.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(cpImpl));
ClassPathProviderMerger instance = new ClassPathProviderMerger(defaultCP);
ClassPathProvider result = instance.merge(lookup);
ClassPath compile = result.findClassPath(null, ClassPath.COMPILE);
assertNotNull(compile);
assertEquals(1, compile.entries().size());
cpImpl.add(root2);
assertEquals(2, compile.entries().size());
}
示例4: testSimpleCompileTestDependency
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testSimpleCompileTestDependency() throws Exception {
generateTestingSuite();
NbModuleProject modD = generateTestingSuiteComponent(testSuite,"d", "",
"<test-dependency>\n" +
"<code-name-base>org.example.a</code-name-base>\n" +
// "<recursive/>\n" +
"<compile-dependency/>\n" +
// "<test/>\n" +
"</test-dependency>\n", "");
ClassPathProvider cpp = modD.getLookup().lookup(ClassPathProvider.class);
ClassPath cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.COMPILE);
Set<String> expectedRoots = new TreeSet<String>();
expectedRoots.addAll(TESTLIBS);
expectedRoots.add(urlForJar(modD.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modA.getModuleJarLocation().getPath()));
assertEquals("correct TEST COMPILE classpath", expectedRoots, urlsOfCp4Tests(cp));
cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.EXECUTE);
expectedRoots.add(urlForJar(modD.getTestClassesDirectory("unit").getPath()));
assertEquals("correct TEST EXECUTE classpath", expectedRoots, urlsOfCp4Tests(cp));
}
示例5: testRecursiveCompileTestDependency
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testRecursiveCompileTestDependency() throws Exception {
generateTestingSuite();
NbModuleProject modD = generateTestingSuiteComponent(testSuite,"d", "",
"<test-dependency>\n" +
"<code-name-base>org.example.a</code-name-base>\n" +
"<recursive/>\n" +
"<compile-dependency/>\n" +
// "<test/>\n" +
"</test-dependency>\n", "");
ClassPathProvider cpp = modD.getLookup().lookup(ClassPathProvider.class);
ClassPath cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.COMPILE);
Set<String> expectedRoots = new TreeSet<String>();
expectedRoots.addAll(TESTLIBS);
expectedRoots.add(urlForJar(modD.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modA.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modB.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modC.getModuleJarLocation().getPath()));
assertEquals("correct TEST COMPILE classpath", expectedRoots, urlsOfCp4Tests(cp));
cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.EXECUTE);
expectedRoots.add(urlForJar(modD.getTestClassesDirectory("unit").getPath()));
assertEquals("correct TEST EXECUTE classpath", expectedRoots, urlsOfCp4Tests(cp));
}
示例6: getHandleClassName
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public static ElementHandle<TypeElement> getHandleClassName(String qualifiedClassName,
Project project) throws IOException {
FileObject root = MiscUtilities.findSourceRoot(project);
ClassPathProvider provider = project.getLookup().lookup(
ClassPathProvider.class);
ClassPath sourceCp = provider.findClassPath(root, ClassPath.SOURCE);
ClassPath compileCp = provider.findClassPath(root, ClassPath.COMPILE);
ClassPath bootCp = provider.findClassPath(root, ClassPath.BOOT);
ClasspathInfo cpInfo = ClasspathInfo.create(bootCp, compileCp, sourceCp);
ClassIndex ci = cpInfo.getClassIndex();
int beginIndex = qualifiedClassName.lastIndexOf('.') + 1;
String simple = qualifiedClassName.substring(beginIndex);
Set<ElementHandle<TypeElement>> handles = ci.getDeclaredTypes(
simple, ClassIndex.NameKind.SIMPLE_NAME,
EnumSet.of(ClassIndex.SearchScope.SOURCE,
ClassIndex.SearchScope.DEPENDENCIES));
for (final ElementHandle<TypeElement> handle : handles) {
if (qualifiedClassName.equals(handle.getQualifiedName())) {
return handle;
}
}
return null;
}
示例7: gerClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public static List<ClassPath> gerClassPath(Project project) {
List<ClassPath> paths = new ArrayList<>();
List<SourceGroup> groups = new ArrayList<>();
groups.addAll(Arrays.asList(ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)));
ClassPathProvider cpp = project.getLookup().lookup(ClassPathProvider.class);
for (SourceGroup group : groups) {
ClassPath cp = cpp.findClassPath(group.getRootFolder(), ClassPath.COMPILE);
if (cp != null) {
paths.add(cp);
}
cp = cpp.findClassPath(group.getRootFolder(), ClassPath.SOURCE);
if (cp != null) {
paths.add(cp);
}
}
return paths;
}
示例8: findClassDirectories
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
/**
* Find directory names holding built classes of the Project
*
* @param project the project which is examined
* @return List<String> the directories storing the build java classes,
* e.g. <code>build/classes</code>
*/
public List<String> findClassDirectories( Project project ) {
List<String> classDirectories = new ArrayList<>();
final ClassPathProvider cpp = (ClassPathProvider)project.getLookup().lookup(ClassPathProvider.class);
final Sources s = (Sources)project.getLookup().lookup(Sources.class);
final SourceGroup []sourceGroups = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int j = 0; j < sourceGroups.length; j++ ) {
final SourceGroup sg = sourceGroups[j];
final FileObject sgRootFolder = sg.getRootFolder();
final ClassPath cp = cpp.findClassPath( sgRootFolder, ClassPath.EXECUTE );
for (FileObject root : cp.getRoots()) {
final File file = FileUtil.toFile( root );
if (file != null && file.isDirectory()) {
classDirectories.add( file.toString() );
}
}
}
return classDirectories;
}
示例9: findClassDirectories
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
/**
* Find directory names holding built classes of the Project
*
* @param project the project which is examined
* @return List<String> the directories storing the build java classes,
* e.g. <code>build/classes</code>
*/
public List<String> findClassDirectories( Project project ) {
List<String> classDirectories = new ArrayList<String>();
final ClassPathProvider cpp = (ClassPathProvider)project.getLookup().lookup(ClassPathProvider.class);
final Sources s = (Sources)project.getLookup().lookup(Sources.class);
final SourceGroup []sourceGroups = s.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
for (int j = 0; j < sourceGroups.length; j++ ) {
final SourceGroup sg = sourceGroups[j];
final FileObject sgRootFolder = sg.getRootFolder();
final ClassPath cp = cpp.findClassPath( sgRootFolder, ClassPath.EXECUTE );
for (FileObject root : cp.getRoots()) {
final File file = FileUtil.toFile( root );
if (file != null && file.isDirectory()) {
classDirectories.add( file.toString() );
}
}
}
return classDirectories;
}
示例10: findClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
@Override
public ClassPath findClassPath(FileObject file, String type) {
Project p = FileOwnerQuery.getOwner(file);
LOG.log(Level.FINE, "findClassPath({0}, {1}) on project {2}", new Object[] {file, type, p});
if (p != null) {
ClassPathProvider cpp = p.getLookup().lookup(ClassPathProvider.class);
if (cpp != null) {
final ClassPath result = cpp.findClassPath(file, type);
LOG.log(Level.FINE, "findClassPath({0}, {1}) -> {2} from {3}", new Object[] {file, type, result, cpp});
return result;
} else {
LOG.log(Level.FINE, "cpp.findClassPath({0}, {1}) -> null", new Object[] {file, type});
return null;
}
} else {
return null;
}
}
示例11: getProjectTestArtifacts
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
private List<FileObject> getProjectTestArtifacts(final Project project) {
final ClassPathProvider cpProvider = project.getLookup().lookup(ClassPathProvider.class);
final Collection<FileObject> testFolders = getTestFolders(project);
List<FileObject> result = null;
for (FileObject testRoot : testFolders) {
ClassPath testClassPath = cpProvider.findClassPath(testRoot, ClassPath.COMPILE);
if (testClassPath != null) {
if (result == null) {
if (testFolders.size() == 1) {
return Collections.<FileObject>singletonList(testRoot);
} else {
result = new ArrayList<FileObject>(3);
}
}
result.add(testRoot);
}
}
return (result != null) ? result : Collections.<FileObject>emptyList();
}
示例12: testPropagatesFlags
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public final void testPropagatesFlags() throws IOException {
InstanceContent ic = new InstanceContent();
Lookup lookup = new AbstractLookup(ic);
final URL root1 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root1")));
final URL root2 = FileUtil.urlForArchiveOrDir(FileUtil.normalizeFile(new File(getWorkDir(),"root2")));
ProviderImpl defaultCP = new ProviderImpl();
final MutableCPImpl cpImpl = new MutableCPImpl(root1);
defaultCP.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(cpImpl));
ClassPathProviderMerger instance = new ClassPathProviderMerger(defaultCP);
ClassPathProvider result = instance.merge(lookup);
ClassPath compile = result.findClassPath(null, ClassPath.COMPILE);
assertNotNull(compile);
assertEquals(0, compile.getFlags().size());
final ProviderImpl additional = new ProviderImpl();
final MutableCPImpl addCpImpl = new MutableCPImpl(root2);
addCpImpl.add(ClassPath.Flag.INCOMPLETE);
additional.paths.put(ClassPath.COMPILE, ClassPathFactory.createClassPath(addCpImpl));
ic.add(additional);
assertEquals(1, compile.getFlags().size());
assertSame(compile, result.findClassPath(null, ClassPath.COMPILE));
addCpImpl.remove(ClassPath.Flag.INCOMPLETE);
assertEquals(0, compile.getFlags().size());
addCpImpl.add(ClassPath.Flag.INCOMPLETE);
assertEquals(1, compile.getFlags().size());
}
示例13: testJavaPlatformCaching
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testJavaPlatformCaching() throws IOException {
FileObject artefact = getSourceFile (FILE_IN_PACKAGE);
Lookup.getDefault().lookup(MockSLQ.class).register(this.srcRoot, new SpecificationVersion("9")); //NOI18N
assertEquals("9", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
ClassPathProvider cpp = new DefaultClassPathProvider ();
final Logger log = Logger.getLogger(DefaultClassPathProvider.class.getName());
final H h = new H();
final Level origLevel = log.getLevel();
log.setLevel(Level.FINE);
log.addHandler(h);
try {
ClassPath cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
j9.getBootstrapLibraries(),
cp);
List<Optional<JavaPlatform>> plts = h.getCachedPlatforms();
assertEquals(1, plts.size());
assertEquals(j9, plts.get(0).get());
h.reset();
artefact = getSourceFile (FILE_IN_PACKAGE);
cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
j9.getBootstrapLibraries(),
cp);
plts = h.getCachedPlatforms();
assertEquals(0, plts.size());
} finally {
log.removeHandler(h);
log.setLevel(origLevel);
}
}
示例14: findClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public ClassPath findClassPath(FileObject file, String type) {
for (ClassPathProvider cpp : lkp.lookupAll(ClassPathProvider.class)) {
ClassPath cp = cpp.findClassPath(file, type);
if (cp != null) {
return cp;
}
}
return null;
}
示例15: testModularSources_UserModules
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入方法依赖的package包/类
public void testModularSources_UserModules() throws Exception {
final FileObject workDir = FileUtil.toFileObject(FileUtil.normalizeFile(this.getWorkDir()));
final FileObject modulesFolder = FileUtil.createFolder(workDir, "modules");
final FileObject[] modules = new FileObject[3];
for (int i = 0; i < modules.length; i++) {
modules[i] = FileUtil.createFolder(modulesFolder, "module" + (char) ('a'+i));
}
final ClassPath mp = ClassPathSupport.createClassPath(modules);
GlobalPathRegistry.getDefault().register(JavaClassPathConstants.MODULE_COMPILE_PATH, new ClassPath[]{mp});
try {
final FileObject artefact = libSourceRoots[0];
Lookup.getDefault().lookup(MockSLQ.class).register(artefact, new SpecificationVersion("1.8")); //NOI18N
assertEquals("1.8", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
ClassPathProvider cpp = new DefaultClassPathProvider ();
ClassPath cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_COMPILE_PATH);
assertNull ("DefaultClassPathProvider returned not null for MODULE_COMPILE_PATH with source level 8",cp);
Lookup.getDefault().lookup(MockSLQ.class).register(artefact, new SpecificationVersion("9")); //NOI18N
assertEquals("9", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
cpp = new DefaultClassPathProvider ();
cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_COMPILE_PATH);
assertEquals(
mp.entries().stream()
.map((e) -> e.getRoot())
.sorted((a,b) -> a.getPath().compareTo(b.getPath()))
.collect(Collectors.toList()),
cp.entries().stream()
.map((e) -> e.getRoot())
.sorted((a,b) -> a.getPath().compareTo(b.getPath()))
.collect(Collectors.toList()));
} finally {
GlobalPathRegistry.getDefault().unregister(JavaClassPathConstants.MODULE_COMPILE_PATH, new ClassPath[]{mp});
}
}