This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 148185
Collapse All | Expand All

(-)a/java.j2seproject/nbproject/project.xml (-1 / +1 lines)
Lines 180-186 Link Here
180
                    <compile-dependency/>
180
                    <compile-dependency/>
181
                    <run-dependency>
181
                    <run-dependency>
182
                        <release-version>1</release-version>
182
                        <release-version>1</release-version>
183
                        <specification-version>1.25</specification-version>
183
                        <specification-version>1.26</specification-version>
184
                    </run-dependency>
184
                    </run-dependency>
185
                </dependency>
185
                </dependency>
186
                <dependency>
186
                <dependency>
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SESources.java (-1 / +1 lines)
Lines 160-166 Link Here
160
        ProjectManager.mutex().postWriteRequest(new Runnable() {
160
        ProjectManager.mutex().postWriteRequest(new Runnable() {
161
            public void run() {                
161
            public void run() {                
162
                if (!externalRootsRegistered) {
162
                if (!externalRootsRegistered) {
163
                    sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT);
163
                    sourcesHelper.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT, false);
164
                    externalRootsRegistered = true;
164
                    externalRootsRegistered = true;
165
                }
165
                }
166
            }
166
            }
(-)a/project.ant/apichanges.xml (-1 / +19 lines)
Lines 104-110 Link Here
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
105
106
    <changes>
106
    <changes>
107
107
        <change id="SourcesHelper-minimalSubfolders">
108
            <api name="general"/>
109
            <summary>Added method SourcesHelper.registerExternalRoots with minimalSubfolders parameter</summary>
110
            <version major="1" minor="26"/>
111
            <date day="29" month="9" year="2008"/>
112
            <author login="tzezula"/>
113
            <compatibility addition="yes"/>
114
            <description>
115
                <p>
116
                    Added <code>SourcesHelper.registerExternalRoots</code> with additional parameter
117
                    <code>minimalSubfolders</code> controlling how the roots having an explicit include
118
                    list are registered. When <code>true</code> only those subfolders which are included 
119
                    (or folders directly containing included files) will be registered, otherwise the 
120
                    whole source root is registered.
121
                </p>
122
            </description>
123
            <class package="org.netbeans.spi.project.support.ant" name="SourcesHelper"/>
124
            <issue number="148185"/>
125
        </change>
108
        <change id="antartifact-enhancement">
126
        <change id="antartifact-enhancement">
109
            <api name="general"/>
127
            <api name="general"/>
110
            <summary>Enhance AntArtifact support with ability to specify build.xml location and name</summary>
128
            <summary>Enhance AntArtifact support with ability to specify build.xml location and name</summary>
(-)a/project.ant/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
2
OpenIDE-Module: org.netbeans.modules.project.ant/1
3
OpenIDE-Module-Specification-Version: 1.25
3
OpenIDE-Module-Specification-Version: 1.26
4
OpenIDE-Module-Layer: org/netbeans/modules/project/ant/resources/mf-layer.xml
4
OpenIDE-Module-Layer: org/netbeans/modules/project/ant/resources/mf-layer.xml
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties
6
OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class
6
OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class
(-)a/project.ant/src/org/netbeans/spi/project/support/ant/SourcesHelper.java (-5 / +64 lines)
Lines 100-106 Link Here
100
            }
100
            }
101
            return project.resolveFile(val);
101
            return project.resolveFile(val);
102
        }
102
        }
103
        public Collection<FileObject> getIncludeRoots() {
103
        public Collection<FileObject> getIncludeRoots(boolean minimalSubfolders) {
104
            File loc = getActualLocation();
104
            File loc = getActualLocation();
105
            if (loc != null) {
105
            if (loc != null) {
106
                FileObject fo = FileUtil.toFileObject(loc);
106
                FileObject fo = FileUtil.toFileObject(loc);
Lines 258-266 Link Here
258
258
259
259
260
        @Override
260
        @Override
261
        public Collection<FileObject> getIncludeRoots() {
261
        public Collection<FileObject> getIncludeRoots(boolean minimalSubfolders) {
262
            Collection<FileObject> supe = super.getIncludeRoots();
262
            Collection<FileObject> supe = super.getIncludeRoots(minimalSubfolders);
263
            if (supe.size() == 1) {
263
            if (!minimalSubfolders) {
264
                return supe;
265
            }
266
            else if (supe.size() == 1) {
264
                Set<FileObject> roots = new HashSet<FileObject>();
267
                Set<FileObject> roots = new HashSet<FileObject>();
265
                computeIncludeExcludePatterns();
268
                computeIncludeExcludePatterns();
266
                for (File r : matcher.findIncludedRoots()) {
269
                for (File r : matcher.findIncludedRoots()) {
Lines 296-301 Link Here
296
    private final List<Root> ownedFiles = new ArrayList<Root>();
299
    private final List<Root> ownedFiles = new ArrayList<Root>();
297
    private final List<TypedSourceRoot> typedSourceRoots = new ArrayList<TypedSourceRoot>();
300
    private final List<TypedSourceRoot> typedSourceRoots = new ArrayList<TypedSourceRoot>();
298
    private int registeredRootAlgorithm;
301
    private int registeredRootAlgorithm;
302
    private boolean minimalSubfolders;
299
    /**
303
    /**
300
     * If not null, external roots that we registered the last time.
304
     * If not null, external roots that we registered the last time.
301
     * Used when a property change is encountered, to see if the set of external
305
     * Used when a property change is encountered, to see if the set of external
Lines 513-522 Link Here
513
     *                               given <code>SourcesHelper</code> object
517
     *                               given <code>SourcesHelper</code> object
514
     */
518
     */
515
    public void registerExternalRoots(int algorithm) throws IllegalArgumentException, IllegalStateException {
519
    public void registerExternalRoots(int algorithm) throws IllegalArgumentException, IllegalStateException {
520
        registerExternalRoots(algorithm, true);
521
    }
522
    
523
    /**
524
     * Register all external source or non-source roots using {@link FileOwnerQuery#markExternalOwner}.
525
     * <p>
526
     * Only roots added by {@link #addPrincipalSourceRoot} and {@link #addNonSourceRoot}
527
     * are considered. They are registered if (and only if) they in fact fall
528
     * outside of the project directory, and of course only if the folders really
529
     * exist on disk. Currently it is not defined when this file existence check
530
     * is done (e.g. when this method is first called, or periodically) or whether
531
     * folders which are created subsequently will be registered, so project type
532
     * providers are encouraged to create all desired external roots before calling
533
     * this method.
534
     * </p>
535
     * <p>
536
     * If the actual value of the location changes (due to changes being
537
     * fired from the property evaluator), roots which were previously internal
538
     * and are now external will be registered, and roots which were previously
539
     * external and are now internal will be unregistered. The (un-)registration
540
     * will be done using the same algorithm as was used initially.
541
     * </p>
542
     * <p>
543
     * If a minimalSubfolders is true and an explicit include list is configured 
544
     * for a principal source root, only those subfolders which are included 
545
     * (or folders directly containing included files)
546
     * will be registered, otherwise the whole source root is registered.
547
     * Note that the source root, or an included subfolder, will
548
     * be registered even if it contains excluded files or folders beneath it.
549
     * </p>
550
     * <p>
551
     * Calling this method causes the helper object to hold strong references to the
552
     * current external roots, which helps a project satisfy the requirements of
553
     * {@link FileOwnerQuery#EXTERNAL_ALGORITHM_TRANSIENT}.
554
     * </p>
555
     * <p>
556
     * You may <em>not</em> call this method inside the project's constructor, as
557
     * it requires the actual project to exist and be registered in {@link ProjectManager}.
558
     * Typically you would use {@link org.openide.util.Mutex#postWriteRequest} to run it
559
     * later, if you were creating the helper in your constructor, since the project construction
560
     * normally occurs in read access.
561
     * </p>
562
     * @param algorithm an external root registration algorithm as per
563
     *                  {@link FileOwnerQuery#markExternalOwner}
564
     * @param minimalSubfolders controls how the roots having an explicit include list 
565
     * are registered. When true only those subfolders which are included 
566
     * (or folders directly containing included files) will be registered,
567
     * otherwise the whole source root is registered.
568
     * @throws IllegalArgumentException if the algorithm is unrecognized
569
     * @throws IllegalStateException if this method is called more than once on a
570
     *                               given <code>SourcesHelper</code> object
571
     * @since 1.26
572
     */
573
    public void registerExternalRoots (int algorithm, boolean minimalSubfolders) throws IllegalArgumentException, IllegalStateException {
516
        if (lastRegisteredRoots != null) {
574
        if (lastRegisteredRoots != null) {
517
            throw new IllegalStateException("registerExternalRoots was already called before"); // NOI18N
575
            throw new IllegalStateException("registerExternalRoots was already called before"); // NOI18N
518
        }
576
        }
519
        registeredRootAlgorithm = algorithm;
577
        registeredRootAlgorithm = algorithm;
578
        this.minimalSubfolders = minimalSubfolders;
520
        remarkExternalRoots();
579
        remarkExternalRoots();
521
    }
580
    }
522
    
581
    
Lines 539-545 Link Here
539
        // that was last computed, and just check if that has changed... otherwise we wind
598
        // that was last computed, and just check if that has changed... otherwise we wind
540
        // up calling APH.resolveFileObject repeatedly (for each property change)
599
        // up calling APH.resolveFileObject repeatedly (for each property change)
541
        for (Root r : allRoots) {
600
        for (Root r : allRoots) {
542
            for (FileObject loc : r.getIncludeRoots()) {
601
            for (FileObject loc : r.getIncludeRoots(minimalSubfolders)) {
543
                if (FileUtil.getRelativePath(pdir, loc) != null) {
602
                if (FileUtil.getRelativePath(pdir, loc) != null) {
544
                    // Inside projdir already. Skip it.
603
                    // Inside projdir already. Skip it.
545
                    continue;
604
                    continue;
(-)a/project.ant/test/unit/src/org/netbeans/spi/project/support/ant/SourcesHelperTest.java (+53 lines)
Lines 562-567 Link Here
562
        assertExcluded("but that does not apply to other children", gg1, "javax/lang/Foo.java");
562
        assertExcluded("but that does not apply to other children", gg1, "javax/lang/Foo.java");
563
        // </editor-fold>
563
        // </editor-fold>
564
    }
564
    }
565
    
566
    public void testMinimalSubfolders () throws Exception {
567
        scratch = TestUtil.makeScratchDir(this); // have our own setup
568
        maindir = scratch.createFolder("dir");
569
        projdir = maindir.createFolder("proj-dir");
570
        src1dir = maindir.createFolder("src1");
571
        
572
        // <editor-fold desc="create files in group #1">
573
        FileUtil.createData(src1dir, "com/sun/tools/javac/Main.java");
574
        FileUtil.createData(src1dir, "com/sun/tools/internal/ws/processor/model/java/JavaArrayType.java");
575
        FileUtil.createData(src1dir, "sun/tools/javac/Main.java");
576
        FileUtil.createData(src1dir, "sunw/io/Serializable.java");
577
        FileUtil.createData(src1dir, "java/lang/Byte.java");
578
        FileUtil.createData(src1dir, "java/text/resources/Messages.properties");
579
        FileUtil.createData(src1dir, "java/text/resources/Messages_zh.properties");
580
        FileUtil.createData(src1dir, "java/text/resources/Messages_zh_TW.properties");
581
        FileUtil.createData(src1dir, "java/text/resources/x_y/z.properties");
582
        // </editor-fold>
583
        
584
        // <editor-fold desc="other setup #1">
585
        h = ProjectGenerator.createProject(projdir, "test");
586
        project = ProjectManager.getDefault().findProject(projdir);
587
        EditableProperties p = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
588
        p.setProperty("src1.dir", "../src1");
589
        // </editor-fold>
590
        // <editor-fold desc="includes & excludes">
591
        p.setProperty("src1.includes", "com/sun/tools/**");
592
        // </editor-fold>
593
        // <editor-fold desc="other setup #2">
594
        h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
595
        ProjectManager.getDefault().saveProject(project);
596
        //minimalSubfolders = true
597
        sh = new SourcesHelper(h, h.getStandardPropertyEvaluator());
598
        sh.addPrincipalSourceRoot("${src1.dir}", "${src1.includes}", "${src1.excludes}", "Sources #1", null, null);
599
        sh.addTypedSourceRoot("${src1.dir}", "${src1.includes}", "${src1.excludes}", "java", "Packages #1", null, null);
600
        sh.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT, true);
601
        Sources s = sh.createSources();
602
        SourceGroup[] groups = s.getSourceGroups("java");
603
        SourceGroup g1 = groups[0];
604
        assertEquals("Packages #1", g1.getDisplayName());
605
        assertNull(FileOwnerQuery.getOwner(src1dir));
606
        //minimalSubfolders = false
607
        sh = new SourcesHelper(h, h.getStandardPropertyEvaluator());
608
        sh.addPrincipalSourceRoot("${src1.dir}", "${src1.includes}", "${src1.excludes}", "Sources #1", null, null);
609
        sh.addTypedSourceRoot("${src1.dir}", "${src1.includes}", "${src1.excludes}", "java", "Packages #1", null, null);
610
        sh.registerExternalRoots(FileOwnerQuery.EXTERNAL_ALGORITHM_TRANSIENT, false);
611
        s = sh.createSources();
612
        groups = s.getSourceGroups("java");
613
        g1 = groups[0];
614
        assertEquals("Packages #1", g1.getDisplayName());
615
        assertEquals(project, FileOwnerQuery.getOwner(src1dir));
616
    }
617
    
565
    private static void assertIncluded(String message, SourceGroup g, String resource) {
618
    private static void assertIncluded(String message, SourceGroup g, String resource) {
566
        FileObject f = g.getRootFolder().getFileObject(resource);
619
        FileObject f = g.getRootFolder().getFileObject(resource);
567
        assertNotNull(resource, f);
620
        assertNotNull(resource, f);

Return to bug 148185