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 57656
Collapse All | Expand All

(-)ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformSources.java (+2 lines)
Lines 93-98 Link Here
93
                String location = Util.findText(locationE);
93
                String location = Util.findText(locationE);
94
                if (folderE.getLocalName().equals("build-folder")) { // NOI18N
94
                if (folderE.getLocalName().equals("build-folder")) { // NOI18N
95
                    h.addNonSourceRoot(location);
95
                    h.addNonSourceRoot(location);
96
                } else if (folderE.getLocalName().equals("build-file")) {
97
                    h.addOwnedFile(location);
96
                } else {
98
                } else {
97
                    assert folderE.getLocalName().equals("source-folder") : folderE;
99
                    assert folderE.getLocalName().equals("source-folder") : folderE;
98
                    Element nameE = Util.findElement(folderE, "label", FreeformProjectType.NS_GENERAL); // NOI18N
100
                    Element nameE = Util.findElement(folderE, "label", FreeformProjectType.NS_GENERAL); // NOI18N
(-)ant/freeform/src/org/netbeans/modules/ant/freeform/resources/freeform-project-general-2.xsd (+1 lines)
Lines 111-116 Link Here
111
                <xsd:element name="source-folder" type="maybe-typed-source-root"/>
111
                <xsd:element name="source-folder" type="maybe-typed-source-root"/>
112
                <!-- Other roots of build files (internal or external). -->
112
                <!-- Other roots of build files (internal or external). -->
113
                <xsd:element name="build-folder" type="root"/>
113
                <xsd:element name="build-folder" type="root"/>
114
                <xsd:element name="build-file" type="root"/>
114
            </xsd:choice>
115
            </xsd:choice>
115
        </xsd:sequence>
116
        </xsd:sequence>
116
    </xsd:complexType>
117
    </xsd:complexType>
(-)ant/project/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
        
108
        <change id="owned-files">
109
            <api name="general"/>
110
            <summary>Support for adding </summary>
111
            <version major="1" minor="17"/>
112
            <date day="4" month="10" year="2007"/>
113
            <author login="mkubec"/>
114
            <compatibility addition="yes"/>
115
            <description>
116
                <p>
117
                  Added a method for registering external file that is supposed to be
118
                  owned by the project, typically used in freeform project to register
119
                  build products that are external to project dir.
120
                </p>
121
            </description>
122
            <class package="org.netbeans.spi.project.support.ant" name="SourcesHelper"/>
123
            <issue number="57656"/>
124
        </change>
125
        
108
        <change id="build-extender">
126
        <change id="build-extender">
109
            <api name="general"/>
127
            <api name="general"/>
110
            <summary>Support for externally extending the project's build script</summary>
128
            <summary>Support for externally extending the project's build script</summary>
(-)ant/project/src/org/netbeans/spi/project/support/ant/SourcesHelper.java (-10 / +34 lines)
Lines 289-294 Link Here
289
    private final PropertyEvaluator evaluator;
289
    private final PropertyEvaluator evaluator;
290
    private final List<SourceRoot> principalSourceRoots = new ArrayList<SourceRoot>();
290
    private final List<SourceRoot> principalSourceRoots = new ArrayList<SourceRoot>();
291
    private final List<Root> nonSourceRoots = new ArrayList<Root>();
291
    private final List<Root> nonSourceRoots = new ArrayList<Root>();
292
    private final List<Root> ownedFiles = new ArrayList<Root>();
292
    private final List<TypedSourceRoot> typedSourceRoots = new ArrayList<TypedSourceRoot>();
293
    private final List<TypedSourceRoot> typedSourceRoots = new ArrayList<TypedSourceRoot>();
293
    private int registeredRootAlgorithm;
294
    private int registeredRootAlgorithm;
294
    /**
295
    /**
Lines 398-403 Link Here
398
    }
399
    }
399
    
400
    
400
    /**
401
    /**
402
     * Add any file that is supposed to be owned by a given project 
403
     * via FileOwnerQuery, affects only {@link #registerExternalRoots} 
404
     * and not {@link #createSources}.
405
     * <p class="nonnormative">
406
     * Useful for project type providers which have external paths holding build
407
     * products. These should not appear in {@link Sources}, yet it may be useful
408
     * for {@link FileOwnerQuery} to know the owning project (for example, in order
409
     * for a project-specific <a href="@org-netbeans-api-java@/org/netbeans/spi/java/queries/SourceForBinaryQueryImplementation.html"><code>SourceForBinaryQueryImplementation</code></a> to work).
410
     * </p>
411
     * @param location a project-relative or absolute path giving the location
412
     *                 of a file; may contain Ant property substitutions
413
     * @throws IllegalStateException if this method is called after
414
     *                               {@link #registerExternalRoots} was called
415
     * @since org.netbeans.modules.project.ant/1 1.17
416
     */
417
    public void addOwnedFile(String location) throws IllegalStateException {
418
        if (lastRegisteredRoots != null) {
419
            throw new IllegalStateException("registerExternalRoots was already called"); // NOI18N
420
        }
421
        ownedFiles.add(new Root(location));
422
    }
423
    
424
    /**
401
     * Add a typed source root which will be considered only in certain contexts.
425
     * Add a typed source root which will be considered only in certain contexts.
402
     * @param location a project-relative or absolute path giving the location
426
     * @param location a project-relative or absolute path giving the location
403
     *                 of a source tree; may contain Ant property substitutions
427
     *                 of a source tree; may contain Ant property substitutions
Lines 495-500 Link Here
495
    private void remarkExternalRoots() throws IllegalArgumentException {
519
    private void remarkExternalRoots() throws IllegalArgumentException {
496
        List<Root> allRoots = new ArrayList<Root>(principalSourceRoots);
520
        List<Root> allRoots = new ArrayList<Root>(principalSourceRoots);
497
        allRoots.addAll(nonSourceRoots);
521
        allRoots.addAll(nonSourceRoots);
522
        allRoots.addAll(ownedFiles);
498
        Project p = getProject();
523
        Project p = getProject();
499
        FileObject pdir = project.getProjectDirectory();
524
        FileObject pdir = project.getProjectDirectory();
500
        // First time: register roots and add to lastRegisteredRoots.
525
        // First time: register roots and add to lastRegisteredRoots.
Lines 511-532 Link Here
511
        // up calling APH.resolveFileObject repeatedly (for each property change)
536
        // up calling APH.resolveFileObject repeatedly (for each property change)
512
        for (Root r : allRoots) {
537
        for (Root r : allRoots) {
513
            for (FileObject loc : r.getIncludeRoots()) {
538
            for (FileObject loc : r.getIncludeRoots()) {
514
                if (!loc.isFolder()) {
515
                    continue;
516
                }
517
                if (FileUtil.getRelativePath(pdir, loc) != null) {
539
                if (FileUtil.getRelativePath(pdir, loc) != null) {
518
                    // Inside projdir already. Skip it.
540
                    // Inside projdir already. Skip it.
519
                    continue;
541
                    continue;
520
                }
542
                }
521
                try {
543
                if (loc.isFolder()) {
522
                    Project other = ProjectManager.getDefault().findProject(loc);
544
                    try {
523
                    if (other != null) {
545
                        Project other = ProjectManager.getDefault().findProject(loc);
524
                        // This is a foreign project; we cannot own it. Skip it.
546
                        if (other != null) {
547
                            // This is a foreign project; we cannot own it. Skip it.
548
                            continue;
549
                        }
550
                    } catch (IOException e) {
551
                        // Assume it is a foreign project and skip it.
525
                        continue;
552
                        continue;
526
                    }
553
                    }
527
                } catch (IOException e) {
528
                    // Assume it is a foreign project and skip it.
529
                    continue;
530
                }
554
                }
531
                // It's OK to go.
555
                // It's OK to go.
532
                newRegisteredRoots.add(loc);
556
                newRegisteredRoots.add(loc);
(-)ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SourcesHelperTest.java (+15 lines)
Lines 73-78 Link Here
73
    private FileObject src3dir;
73
    private FileObject src3dir;
74
    private FileObject src4dir;
74
    private FileObject src4dir;
75
    private FileObject builddir;
75
    private FileObject builddir;
76
    private FileObject extdir;
77
    private FileObject ext2dir;
76
    private AntProjectHelper h;
78
    private AntProjectHelper h;
77
    private Project project;
79
    private Project project;
78
    private SourcesHelper sh;
80
    private SourcesHelper sh;
Lines 102-107 Link Here
102
        src4dir.createData("src4file");
104
        src4dir.createData("src4file");
103
        builddir = scratch.createFolder("build");
105
        builddir = scratch.createFolder("build");
104
        builddir.createData("buildfile");
106
        builddir.createData("buildfile");
107
        extdir = scratch.createFolder("external");
108
        extdir.createData("extFile");
105
        h = ProjectGenerator.createProject(projdir, "test");
109
        h = ProjectGenerator.createProject(projdir, "test");
106
        project = ProjectManager.getDefault().findProject(projdir);
110
        project = ProjectManager.getDefault().findProject(projdir);
107
        assertNotNull("have a project", project);
111
        assertNotNull("have a project", project);
Lines 113-118 Link Here
113
        p.setProperty("src4.dir", "..");
117
        p.setProperty("src4.dir", "..");
114
        p.setProperty("src5.dir", "../../nonesuch");
118
        p.setProperty("src5.dir", "../../nonesuch");
115
        p.setProperty("build.dir", "../../build");
119
        p.setProperty("build.dir", "../../build");
120
        p.setProperty("ext.file", "../../external/extFile");
116
        h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
121
        h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, p);
117
        ProjectManager.getDefault().saveProject(project);
122
        ProjectManager.getDefault().saveProject(project);
118
        sh = new SourcesHelper(h, h.getStandardPropertyEvaluator());
123
        sh = new SourcesHelper(h, h.getStandardPropertyEvaluator());
Lines 123-128 Link Here
123
        sh.addPrincipalSourceRoot("${src4.dir}", "The Whole Shebang", null, null); // above proj dir
128
        sh.addPrincipalSourceRoot("${src4.dir}", "The Whole Shebang", null, null); // above proj dir
124
        sh.addPrincipalSourceRoot("${src5.dir}", "None such", null, null); // does not exist on disk
129
        sh.addPrincipalSourceRoot("${src5.dir}", "None such", null, null); // does not exist on disk
125
        sh.addNonSourceRoot("${build.dir}");
130
        sh.addNonSourceRoot("${build.dir}");
131
        sh.addOwnedFile("${ext.file}");
126
        sh.addTypedSourceRoot("${src1.dir}", "java", "Packages #1", null, null);
132
        sh.addTypedSourceRoot("${src1.dir}", "java", "Packages #1", null, null);
127
        sh.addTypedSourceRoot("${src3.dir}", "java", "Packages #3", null, null);
133
        sh.addTypedSourceRoot("${src3.dir}", "java", "Packages #3", null, null);
128
        sh.addTypedSourceRoot("${src5.dir}", "java", "No Packages", null, null);
134
        sh.addTypedSourceRoot("${src5.dir}", "java", "No Packages", null, null);
Lines 136-141 Link Here
136
        proj2src1dir.createData("proj2src1file");
142
        proj2src1dir.createData("proj2src1file");
137
        proj2src2dir = proj2dir.createFolder("src2");
143
        proj2src2dir = proj2dir.createFolder("src2");
138
        proj2src2dir.createData("proj2src2file");
144
        proj2src2dir.createData("proj2src2file");
145
        ext2dir = scratch.createFolder("external2");
146
        FileObject ext2File = ext2dir.createData("ext2File");
139
        h2 = ProjectGenerator.createProject(proj2dir, "test");
147
        h2 = ProjectGenerator.createProject(proj2dir, "test");
140
        project2 = ProjectManager.getDefault().findProject(proj2dir);
148
        project2 = ProjectManager.getDefault().findProject(proj2dir);
141
        assertNotNull("have a project2", project2);
149
        assertNotNull("have a project2", project2);
Lines 143-148 Link Here
143
        sh2.addPrincipalSourceRoot("src1", "Sources #1", null, null);
151
        sh2.addPrincipalSourceRoot("src1", "Sources #1", null, null);
144
        sh2.addPrincipalSourceRoot("src2", "Sources #2", null, null);
152
        sh2.addPrincipalSourceRoot("src2", "Sources #2", null, null);
145
        sh2.addNonSourceRoot("build");
153
        sh2.addNonSourceRoot("build");
154
        sh2.addOwnedFile(FileUtil.toFile(ext2File).getAbsolutePath());
146
        sh2.addTypedSourceRoot("src1", "java", "Packages #1", null, null);
155
        sh2.addTypedSourceRoot("src1", "java", "Packages #1", null, null);
147
        sh2.addTypedSourceRoot("src2", "java", "Packages #2", null, null);
156
        sh2.addTypedSourceRoot("src2", "java", "Packages #2", null, null);
148
    }
157
    }
Lines 204-209 Link Here
204
        assertEquals("src3file registered", project, FileOwnerQuery.getOwner(f));
213
        assertEquals("src3file registered", project, FileOwnerQuery.getOwner(f));
205
        f = builddir.getFileObject("buildfile");
214
        f = builddir.getFileObject("buildfile");
206
        assertEquals("buildfile registered", project, FileOwnerQuery.getOwner(f));
215
        assertEquals("buildfile registered", project, FileOwnerQuery.getOwner(f));
216
        f = extdir.getFileObject("extFile");
217
        assertEquals("extfile registered", project, FileOwnerQuery.getOwner(f));
218
        assertEquals("extdir not registered", null, FileOwnerQuery.getOwner(extdir));
207
        f = scratch.getFileObject("otherfile");
219
        f = scratch.getFileObject("otherfile");
208
        assertEquals("otherfile not registered", null, FileOwnerQuery.getOwner(f));
220
        assertEquals("otherfile not registered", null, FileOwnerQuery.getOwner(f));
209
        // Test the simpler project type.
221
        // Test the simpler project type.
Lines 214-219 Link Here
214
        assertEquals("proj2src1file registered", project2, FileOwnerQuery.getOwner(f));
226
        assertEquals("proj2src1file registered", project2, FileOwnerQuery.getOwner(f));
215
        f = proj2src2dir.getFileObject("proj2src2file");
227
        f = proj2src2dir.getFileObject("proj2src2file");
216
        assertEquals("proj2src2file registered", project2, FileOwnerQuery.getOwner(f));
228
        assertEquals("proj2src2file registered", project2, FileOwnerQuery.getOwner(f));
229
        f = ext2dir.getFileObject("ext2File");
230
        assertEquals("ext2File registered", project2, FileOwnerQuery.getOwner(f));
231
        assertEquals("ext2dir not registered", null, FileOwnerQuery.getOwner(ext2dir));
217
    }
232
    }
218
    
233
    
219
    public void testSourceLocationChanges() throws Exception {
234
    public void testSourceLocationChanges() throws Exception {
(-)java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java (-25 / +67 lines)
Lines 42-47 Link Here
42
package org.netbeans.modules.java.freeform;
42
package org.netbeans.modules.java.freeform;
43
43
44
import java.io.File;
44
import java.io.File;
45
import java.net.MalformedURLException;
45
import java.util.ArrayList;
46
import java.util.ArrayList;
46
import java.util.HashSet;
47
import java.util.HashSet;
47
import java.util.Iterator;
48
import java.util.Iterator;
Lines 57-62 Link Here
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
58
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
58
import org.netbeans.spi.project.support.ant.PropertyUtils;
59
import org.netbeans.spi.project.support.ant.PropertyUtils;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.FileUtil;
61
import org.openide.util.Exceptions;
60
import org.w3c.dom.Document;
62
import org.w3c.dom.Document;
61
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
62
64
Lines 74-80 Link Here
74
    private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N
76
    private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N
75
    
77
    
76
    // this order is not required by schema, but follow it to minimize randomness a bit
78
    // this order is not required by schema, but follow it to minimize randomness a bit
77
    private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder"}; // NOI18N
79
    private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder", "build-file"}; // NOI18N
78
    private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N
80
    private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N
79
    
81
    
80
    /**
82
    /**
Lines 717-745 Link Here
717
     */
719
     */
718
    public static List<String> guessBuildFolders(PropertyEvaluator evaluator,
720
    public static List<String> guessBuildFolders(PropertyEvaluator evaluator,
719
            List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) {
721
            List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) {
720
        //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
722
721
        List<String> buildFolders = new ArrayList<String>();
723
        List<String> buildFolders = new ArrayList<String>();
722
        for (JavaCompilationUnit cu : javaCompilationUnits) {
724
        for (JavaCompilationUnit cu : javaCompilationUnits) {
723
            if (cu.output != null) {
725
            if (cu.output != null) {
724
                for (String output : cu.output) {
726
                for (String output : cu.output) {
725
                    File f = Util.resolveFile(evaluator, freeformBase, output);
727
                    File f = Util.resolveFile(evaluator, freeformBase, output);
726
                    if (f.exists()) {
728
                    // include only directories
727
                        if (f.isFile()) {
729
                    if (!f.isDirectory()) {
728
                            f = f.getParentFile();
730
                        continue;
729
                        }
730
                    } else {
731
                        // guess: if name contains dot then it is probably file
732
                        if (f.getName().indexOf('.') != -1) {
733
                            f = f.getParentFile();
734
                        }
735
                    }
731
                    }
736
                    output = f.getAbsolutePath();
732
                    String absOutput = f.getAbsolutePath();
737
                    if (!output.endsWith(File.separator)) {
733
                    if (!absOutput.endsWith(File.separator)) {
738
                        output += File.separatorChar;
734
                        absOutput += File.separatorChar;
739
                    }
735
                    }
740
736
741
                    if (output.startsWith(projectBase.getAbsolutePath()+File.separatorChar) ||
737
                    if (absOutput.startsWith(projectBase.getAbsolutePath()+File.separatorChar) ||
742
                        output.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) {
738
                        absOutput.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) {
743
                        // ignore output which lies below project base or freeform base
739
                        // ignore output which lies below project base or freeform base
744
                        continue;
740
                        continue;
745
                    }
741
                    }
Lines 750-769 Link Here
750
                        if (!path.endsWith(File.separator)) {
746
                        if (!path.endsWith(File.separator)) {
751
                            path += File.separatorChar;
747
                            path += File.separatorChar;
752
                        }
748
                        }
753
                        if (path.equals(output)) {
749
                        if (path.equals(absOutput)) {
754
                            // such a path is already there
750
                            // such a path is already there
755
                            add = false;
751
                            add = false;
756
                            break;
752
                            break;
757
                        } else if (output.startsWith(path)) {
753
                        } else if (absOutput.startsWith(path)) {
758
                            // such a patch is already there
754
                            // such a patch is already there
759
                            add = false;
755
                            add = false;
760
                            break;
756
                            break;
761
                        } else if (path.startsWith(output)) {
757
                        } else if (path.startsWith(absOutput)) {
762
                            it.remove();
758
                            it.remove();
763
                        }
759
                        }
764
                    }
760
                    }
765
                    if (add) {
761
                    if (add) {
766
                        buildFolders.add(f.getAbsolutePath());
762
                        buildFolders.add(output);
767
                    }
763
                    }
768
                }
764
                }
769
            }
765
            }
Lines 778-785 Link Here
778
     * @param buildFolders list of build folder locations
774
     * @param buildFolders list of build folder locations
779
     */
775
     */
780
    public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) {
776
    public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) {
781
        //assert ProjectManager.mutex().isWriteAccess();
777
        putBuildElement(helper, buildFolders, "build-folder");
782
        ArrayList list = new ArrayList();
778
    }
779
    
780
    private static void putBuildElement(AntProjectHelper helper, List<String> buildFolders, String elemName) {
783
        Element data = Util.getPrimaryConfigurationData(helper);
781
        Element data = Util.getPrimaryConfigurationData(helper);
784
        Document doc = data.getOwnerDocument();
782
        Document doc = data.getOwnerDocument();
785
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
783
        Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N
Lines 791-797 Link Here
791
            Iterator it = folders.iterator();
789
            Iterator it = folders.iterator();
792
            while (it.hasNext()) {
790
            while (it.hasNext()) {
793
                Element buildFolderEl = (Element)it.next();
791
                Element buildFolderEl = (Element)it.next();
794
                if (!buildFolderEl.getLocalName().equals("build-folder")) { // NOI18N
792
                if (!buildFolderEl.getLocalName().equals(elemName)) { // NOI18N
795
                    continue;
793
                    continue;
796
                }
794
                }
797
                foldersEl.removeChild(buildFolderEl);
795
                foldersEl.removeChild(buildFolderEl);
Lines 800-806 Link Here
800
        Iterator it = buildFolders.iterator();
798
        Iterator it = buildFolders.iterator();
801
        while (it.hasNext()) {
799
        while (it.hasNext()) {
802
            String location = (String)it.next();
800
            String location = (String)it.next();
803
            Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, "build-folder"); // NOI18N
801
            Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, elemName); // NOI18N
804
            Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
802
            Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N
805
            locationEl.appendChild(doc.createTextNode(location));
803
            locationEl.appendChild(doc.createTextNode(location));
806
            buildFolderEl.appendChild(locationEl);
804
            buildFolderEl.appendChild(locationEl);
Lines 808-814 Link Here
808
        }
806
        }
809
        Util.putPrimaryConfigurationData(helper, data);
807
        Util.putPrimaryConfigurationData(helper, data);
810
    }
808
    }
811
809
    
810
    public static List<String> getBuildFiles(PropertyEvaluator evaluator,
811
            List<JavaCompilationUnit> compUnits, File projectBase, File freeformBase) {
812
        
813
        List<String> buildFiles = new ArrayList<String>();
814
        for (JavaCompilationUnit cu : compUnits) {
815
            if (cu.output != null) {
816
                for (String output : cu.output) {
817
                    File f = Util.resolveFile(evaluator, freeformBase, output);
818
                    try {
819
                        if (f.exists() && !FileUtil.isArchiveFile(f.toURL())) {
820
                            continue;
821
                        }
822
                    } catch (MalformedURLException murle) {
823
                        Exceptions.printStackTrace(murle);
824
                    }
825
                    String absOutput = f.getAbsolutePath();
826
                    if (absOutput.startsWith(projectBase.getAbsolutePath() + File.separatorChar) ||
827
                        absOutput.startsWith(freeformBase.getAbsolutePath() + File.separatorChar)) {
828
                        // ignore output which lies below project base or freeform base
829
                        continue;
830
                    }
831
                    boolean add = true;
832
                    Iterator<String> it = buildFiles.iterator();
833
                    while (it.hasNext()) {
834
                        String path = it.next();
835
                        if (path.equals(absOutput)) {
836
                            // such a path is already there
837
                            add = false;
838
                            break;
839
                        }
840
                    }
841
                    if (add) {
842
                        buildFiles.add(output);
843
                    }
844
                }
845
            }
846
        }
847
        return buildFiles;
848
    }
849
    
850
    public static void putBuildFiles(AntProjectHelper helper, List<String> buildFiles) {
851
        putBuildElement(helper, buildFiles, "build-file");
852
    }
853
    
812
    // XXX: copy&pasted from FreeformProjectGenerator
854
    // XXX: copy&pasted from FreeformProjectGenerator
813
    /**
855
    /**
814
     * Read target mappings from project.
856
     * Read target mappings from project.
(-)java/freeform/src/org/netbeans/modules/java/freeform/ui/ProjectModel.java (+4 lines)
Lines 222-227 Link Here
222
                    model.javaCompilationUnitsList, model.baseFolder, model.nbProjectFolder);
222
                    model.javaCompilationUnitsList, model.baseFolder, model.nbProjectFolder);
223
                JavaProjectGenerator.putBuildFolders(helper, buildFolders);
223
                JavaProjectGenerator.putBuildFolders(helper, buildFolders);
224
                
224
                
225
                List<String> buildFiles = JavaProjectGenerator.getBuildFiles(model.getEvaluator(), 
226
                    model.javaCompilationUnitsList, model.baseFolder, model.nbProjectFolder);
227
                JavaProjectGenerator.putBuildFiles(helper, buildFiles);
228
                
225
                return null;
229
                return null;
226
            }
230
            }
227
        });
231
        });
(-)java/freeform/test/unit/src/org/netbeans/modules/java/freeform/JavaProjectGeneratorTest.java (-21 / +61 lines)
Lines 1187-1193 Link Here
1187
        File proj1 = new File(base, "proj1");
1187
        File proj1 = new File(base, "proj1");
1188
        proj1.mkdir();
1188
        proj1.mkdir();
1189
        File base2 = new File(getWorkDir(), "folder2");
1189
        File base2 = new File(getWorkDir(), "folder2");
1190
        
1190
        base2.mkdir();
1191
                
1191
        JavaProjectGenerator.JavaCompilationUnit cu = new JavaProjectGenerator.JavaCompilationUnit();
1192
        JavaProjectGenerator.JavaCompilationUnit cu = new JavaProjectGenerator.JavaCompilationUnit();
1192
        cu.output = new ArrayList();
1193
        cu.output = new ArrayList();
1193
        cu.output.add("${outputfile}");
1194
        cu.output.add("${outputfile}");
Lines 1200-1226 Link Here
1200
            PropertyUtils.fixedPropertyProvider(m)});
1201
            PropertyUtils.fixedPropertyProvider(m)});
1201
        List buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1202
        List buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1202
        assertEquals("no build folder", 0, buildFolders.size());
1203
        assertEquals("no build folder", 0, buildFolders.size());
1203
        
1204
                
1204
        m.put("outputfile", "../proj1_diff/out.jar");
1205
        evaluator = PropertyUtils.sequentialPropertyEvaluator(null, new PropertyProvider[]{
1206
            PropertyUtils.fixedPropertyProvider(m)});
1207
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1208
        assertEquals("one build-folder created", 1, buildFolders.size());
1209
        assertEquals("export is properly configured", base.getAbsolutePath()+File.separator+"proj1_diff", buildFolders.get(0));
1210
        
1211
        m.put("outputfile", "../out.jar");
1212
        evaluator = PropertyUtils.sequentialPropertyEvaluator(null, new PropertyProvider[]{
1213
            PropertyUtils.fixedPropertyProvider(m)});
1214
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1215
        assertEquals("one build-folder created", 1, buildFolders.size());
1216
        assertEquals("export is properly configured", base.getAbsolutePath(), buildFolders.get(0));
1217
        
1218
        cu.output.add(base2.getAbsolutePath());
1205
        cu.output.add(base2.getAbsolutePath());
1219
        cu.output.add("other.jar");
1220
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1206
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1221
        assertEquals("two build-folder created", 2, buildFolders.size());
1207
        assertEquals("one build-folder created", 1, buildFolders.size());
1222
        assertEquals("export is properly configured", base.getAbsolutePath(), buildFolders.get(0));
1208
        assertEquals("export is properly configured", base2.getAbsolutePath(), buildFolders.get(0));
1223
        assertEquals("export is properly configured", base2.getAbsolutePath(), buildFolders.get(1));
1224
        
1209
        
1225
        cu.output.add(getWorkDir().getAbsolutePath());
1210
        cu.output.add(getWorkDir().getAbsolutePath());
1226
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
1211
        buildFolders = JavaProjectGenerator.guessBuildFolders(evaluator, units, proj1, proj1);
Lines 1295-1301 Link Here
1295
        validate(p);
1280
        validate(p);
1296
        
1281
        
1297
    }    
1282
    }    
1298
1283
    
1284
    public void testPutBuildFiles() throws Exception {
1285
        AntProjectHelper helper = createEmptyProject("proj", "proj", false);
1286
        FileObject base = helper.getProjectDirectory();
1287
        Project p = ProjectManager.getDefault().findProject(base);
1288
        assertNotNull("Project was not created", p);
1289
        assertEquals("Project folder is incorrect", base, p.getProjectDirectory());
1290
        
1291
        List buildFiles = new ArrayList();
1292
        buildFiles.add("/some/path/projA/archive.jar");
1293
        buildFiles.add("C:\\dev\\projB\\library.jar");
1294
        
1295
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1296
        Element el = Util.getPrimaryConfigurationData(helper);
1297
        Element foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1298
        assertNotNull("<folders> element exists", foldersEl);
1299
        List subElements = Util.findSubElements(foldersEl);
1300
        assertEquals("project has two build-files", 2, subElements.size());
1301
        Element el2 = (Element)subElements.get(0);
1302
        assertElement(el2, "build-file", null);
1303
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1304
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/some/path/projA/archive.jar");
1305
        el2 = (Element)subElements.get(1);
1306
        assertElement(el2, "build-file", null);
1307
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1308
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "C:\\dev\\projB\\library.jar");
1309
        
1310
        // validate against schema:
1311
        ProjectManager.getDefault().saveAllProjects();
1312
        validate(p);
1313
        
1314
        // now test updating
1315
        buildFiles = new ArrayList();
1316
        buildFiles.add("/projC/dist/projC.jar");
1317
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1318
        el = Util.getPrimaryConfigurationData(helper);
1319
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1320
        subElements = Util.findSubElements(foldersEl);
1321
        assertEquals("project has one build-file", 1, subElements.size());
1322
        el2 = (Element)subElements.get(0);
1323
        assertElement(el2, "build-file", null);
1324
        assertEquals("build-file has one subelement", 1, Util.findSubElements(el2).size());
1325
        assertElement((Element)Util.findSubElements(el2).get(0), "location", "/projC/dist/projC.jar");
1326
        
1327
        buildFiles = new ArrayList();
1328
        JavaProjectGenerator.putBuildFiles(helper, buildFiles);
1329
        el = Util.getPrimaryConfigurationData(helper);
1330
        foldersEl = Util.findElement(el, "folders", Util.NAMESPACE);
1331
        subElements = Util.findSubElements(foldersEl);
1332
        assertEquals("project has no build-file", 0, subElements.size());
1333
        
1334
        // validate against schema:
1335
        ProjectManager.getDefault().saveAllProjects();
1336
        validate(p);
1337
    }
1338
    
1299
    private static class Listener implements ChangeListener {
1339
    private static class Listener implements ChangeListener {
1300
        int count = 0;
1340
        int count = 0;
1301
        public void stateChanged(ChangeEvent ev) {
1341
        public void stateChanged(ChangeEvent ev) {

Return to bug 57656