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

(-)src/org/netbeans/api/project/ant/AntArtifact.java (-1 / +11 lines)
Lines 91-97 Link Here
91
     *         may be either relative, or an absolute <code>file</code>-protocol URI
91
     *         may be either relative, or an absolute <code>file</code>-protocol URI
92
     */
92
     */
93
    public abstract URI getArtifactLocation();
93
    public abstract URI getArtifactLocation();
94
    
94
95
    /**
96
     * Returns identifier of the AntArtifact which must be <strong>unique within
97
     * one project</strong>. By default it is target name which produces the
98
     * artifact, but if your target produces more that one artifact then
99
     * you must override this method and uniquely identify each artifact.
100
     */
101
    public String getID() {
102
        return getTargetName();
103
    }
104
95
    /**
105
    /**
96
     * Convenience method to find the actual artifact, if it currently exists.
106
     * Convenience method to find the actual artifact, if it currently exists.
97
     * Uses {@link #getScriptFile} or {@link #getScriptLocation} and resolves {@link #getArtifactLocation} from it.
107
     * Uses {@link #getScriptFile} or {@link #getScriptLocation} and resolves {@link #getArtifactLocation} from it.
(-)src/org/netbeans/api/project/ant/AntArtifactQuery.java (-3 / +3 lines)
Lines 60-77 Link Here
60
     * Try to find a particular build artifact according to the Ant target producing it.
60
     * Try to find a particular build artifact according to the Ant target producing it.
61
     * @param p a project (should have {@link AntArtifactProvider} in lookup
61
     * @param p a project (should have {@link AntArtifactProvider} in lookup
62
     *          in order for this query to work)
62
     *          in order for this query to work)
63
     * @param targetName a desired {@link AntArtifact#getTargetName target name}
63
     * @param id a desired {@link AntArtifact#getID ID}
64
     * @return an artifact produced by that project with the specified target,
64
     * @return an artifact produced by that project with the specified target,
65
     *         or null if none such can be found
65
     *         or null if none such can be found
66
     */
66
     */
67
    public static AntArtifact findArtifactByTarget(Project p, String targetName) {
67
    public static AntArtifact findArtifactByID(Project p, String id) {
68
        AntArtifactProvider prov = (AntArtifactProvider)p.getLookup().lookup(AntArtifactProvider.class);
68
        AntArtifactProvider prov = (AntArtifactProvider)p.getLookup().lookup(AntArtifactProvider.class);
69
        if (prov == null) {
69
        if (prov == null) {
70
            return null;
70
            return null;
71
        }
71
        }
72
        AntArtifact[] artifacts = prov.getBuildArtifacts();
72
        AntArtifact[] artifacts = prov.getBuildArtifacts();
73
        for (int i = 0; i < artifacts.length; i++) {
73
        for (int i = 0; i < artifacts.length; i++) {
74
            if (artifacts[i].getTargetName().equals(targetName)) {
74
            if (artifacts[i].getID().equals(id)) {
75
                return artifacts[i];
75
                return artifacts[i];
76
            }
76
            }
77
        }
77
        }
(-)src/org/netbeans/spi/project/ant/AntArtifactProvider.java (-1 / +2 lines)
Lines 30-36 Link Here
30
     * @return a list of build artifacts produced by this project;
30
     * @return a list of build artifacts produced by this project;
31
     *         the target names must be distinct, and if this provider is in a
31
     *         the target names must be distinct, and if this provider is in a
32
     *         project's lookup, {@link AntArtifact#getProject} must return the
32
     *         project's lookup, {@link AntArtifact#getProject} must return the
33
     *         same project
33
     *         same project; list of artifacts for one project cannot contain
34
     *         two artifacts with the same {@link AntArtifact#getID ID}
34
     */
35
     */
35
    AntArtifact[] getBuildArtifacts();
36
    AntArtifact[] getBuildArtifacts();
36
    
37
    
(-)src/org/netbeans/spi/project/support/ant/ReferenceHelper.java (-30 / +45 lines)
Lines 193-199 Link Here
193
                }
193
                }
194
                File scriptFile = artifact.getScriptLocation();
194
                File scriptFile = artifact.getScriptLocation();
195
                URI scriptLocation = forProjDir.toURI().relativize(scriptFile.toURI());
195
                URI scriptLocation = forProjDir.toURI().relativize(scriptFile.toURI());
196
                RawReference ref = new RawReference(forProjName, artifact.getType(), scriptLocation, artifact.getTargetName(), artifact.getCleanTargetName());
196
                RawReference ref = new RawReference(forProjName, artifact.getType(), scriptLocation, artifact.getTargetName(), artifact.getCleanTargetName(), artifact.getID());
197
                Element references = loadReferences(true);
197
                Element references = loadReferences(true);
198
                boolean success;
198
                boolean success;
199
                try {
199
                try {
Lines 237-243 Link Here
237
                    propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
237
                    propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
238
                }
238
                }
239
                props = h.getProperties(propertiesFile);
239
                props = h.getProperties(propertiesFile);
240
                String refPathProp = "reference." + forProjName + '.' + artifact.getTargetName(); // NOI18N
240
                String refPathProp = "reference." + forProjName + '.' + artifact.getID(); // NOI18N
241
                if (!refPath.equals(props.getProperty(refPathProp))) {
241
                if (!refPath.equals(props.getProperty(refPathProp))) {
242
                    props.setProperty(refPathProp, refPath);
242
                    props.setProperty(refPathProp, refPath);
243
                    h.putProperties(propertiesFile, props);
243
                    h.putProperties(propertiesFile, props);
Lines 303-317 Link Here
303
                break;
303
                break;
304
            }
304
            }
305
            if (testRef.getForeignProjectName().equals(ref.getForeignProjectName())) {
305
            if (testRef.getForeignProjectName().equals(ref.getForeignProjectName())) {
306
                if (testRef.getTargetName().compareTo(ref.getTargetName()) > 0) {
306
                if (testRef.getID().compareTo(ref.getID()) > 0) {
307
                    // again, gone too far, go back
307
                    // again, gone too far, go back
308
                    nextRefEl = testRefEl;
308
                    nextRefEl = testRefEl;
309
                    break;
309
                    break;
310
                }
310
                }
311
                if (testRef.getTargetName().equals(ref.getTargetName())) {
311
                if (testRef.getID().equals(ref.getID())) {
312
                    // Key match, check if it needs to be updated.
312
                    // Key match, check if it needs to be updated.
313
                    if (testRef.getArtifactType().equals(ref.getArtifactType()) &&
313
                    if (testRef.getArtifactType().equals(ref.getArtifactType()) &&
314
                            testRef.getScriptLocation().equals(ref.getScriptLocation()) &&
314
                            testRef.getScriptLocation().equals(ref.getScriptLocation()) &&
315
                            testRef.getTargetName().equals(ref.getTargetName()) &&
315
                            testRef.getCleanTargetName().equals(ref.getCleanTargetName())) {
316
                            testRef.getCleanTargetName().equals(ref.getCleanTargetName())) {
316
                        // Match on other fields. Return without changing anything.
317
                        // Match on other fields. Return without changing anything.
317
                        return false;
318
                        return false;
Lines 348-364 Link Here
348
     * Acquires write access.
349
     * Acquires write access.
349
     * @param foreignProjectName the local name of the foreign project
350
     * @param foreignProjectName the local name of the foreign project
350
     *                           (usually its code name)
351
     *                           (usually its code name)
351
     * @param targetName the name of the Ant target corresponding to the build artifact
352
     * @param id the ID of the build artifact (usually build target name)
352
     * @return true if a reference or some property was actually removed,
353
     * @return true if a reference or some property was actually removed,
353
     *         false if the reference was not there and no property was removed
354
     *         false if the reference was not there and no property was removed
354
     */
355
     */
355
    public boolean removeReference(final String foreignProjectName, final String targetName) {
356
    public boolean removeReference(final String foreignProjectName, final String id) {
356
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
357
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
357
            public Object run() {
358
            public Object run() {
358
                Element references = loadReferences(true);
359
                Element references = loadReferences(true);
359
                boolean success;
360
                boolean success;
360
                try {
361
                try {
361
                    success = removeRawReference(foreignProjectName, targetName, references);
362
                    success = removeRawReference(foreignProjectName, id, references);
362
                } catch (IllegalArgumentException e) {
363
                } catch (IllegalArgumentException e) {
363
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
364
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
364
                    return Boolean.FALSE;
365
                    return Boolean.FALSE;
Lines 393-399 Link Here
393
                        }
394
                        }
394
                    }
395
                    }
395
                }
396
                }
396
                String refProp = "reference." + foreignProjectName + '.' + targetName; // NOI18N
397
                String refProp = "reference." + foreignProjectName + '.' + id; // NOI18N
397
                for (int i = 0; i < PROPS_PATHS.length; i++) {
398
                for (int i = 0; i < PROPS_PATHS.length; i++) {
398
                    EditableProperties props = h.getProperties(PROPS_PATHS[i]);
399
                    EditableProperties props = h.getProperties(PROPS_PATHS[i]);
399
                    if (props.containsKey(refProp)) {
400
                    if (props.containsKey(refProp)) {
Lines 454-469 Link Here
454
     * Acquires write access.
455
     * Acquires write access.
455
     * @param foreignProjectName the local name of the foreign project
456
     * @param foreignProjectName the local name of the foreign project
456
     *                           (usually its code name)
457
     *                           (usually its code name)
457
     * @param targetName the name of the Ant target corresponding to the build artifact
458
     * @param id the ID of the build artifact (usually build target name)
458
     * @return true if a reference was actually removed, false if it was not there
459
     * @return true if a reference was actually removed, false if it was not there
459
     */
460
     */
460
    public boolean removeRawReference(final String foreignProjectName, final String targetName) {
461
    public boolean removeRawReference(final String foreignProjectName, final String id) {
461
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
462
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
462
            public Object run() {
463
            public Object run() {
463
                Element references = loadReferences(true);
464
                Element references = loadReferences(true);
464
                boolean success;
465
                boolean success;
465
                try {
466
                try {
466
                    success = removeRawReference(foreignProjectName, targetName, references);
467
                    success = removeRawReference(foreignProjectName, id, references);
467
                } catch (IllegalArgumentException e) {
468
                } catch (IllegalArgumentException e) {
468
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
469
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
469
                    return Boolean.FALSE;
470
                    return Boolean.FALSE;
Lines 478-484 Link Here
478
        })).booleanValue();
479
        })).booleanValue();
479
    }
480
    }
480
    
481
    
481
    private static boolean removeRawReference(String foreignProjectName, String targetName, Element references) throws IllegalArgumentException {
482
    private static boolean removeRawReference(String foreignProjectName, String id, Element references) throws IllegalArgumentException {
482
        // As with addRawReference, do a linear search through.
483
        // As with addRawReference, do a linear search through.
483
        List/*<Element>*/subEls = Util.findSubElements(references);
484
        List/*<Element>*/subEls = Util.findSubElements(references);
484
        Iterator it = subEls.iterator();
485
        Iterator it = subEls.iterator();
Lines 490-500 Link Here
490
                return false;
491
                return false;
491
            }
492
            }
492
            if (testRef.getForeignProjectName().equals(foreignProjectName)) {
493
            if (testRef.getForeignProjectName().equals(foreignProjectName)) {
493
                if (testRef.getTargetName().compareTo(targetName) > 0) {
494
                if (testRef.getID().compareTo(id) > 0) {
494
                    // again, searched past it
495
                    // again, searched past it
495
                    return false;
496
                    return false;
496
                }
497
                }
497
                if (testRef.getTargetName().equals(targetName)) {
498
                if (testRef.getID().equals(id)) {
498
                    // Key match, remove it.
499
                    // Key match, remove it.
499
                    references.removeChild(testRefEl);
500
                    references.removeChild(testRefEl);
500
                    return true;
501
                    return true;
Lines 547-563 Link Here
547
     * Acquires read access.
548
     * Acquires read access.
548
     * @param foreignProjectName the local name of the foreign project
549
     * @param foreignProjectName the local name of the foreign project
549
     *                           (usually its code name)
550
     *                           (usually its code name)
550
     * @param targetName the name of the Ant target corresponding to the build artifact
551
     * @param id the ID of the build artifact (usually the build target name)
551
     * @return the specified raw reference from this project,
552
     * @return the specified raw reference from this project,
552
     *         or null if none such could be found
553
     *         or null if none such could be found
553
     */
554
     */
554
    public RawReference getRawReference(final String foreignProjectName, final String targetName) {
555
    public RawReference getRawReference(final String foreignProjectName, final String id) {
555
        return (RawReference)ProjectManager.mutex().readAccess(new Mutex.Action() {
556
        return (RawReference)ProjectManager.mutex().readAccess(new Mutex.Action() {
556
            public Object run() {
557
            public Object run() {
557
                Element references = loadReferences(false);
558
                Element references = loadReferences(false);
558
                if (references != null) {
559
                if (references != null) {
559
                    try {
560
                    try {
560
                        return getRawReference(foreignProjectName, targetName, references);
561
                        return getRawReference(foreignProjectName, id, references);
561
                    } catch (IllegalArgumentException e) {
562
                    } catch (IllegalArgumentException e) {
562
                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
563
                        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
563
                    }
564
                    }
Lines 567-579 Link Here
567
        });
568
        });
568
    }
569
    }
569
    
570
    
570
    private static RawReference getRawReference(String foreignProjectName, String targetName, Element references) throws IllegalArgumentException {
571
    private static RawReference getRawReference(String foreignProjectName, String id, Element references) throws IllegalArgumentException {
571
        List/*<Element>*/subEls = Util.findSubElements(references);
572
        List/*<Element>*/subEls = Util.findSubElements(references);
572
        Iterator it = subEls.iterator();
573
        Iterator it = subEls.iterator();
573
        while (it.hasNext()) {
574
        while (it.hasNext()) {
574
            RawReference ref = RawReference.create((Element)it.next());
575
            RawReference ref = RawReference.create((Element)it.next());
575
            if (ref.getForeignProjectName().equals(foreignProjectName) &&
576
            if (ref.getForeignProjectName().equals(foreignProjectName) &&
576
                    ref.getTargetName().equals(targetName)) {
577
                    ref.getID().equals(id)) {
577
                return ref;
578
                return ref;
578
            }
579
            }
579
        }
580
        }
Lines 709-715 Link Here
709
    public String createForeignFileReference(AntArtifact artifact) throws IllegalArgumentException {
710
    public String createForeignFileReference(AntArtifact artifact) throws IllegalArgumentException {
710
        addReference(artifact);
711
        addReference(artifact);
711
        String projID = findReferenceID(artifact);
712
        String projID = findReferenceID(artifact);
712
        return "${reference." + projID + '.' + artifact.getTargetName() + '}'; // NOI18N
713
        return "${reference." + projID + '.' + artifact.getID() + '}'; // NOI18N
713
    }
714
    }
714
    
715
    
715
    private static final Pattern FOREIGN_FILE_REFERENCE = Pattern.compile("\\$\\{reference\\.([^.${}]+)\\.([^.${}]+)\\}"); // NOI18N
716
    private static final Pattern FOREIGN_FILE_REFERENCE = Pattern.compile("\\$\\{reference\\.([^.${}]+)\\.([^.${}]+)\\}"); // NOI18N
Lines 762-769 Link Here
762
        Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
763
        Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
763
        if (m.matches()) {
764
        if (m.matches()) {
764
            String forProjName = m.group(1);
765
            String forProjName = m.group(1);
765
            String targetName = m.group(2);
766
            String id = m.group(2);
766
            removeReference(forProjName, targetName);
767
            removeReference(forProjName, id);
767
            return;
768
            return;
768
        }
769
        }
769
        m = FOREIGN_PLAIN_FILE_REFERENCE.matcher(reference);
770
        m = FOREIGN_PLAIN_FILE_REFERENCE.matcher(reference);
Lines 804-809 Link Here
804
        private final URI scriptLocation;
805
        private final URI scriptLocation;
805
        private final String targetName;
806
        private final String targetName;
806
        private final String cleanTargetName;
807
        private final String cleanTargetName;
808
        private final String artifactID;
807
        
809
        
808
        /**
810
        /**
809
         * Create a raw reference descriptor.
811
         * Create a raw reference descriptor.
Lines 813-821 Link Here
813
         * @param scriptLocation the relative URI to the build script from the project directory
815
         * @param scriptLocation the relative URI to the build script from the project directory
814
         * @param targetName the Ant target name
816
         * @param targetName the Ant target name
815
         * @param cleanTargetName the Ant clean target name
817
         * @param cleanTargetName the Ant clean target name
818
         * @param artifactID the {@link AntArtifact#getID ID} of the build artifact
816
         * @throws IllegalArgumentException if the script location is given an absolute URI
819
         * @throws IllegalArgumentException if the script location is given an absolute URI
817
         */
820
         */
818
        public RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String targetName, String cleanTargetName) throws IllegalArgumentException {
821
        public RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String targetName, String cleanTargetName, String artifactID) throws IllegalArgumentException {
819
            this.foreignProjectName = foreignProjectName;
822
            this.foreignProjectName = foreignProjectName;
820
            this.artifactType = artifactType;
823
            this.artifactType = artifactType;
821
            if (scriptLocation.isAbsolute()) {
824
            if (scriptLocation.isAbsolute()) {
Lines 824-829 Link Here
824
            this.scriptLocation = scriptLocation;
827
            this.scriptLocation = scriptLocation;
825
            this.targetName = targetName;
828
            this.targetName = targetName;
826
            this.cleanTargetName = cleanTargetName;
829
            this.cleanTargetName = cleanTargetName;
830
            this.artifactID = artifactID;
827
        }
831
        }
828
        
832
        
829
        private static final List/*<String>*/ SUB_ELEMENT_NAMES = Arrays.asList(new String[] {
833
        private static final List/*<String>*/ SUB_ELEMENT_NAMES = Arrays.asList(new String[] {
Lines 832-837 Link Here
832
            "script", // NOI18N
836
            "script", // NOI18N
833
            "target", // NOI18N
837
            "target", // NOI18N
834
            "clean-target", // NOI18N
838
            "clean-target", // NOI18N
839
            "id", // NOI18N
835
        });
840
        });
836
        
841
        
837
        /**
842
        /**
Lines 843-853 Link Here
843
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
848
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
844
            }
849
            }
845
            NodeList nl = xml.getElementsByTagNameNS("*", "*"); // NOI18N
850
            NodeList nl = xml.getElementsByTagNameNS("*", "*"); // NOI18N
846
            if (nl.getLength() != 5) {
851
            if (nl.getLength() != 6) {
847
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
852
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
848
            }
853
            }
849
            String[] values = new String[5];
854
            String[] values = new String[nl.getLength()];
850
            for (int i = 0; i < 5; i++) {
855
            for (int i = 0; i < nl.getLength(); i++) {
851
                Element el = (Element)nl.item(i);
856
                Element el = (Element)nl.item(i);
852
                if (!REFS_NS.equals(el.getNamespaceURI())) {
857
                if (!REFS_NS.equals(el.getNamespaceURI())) {
853
                    throw new IllegalArgumentException("bad subelement ns: " + el); // NOI18N
858
                    throw new IllegalArgumentException("bad subelement ns: " + el); // NOI18N
Lines 868-874 Link Here
868
            }
873
            }
869
            assert !Arrays.asList(values).contains(null);
874
            assert !Arrays.asList(values).contains(null);
870
            URI scriptLocation = URI.create(values[2]); // throws IllegalArgumentException
875
            URI scriptLocation = URI.create(values[2]); // throws IllegalArgumentException
871
            return new RawReference(values[0], values[1], scriptLocation, values[3], values[4]);
876
            return new RawReference(values[0], values[1], scriptLocation, values[3], values[4], values[5]);
872
        }
877
        }
873
        
878
        
874
        /**
879
        /**
Lines 882-889 Link Here
882
                scriptLocation.toString(),
887
                scriptLocation.toString(),
883
                targetName,
888
                targetName,
884
                cleanTargetName,
889
                cleanTargetName,
890
                artifactID,
885
            };
891
            };
886
            for (int i = 0; i < 5; i++) {
892
            for (int i = 0; i < 6; i++) {
887
                Element subel = ownerDocument.createElementNS(REFS_NS, (String)SUB_ELEMENT_NAMES.get(i));
893
                Element subel = ownerDocument.createElementNS(REFS_NS, (String)SUB_ELEMENT_NAMES.get(i));
888
                subel.appendChild(ownerDocument.createTextNode(values[i]));
894
                subel.appendChild(ownerDocument.createTextNode(values[i]));
889
                el.appendChild(subel);
895
                el.appendChild(subel);
Lines 939-944 Link Here
939
        }
945
        }
940
        
946
        
941
        /**
947
        /**
948
         * Get the ID of the foreign project's build artifact.
949
         * See also {@link AntArtifact#getID}.
950
         * @return the artifact identifier
951
         */
952
        public String getID() {
953
            return artifactID;
954
        }
955
        
956
        /**
942
         * Attempt to convert this reference to a live artifact object.
957
         * Attempt to convert this reference to a live artifact object.
943
         * This involves finding the referenced foreign project on disk
958
         * This involves finding the referenced foreign project on disk
944
         * (among standard project and private properties) and asking it
959
         * (among standard project and private properties) and asking it
Lines 981-993 Link Here
981
                        // Was not a project dir.
996
                        // Was not a project dir.
982
                        return null;
997
                        return null;
983
                    }
998
                    }
984
                    return AntArtifactQuery.findArtifactByTarget(p, targetName);
999
                    return AntArtifactQuery.findArtifactByID(p, artifactID);
985
                }
1000
                }
986
            });
1001
            });
987
        }
1002
        }
988
        
1003
        
989
        public String toString() {
1004
        public String toString() {
990
            return "ReferenceHelper.RawReference<" + foreignProjectName + "," + artifactType + "," + scriptLocation + "," + targetName + "," + cleanTargetName + ">"; // NOI18N
1005
            return "ReferenceHelper.RawReference<" + foreignProjectName + "," + artifactType + "," + scriptLocation + "," + targetName + "," + cleanTargetName + "," + artifactID + ">"; // NOI18N
991
        }
1006
        }
992
        
1007
        
993
    }
1008
    }
(-)test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java (-22 / +33 lines)
Lines 175-193 Link Here
175
    public void testRawReferenceManipulation() throws Exception {
175
    public void testRawReferenceManipulation() throws Exception {
176
        assertEquals("starting with no raw references", Collections.EMPTY_LIST, Arrays.asList(r.getRawReferences()));
176
        assertEquals("starting with no raw references", Collections.EMPTY_LIST, Arrays.asList(r.getRawReferences()));
177
        // Test simple adding of a reference.
177
        // Test simple adding of a reference.
178
        ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean");
178
        ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean", "dojarID");
179
        assertTrue("successfully added a raw ref to otherproj.dojar", r.addRawReference(ref));
179
        assertTrue("successfully added a raw ref to otherproj.dojar", r.addRawReference(ref));
180
        assertNull("project.properties not changed", pev.getProperty("project.otherproj"));
180
        assertNull("project.properties not changed", pev.getProperty("project.otherproj"));
181
        assertTrue("project is modified", pm.isModified(p));
181
        assertTrue("project is modified", pm.isModified(p));
182
        ref = r.getRawReference("otherproj", "dojar");
182
        ref = r.getRawReference("otherproj", "dojarID");
183
        assertNotNull("found otherproj.dojar", ref);
183
        assertNotNull("found otherproj.dojar", ref);
184
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
184
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
185
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
185
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
186
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
186
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
187
        assertEquals("correct target name", "dojar", ref.getTargetName());
187
        assertEquals("correct target name", "dojar", ref.getTargetName());
188
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
188
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
189
        assertEquals("correct ID name", "dojarID", ref.getID());
189
        // Nonexistent references are not returned.
190
        // Nonexistent references are not returned.
190
        ref = r.getRawReference("otherproj2", "dojar");
191
        ref = r.getRawReference("otherproj2", "dojarID");
191
        assertNull("no such ref otherproj2.dojar", ref);
192
        assertNull("no such ref otherproj2.dojar", ref);
192
        ref = r.getRawReference("otherproj", "dojar2");
193
        ref = r.getRawReference("otherproj", "dojar2");
193
        assertNull("no such ref otherproj.dojar2", ref);
194
        assertNull("no such ref otherproj.dojar2", ref);
Lines 202-225 Link Here
202
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
203
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
203
        assertEquals("correct target name", "dojar", ref.getTargetName());
204
        assertEquals("correct target name", "dojar", ref.getTargetName());
204
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
205
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
206
        assertEquals("correct ID name", "dojarID", ref.getID());
205
        // Test removing it.
207
        // Test removing it.
206
        assertTrue("successfully removed otherproj.dojar", r.removeRawReference("otherproj", "dojar"));
208
        assertTrue("successfully removed otherproj.dojar", r.removeRawReference("otherproj", "dojarID"));
207
        refs = r.getRawReferences();
209
        refs = r.getRawReferences();
208
        assertEquals("no references here", 0, refs.length);
210
        assertEquals("no references here", 0, refs.length);
209
        ref = r.getRawReference("otherproj", "dojar");
211
        ref = r.getRawReference("otherproj", "dojar");
210
        assertNull("otherproj.dojar is gone", ref);
212
        assertNull("otherproj.dojar is gone", ref);
211
        // Test adding several references.
213
        // Test adding several references.
212
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean");
214
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean", "dojarID");
213
        assertTrue("added ref to otherproj.dojar", r.addRawReference(ref));
215
        assertTrue("added ref to otherproj.dojar", r.addRawReference(ref));
214
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar2", "clean");
216
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar2", "clean", "dojar2ID");
215
        assertTrue("added ref to otherproj.dojar2", r.addRawReference(ref));
217
        assertTrue("added ref to otherproj.dojar2", r.addRawReference(ref));
216
        ref = new ReferenceHelper.RawReference("otherproj2", "ear", URI.create("build.xml"), "dojar", "clean");
218
        ref = new ReferenceHelper.RawReference("otherproj2", "ear", URI.create("build.xml"), "dojar", "clean", "dojarID");
217
        assertTrue("added ref to otherproj2.dojar", r.addRawReference(ref));
219
        assertTrue("added ref to otherproj2.dojar", r.addRawReference(ref));
218
        assertEquals("have three refs", 3, r.getRawReferences().length);
220
        assertEquals("have three refs", 3, r.getRawReferences().length);
219
        // Test no-op adds and removes.
221
        // Test no-op adds and removes.
220
        pm.saveProject(p);
222
        pm.saveProject(p);
221
        assertFalse("project is saved", pm.isModified(p));
223
        assertFalse("project is saved", pm.isModified(p));
222
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean");
224
        ref = new ReferenceHelper.RawReference("otherproj", "jar", URI.create("build.xml"), "dojar", "clean", "dojarID");
223
        assertFalse("already had ref to otherproj.dojar", r.addRawReference(ref));
225
        assertFalse("already had ref to otherproj.dojar", r.addRawReference(ref));
224
        assertFalse("project is not modified by no-op add", pm.isModified(p));
226
        assertFalse("project is not modified by no-op add", pm.isModified(p));
225
        assertEquals("still have three refs", 3, r.getRawReferences().length);
227
        assertEquals("still have three refs", 3, r.getRawReferences().length);
Lines 227-260 Link Here
227
        assertFalse("project is not modified by no-op remove", pm.isModified(p));
229
        assertFalse("project is not modified by no-op remove", pm.isModified(p));
228
        assertEquals("still have three refs", 3, r.getRawReferences().length);
230
        assertEquals("still have three refs", 3, r.getRawReferences().length);
229
        // Test modifications.
231
        // Test modifications.
230
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build.xml"), "dojar", "clean");
232
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build.xml"), "dojar", "clean", "dojarID");
231
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
233
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
232
        assertTrue("project is modified by changed ref", pm.isModified(p));
234
        assertTrue("project is modified by changed ref", pm.isModified(p));
233
        assertEquals("still have three refs", 3, r.getRawReferences().length);
235
        assertEquals("still have three refs", 3, r.getRawReferences().length);
234
        ref = r.getRawReference("otherproj", "dojar");
236
        ref = r.getRawReference("otherproj", "dojarID");
235
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
237
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
236
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
238
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
237
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
239
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
238
        assertEquals("correct target name", "dojar", ref.getTargetName());
240
        assertEquals("correct target name", "dojar", ref.getTargetName());
239
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
241
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
240
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build2.xml"), "dojar", "clean");
242
        assertEquals("correct ID name", "dojarID", ref.getID());
243
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build2.xml"), "dojar", "clean", "dojarID");
241
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
244
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
242
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build2.xml"), "dojar", "clean2");
245
        ref = new ReferenceHelper.RawReference("otherproj", "war", URI.create("build2.xml"), "dojar", "clean2", "dojarID");
243
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
246
        assertTrue("modified ref to otherproj.dojar", r.addRawReference(ref));
244
        ref = r.getRawReference("otherproj", "dojar");
247
        ref = r.getRawReference("otherproj", "dojarID");
245
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
248
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
246
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
249
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
247
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
250
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
248
        assertEquals("correct target name", "dojar", ref.getTargetName());
251
        assertEquals("correct target name", "dojar", ref.getTargetName());
249
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
252
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
253
        assertEquals("correct ID name", "dojarID", ref.getID());
250
        assertEquals("still have three refs", 3, r.getRawReferences().length);
254
        assertEquals("still have three refs", 3, r.getRawReferences().length);
251
        // More removals and adds.
255
        // More removals and adds.
252
        assertTrue("now removing otherproj.dojar2", r.removeRawReference("otherproj", "dojar2"));
256
        assertTrue("now removing otherproj.dojar2", r.removeRawReference("otherproj", "dojar2ID"));
253
        assertNull("otherproj.dojar2 is gone", r.getRawReference("otherproj", "dojar2"));
257
        assertNull("otherproj.dojar2 is gone", r.getRawReference("otherproj", "dojar2ID"));
254
        assertNotNull("otherproj.jar is still there", r.getRawReference("otherproj", "dojar"));
258
        assertNotNull("otherproj.jar is still there", r.getRawReference("otherproj", "dojarID"));
255
        assertNotNull("otherproj2.dojar is still there", r.getRawReference("otherproj2", "dojar"));
259
        assertNotNull("otherproj2.dojar is still there", r.getRawReference("otherproj2", "dojarID"));
256
        assertEquals("down to two refs", 2, r.getRawReferences().length);
260
        assertEquals("down to two refs", 2, r.getRawReferences().length);
257
        ref = new ReferenceHelper.RawReference("aardvark", "jar", URI.create("build.xml"), "jar", "clean");
261
        ref = new ReferenceHelper.RawReference("aardvark", "jar", URI.create("build.xml"), "jar", "clean", "jarID");
258
        assertTrue("added ref to aardvark.jar", r.addRawReference(ref));
262
        assertTrue("added ref to aardvark.jar", r.addRawReference(ref));
259
        // Check list of refs.
263
        // Check list of refs.
260
        refs = r.getRawReferences();
264
        refs = r.getRawReferences();
Lines 266-283 Link Here
266
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
270
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
267
        assertEquals("correct target name", "jar", ref.getTargetName());
271
        assertEquals("correct target name", "jar", ref.getTargetName());
268
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
272
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
273
        assertEquals("correct ID name", "jarID", ref.getID());
269
        ref = refs[1];
274
        ref = refs[1];
270
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
275
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
271
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
276
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
272
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
277
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
273
        assertEquals("correct target name", "dojar", ref.getTargetName());
278
        assertEquals("correct target name", "dojar", ref.getTargetName());
274
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
279
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
280
        assertEquals("correct ID name", "dojarID", ref.getID());
275
        ref = refs[2];
281
        ref = refs[2];
276
        assertEquals("correct foreign project name", "otherproj2", ref.getForeignProjectName());
282
        assertEquals("correct foreign project name", "otherproj2", ref.getForeignProjectName());
277
        assertEquals("correct modified artifact type", "ear", ref.getArtifactType());
283
        assertEquals("correct modified artifact type", "ear", ref.getArtifactType());
278
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
284
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
279
        assertEquals("correct target name", "dojar", ref.getTargetName());
285
        assertEquals("correct target name", "dojar", ref.getTargetName());
280
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
286
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
287
        assertEquals("correct ID name", "dojarID", ref.getID());
281
        // Try saving and checking that project.xml is correct.
288
        // Try saving and checking that project.xml is correct.
282
        assertTrue("Project is still modified", pm.isModified(p));
289
        assertTrue("Project is still modified", pm.isModified(p));
283
        pm.saveProject(p);
290
        pm.saveProject(p);
Lines 294-299 Link Here
294
            "script",
301
            "script",
295
            "target",
302
            "target",
296
            "clean-target",
303
            "clean-target",
304
            "id",
297
        };
305
        };
298
        String[][] values = {
306
        String[][] values = {
299
            {
307
            {
Lines 302-307 Link Here
302
                "build.xml",
310
                "build.xml",
303
                "jar",
311
                "jar",
304
                "clean",
312
                "clean",
313
                "jarID",
305
            },
314
            },
306
            {
315
            {
307
                "otherproj",
316
                "otherproj",
Lines 309-314 Link Here
309
                "build2.xml",
318
                "build2.xml",
310
                "dojar",
319
                "dojar",
311
                "clean2",
320
                "clean2",
321
                "dojarID",
312
            },
322
            },
313
            {
323
            {
314
                "otherproj2",
324
                "otherproj2",
Lines 316-326 Link Here
316
                "build.xml",
326
                "build.xml",
317
                "dojar",
327
                "dojar",
318
                "clean",
328
                "clean",
329
                "dojarID",
319
            },
330
            },
320
        };
331
        };
321
        for (int i = 0; i < 3; i++) {
332
        for (int i = 0; i < 3; i++) {
322
            Element reference = (Element)nl.item(i);
333
            Element reference = (Element)nl.item(i);
323
            for (int j = 0; j < 5; j++) {
334
            for (int j = 0; j < 6; j++) {
324
                String elementName = elementNames[j];
335
                String elementName = elementNames[j];
325
                Element element = Util.findElement(reference, elementName, ReferenceHelper.REFS_NS);
336
                Element element = Util.findElement(reference, elementName, ReferenceHelper.REFS_NS);
326
                assertNotNull("had element " + elementName + " in ref #" + i, element);
337
                assertNotNull("had element " + elementName + " in ref #" + i, element);
Lines 549-555 Link Here
549
        // test non-collocated foreign project reference
560
        // test non-collocated foreign project reference
550
        FileObject nonCollocatedProjectLib = scratch.getFileObject("separate/proj3").createFolder("dist").createData("proj3.jar");
561
        FileObject nonCollocatedProjectLib = scratch.getFileObject("separate/proj3").createFolder("dist").createData("proj3.jar");
551
        f = FileUtil.toFile(nonCollocatedProjectLib);
562
        f = FileUtil.toFile(nonCollocatedProjectLib);
552
        art = AntArtifactQuery.findArtifactByTarget(pm.findProject(sepprojdir), "dojar");
563
        art = AntArtifactQuery.findArtifactByID(pm.findProject(sepprojdir), "dojar");
553
        assertNotNull("have an artifact proj3.dojar", art);
564
        assertNotNull("have an artifact proj3.dojar", art);
554
        assertEquals("can add a reference to a direct artifact", "${reference.proj3.dojar}", r.createForeignFileReference(art));
565
        assertEquals("can add a reference to a direct artifact", "${reference.proj3.dojar}", r.createForeignFileReference(art));
555
        assertEquals("creating reference second time must return already existing ID", "${reference.proj3.dojar}", r.createForeignFileReference(art));
566
        assertEquals("creating reference second time must return already existing ID", "${reference.proj3.dojar}", r.createForeignFileReference(art));
Lines 634-640 Link Here
634
    
645
    
635
    public void testToAntArtifact() throws Exception {
646
    public void testToAntArtifact() throws Exception {
636
        ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference(
647
        ReferenceHelper.RawReference ref = new ReferenceHelper.RawReference(
637
            "proj2", "irrelevant", new URI("also-irrelevant"), "dojar", "totally-irrelevant");
648
            "proj2", "irrelevant", new URI("also-irrelevant"), "dojar", "totally-irrelevant", "dojar");
638
        AntArtifact art = ref.toAntArtifact(r);
649
        AntArtifact art = ref.toAntArtifact(r);
639
        assertNull("${project.proj2} not set, will not be found", art);
650
        assertNull("${project.proj2} not set, will not be found", art);
640
        EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
651
        EditableProperties props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
Lines 648-654 Link Here
648
        assertEquals("correct target name", "dojar", art.getTargetName());
659
        assertEquals("correct target name", "dojar", art.getTargetName());
649
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
660
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
650
        ref = new ReferenceHelper.RawReference(
661
        ref = new ReferenceHelper.RawReference(
651
            "proj2", "irrelevant", new URI("also-irrelevant"), "doojar", "totally-irrelevant");
662
            "proj2", "irrelevant", new URI("also-irrelevant"), "doojar", "totally-irrelevant", "doojar");
652
        art = ref.toAntArtifact(r);
663
        art = ref.toAntArtifact(r);
653
        assertNull("wrong target name, will not be found", art);
664
        assertNull("wrong target name, will not be found", art);
654
    }
665
    }

Return to bug 42903