本文整理汇总了Java中org.netbeans.spi.java.classpath.ClassPathProvider类的典型用法代码示例。如果您正苦于以下问题:Java ClassPathProvider类的具体用法?Java ClassPathProvider怎么用?Java ClassPathProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassPathProvider类属于org.netbeans.spi.java.classpath包,在下文中一共展示了ClassPathProvider类的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: testModularSources_SystemModules
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
public void testModularSources_SystemModules() throws Exception {
final FileObject artefact = getSourceFile (FILE_IN_PACKAGE);
Lookup.getDefault().lookup(MockSLQ.class).register(this.srcRoot, new SpecificationVersion("1.8")); //NOI18N
assertEquals("1.8", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
ClassPathProvider cpp = new DefaultClassPathProvider ();
ClassPath cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
assertNull ("DefaultClassPathProvider returned not null for MODULE_BOOT_PATH with source level 8",cp);
cp = cpp.findClassPath(artefact, ClassPath.BOOT);
assertEquals("DefaultClassPathProvider returned invalid classpath for BOOT with source level 8",
JavaPlatform.getDefault().getBootstrapLibraries(),
cp);
Lookup.getDefault().lookup(MockSLQ.class).register(this.srcRoot, new SpecificationVersion("9")); //NOI18N
assertEquals("9", SourceLevelQuery.getSourceLevel(artefact)); //NOI18N
cpp = new DefaultClassPathProvider ();
cp = cpp.findClassPath(artefact, JavaClassPathConstants.MODULE_BOOT_PATH);
assertEquals ("DefaultClassPathProvider returned invalid classpath for MODULE_BOOT_PATH with source level 9",
j9.getBootstrapLibraries(),
cp);
cp = cpp.findClassPath(artefact, ClassPath.BOOT);
assertEquals("DefaultClassPathProvider returned invalid classpath for BOOT with source level 9",
j9.getBootstrapLibraries(),
cp);
}
示例3: getProjectClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
/**
* Returns the project classpath including project build paths.
* Can be used to set classpath for custom classloader.
*
* @param projectFile may not be used in method realization
* @return List of java.io.File objects representing each entry on the classpath.
*/
@Override
public List<URL> getProjectClassPath(FileObject projectFile) {
List<URL> projectClassPathEntries = new ArrayList<URL>();
SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
if (sgs.length < 1) {
return projectClassPathEntries;
}
FileObject sourceRoot = sgs[0].getRootFolder();
ClassPathProvider cpProv = project.getLookup().lookup(ClassPathProvider.class);
ClassPath cp = cpProv.findClassPath(sourceRoot, ClassPath.EXECUTE);
if(cp == null){
cp = cpProv.findClassPath(sourceRoot, ClassPath.COMPILE);
}
for (ClassPath.Entry cpEntry : cp.entries()) {
if(cpEntry.isValid()){
//if project isn't build, there may be number of invalid entries and may be in some other cases
projectClassPathEntries.add(cpEntry.getURL());
}
}
return projectClassPathEntries;
}
示例4: testSimpleRuntimeTestDependency
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
public void testSimpleRuntimeTestDependency() 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()));
assertEquals("correct TEST COMPILE classpath", expectedRoots, urlsOfCp4Tests(cp));
cp = cpp.findClassPath(modD.getTestSourceDirectory("unit"), ClassPath.EXECUTE);
expectedRoots = new TreeSet<String>();
expectedRoots.addAll(TESTLIBS);
expectedRoots.add(urlForJar(modD.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modA.getModuleJarLocation().getPath()));
expectedRoots.add(urlForJar(modD.getTestClassesDirectory("unit").getPath()));
assertEquals("correct TEST EXECUTE classpath", expectedRoots, urlsOfCp4Tests(cp));
}
示例5: 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));
}
示例6: 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));
}
示例7: setUp
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
ClassPathProvider cpp = new ClassPathProvider() {
@Override
public ClassPath findClassPath(FileObject file, String type) {
if (type.equals(ClassPath.SOURCE)) {
return ClassPathSupport.createClassPath(new FileObject[]{FileUtil.toFileObject(getDataDir())});
}
if (type.equals(ClassPath.COMPILE)) {
return ClassPathSupport.createClassPath(new FileObject[0]);
}
if (type.equals(ClassPath.BOOT)) {
return createClassPath(System.getProperty("sun.boot.class.path"));
}
return null;
}
};
SharedClassObject loader = JavaDataLoader.findObject(JavaDataLoader.class, true);
SourceUtilsTestUtil.prepareTest(new String[]{"org/netbeans/modules/java/source/resources/layer.xml","org/netbeans/modules/java/source/base/layer.xml"}, new Object[]{loader/*, cpp*/});
JEditorPane.registerEditorKitForContentType("text/x-java", "org.netbeans.modules.editor.java.JavaKit");
File cacheFolder = new File(getWorkDir(), "var/cache/index");
cacheFolder.mkdirs();
IndexUtil.setCacheFolder(cacheFolder);
}
示例8: setUp
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
/**
* We need our own data loader to use guarded blocks.
*/
@Override
protected void setUp() throws Exception {
SourceUtilsTestUtil.prepareTest(new String[0], new Object[0]); //to initialize the correct lookup instance
FileUtil.setMIMEType("java", "text/x-java");
MockMimeLookup.setInstances(
MimePath.parse("text/x-java"),
new JavaGuardedSectionsFactory(),
new org.netbeans.modules.editor.NbEditorKit());
MockMimeLookup mml = new MockMimeLookup();
ClassPathProvider cpp = new ClassPathProvider() {
public ClassPath findClassPath(FileObject file, String type) {
if (type.equals(ClassPath.SOURCE))
return ClassPathSupport.createClassPath(new FileObject[] {FileUtil.toFileObject(getDataDir())});
if (type.equals(ClassPath.COMPILE))
return ClassPathSupport.createClassPath(new FileObject[0]);
if (type.equals(ClassPath.BOOT))
return createClassPath(System.getProperty("sun.boot.class.path"));
return null;
}
};
SourceUtilsTestUtil.prepareTest(new String[0], new Object[] {mml, new GuardedDataLoader(), cpp});
File cacheFolder = new File(getWorkDir(), "var/cache/index");
cacheFolder.mkdirs();
IndexUtil.setCacheFolder(cacheFolder);
}
示例9: 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;
}
}
示例10: ProxyClassPathImplementation
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
public ProxyClassPathImplementation(ClassPathProvider dominant, Lookup context, FileObject fo, String type) {
assert dominant != null;
this.type = type;
this.file = fo;
mainProvider = dominant;
providers = context.lookupResult(ClassPathProvider.class);
flagsListener = (ev) -> {
if (ProxyFilteringCPI.PROP_CP_FLAGS.equals(ev.getPropertyName())) {
synchronized (this) {
this.flagsCache = null;
}
firePropertyChange(new PropertyChangeEvent(this, PROP_FLAGS, null, null));
}
};
checkProviders();
lookupList = (ev) -> {
checkProviders();
};
providers.addLookupListener(lookupList);
}
示例11: 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());
}
示例12: gerClassPath
import org.netbeans.spi.java.classpath.ClassPathProvider; //导入依赖的package包/类
public static List<ClassPath> gerClassPath(Project project) {
List<ClassPath> paths = new ArrayList<ClassPath>();
List<SourceGroup> groups = new ArrayList<SourceGroup>();
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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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;
}