Java Code Examples for org.netbeans.api.java.classpath.ClassPath#addPropertyChangeListener()

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#addPropertyChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClassPathProviderImplTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 2
Source File: WebAppParseSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static WebAppParseProxy create(JspParserImpl jspParser, WebModule wm) {
    WebAppParseSupport instance = new WebAppParseSupport(jspParser, wm);

    // register file listener (listen to changes of tld files, web.xml)
    try {
        FileSystem fs = wm.getDocumentBase().getFileSystem();
        fs.addFileChangeListener(FileUtil.weakFileChangeListener(instance.fileSystemListener, fs));
    } catch (FileStateInvalidException ex) {
        LOG.log(Level.INFO, null, ex);
    }

    // register weak class path listeners
    if (instance.wmRoot != null) { // in fact should not happen, see #154892 for more information
        ClassPath compileCP = ClassPath.getClassPath(instance.wmRoot, ClassPath.COMPILE);
        if (compileCP != null) {
            compileCP.addPropertyChangeListener(WeakListeners.propertyChange(instance, compileCP));
        }
        ClassPath executeCP = ClassPath.getClassPath(instance.wmRoot, ClassPath.EXECUTE);
        if (executeCP != null) {
            executeCP.addPropertyChangeListener(WeakListeners.propertyChange(instance, executeCP));
        }
    }

    return instance;
}
 
Example 3
Source File: SourcePathImplementationTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 4
Source File: MuxClassPathImplementationTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: JavadocRegistry.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
    
}
 
Example 6
Source File: J2SEPlatformImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 7
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void addNotify() {
    pp.addChangeListener(this);
    endorsed = pp.project.getLookup().lookup(ProjectSourcesClassPathProvider.class).getProjectClassPath(ENDORSED);
    for (ClassPath cp : endorsed) {
        cp.addPropertyChangeListener(this);
    }
}
 
Example 8
Source File: ClassPathProviderMergerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: SourcePathImplementationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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()));
}
 
Example 10
Source File: MultiModuleTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: MultiModuleTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: MultiModuleFileBuiltQueryImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 13
Source File: ClassPathProviderImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 14
Source File: APTUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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
    }
}
 
Example 15
Source File: MultiModuleBinariesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testModuleSetChangesFires() throws IOException {
    assertTrue(mtu.updateModuleRoots(false, src1));
    final SourceRoots modules = mtu.newModuleRoots(false);
    assertTrue(Arrays.equals(new FileObject[]{src1}, modules.getRoots()));
    final SourceRoots sources = mtu.newSourceRoots(false);
    assertEquals(
            Arrays.stream(new FileObject[]{mod1a, mod1b, mod1d})
                .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);
    final SourceRoots testModules = mtu.newModuleRoots(true);
    assertTrue(Arrays.equals(new FileObject[]{}, testModules.getRoots()));
    final SourceRoots testSources = mtu.newSourceRoots(true);

    final BinaryForSourceQueryImplementation impl = QuerySupport.createMultiModuleBinaryForSourceQuery(
            tp.getUpdateHelper().getAntProjectHelper(),
            tp.getEvaluator(),
            modules,
            sources,
            testModules,
            testSources);
    assertNotNull(impl);
    Lookup.getDefault().lookup(DelegatingB4SQImpl.class).setDelegate(impl);
    final ClassPathImplementation cpImpl = ModuleClassPaths.createMultiModuleBinariesPath(model, true, false);
    assertNotNull(cpImpl);
    final ClassPath cp = ClassPathFactory.createClassPath(cpImpl);
    assertEquals(
            Arrays.stream(new FileObject[]{mod1a, mod1b, mod1d})
                .flatMap((fo) -> Arrays.stream(new URL[]{
                    mtu.distFor(fo.getParent().getNameExt())}))
                .sorted((u1,u2) -> u1.toString().compareTo(u2.toString()))
                .distinct()
                .collect(Collectors.toList()),
            cp.entries().stream()
                .map((e) -> e.getURL())
                .sorted((u1,u2) -> u1.toString().compareTo(u2.toString()))
                .collect(Collectors.toList()));

    final MockPropertyChangeListener l = new MockPropertyChangeListener();
    cp.addPropertyChangeListener(l);
    final FileObject foomodule = src1.createFolder("foomodule").createFolder("classes");    //NOI18N
    l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
    foomodule.getParent().delete();
    l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
}
 
Example 16
Source File: MultiModuleBinariesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testDistFolderChangesFires() {
    assertTrue(mtu.updateModuleRoots(false, src1));
    final SourceRoots modules = mtu.newModuleRoots(false);
    assertTrue(Arrays.equals(new FileObject[]{src1}, modules.getRoots()));
    final SourceRoots sources = mtu.newSourceRoots(false);
    assertEquals(
            Arrays.stream(new FileObject[]{mod1a, mod1b, mod1d})
                .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);
    final SourceRoots testModules = mtu.newModuleRoots(true);
    assertTrue(Arrays.equals(new FileObject[]{}, testModules.getRoots()));
    final SourceRoots testSources = mtu.newSourceRoots(true);

    final BinaryForSourceQueryImplementation impl = QuerySupport.createMultiModuleBinaryForSourceQuery(
            tp.getUpdateHelper().getAntProjectHelper(),
            tp.getEvaluator(),
            modules,
            sources,
            testModules,
            testSources);
    assertNotNull(impl);
    Lookup.getDefault().lookup(DelegatingB4SQImpl.class).setDelegate(impl);
    final ClassPathImplementation cpImpl = ModuleClassPaths.createMultiModuleBinariesPath(model, true, false);
    assertNotNull(cpImpl);
    final ClassPath cp = ClassPathFactory.createClassPath(cpImpl);
    assertEquals(
            Arrays.stream(new FileObject[]{mod1a, mod1b, mod1d})
                .flatMap((fo) -> Arrays.stream(new URL[]{
                    mtu.distFor(fo.getParent().getNameExt())}))
                .sorted((u1,u2) -> u1.toString().compareTo(u2.toString()))
                .distinct()
                .collect(Collectors.toList()),
            cp.entries().stream()
                .map((e) -> e.getURL())
                .sorted((u1,u2) -> u1.toString().compareTo(u2.toString()))
                .collect(Collectors.toList()));

    final MockPropertyChangeListener l = new MockPropertyChangeListener();
    cp.addPropertyChangeListener(l);
    setProperty(ProjectProperties.DIST_DIR, "release"); //NOI18N
    l.assertEvents(ClassPath.PROP_ENTRIES, ClassPath.PROP_ROOTS);
}
 
Example 17
Source File: ClasspathsTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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"));
     */
}
 
Example 18
Source File: SourcePathImplementationTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testIncludesFiredJustOnce() throws Exception {
    File src1 = new File(getWorkDir(), "src1");
    src1.mkdir();
    File src2 = new File(getWorkDir(), "src2");
    src2.mkdir();
    AntProjectHelper h = J2SEProjectGenerator.createProject(new File(getWorkDir(), "prj"), "test", new File[] {src1, src2}, new File[0], null, null, null);
    Project p = ProjectManager.getDefault().findProject(h.getProjectDirectory());
    FileOwnerQuery.markExternalOwner(Utilities.toURI(src1), p, FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
    ClassPath cp = ClassPath.getClassPath(FileUtil.toFileObject(src1), ClassPath.SOURCE);
    assertNotNull(cp);        
    assertEquals(2, cp.getRoots().length);
    ClassPath.Entry cpe2 = cp.entries().get(1);
    assertEquals(Utilities.toURI(src2).toURL(), cpe2.getURL());
    assertTrue(cpe2.includes("stuff/"));
    assertTrue(cpe2.includes("whatever/"));
    class L implements PropertyChangeListener {
        int cnt;
        public void propertyChange(PropertyChangeEvent e) {
            if (ClassPath.PROP_INCLUDES.equals(e.getPropertyName())) {
                cnt++;
            }
        }
    }
    L l = new L();
    cp.addPropertyChangeListener(l);
    EditableProperties ep = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
    ep.setProperty(ProjectProperties.INCLUDES, "whatever/");
    h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    ProjectManager.getDefault().saveProject(p);
    assertEquals(1, l.cnt);
    assertFalse(cpe2.includes("stuff/"));
    assertTrue(cpe2.includes("whatever/"));
    ep.setProperty(ProjectProperties.INCLUDES, "whateverelse/");
    h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    ProjectManager.getDefault().saveProject(p);
    assertEquals(2, l.cnt);
    assertFalse(cpe2.includes("stuff/"));
    assertFalse(cpe2.includes("whatever/"));
    ep.remove(ProjectProperties.INCLUDES);
    h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
    ProjectManager.getDefault().saveProject(p);
    assertEquals(3, l.cnt);
    assertTrue(cpe2.includes("stuff/"));
    assertTrue(cpe2.includes("whatever/"));
}
 
Example 19
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override protected void addNotify() {
    endorsed = p.getLookup().lookup(ProjectSourcesClassPathProvider.class).getProjectClassPaths(ClassPathSupport.ENDORSED);
    for (ClassPath cp : endorsed) {
        cp.addPropertyChangeListener(this);
    }
}
 
Example 20
Source File: MuxClassPathImplementationTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testEvents() throws IOException {
    final File wd = FileUtil.normalizeFile(getWorkDir());
    final URL cp1r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp1_root1"));   //NOI18N
    final URL cp1r2 = FileUtil.urlForArchiveOrDir(new File(wd, "cp1_root2"));   //NOI18N
    final URL cp2r1 = FileUtil.urlForArchiveOrDir(new File(wd, "cp2_root1"));   //NOI18N
    final URL cp2r2 = FileUtil.urlForArchiveOrDir(new File(wd, "cp2_root2"));   //NOI18N
    final MutableClassPathImpl cp1 = new MutableClassPathImpl(cp1r1);
    final MutableClassPathImpl cp2 = new MutableClassPathImpl(cp2r1);
    final SelectorImpl selector = new SelectorImpl(
            ClassPathFactory.createClassPath(cp1),
            ClassPathFactory.createClassPath(cp2));
    final ClassPath cp = ClassPathSupport.createMultiplexClassPath(selector);
    List<URL> res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Collections.singletonList(cp1r1), res);
    final MockPropertyChangeListener mpcl = new MockPropertyChangeListener(ClassPath.PROP_ENTRIES);
    mpcl.ignore(ClassPath.PROP_FLAGS);
    mpcl.ignore(ClassPath.PROP_INCLUDES);
    mpcl.ignore(ClassPath.PROP_ROOTS);
    cp.addPropertyChangeListener(mpcl);
    cp1.add(cp1r2);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Arrays.asList(cp1r1, cp1r2), res);
    mpcl.assertEventCount(1);
    cp1.remove(cp1r1);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Collections.singletonList(cp1r2), res);
    mpcl.assertEventCount(1);
    selector.select(1);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Collections.singletonList(cp2r1), res);
    mpcl.assertEventCount(1);
    cp2.add(cp2r2);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Arrays.asList(cp2r1, cp2r2), res);
    mpcl.assertEventCount(1);
    cp2.remove(cp2r1);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Collections.singletonList(cp2r2), res);
    mpcl.assertEventCount(1);
    cp1.remove(cp1r2);
    mpcl.assertEventCount(0);
    cp1.add(cp1r1);
    mpcl.assertEventCount(0);
    res = cp.entries().stream()
            .map((e)->e.getURL())
            .collect(Collectors.toList());
    assertEquals(Collections.singletonList(cp2r2), res);
}