本文整理汇总了Java中org.netbeans.api.java.classpath.ClassPath.addPropertyChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java ClassPath.addPropertyChangeListener方法的具体用法?Java ClassPath.addPropertyChangeListener怎么用?Java ClassPath.addPropertyChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.api.java.classpath.ClassPath
的用法示例。
在下文中一共展示了ClassPath.addPropertyChangeListener方法的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: testCompileClasspathChanges
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testCompileClasspathChanges() throws Exception {
ClassPath cp = ClassPath.getClassPath(copyOfMiscDir.getFileObject("src"), ClassPath.COMPILE);
Set<String> expectedRoots = new TreeSet<String>();
assertEquals("right initial COMPILE classpath", expectedRoots, urlsOfCp(cp));
TestBase.TestPCL l = new TestBase.TestPCL();
cp.addPropertyChangeListener(l);
ModuleEntry ioEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.io");
assertNotNull(ioEntry);
copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(ioEntry)));
assertTrue("got changes", l.changed.contains(ClassPath.PROP_ROOTS));
l.changed.clear();
expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/modules/org-openide-io.jar"));
assertEquals("right COMPILE classpath after changing project.xml", expectedRoots, urlsOfCp(cp));
ModuleEntry utilEntry = copyOfMiscProject.getModuleList().getEntry("org.openide.util");
assertNotNull(utilEntry);
copyOfMiscXMLManager.addDependencies(Collections.singleton(new ModuleDependency(utilEntry)));
assertTrue("got changes again", l.changed.contains(ClassPath.PROP_ROOTS));
l.changed.clear();
expectedRoots.add(urlForJar("nbbuild/netbeans/" + TestBase.CLUSTER_PLATFORM + "/lib/org-openide-util.jar"));
assertEquals("right COMPILE classpath after changing project.xml again", expectedRoots, urlsOfCp(cp));
}
示例3: testFlagsEvents
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testFlagsEvents() throws IOException {
final File wd = FileUtil.normalizeFile(getWorkDir());
final URL cp1r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp1_root1")); //NOI18N
final URL cp2r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp2_root1")); //NOI18N
final MutableClassPathImpl cpImpl1 = new MutableClassPathImpl(cp1r1);
final MutableClassPathImpl cpImpl2 = new MutableClassPathImpl(cp2r1)
.add(ClassPath.Flag.INCOMPLETE);
final SelectorImpl selector = new SelectorImpl(
ClassPathFactory.createClassPath(cpImpl1),
ClassPathFactory.createClassPath(cpImpl2));
final ClassPath cp = ClassPathSupport.createMultiplexClassPath(selector);
assertEquals(0, cp.getFlags().size());
final MockPropertyChangeListener l = new MockPropertyChangeListener();
cp.addPropertyChangeListener(l);
selector.select(1);
l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS);
selector.select(0);
l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS);
cpImpl1.add(ClassPath.Flag.INCOMPLETE);
l.assertEvents(ClassPath.PROP_FLAGS);
cpImpl1.remove(ClassPath.Flag.INCOMPLETE);
l.assertEvents(ClassPath.PROP_FLAGS);
selector.select(1);
l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS, ClassPath.PROP_FLAGS);
}
示例4: registerListeners
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static void registerListeners(
JavadocRegistry jdr,
Set<ClassPath> classpaths,
Set<JavadocForBinaryQuery.Result> results,
ClassPath docRoots) {
for (ClassPath cpath : classpaths) {
cpath.addPropertyChangeListener(jdr);
}
for (JavadocForBinaryQuery.Result result : results) {
result.addChangeListener(jdr);
}
docRoots.addPropertyChangeListener (jdr);
}
示例5: testSourcePathImplementation
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testSourcePathImplementation () throws Exception {
ClassPathProviderImpl cpProvider = pp.getClassPathProvider();
ClassPath[] cps = cpProvider.getProjectClassPaths(ClassPath.SOURCE);
ClassPath cp = cps[0];
FileObject[] roots = cp.getRoots();
assertNotNull ("Roots can not be null",roots);
assertEquals("There must be one source root", 1, roots.length);
assertEquals("There must be src root",roots[0],sources);
TestListener tl = new TestListener();
cp.addPropertyChangeListener (tl);
FileObject newRoot = SourceRootsTest.addSourceRoot(helper, projdir,"src.other.dir","other");
assertTrue("Classpath must fire PROP_ENTRIES and PROP_ROOTS", tl.getEvents().containsAll(Arrays.asList(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS)));
roots = cp.getRoots();
assertNotNull ("Roots can not be null",roots);
assertEquals("There must be two source roots", 2, roots.length);
assertEquals("There must be src root",roots[0],sources);
assertEquals("There must be other root",roots[1],newRoot);
cp.removePropertyChangeListener(tl);
}
示例6: listenOnProcessorPath
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
private static void listenOnProcessorPath(
@NullAllowed final ClassPath cp,
@NonNull final APTUtils target) {
if (cp != null) {
cp.addPropertyChangeListener(WeakListeners.propertyChange(target, cp));
cp.getRoots();//so that the ClassPath starts listening on the filesystem
}
}
示例7: testNewlyCreatedSourceGroup
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testNewlyCreatedSourceGroup() throws Exception { // #190852
TestFileUtils.writeFile(d,
"pom.xml",
"<project xmlns='http://maven.apache.org/POM/4.0.0'>" +
"<modelVersion>4.0.0</modelVersion>" +
"<groupId>grp</groupId>" +
"<artifactId>art</artifactId>" +
"<packaging>jar</packaging>" +
"<version>0</version>" +
"</project>");
FileObject src = FileUtil.createFolder(d, "src/main/java");
FileObject tsrc = FileUtil.createFolder(d, "src/test/java");
ClassPath sourcepath = ClassPath.getClassPath(src, ClassPath.SOURCE);
ClassPath tsourcepath = ClassPath.getClassPath(tsrc, ClassPath.SOURCE);
assertRoots(sourcepath, src);
assertRoots(tsourcepath, tsrc);
MockPropertyChangeListener l = new MockPropertyChangeListener();
sourcepath.addPropertyChangeListener(l);
FileObject gsrc = FileUtil.createFolder(d, "target/generated-sources/xjc");
gsrc.createData("Whatever.class");
l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
assertRoots(sourcepath, src, gsrc);
assertSame(sourcepath, ClassPath.getClassPath(gsrc, ClassPath.SOURCE));
tsourcepath.addPropertyChangeListener(l);
FileObject gtsrc = FileUtil.createFolder(d, "target/generated-test-sources/jaxb");
gtsrc.createData("Whatever.class");
l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
assertRoots(tsourcepath, tsrc, gtsrc);
assertSame(tsourcepath, ClassPath.getClassPath(gtsrc, ClassPath.SOURCE));
}
示例8: getDelegate
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@NonNull
private FileBuiltQueryImplementation getDelegate() {
FileBuiltQueryImplementation res;
synchronized (this) {
res = delegate;
}
if (res == null) {
final List<String> from = new ArrayList<>();
final List<String> to = new ArrayList<>();
final Set<ClassPath> classpaths = Collections.newSetFromMap(new IdentityHashMap<>());
collectRoots(sourceModules, ProjectProperties.BUILD_MODULES_DIR, from, to, classpaths);
collectRoots(testModules, ProjectProperties.BUILD_TEST_MODULES_DIR, from, to, classpaths);
res = helper.createGlobFileBuiltQuery(
eval,
from.toArray(new String[from.size()]),
to.toArray(new String[to.size()]));
synchronized (this) {
if (delegate == null) {
for (Pair<ClassPath,PropertyChangeListener> cplp : currentPaths) {
cplp.first().removePropertyChangeListener(cplp.second());
}
currentPaths.clear();
for (ClassPath scp : classpaths) {
final PropertyChangeListener l = WeakListeners.propertyChange(this, scp);
scp.addPropertyChangeListener(l);
currentPaths.add(Pair.of(scp, l));
}
delegate = res;
} else {
res = delegate;
}
}
}
return res;
}
示例9: testModulesSetChangesFires
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testModulesSetChangesFires() throws IOException {
assertTrue(mtu.updateModuleRoots(false, src2));
final SourceRoots modules = mtu.newModuleRoots(false);
assertTrue(Arrays.equals(new FileObject[]{src2}, modules.getRoots()));
final SourceRoots sources = mtu.newSourceRoots(false);
assertEquals(
Arrays.stream(new FileObject[]{mod2c, mod2d})
.map((fo) -> fo.getPath())
.sorted()
.collect(Collectors.toList()),
Arrays.stream(sources.getRoots())
.map((fo) -> fo.getPath())
.sorted()
.collect(Collectors.toList()));
final MultiModule model = MultiModule.getOrCreate(modules, sources);
assertNotNull(model);
ClassPath scp = model.getModuleSources(mod2c.getParent().getNameExt());
assertNotNull(scp);
assertEquals(Arrays.asList(mod2c), Arrays.asList(scp.getRoots()));
scp = model.getModuleSources(mod2d.getParent().getNameExt());
assertNotNull(scp);
assertEquals(Arrays.asList(mod2d), Arrays.asList(scp.getRoots()));
final MockPropertyChangeListener l = new MockPropertyChangeListener(MultiModule.PROP_MODULES);
model.addPropertyChangeListener(l);
final String newModName = "lib.temp"; //NOI18N
final FileObject mod2e = src2.createFolder(newModName).createFolder("classes"); //NOI18N
l.assertEventCount(1);
scp = model.getModuleSources(newModName);
assertNotNull(scp);
assertEquals(Arrays.asList(mod2e), Arrays.asList(scp.getRoots()));
final MockPropertyChangeListener cpl = new MockPropertyChangeListener();
scp.addPropertyChangeListener(cpl);
mod2e.getParent().delete();
l.assertEventCount(1);
cpl.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
}
示例10: testModuleSourcesChangesFires
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testModuleSourcesChangesFires() throws IOException {
final FileObject wd = FileUtil.toFileObject(FileUtil.normalizeFile(getWorkDir()));
final FileObject modulesFolder = wd.createFolder("modules"); //NOI18N
assertNotNull(modulesFolder);
final FileObject classesFolder = modulesFolder.createFolder("module").createFolder("classes"); //NOI18N
assertTrue(mtu.updateModuleRoots(false, "classes:resources",modulesFolder)); //NOI18N
final SourceRoots modules = mtu.newModuleRoots(false);
assertTrue(Arrays.equals(new FileObject[]{modulesFolder}, modules.getRoots()));
final SourceRoots sources = mtu.newSourceRoots(false);
assertEquals(
Arrays.stream(new FileObject[]{classesFolder})
.map((fo) -> fo.getPath())
.sorted()
.collect(Collectors.toList()),
Arrays.stream(sources.getRoots())
.map((fo) -> fo.getPath())
.sorted()
.collect(Collectors.toList()));
final MultiModule model = MultiModule.getOrCreate(modules, sources);
assertNotNull(model);
ClassPath scp = model.getModuleSources("module"); //NOI18N
assertNotNull(scp);
assertEquals(Arrays.asList(classesFolder), Arrays.asList(scp.getRoots()));
final MockPropertyChangeListener l = new MockPropertyChangeListener();
scp.addPropertyChangeListener(l);
final FileObject resourcesFolder = modulesFolder.getFileObject("module").createFolder("resources"); //NOI18N
l.assertEvents(ClassPath.PROP_ROOTS);
classesFolder.delete();
l.assertEvents(ClassPath.PROP_ROOTS);
}
示例11: testIncludesExcludes
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testIncludesExcludes() throws Exception {
ClassPath cp = pp.getClassPathProvider().getProjectSourcesClassPath(ClassPath.SOURCE);
assertEquals(Collections.singletonList(sources), Arrays.asList(cp.getRoots()));
FileObject objectJava = FileUtil.createData(sources, "java/lang/Object.java");
FileObject jcJava = FileUtil.createData(sources, "javax/swing/JComponent.java");
FileObject doc = FileUtil.createData(sources, "javax/swing/doc-files/index.html");
assertTrue(cp.contains(objectJava));
assertTrue(cp.contains(objectJava.getParent()));
assertTrue(cp.contains(jcJava));
assertTrue(cp.contains(jcJava.getParent()));
assertTrue(cp.contains(doc));
assertTrue(cp.contains(doc.getParent()));
TestListener tl = new TestListener();
// XXX #97391: sometimes, unpredictably, fired:
tl.forbid(ClassPath.PROP_ENTRIES);
tl.forbid(ClassPath.PROP_ROOTS);
cp.addPropertyChangeListener(tl);
EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
ep.setProperty(ProjectProperties.INCLUDES, "javax/swing/");
ep.setProperty(ProjectProperties.EXCLUDES, "**/doc-files/");
helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
pm.saveProject(pp);
assertEquals(Collections.singleton(ClassPath.PROP_INCLUDES), tl.getEvents());
assertFalse(cp.contains(objectJava));
assertFalse(cp.contains(objectJava.getParent()));
assertTrue(cp.contains(jcJava));
assertTrue(cp.contains(jcJava.getParent()));
assertTrue(cp.contains(jcJava.getParent().getParent()));
assertFalse(cp.contains(doc));
assertFalse(cp.contains(doc.getParent()));
}
示例12: testFlagsEvents
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testFlagsEvents() throws Exception {
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);
final AtomicInteger count = new AtomicInteger();
compile.addPropertyChangeListener((evt) -> {
if (ClassPath.PROP_FLAGS.equals(evt.getPropertyName())) {
count.incrementAndGet();
}
});
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, count.get());
count.set(0);
addCpImpl.remove(ClassPath.Flag.INCOMPLETE);
assertEquals(1, count.get());
count.set(0);
addCpImpl.add(ClassPath.Flag.INCOMPLETE);
assertEquals(1, count.get());
count.set(0);
}
示例13: testEvents
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
/**
* Checks that single event is fired during opening (closing) of projects
*/
public void testEvents() throws Exception {
final File wd = getWorkDir();
final File root1 = FileUtil.normalizeFile(new File (wd,"src1")); //NOI18N
final File root2 = FileUtil.normalizeFile(new File (wd,"src2")); //NOI18N
root1.mkdir();
root2.mkdir();
final ClassPathProvider cpp = new DefaultClassPathProvider ();
final ClassPath defaultCompile = cpp.findClassPath(FileUtil.toFileObject(wd), ClassPath.COMPILE);
assertNotNull(defaultCompile);
assertFalse(contains(defaultCompile, Utilities.toURI(root1).toURL()));
assertFalse(contains(defaultCompile, Utilities.toURI(root2).toURL()));
final Listener listener = new Listener();
defaultCompile.addPropertyChangeListener(listener);
final GlobalPathRegistry regs = GlobalPathRegistry.getDefault();
final ClassPath compileCpProject1 = ClassPathSupport.createClassPath(Utilities.toURI(root1).toURL());
final ClassPath compileCpProject2 = ClassPathSupport.createClassPath(Utilities.toURI(root2).toURL());
//Simulate projects open
RunnableFuture<Project[]> barrier = new FutureTask<Project[]>(new Callable<Project[]>() {
@Override
public Project[] call() throws Exception {
return new Project[0];
}
});
OpenProject.future = barrier;
regs.register(ClassPath.COMPILE, new ClassPath[]{compileCpProject1});
assertFalse(contains(defaultCompile, Utilities.toURI(root1).toURL()));
assertFalse(listener.awaitEvent());
assertEquals(0, listener.get());
regs.register(ClassPath.COMPILE, new ClassPath[]{compileCpProject2});
assertFalse(contains(defaultCompile, Utilities.toURI(root2).toURL()));
assertFalse(listener.awaitEvent());
assertEquals(0, listener.get());
barrier.run();
assertTrue(listener.awaitEvent());
assertEquals(1, listener.get());
assertTrue(contains(defaultCompile, Utilities.toURI(root1).toURL()));
assertTrue(contains(defaultCompile, Utilities.toURI(root2).toURL()));
//Simulate projects close
barrier = new FutureTask<Project[]>(new Callable<Project[]>() {
@Override
public Project[] call() throws Exception {
return new Project[0];
}
});
OpenProject.future = barrier;
listener.reset();
regs.unregister(ClassPath.COMPILE, new ClassPath[]{compileCpProject1});
assertTrue(contains(defaultCompile, Utilities.toURI(root1).toURL()));
assertFalse(listener.awaitEvent());
assertEquals(0, listener.get());
regs.unregister(ClassPath.COMPILE, new ClassPath[]{compileCpProject2});
assertTrue(contains(defaultCompile, Utilities.toURI(root2).toURL()));
assertFalse(listener.awaitEvent());
assertEquals(0, listener.get());
barrier.run();
assertTrue(listener.awaitEvent());
assertEquals(1, listener.get());
assertFalse(contains(defaultCompile, Utilities.toURI(root1).toURL()));
assertFalse(contains(defaultCompile, Utilities.toURI(root2).toURL()));
}
示例14: addNotify
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
@Override protected void addNotify() {
endorsed = p.getLookup().lookup(ProjectSourcesClassPathProvider.class).getProjectClassPaths(ClassPathSupport.ENDORSED);
for (ClassPath cp : endorsed) {
cp.addPropertyChangeListener(this);
}
}
示例15: testCompileClasspathChanges
import org.netbeans.api.java.classpath.ClassPath; //导入方法依赖的package包/类
public void testCompileClasspathChanges() throws Exception {
clearWorkDir();
FreeformProject simple2 = copyProject(simple);
FileObject myAppJava2 = simple2.getProjectDirectory().getFileObject("src/org/foo/myapp/MyApp.java");
assertNotNull("found MyApp.java", myAppJava2);
ClassPath cp = ClassPath.getClassPath(myAppJava2, ClassPath.COMPILE);
assertNotNull("have some COMPILE classpath for src/", cp);
assertEquals("have two entries in " + cp, 2, cp.entries().size());
assertEquals("have two roots in " + cp, 2, cp.getRoots().length);
assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class"));
assertNotNull("found NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class"));
TestPCL l = new TestPCL();
cp.addPropertyChangeListener(l);
EditableProperties props = new EditableProperties();
FileObject buildProperties = simple2.getProjectDirectory().getFileObject("build.properties");
assertNotNull("have build.properties", buildProperties);
InputStream is = buildProperties.getInputStream();
try {
props.load(is);
} finally {
is.close();
}
assertEquals("right original src.cp", "${lib.dir}/lib1.jar:${lib.dir}/lib2.jar", props.getProperty("src.cp"));
props.setProperty("src.cp", "${lib.dir}/lib1.jar");
FileLock lock = buildProperties.lock();
try {
final OutputStream os = buildProperties.getOutputStream(lock);
try {
props.store(os);
} finally {
// close file under ProjectManager.readAccess so that events are fired synchronously
ProjectManager.mutex().readAccess(new Mutex.ExceptionAction<Void>() {
public Void run() throws Exception {
os.close();
return null;
}
});
}
} finally {
lock.releaseLock();
}
/* XXX failing: #137767
assertEquals("ROOTS fired", new HashSet<String>(Arrays.asList(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS)), l.changed);
assertEquals("have one entry in " + cp, 1, cp.entries().size());
assertEquals("have one root in " + cp, 1, cp.getRoots().length);
assertNotNull("found WeakSet in " + cp, cp.findResource("org/openide/util/WeakSet.class"));
assertNull("did not find NullInputStream", cp.findResource("org/openide/util/io/NullInputStream.class"));
*/
}