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

(-)ant/freeform/src/org/netbeans/modules/ant/freeform/ArtifactProvider.java (-23 / +32 lines)
Lines 26-31 Link Here
26
import org.netbeans.api.project.ant.AntArtifact;
26
import org.netbeans.api.project.ant.AntArtifact;
27
import org.netbeans.modules.ant.freeform.spi.support.Util;
27
import org.netbeans.modules.ant.freeform.spi.support.Util;
28
import org.netbeans.spi.project.ant.AntArtifactProvider;
28
import org.netbeans.spi.project.ant.AntArtifactProvider;
29
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
29
import org.openide.ErrorManager;
30
import org.openide.ErrorManager;
30
import org.w3c.dom.Element;
31
import org.w3c.dom.Element;
31
32
Lines 57-67 Link Here
57
            String artifactKey = artifact.getType() + artifact.getTargetName() + artifact.getScriptLocation().getAbsolutePath();
58
            String artifactKey = artifact.getType() + artifact.getTargetName() + artifact.getScriptLocation().getAbsolutePath();
58
            FreeformArtifact alreadyHasArtifact = (FreeformArtifact)uniqueArtifacts.get(artifactKey);
59
            FreeformArtifact alreadyHasArtifact = (FreeformArtifact)uniqueArtifacts.get(artifactKey);
59
            if (alreadyHasArtifact != null) {
60
            if (alreadyHasArtifact != null) {
60
                // #50076: There is multiple output jars produced by
61
                alreadyHasArtifact.addLocation(readArtifactLocation(export, project.evaluator()));
61
                // one type/target/script. Do not report this AA.
62
                artifacts.remove(alreadyHasArtifact);
63
                continue;
62
                continue;
64
            } else {
63
            } else {
64
                artifact.addLocation(readArtifactLocation(export, project.evaluator()));
65
                uniqueArtifacts.put(artifactKey, artifact);
65
                uniqueArtifacts.put(artifactKey, artifact);
66
            }
66
            }
67
            
67
            
Lines 84-93 Link Here
84
        return (AntArtifact[]) artifacts.toArray(new AntArtifact[artifacts.size()]);
84
        return (AntArtifact[]) artifacts.toArray(new AntArtifact[artifacts.size()]);
85
    }
85
    }
86
    
86
    
87
    public static URI readArtifactLocation(Element export, PropertyEvaluator eval) {
88
        Element locEl = Util.findElement(export, "location", FreeformProjectType.NS_GENERAL); // NOI18N
89
        assert locEl != null;
90
        String loc = Util.findText(locEl);
91
        assert loc != null;
92
        String locationResolved = eval.evaluate(loc);
93
        if (locationResolved == null) {
94
            return URI.create("file:/UNDEFINED"); // NOI18N
95
        }
96
        File locF = new File(locationResolved);
97
        if (locF.isAbsolute()) {
98
            return locF.toURI();
99
        } else {
100
            // Project-relative path.
101
            try {
102
                return new URI(null, null, locationResolved.replace(File.separatorChar, '/'), null);
103
            } catch (URISyntaxException e) {
104
                ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
105
                return URI.create("file:/BROKEN"); // NOI18N
106
            }
107
        }
108
    }
109
87
    private final class FreeformArtifact extends AntArtifact {
110
    private final class FreeformArtifact extends AntArtifact {
88
        
111
        
89
        private final Element export;
112
        private final Element export;
90
        private String id = null;
113
        private String id = null;
114
        private Set locations = new HashSet();
91
        
115
        
92
        public FreeformArtifact(Element export) {
116
        public FreeformArtifact(Element export) {
93
            this.export = export;
117
            this.export = export;
Lines 188-214 Link Here
188
            return id;
212
            return id;
189
        }
213
        }
190
214
191
        public URI getArtifactLocation() {
215
        public URI[] getArtifactLocations() {
192
            Element locEl = Util.findElement(export, "location", FreeformProjectType.NS_GENERAL); // NOI18N
216
            return (URI[])locations.toArray(new URI[locations.size()]);
193
            assert locEl != null;
194
            String loc = Util.findText(locEl);
195
            assert loc != null;
196
            String locationResolved = project.evaluator().evaluate(loc);
197
            if (locationResolved == null) {
198
                return URI.create("file:/UNDEFINED"); // NOI18N
199
            }
200
            File locF = new File(locationResolved);
201
            if (locF.isAbsolute()) {
202
                return locF.toURI();
203
            } else {
204
                // Project-relative path.
205
                try {
206
                    return new URI(null, null, locationResolved.replace(File.separatorChar, '/'), null);
207
                } catch (URISyntaxException e) {
208
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
209
                    return URI.create("file:/BROKEN"); // NOI18N
210
                }
211
            }
217
            }
218
        
219
        private void addLocation(URI u) {
220
            locations.add(u);
212
        }
221
        }
213
        
222
        
214
        public String toString() {
223
        public String toString() {
(-)ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/ArtifactProviderTest.java (-2 / +9 lines)
Lines 51-57 Link Here
51
    
51
    
52
    private void verifyArtifact(AntArtifact aa) {
52
    private void verifyArtifact(AntArtifact aa) {
53
        assertEquals("right project", simple, aa.getProject());
53
        assertEquals("right project", simple, aa.getProject());
54
        assertEquals("right location", URI.create("build/simple-app.jar"), aa.getArtifactLocation());
54
        assertEquals("right location", URI.create("build/simple-app.jar"), aa.getArtifactLocations()[0]);
55
        assertEquals("right target", "jar", aa.getTargetName());
55
        assertEquals("right target", "jar", aa.getTargetName());
56
        assertEquals("right clean target", "clean", aa.getCleanTargetName());
56
        assertEquals("right clean target", "clean", aa.getCleanTargetName());
57
        // ID should be target name if that does not cause a conflict
57
        // ID should be target name if that does not cause a conflict
Lines 83-89 Link Here
83
        putExports(helper, exports);
83
        putExports(helper, exports);
84
        aa = AntArtifactQuery.findArtifactsByType(simple, "jar");
84
        aa = AntArtifactQuery.findArtifactsByType(simple, "jar");
85
        assertNotNull("some artifact found", aa);
85
        assertNotNull("some artifact found", aa);
86
        assertEquals("one artifact found", 2, aa.length);
86
        assertEquals("two artifacts found", 2, aa.length);
87
87
88
        // one type/target/script produces two outputs -> no AA
88
        // one type/target/script produces two outputs -> no AA
89
        e = new Export();
89
        e = new Export();
Lines 95-101 Link Here
95
        putExports(helper, exports);
95
        putExports(helper, exports);
96
        aa = AntArtifactQuery.findArtifactsByType(simple, "jar");
96
        aa = AntArtifactQuery.findArtifactsByType(simple, "jar");
97
        assertNotNull("some artifact found", aa);
97
        assertNotNull("some artifact found", aa);
98
        assertEquals("two artifacts found", 2, aa.length);
99
        
100
        exports.remove(0);
101
        putExports(helper, exports);
102
        aa = AntArtifactQuery.findArtifactsByType(simple, "jar");
103
        assertNotNull("some artifact found", aa);
98
        assertEquals("one artifact found", 1, aa.length);
104
        assertEquals("one artifact found", 1, aa.length);
105
        assertEquals("the artifact has two locations", 2, aa[0].getArtifactLocations().length);
99
    }
106
    }
100
107
101
    private static void putExports(AntProjectHelper helper, List/*<Export>*/ exports) {
108
    private static void putExports(AntProjectHelper helper, List/*<Export>*/ exports) {
(-)ant/project/apichanges.xml (+37 lines)
Lines 96-101 Link Here
96
            <issue number="51468"/>
96
            <issue number="51468"/>
97
        </change>
97
        </change>
98
98
99
        <change>
100
            <api name="general"/>
101
            <summary>AntArtifact enhancements</summary>
102
            <version major="1" minor="4"/>
103
            <date day="3" month="1" year="2005"/>
104
            <author login="dkonecny"/>
105
            <compatibility addition="yes" deprecation="yes">
106
                <p>
107
                    New schema was defined, but upgrade from old schema to new
108
                    one is realized only after some new features are used. If
109
                    project's artifact does not define any properties for 
110
                    artifact nor produce multiple outputs and Ant script lies
111
                    under the project's directory then old schema is
112
                    always used. Once project start using some of these new 
113
                    features the schema will be upgraded automatically to new
114
                    version. This affects any project type which is using 
115
                    ant/project module.
116
                </p>
117
            </compatibility>
118
            <description>
119
                <p>
120
                    Several enhancements of AntArtifact were implemented:
121
                </p>
122
                <ol>
123
                    <li>execution of artifact's target can be customized by properties</li>
124
                    <li>artifact can produce several build outputs</li>
125
                    <li>Ant script path is not persisted as URI, but string possibly containing Ant properties</li>
126
                </ol>
127
                <p>
128
                    ReferenceHelper class was simplified as part of the implementation.
129
                </p>
130
            </description>
131
            <issue number="47788"/>
132
            <issue number="50484"/>
133
            <issue number="50092"/>
134
        </change>
135
99
    </changes>
136
    </changes>
100
137
101
    <!-- Now the surrounding HTML text and document structure: -->
138
    <!-- Now the surrounding HTML text and document structure: -->
(-)ant/project/src/org/netbeans/api/project/ant/AntArtifact.java (-9 / +75 lines)
Lines 17-22 Link Here
17
import java.net.MalformedURLException;
17
import java.net.MalformedURLException;
18
import java.net.URI;
18
import java.net.URI;
19
import java.net.URL;
19
import java.net.URL;
20
import java.util.ArrayList;
21
import java.util.Properties;
20
import org.netbeans.api.project.FileOwnerQuery;
22
import org.netbeans.api.project.FileOwnerQuery;
21
import org.netbeans.api.project.Project;
23
import org.netbeans.api.project.Project;
22
import org.openide.ErrorManager;
24
import org.openide.ErrorManager;
Lines 38-43 Link Here
38
 */
40
 */
39
public abstract class AntArtifact {
41
public abstract class AntArtifact {
40
    
42
    
43
    private final Properties PROPS = new Properties();
44
    
41
    /**
45
    /**
42
     * Empty constructor for use from subclasses.
46
     * Empty constructor for use from subclasses.
43
     */
47
     */
Lines 86-96 Link Here
86
    
90
    
87
    /**
91
    /**
88
     * Get the location of the build artifact relative to the Ant script.
92
     * Get the location of the build artifact relative to the Ant script.
89
     * For example, <samp>dist/mylib.jar</samp>.
93
     * See {@link #getArtifactLocations}.
90
     * @return a URI to the build artifact, resolved relative to {@link #getScriptLocation};
94
     * @return a URI to the build artifact, resolved relative to {@link #getScriptLocation};
91
     *         may be either relative, or an absolute <code>file</code>-protocol URI
95
     *         may be either relative, or an absolute <code>file</code>-protocol URI
96
     * @deprecated use {@link #getArtifactLocations} instead
97
     */
98
    public URI getArtifactLocation() {
99
        // XXX: diagnostic thread dump - this method should not be called anymore
100
        Thread.dumpStack();
101
        return getArtifactLocations()[0];
102
    }
103
104
    /**
105
     * Get the locations of the build artifacts relative to the Ant script.
106
     * For example, <samp>dist/mylib.jar</samp>. The method is not defined 
107
     * as abstract only for backward compatibility reasons. It has to be 
108
     * always overriden. The order is important and should stay the same
109
     * unless the artifact was changed.
110
     * @return an array of URIs to the build artifacts, resolved relative to {@link #getScriptLocation};
111
     *         may be either relative, or an absolute <code>file</code>-protocol URI
112
     * @since X.XX
92
     */
113
     */
93
    public abstract URI getArtifactLocation();
114
    public URI[] getArtifactLocations() {
115
        // XXX: diagnostic thread dump - this method must be always overriden
116
        Thread.dumpStack();
117
        return new URI[]{getArtifactLocation()};
118
    }
94
119
95
    /**
120
    /**
96
     * Returns identifier of the AntArtifact which must be <strong>unique within
121
     * Returns identifier of the AntArtifact which must be <strong>unique within
Lines 104-125 Link Here
104
129
105
    /**
130
    /**
106
     * Convenience method to find the actual artifact, if it currently exists.
131
     * Convenience method to find the actual artifact, if it currently exists.
107
     * Uses {@link #getScriptFile} or {@link #getScriptLocation} and resolves {@link #getArtifactLocation} from it.
132
     * See {@link #getArtifactFiles}.
108
     * Note that a project which has been cleaned more recently than it has been built
109
     * will generally not have the build artifact on disk and so this call may easily
110
     * return null. If you do not rely on the actual presence of the file but just need to
111
     * refer to it abstractly, use {@link #getArtifactLocation} instead.
112
     * @return the artifact file on disk, or null if it could not be found
133
     * @return the artifact file on disk, or null if it could not be found
134
     * @deprecated use {@link #getArtifactFiles} instead
113
     */
135
     */
114
    public final FileObject getArtifactFile() {
136
    public final FileObject getArtifactFile() {
115
        URI artifactLocation = getArtifactLocation();
137
        // XXX: diagnostic thread dump - do not call this method
138
        Thread.dumpStack();
139
        FileObject fos[] = getArtifactFiles();
140
        if (fos.length > 0) {
141
            return fos[0];
142
        } else {
143
            return null;
144
        }
145
    }
146
    
147
    private FileObject getArtifactFile(URI artifactLocation) {
116
        assert !artifactLocation.isAbsolute() ||
148
        assert !artifactLocation.isAbsolute() ||
117
            (!artifactLocation.isOpaque() && "file".equals(artifactLocation.getScheme())) // NOI18N
149
            (!artifactLocation.isOpaque() && "file".equals(artifactLocation.getScheme())) // NOI18N
118
            : artifactLocation;
150
            : artifactLocation;
119
        URL artifact;
151
        URL artifact;
120
        try {
152
        try {
121
            // XXX this should probably use something in PropertyUtils?
153
            // XXX this should probably use something in PropertyUtils?
122
            artifact = getScriptLocation().toURI().resolve(getArtifactLocation()).normalize().toURL();
154
            artifact = getScriptLocation().toURI().resolve(artifactLocation).normalize().toURL();
123
        } catch (MalformedURLException e) {
155
        } catch (MalformedURLException e) {
124
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
156
            ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
125
            return null;
157
            return null;
Lines 134-139 Link Here
134
    }
166
    }
135
    
167
    
136
    /**
168
    /**
169
     * Convenience method to find the actual artifacts, if they currently exist.
170
     * Uses {@link #getScriptFile} or {@link #getScriptLocation} and resolves {@link #getArtifactLocations} from it.
171
     * Note that a project which has been cleaned more recently than it has been built
172
     * will generally not have the build artifacts on disk and so this call may easily
173
     * return empty array. If you do not rely on the actual presence of the file but just need to
174
     * refer to it abstractly, use {@link #getArtifactLocations} instead.
175
     * @return the artifact files which exist on disk, or empty array if none could be found
176
     * @since X.XX
177
     */
178
    public final FileObject[] getArtifactFiles() {
179
        URI artifactLocations[] = getArtifactLocations();
180
        ArrayList l = new ArrayList();
181
        for (int i=0; i<artifactLocations.length; i++) {
182
            FileObject fo = getArtifactFile(artifactLocations[i]);
183
            if (fo != null) {
184
                l.add(fo);
185
            }
186
        }
187
        return (FileObject[])l.toArray(new FileObject[l.size()]);
188
    }
189
    
190
    /**
137
     * Convenience method to find the actual script file, if it currently exists.
191
     * Convenience method to find the actual script file, if it currently exists.
138
     * Uses {@link #getScriptLocation}.
192
     * Uses {@link #getScriptLocation}.
139
     * The script must exist on disk (Ant cannot run scripts from NetBeans
193
     * The script must exist on disk (Ant cannot run scripts from NetBeans
Lines 154-159 Link Here
154
     */
208
     */
155
    public Project getProject() {
209
    public Project getProject() {
156
        return FileOwnerQuery.getOwner(getScriptLocation().toURI());
210
        return FileOwnerQuery.getOwner(getScriptLocation().toURI());
211
    }
212
213
    /**
214
     * Optional properties which are used for Ant target execution. Only
215
     * properties necessary for customization of Ant target execution should
216
     * be used. These properties are stored in project.xml of project using 
217
     * this artifact so care should be taken in defining what properties
218
     * are used, e.g. never use absolute path like values
219
     * @since X.XX
220
     */
221
    public Properties getProperties() {
222
        return PROPS;
157
    }
223
    }
158
    
224
    
159
}
225
}
(-)ant/project/src/org/netbeans/modules/project/ant/StandardAntArtifactQueryImpl.java (-1 / +5 lines)
Lines 14-19 Link Here
14
package org.netbeans.modules.project.ant;
14
package org.netbeans.modules.project.ant;
15
15
16
import java.io.File;
16
import java.io.File;
17
import java.net.URI;
17
import org.netbeans.api.project.FileOwnerQuery;
18
import org.netbeans.api.project.FileOwnerQuery;
18
import org.netbeans.api.project.Project;
19
import org.netbeans.api.project.Project;
19
import org.netbeans.api.project.ant.AntArtifact;
20
import org.netbeans.api.project.ant.AntArtifact;
Lines 41-49 Link Here
41
        }
42
        }
42
        AntArtifact[] artifacts = prov.getBuildArtifacts();
43
        AntArtifact[] artifacts = prov.getBuildArtifacts();
43
        for (int i = 0; i < artifacts.length; i++) {
44
        for (int i = 0; i < artifacts.length; i++) {
44
            File testFile = new File(artifacts[i].getScriptLocation().toURI().resolve(artifacts[i].getArtifactLocation()));
45
            URI uris[] = artifacts[i].getArtifactLocations();
46
            for (int y = 0; y < uris.length; y++) {
47
                File testFile = new File(artifacts[i].getScriptLocation().toURI().resolve(uris[y]));
45
            if (file.equals(testFile)) {
48
            if (file.equals(testFile)) {
46
                return artifacts[i];
49
                return artifacts[i];
50
                }
47
            }
51
            }
48
        }
52
        }
49
        return null;
53
        return null;
(-)ant/project/src/org/netbeans/modules/project/ant/ant-project-references2.xsd (+55 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
                Sun Public License Notice
4
5
The contents of this file are subject to the Sun Public License
6
Version 1.0 (the "License"). You may not use this file except in
7
compliance with the License. A copy of the License is available at
8
http://www.sun.com/
9
10
The Original Code is NetBeans. The Initial Developer of the Original
11
Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
12
Microsystems, Inc. All Rights Reserved.
13
-->
14
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
15
            targetNamespace="http://www.netbeans.org/ns/ant-project-references/2"
16
            xmlns="http://www.netbeans.org/ns/ant-project-references/2"
17
            elementFormDefault="qualified">
18
    <xsd:element name="references">
19
        <xsd:complexType>
20
            <xsd:sequence>
21
                <xsd:element name="reference" minOccurs="0" maxOccurs="unbounded">
22
                    <xsd:complexType>
23
                        <xsd:sequence>
24
                            <xsd:element name="foreign-project" type="xsd:NCName"/>
25
                            <xsd:element name="artifact-type" type="xsd:NCName"/>
26
                            <!-- semantics of script field changed in /2 version (#50092) -->
27
                            <xsd:element name="script" type="xsd:NCName"/>
28
                            <xsd:element name="target" type="xsd:NCName"/>
29
                            <xsd:element name="clean-target" type="xsd:NCName"/>
30
                            <xsd:element name="id" type="xsd:NCName"/>
31
                            <xsd:element name="properties" minOccurs="0" type="properties"/>
32
                        </xsd:sequence>
33
                    </xsd:complexType>
34
                </xsd:element>
35
            </xsd:sequence>
36
        </xsd:complexType>
37
    </xsd:element>
38
39
    <xsd:complexType name="properties">
40
        <xsd:sequence>
41
            <xsd:choice minOccurs="0" maxOccurs="unbounded">
42
                <xsd:element name="property" type="property-definition"/>
43
            </xsd:choice>
44
        </xsd:sequence>
45
    </xsd:complexType>
46
    
47
    <xsd:complexType name="property-definition">
48
        <xsd:simpleContent>
49
            <xsd:extension base="substitutable-text">
50
                <xsd:attribute name="name" type="xsd:NMTOKEN"/>
51
            </xsd:extension>
52
        </xsd:simpleContent>
53
    </xsd:complexType>
54
        
55
</xsd:schema>
(-)ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java (-136 / +523 lines)
Lines 19-27 Link Here
19
import java.net.URISyntaxException;
19
import java.net.URISyntaxException;
20
import java.util.ArrayList;
20
import java.util.ArrayList;
21
import java.util.Arrays;
21
import java.util.Arrays;
22
import java.util.Collections;
22
import java.util.Iterator;
23
import java.util.Iterator;
23
import java.util.List;
24
import java.util.List;
24
import java.util.Map;
25
import java.util.Map;
26
import java.util.Properties;
25
import java.util.regex.Matcher;
27
import java.util.regex.Matcher;
26
import java.util.regex.Pattern;
28
import java.util.regex.Pattern;
27
import org.netbeans.api.project.Project;
29
import org.netbeans.api.project.Project;
Lines 84-89 Link Here
84
     */
86
     */
85
    static final String REFS_NS = "http://www.netbeans.org/ns/ant-project-references/1"; // NOI18N
87
    static final String REFS_NS = "http://www.netbeans.org/ns/ant-project-references/1"; // NOI18N
86
    
88
    
89
    /**
90
     * Newer version of {@link #REFS_NS} supporting Properties and with changed semantics of <script>.
91
     */
92
    static final String REFS_NS2 = "http://www.netbeans.org/ns/ant-project-references/2"; // NOI18N
93
    
87
    private final AntProjectHelper h;
94
    private final AntProjectHelper h;
88
    final PropertyEvaluator eval;
95
    final PropertyEvaluator eval;
89
    private final AuxiliaryConfiguration aux;
96
    private final AuxiliaryConfiguration aux;
Lines 116-128 Link Here
116
123
117
    /**
124
    /**
118
     * Load <references> from project.xml.
125
     * Load <references> from project.xml.
119
     * @param create if true, create an empty element if it was missing, else leave as null
126
     * @return can return null if there are no references stored yet
120
     */
127
     */
121
    private Element loadReferences(boolean create) {
128
    private Element loadReferences() {
122
        assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
129
        assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
123
        Element references = aux.getConfigurationFragment(REFS_NAME, REFS_NS, true);
130
        Element references = aux.getConfigurationFragment(REFS_NAME, REFS_NS2, true);
124
        if (references == null && create) {
131
        if (references == null) {
125
            references = XMLUtil.createDocument("ignore", null, null, null).createElementNS(REFS_NS, REFS_NAME); // NOI18N
132
            references = aux.getConfigurationFragment(REFS_NAME, REFS_NS, true);
126
        }
133
        }
127
        return references;
134
        return references;
128
    }
135
    }
Lines 132-180 Link Here
132
     */
139
     */
133
    private void storeReferences(Element references) {
140
    private void storeReferences(Element references) {
134
        assert ProjectManager.mutex().isWriteAccess();
141
        assert ProjectManager.mutex().isWriteAccess();
135
        assert references != null && references.getLocalName().equals(REFS_NAME) && REFS_NS.equals(references.getNamespaceURI());
142
        assert references != null && references.getLocalName().equals(REFS_NAME) && 
143
            (REFS_NS.equals(references.getNamespaceURI()) || REFS_NS2.equals(references.getNamespaceURI()));
136
        aux.putConfigurationFragment(references, true);
144
        aux.putConfigurationFragment(references, true);
137
    }
145
    }
138
    
146
    
147
    private void removeOldReferences() {
148
        assert ProjectManager.mutex().isWriteAccess();
149
        aux.removeConfigurationFragment(REFS_NS, REFS_NAME, true);
150
    }
151
    
139
    /**
152
    /**
140
     * Add a reference to an artifact coming from a foreign project.
153
     * Add a reference to an artifact coming from a foreign project.
141
     * <p>
154
     * <p>
142
     * Records the name of the foreign project.
155
     * For more info see {@link #addReference(AntArtifact, URI)}.
143
     * Normally the foreign project name is that project's code name,
144
     * but it may be uniquified if that name is already taken to refer
145
     * to a different project with the same code name.
146
     * <p>
147
     * Adds a project property if necessary to refer to its location of the foreign
148
     * project - a shared property if the foreign project
149
     * is {@link CollocationQuery collocated} with this one, else a private property.
150
     * This property is named <samp>project.<i>foreignProjectName</i></samp>.
151
     * Example: <samp>project.mylib=../mylib</samp>
152
     * <p>
153
     * Adds a project property to refer to the location of the artifact itself.
154
     * This property is named <samp>reference.<i>foreignProjectName</i>.<i>targetName</i></samp>
155
     * and will use <samp>${project.<i>foreignProjectName</i>}</samp> and be a shared
156
     * property - unless the artifact location is an absolute URI, in which case the property
157
     * will also be private.
158
     * Example: <samp>reference.mylib.jar=${project.mylib}/dist/mylib.jar</samp>
159
     * <p>
160
     * Also records the artifact type, (relative) script path, and build and
161
     * clean target names.
162
     * <p>
163
     * If the reference already exists (keyed by foreign project object
164
     * and target name), nothing is done, unless some other field (script location,
165
     * clean target name, or artifact type) needed to be updated, in which case
166
     * the new information replaces the old. Similarly, the artifact location
167
     * property is updated if necessary.
168
     * <p>
169
     * Acquires write access.
170
     * @param artifact the artifact to add
156
     * @param artifact the artifact to add
171
     * @return true if a reference or some property was actually added or modified,
157
     * @return true if a reference or some property was actually added or modified,
172
     *         false if everything already existed and was not modified
158
     *         false if everything already existed and was not modified
173
     * @throws IllegalArgumentException if the artifact is not associated with a project
159
     * @throws IllegalArgumentException if the artifact is not associated with a project
160
     * @deprecated to add reference use {@link #addReference(AntArtifact, URI)};
161
     *   to check whether reference exist or not use {@link #isReferenced(AntArtifact, URI)}.
162
     *   This method creates reference for the first artifact location only.
174
     */
163
     */
175
    public boolean addReference(final AntArtifact artifact) throws IllegalArgumentException {
164
    public boolean addReference(final AntArtifact artifact) throws IllegalArgumentException {
176
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
165
        Object ret[] = addReference0(artifact, artifact.getArtifactLocations()[0]);
166
        return ((Boolean)ret[0]).booleanValue();
167
    }
168
169
    // @return array of two elements: [Boolean - any modification, String - reference]
170
    private Object[] addReference0(final AntArtifact artifact, final URI location) throws IllegalArgumentException {
171
        return ((List)ProjectManager.mutex().writeAccess(new Mutex.Action() {
177
            public Object run() {
172
            public Object run() {
173
                int index = findLocationIndex(artifact, location);
178
                Project forProj = artifact.getProject();
174
                Project forProj = artifact.getProject();
179
                if (forProj == null) {
175
                if (forProj == null) {
180
                    throw new IllegalArgumentException("No project associated with " + artifact); // NOI18N
176
                    throw new IllegalArgumentException("No project associated with " + artifact); // NOI18N
Lines 187-236 Link Here
187
                if (forProjName == null) {
183
                if (forProjName == null) {
188
                    forProjName = generateUniqueID(projName, "project.", forProjDir.getAbsolutePath());
184
                    forProjName = generateUniqueID(projName, "project.", forProjDir.getAbsolutePath());
189
                }
185
                }
186
                RawReference ref;
190
                File scriptFile = artifact.getScriptLocation();
187
                File scriptFile = artifact.getScriptLocation();
191
                URI scriptLocation;
188
                if (canUseVersion10(artifact, forProjDir)) {
192
                String rel = PropertyUtils.relativizeFile(forProjDir, scriptFile);
189
                String rel = PropertyUtils.relativizeFile(forProjDir, scriptFile);
190
                    URI scriptLocation;
193
                try {
191
                try {
194
                    scriptLocation = new URI(null, null, rel, null);
192
                    scriptLocation = new URI(null, null, rel, null);
195
                } catch (URISyntaxException ex) {
193
                } catch (URISyntaxException ex) {
196
                    scriptLocation = forProjDir.toURI().relativize(scriptFile.toURI());
194
                    scriptLocation = forProjDir.toURI().relativize(scriptFile.toURI());
197
                }
195
                }
198
                RawReference ref = new RawReference(forProjName, artifact.getType(), scriptLocation, artifact.getTargetName(), artifact.getCleanTargetName(), artifact.getID());
196
                    ref = new RawReference(forProjName, artifact.getType(), scriptLocation, artifact.getTargetName(), artifact.getCleanTargetName(), artifact.getID());
199
                Element references = loadReferences(true);
197
                } else {
200
                boolean success;
198
                    String scriptLocation;
201
                try {
199
                    if (scriptFile.getAbsolutePath().startsWith(forProjDir.getAbsolutePath())) {
202
                    success = addRawReference(ref, references);
200
                        String rel = PropertyUtils.relativizeFile(forProjDir, scriptFile);
203
                } catch (IllegalArgumentException e) {
201
                        assert rel != null : "Relativization must succeed for files: "+forProjDir+ " "+scriptFile;
204
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
202
                        scriptLocation = "${project."+forProjName+"}/"+rel;
205
                    return Boolean.FALSE;
203
                    } else {
206
                }
204
                        scriptLocation = "build.script.reference." + forProjName;
207
                if (success) {
205
                        setPathProperty(forProjDir, scriptFile, scriptLocation);
208
                    storeReferences(references);
206
                        scriptLocation = "${"+scriptLocation+"}";
207
                    }
208
                    ref = new RawReference(forProjName, artifact.getType(), scriptLocation, 
209
                        artifact.getTargetName(), artifact.getCleanTargetName(), 
210
                        artifact.getID(), artifact.getProperties());
209
                }
211
                }
212
                boolean success = addRawReference0(ref);
210
                // Set up ${project.whatever}.
213
                // Set up ${project.whatever}.
211
                FileObject myProjDirFO = AntBasedProjectFactorySingleton.getProjectFor(h).getProjectDirectory();
214
                FileObject myProjDirFO = AntBasedProjectFactorySingleton.getProjectFor(h).getProjectDirectory();
212
                File myProjDir = FileUtil.toFile(myProjDirFO);
215
                File myProjDir = FileUtil.toFile(myProjDirFO);
213
                String forProjPath;
216
                if (setPathProperty(myProjDir, forProjDir, "project." + forProjName)) {
214
                String propertiesFile;
215
                if (CollocationQuery.areCollocated(myProjDir, forProjDir)) {
216
                    // Fine, using a relative path to subproject.
217
                    forProjPath = PropertyUtils.relativizeFile(myProjDir, forProjDir);
218
                    assert forProjPath != null : "These dirs are not really collocated: " + myProjDir + " & " + forProjDir;
219
                    propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
220
                } else {
221
                    // Use an absolute path.
222
                    forProjPath = forProjDir.getAbsolutePath();
223
                    propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH;
224
                }
225
                EditableProperties props = h.getProperties(propertiesFile);
226
                String forProjPathProp = "project." + forProjName; // NOI18N
227
                if (!forProjPath.equals(props.getProperty(forProjPathProp))) {
228
                    props.put(forProjPathProp, forProjPath);
229
                    h.putProperties(propertiesFile, props);
230
                    success = true;
217
                    success = true;
231
                }
218
                }
232
                // Set up ${reference.whatever.whatever}.
219
                // Set up ${reference.whatever.whatever}.
233
                URI artFile = artifact.getArtifactLocation();
220
                String propertiesFile;
221
                String forProjPathProp = "project." + forProjName; // NOI18N
222
                URI artFile = location;
234
                String refPath;
223
                String refPath;
235
                if (artFile.isAbsolute()) {
224
                if (artFile.isAbsolute()) {
236
                    refPath = new File(artFile).getAbsolutePath();
225
                    refPath = new File(artFile).getAbsolutePath();
Lines 239-252 Link Here
239
                    refPath = "${" + forProjPathProp + "}/" + artFile.getPath(); // NOI18N
228
                    refPath = "${" + forProjPathProp + "}/" + artFile.getPath(); // NOI18N
240
                    propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
229
                    propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
241
                }
230
                }
242
                props = h.getProperties(propertiesFile);
231
                EditableProperties props = h.getProperties(propertiesFile);
243
                String refPathProp = "reference." + forProjName + '.' + getUsableReferenceID(artifact.getID()); // NOI18N
232
                String refPathProp = "reference." + forProjName + '.' + getUsableReferenceID(artifact.getID()); // NOI18N
233
                if (index > 0) {
234
                    refPathProp += "."+index;
235
                }
244
                if (!refPath.equals(props.getProperty(refPathProp))) {
236
                if (!refPath.equals(props.getProperty(refPathProp))) {
245
                    props.put(refPathProp, refPath);
237
                    props.put(refPathProp, refPath);
246
                    h.putProperties(propertiesFile, props);
238
                    h.putProperties(propertiesFile, props);
247
                    success = true;
239
                    success = true;
248
                }
240
                }
249
                return Boolean.valueOf(success);
241
                ArrayList l = new ArrayList();
242
                l.add(Boolean.valueOf(success));
243
                l.add("${"+refPathProp+"}"); // NOI18N
244
                return l;
245
            }
246
        })).toArray(new Object[2]);
247
    }
248
    
249
    private int findLocationIndex(final AntArtifact artifact, final URI location) throws IllegalArgumentException {
250
        if (location == null) {
251
            throw new IllegalArgumentException("location cannot be null");
252
        }
253
        URI uris[] = artifact.getArtifactLocations();
254
        for (int i=0; i<uris.length; i++) {
255
            if (uris[i].equals(location)) {
256
                return i;
257
            }
258
        }
259
        throw new IllegalArgumentException("location ("+location+") must be in AntArtifact's locations ("+artifact+")");
260
    }
261
262
    /**
263
     * Test whether the artifact can be stored as /1 artifact or not.
264
     */
265
    private static boolean canUseVersion10(AntArtifact aa, File projectDirectory) {
266
        // is there multiple outputs?
267
        if (aa.getArtifactLocations().length > 1) {
268
            return false;
269
        }
270
        // has some properties?
271
        if (aa.getProperties().keySet().size() > 0) {
272
            return false;
273
        }
274
        // does Ant script lies under project directory?
275
        if (!aa.getScriptLocation().getAbsolutePath().startsWith(projectDirectory.getAbsolutePath())) {
276
            return false;
277
        }
278
        return true;
279
    }
280
281
    /**
282
     * Helper method which checks collocation status of two files and based on
283
     * that it will in private or project properties file set up property with
284
     * the given name and with absolute or relative path value.
285
     * @return was there any change or not
286
     */
287
    private boolean setPathProperty(File base, File path, String propertyName) {
288
        String value;
289
        String propertiesFile;
290
        if (CollocationQuery.areCollocated(base, path)) {
291
            // Fine, using a relative path to subproject.
292
            value = PropertyUtils.relativizeFile(base, path);
293
            assert value != null : "These dirs are not really collocated: " + base + " & " + path;
294
            propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
295
        } else {
296
            // Use an absolute path.
297
            value = path.getAbsolutePath();
298
            propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH;
299
        }
300
        EditableProperties props = h.getProperties(propertiesFile);
301
        if (!value.equals(props.getProperty(propertyName))) {
302
            props.put(propertyName, value);
303
            h.putProperties(propertiesFile, props);
304
            // check presence of this property in opposite property file and
305
            // remove it if necessary
306
            propertiesFile = (propertiesFile == AntProjectHelper.PROJECT_PROPERTIES_PATH ? 
307
                AntProjectHelper.PRIVATE_PROPERTIES_PATH : AntProjectHelper.PROJECT_PROPERTIES_PATH);
308
            props = h.getProperties(propertiesFile);
309
            if (props.remove(propertyName) != null) {
310
                h.putProperties(propertiesFile, props);
311
            }
312
            return true;
313
        } else {
314
            return false;
315
        }
316
        
317
    }
318
    
319
    /**
320
     * Add a reference to an artifact's location coming from a foreign project.
321
     * <p>
322
     * Records the name of the foreign project.
323
     * Normally the foreign project name is that project's code name,
324
     * but it may be uniquified if that name is already taken to refer
325
     * to a different project with the same code name.
326
     * <p>
327
     * Adds a project property if necessary to refer to its location of the foreign
328
     * project - a shared property if the foreign project
329
     * is {@link CollocationQuery collocated} with this one, else a private property.
330
     * This property is named <samp>project.<i>foreignProjectName</i></samp>.
331
     * Example: <samp>project.mylib=../mylib</samp>
332
     * <p>
333
     * Adds a project property to refer to the artifact's location.
334
     * This property is named <samp>reference.<i>foreignProjectName</i>.<i>targetName</i></samp>
335
     * and will use <samp>${project.<i>foreignProjectName</i>}</samp> and be a shared
336
     * property - unless the artifact location is an absolute URI, in which case the property
337
     * will also be private.
338
     * Example: <samp>reference.mylib.jar=${project.mylib}/dist/mylib.jar</samp>
339
     * <p>
340
     * Also records the artifact type, (relative) script path, and build and
341
     * clean target names.
342
     * <p>
343
     * If the reference already exists (keyed by foreign project object
344
     * and target name), nothing is done, unless some other field (script location,
345
     * clean target name, or artifact type) needed to be updated, in which case
346
     * the new information replaces the old. Similarly, the artifact location
347
     * property is updated if necessary.
348
     * <p>
349
     * Acquires write access.
350
     * @param artifact the artifact to add
351
     * @param location the artifact's location to create reference to
352
     * @return name of reference which was created or already existed
353
     * @throws IllegalArgumentException if the artifact is not associated with a project
354
     *   or if the location is not artifact's location
355
     * @since X.XX
356
     */
357
    public String addReference(final AntArtifact artifact, URI location) throws IllegalArgumentException {
358
        Object ret[] = addReference0(artifact, location);
359
        return (String)ret[1];
360
    }
361
    
362
    /**
363
     * Tests whether reference for artifact's location was already created by
364
     * {@link #addReference(AntArtifact, URI)} for this project or not. This
365
     * method returns false also in case when reference exist but needs to be
366
     * updated.
367
     * <p>
368
     * Acquires read access.
369
     * @param artifact the artifact to add
370
     * @param location the artifact's location to create reference to
371
     * @return true if already referenced
372
     * @throws IllegalArgumentException if the artifact is not associated with a project
373
     *   or if the location is not artifact's location
374
     * @since X.XX
375
     */
376
    public boolean isReferenced(final AntArtifact artifact, final URI location) throws IllegalArgumentException {
377
        return ((Boolean)ProjectManager.mutex().readAccess(new Mutex.Action() {
378
            public Object run() {
379
                int index = findLocationIndex(artifact, location);
380
                Project forProj = artifact.getProject();
381
                if (forProj == null) {
382
                    throw new IllegalArgumentException("No project associated with " + artifact); // NOI18N
383
                }
384
                File forProjDir = FileUtil.toFile(forProj.getProjectDirectory());
385
                assert forProjDir != null : forProj.getProjectDirectory();
386
                String projName = getUsableReferenceID(ProjectUtils.getInformation(forProj).getName());
387
                String forProjName = findReferenceID(projName, "project.", forProjDir.getAbsolutePath());
388
                if (forProjName == null) {
389
                    return Boolean.FALSE;
390
                }
391
                RawReference ref = getRawReference(forProjName, getUsableReferenceID(artifact.getID()));
392
                if (ref == null) {
393
                    return Boolean.FALSE;
394
                }
395
                File script = h.resolveFile(eval.evaluate(ref.getScriptLocationValue()));
396
                if (!artifact.getType().equals(ref.getArtifactType()) ||
397
                        !artifact.getID().equals(ref.getID()) ||
398
                        !artifact.getScriptLocation().equals(script) ||
399
                        !artifact.getProperties().equals(ref.getProperties()) ||
400
                        !artifact.getTargetName().equals(ref.getTargetName()) ||
401
                        !artifact.getCleanTargetName().equals(ref.getCleanTargetName())) {
402
                    return Boolean.FALSE;
403
                }
404
                
405
                String reference = "reference." + forProjName + '.' + getUsableReferenceID(artifact.getID()); // NOI18N
406
                if (index > 0) {
407
                    reference += "."+index;
408
                }
409
                return Boolean.valueOf(eval.getProperty(reference) != null);
250
            }
410
            }
251
        })).booleanValue();
411
        })).booleanValue();
252
    }
412
    }
Lines 273-297 Link Here
273
    public boolean addRawReference(final RawReference ref) {
433
    public boolean addRawReference(final RawReference ref) {
274
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
434
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
275
            public Object run() {
435
            public Object run() {
276
                Element references = loadReferences(true);
277
                boolean success;
278
                try {
436
                try {
279
                    success = addRawReference(ref, references);
437
                    return Boolean.valueOf(addRawReference0(ref));
280
                } catch (IllegalArgumentException e) {
438
                } catch (IllegalArgumentException e) {
281
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
439
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
282
                    return Boolean.FALSE;
440
                    return Boolean.FALSE;
283
                }
441
                }
284
                if (success) {
442
            }
443
        })).booleanValue();
444
    }
445
    
446
    private boolean addRawReference0(final RawReference ref) throws IllegalArgumentException {
447
        Element references = loadReferences();
448
        if (references == null) {
449
            references = XMLUtil.createDocument("ignore", null, null, null).createElementNS(ref.getNS(), REFS_NAME); // NOI18N
450
        }
451
        boolean modified = false;
452
        if (references.getNamespaceURI().equals(REFS_NS) && ref.getNS().equals(REFS_NS2)) {
453
            // upgrade all references to version /2 here:
454
            references = upgradeTo20(references);
455
            removeOldReferences();
456
            modified = true;
457
        }
458
        modified = updateRawReferenceElement(ref, references);
459
        if (modified) {
285
                    storeReferences(references);
460
                    storeReferences(references);
286
                    return Boolean.TRUE;
287
                } else {
288
                    return Boolean.FALSE;
289
                }
461
                }
462
        return modified;
290
            }
463
            }
291
        })).booleanValue();
464
    
465
    private Element upgradeTo20(Element references) {
466
        Element references20 = XMLUtil.createDocument("ignore", null, null, null).createElementNS(REFS_NS2, REFS_NAME); // NOI18N
467
        RawReference rr[] = getRawReferences(references);
468
        for (int i=0; i<rr.length; i++) {
469
            rr[i].upgrade();
470
            updateRawReferenceElement(rr[i], references20);
471
        }
472
        return references20;
292
    }
473
    }
293
    
474
    
294
    private static boolean addRawReference(RawReference ref, Element references) throws IllegalArgumentException {
475
    private static boolean updateRawReferenceElement(RawReference ref, Element references) throws IllegalArgumentException {
295
        // Linear search; always keeping references sorted first by foreign project
476
        // Linear search; always keeping references sorted first by foreign project
296
        // name, then by target name.
477
        // name, then by target name.
297
        Element nextRefEl = null;
478
        Element nextRefEl = null;
Lines 314-320 Link Here
314
                if (testRef.getID().equals(ref.getID())) {
495
                if (testRef.getID().equals(ref.getID())) {
315
                    // Key match, check if it needs to be updated.
496
                    // Key match, check if it needs to be updated.
316
                    if (testRef.getArtifactType().equals(ref.getArtifactType()) &&
497
                    if (testRef.getArtifactType().equals(ref.getArtifactType()) &&
317
                            testRef.getScriptLocation().equals(ref.getScriptLocation()) &&
498
                            testRef.getScriptLocationValue().equals(ref.getScriptLocationValue()) &&
499
                            testRef.getProperties().equals(ref.getProperties()) &&
318
                            testRef.getTargetName().equals(ref.getTargetName()) &&
500
                            testRef.getTargetName().equals(ref.getTargetName()) &&
319
                            testRef.getCleanTargetName().equals(ref.getCleanTargetName())) {
501
                            testRef.getCleanTargetName().equals(ref.getCleanTargetName())) {
320
                        // Match on other fields. Return without changing anything.
502
                        // Match on other fields. Return without changing anything.
Lines 333-339 Link Here
333
            }
515
            }
334
        }
516
        }
335
        // Need to insert a new record before nextRef.
517
        // Need to insert a new record before nextRef.
336
        Element newRefEl = ref.toXml(references.getOwnerDocument());
518
        Element newRefEl = ref.toXml(references.getNamespaceURI(), references.getOwnerDocument());
337
        // Note: OK if nextRefEl == null, that means insert as last child.
519
        // Note: OK if nextRefEl == null, that means insert as last child.
338
        references.insertBefore(newRefEl, nextRefEl);
520
        references.insertBefore(newRefEl, nextRefEl);
339
        return true;
521
        return true;
Lines 355-379 Link Here
355
     * @param id the ID of the build artifact (usually build target name)
537
     * @param id the ID of the build artifact (usually build target name)
356
     * @return true if a reference or some property was actually removed,
538
     * @return true if a reference or some property was actually removed,
357
     *         false if the reference was not there and no property was removed
539
     *         false if the reference was not there and no property was removed
540
     * @deprecated use {@link #destroyReference} instead; was unused anyway
358
     */
541
     */
359
    public boolean removeReference(final String foreignProjectName, final String id) {
542
    public boolean removeReference(final String foreignProjectName, final String id) {
360
        return removeReference(foreignProjectName, id, false);
543
        return removeReference(foreignProjectName, id, false, null);
361
    }
544
    }
362
    
545
    
363
    private boolean removeReference(final String foreignProjectName, final String id, final boolean escaped) {
546
    private boolean removeReference(final String foreignProjectName, final String id, final boolean escaped, final String reference) {
364
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
547
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
365
            public Object run() {
548
            public Object run() {
366
                Element references = loadReferences(true);
367
                boolean success;
549
                boolean success;
368
                try {
550
                try {
369
                    success = removeRawReference(foreignProjectName, id, references, escaped);
551
                    success = removeRawReference0(foreignProjectName, id, escaped);
370
                } catch (IllegalArgumentException e) {
552
                } catch (IllegalArgumentException e) {
371
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
553
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
372
                    return Boolean.FALSE;
554
                    return Boolean.FALSE;
373
                }
555
                }
374
                if (success) {
375
                    storeReferences(references);
376
                }
377
                // Note: try to delete obsoleted properties from both project.properties
556
                // Note: try to delete obsoleted properties from both project.properties
378
                // and private.properties, just in case.
557
                // and private.properties, just in case.
379
                String[] PROPS_PATHS = {
558
                String[] PROPS_PATHS = {
Lines 382-388 Link Here
382
                };
561
                };
383
                // Check whether there are any other references using foreignProjectName.
562
                // Check whether there are any other references using foreignProjectName.
384
                // If not, we can delete ${project.foreignProjectName}.
563
                // If not, we can delete ${project.foreignProjectName}.
385
                RawReference[] refs = getRawReferences(references);
564
                RawReference[] refs = new RawReference[0];
565
                Element references = loadReferences();
566
                if (references != null) {
567
                    refs = getRawReferences(references);
568
                }
386
                boolean deleteProjProp = true;
569
                boolean deleteProjProp = true;
387
                for (int i = 0; i < refs.length; i++) {
570
                for (int i = 0; i < refs.length; i++) {
388
                    if (refs[i].getForeignProjectName().equals(foreignProjectName)) {
571
                    if (refs[i].getForeignProjectName().equals(foreignProjectName)) {
Lines 401-407 Link Here
401
                        }
584
                        }
402
                    }
585
                    }
403
                }
586
                }
404
                String refProp = "reference." + foreignProjectName + '.' + getUsableReferenceID(id); // NOI18N
587
                
588
                String refProp = reference;
589
                if (refProp == null) {
590
                    refProp = "reference." + foreignProjectName + '.' + getUsableReferenceID(id); // NOI18N
591
                }
592
                // remove also build script property if exist any:
593
                String buildScriptProperty = "build.script.reference." + foreignProjectName;
405
                for (int i = 0; i < PROPS_PATHS.length; i++) {
594
                for (int i = 0; i < PROPS_PATHS.length; i++) {
406
                    EditableProperties props = h.getProperties(PROPS_PATHS[i]);
595
                    EditableProperties props = h.getProperties(PROPS_PATHS[i]);
407
                    if (props.containsKey(refProp)) {
596
                    if (props.containsKey(refProp)) {
Lines 409-414 Link Here
409
                        h.putProperties(PROPS_PATHS[i], props);
598
                        h.putProperties(PROPS_PATHS[i], props);
410
                        success = true;
599
                        success = true;
411
                    }
600
                    }
601
                    if (props.containsKey(buildScriptProperty)) {
602
                        props.remove(buildScriptProperty);
603
                        h.putProperties(PROPS_PATHS[i], props);
604
                        success = true;
605
                    }
412
                }
606
                }
413
                return Boolean.valueOf(success);
607
                return Boolean.valueOf(success);
414
            }
608
            }
Lines 424-431 Link Here
424
     * @param fileReference file reference as created by 
618
     * @param fileReference file reference as created by 
425
     *    {@link #createForeignFileReference(File, String)}
619
     *    {@link #createForeignFileReference(File, String)}
426
     * @return true if the reference was actually removed; otherwise false
620
     * @return true if the reference was actually removed; otherwise false
621
     * @deprecated use {@link #destroyReference} instead; was unused anyway
427
     */
622
     */
428
    public boolean removeReference(final String fileReference) {
623
    public boolean removeReference(final String fileReference) {
624
        return removeFileReference(fileReference);
625
    }
626
    
627
    private boolean removeFileReference(final String fileReference) {
429
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
628
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
430
            public Object run() {
629
            public Object run() {
431
                boolean success = false;
630
                boolean success = false;
Lines 468-492 Link Here
468
    public boolean removeRawReference(final String foreignProjectName, final String id) {
667
    public boolean removeRawReference(final String foreignProjectName, final String id) {
469
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
668
        return ((Boolean)ProjectManager.mutex().writeAccess(new Mutex.Action() {
470
            public Object run() {
669
            public Object run() {
471
                Element references = loadReferences(true);
472
                boolean success;
473
                try {
670
                try {
474
                    success = removeRawReference(foreignProjectName, id, references, false);
671
                    return Boolean.valueOf(removeRawReference0(foreignProjectName, id, false));
475
                } catch (IllegalArgumentException e) {
672
                } catch (IllegalArgumentException e) {
476
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
673
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
477
                    return Boolean.FALSE;
674
                    return Boolean.FALSE;
478
                }
675
                }
676
            }
677
        })).booleanValue();
678
    }
679
    
680
    private boolean removeRawReference0(final String foreignProjectName, final String id, boolean escaped) throws IllegalArgumentException {
681
        Element references = loadReferences();
682
        if (references == null) {
683
            return false;
684
        }
685
        boolean success = removeRawReferenceElement(foreignProjectName, id, references, escaped);
479
                if (success) {
686
                if (success) {
480
                    storeReferences(references);
687
                    storeReferences(references);
481
                    return Boolean.TRUE;
482
                } else {
483
                    return Boolean.FALSE;
484
                }
688
                }
485
            }
689
        return success;
486
        })).booleanValue();
487
    }
690
    }
488
    
691
    
489
    private static boolean removeRawReference(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
692
    private static boolean removeRawReferenceElement(String foreignProjectName, String id, Element references, boolean escaped) throws IllegalArgumentException {
490
        // As with addRawReference, do a linear search through.
693
        // As with addRawReference, do a linear search through.
491
        List/*<Element>*/subEls = Util.findSubElements(references);
694
        List/*<Element>*/subEls = Util.findSubElements(references);
492
        Iterator it = subEls.iterator();
695
        Iterator it = subEls.iterator();
Lines 530-536 Link Here
530
    public RawReference[] getRawReferences() {
733
    public RawReference[] getRawReferences() {
531
        return (RawReference[])ProjectManager.mutex().readAccess(new Mutex.Action() {
734
        return (RawReference[])ProjectManager.mutex().readAccess(new Mutex.Action() {
532
            public Object run() {
735
            public Object run() {
533
                Element references = loadReferences(false);
736
                Element references = loadReferences();
534
                if (references != null) {
737
                if (references != null) {
535
                    try {
738
                    try {
536
                        return getRawReferences(references);
739
                        return getRawReferences(references);
Lines 573-579 Link Here
573
    RawReference getRawReference(final String foreignProjectName, final String id, final boolean escaped) {
776
    RawReference getRawReference(final String foreignProjectName, final String id, final boolean escaped) {
574
        return (RawReference)ProjectManager.mutex().readAccess(new Mutex.Action() {
777
        return (RawReference)ProjectManager.mutex().readAccess(new Mutex.Action() {
575
            public Object run() {
778
            public Object run() {
576
                Element references = loadReferences(false);
779
                Element references = loadReferences();
577
                if (references != null) {
780
                if (references != null) {
578
                    try {
781
                    try {
579
                        return getRawReference(foreignProjectName, id, references, escaped);
782
                        return getRawReference(foreignProjectName, id, references, escaped);
Lines 638-652 Link Here
638
                    String propertiesFile;
841
                    String propertiesFile;
639
                    String path;
842
                    String path;
640
                    File myProjDir = FileUtil.toFile(AntBasedProjectFactorySingleton.getProjectFor(h).getProjectDirectory());
843
                    File myProjDir = FileUtil.toFile(AntBasedProjectFactorySingleton.getProjectFor(h).getProjectDirectory());
641
                    if (CollocationQuery.areCollocated(myProjDir, file)) {
642
                        propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH;
643
                        path = PropertyUtils.relativizeFile(myProjDir, file);
644
                        assert path != null : "expected relative path from " + myProjDir + " to " + file;
645
                    } else {
646
                        propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH;
647
                        path = file.getAbsolutePath();
648
                    }
649
                    EditableProperties props = h.getProperties(propertiesFile);
650
                    String fileID = file.getName();
844
                    String fileID = file.getName();
651
                    // if the file is folder then add to ID string also parent folder name,
845
                    // if the file is folder then add to ID string also parent folder name,
652
                    // i.e. if external source folder name is "src" the ID will
846
                    // i.e. if external source folder name is "src" the ID will
Lines 660-669 Link Here
660
                    if (prop == null) {
854
                    if (prop == null) {
661
                        prop = generateUniqueID(fileID, "file.reference.", file.getAbsolutePath()); // NOI18N
855
                        prop = generateUniqueID(fileID, "file.reference.", file.getAbsolutePath()); // NOI18N
662
                    }
856
                    }
663
                    if (!path.equals(props.getProperty("file.reference." + prop))) { // NOI18N
857
                    setPathProperty(myProjDir, file, "file.reference." + prop);
664
                        props.put("file.reference." + prop, path); // NOI18N
665
                        h.putProperties(propertiesFile, props);
666
                    }
667
                    return "${file.reference." + prop + '}'; // NOI18N
858
                    return "${file.reference." + prop + '}'; // NOI18N
668
                }
859
                }
669
            }
860
            }
Lines 742-752 Link Here
742
     * @param artifact a known build artifact to refer to
933
     * @param artifact a known build artifact to refer to
743
     * @return a string which can refer to that artifact file somehow
934
     * @return a string which can refer to that artifact file somehow
744
     * @throws IllegalArgumentException if the artifact is not associated with a project
935
     * @throws IllegalArgumentException if the artifact is not associated with a project
936
     * @deprecated use {@link #addReference(AntArtifact, URI)} instead
745
     */
937
     */
746
    public String createForeignFileReference(AntArtifact artifact) throws IllegalArgumentException {
938
    public String createForeignFileReference(AntArtifact artifact) throws IllegalArgumentException {
747
        addReference(artifact);
939
        Object ret[] = addReference0(artifact, artifact.getArtifactLocations()[0]);
748
        String projID = findReferenceID(artifact);
940
        return (String)ret[1];
749
        return "${reference." + projID + '.' + getUsableReferenceID(artifact.getID()) + '}'; // NOI18N
750
    }
941
    }
751
942
752
    /**
943
    /**
Lines 758-764 Link Here
758
    }
949
    }
759
    
950
    
760
    
951
    
761
    private static final Pattern FOREIGN_FILE_REFERENCE = Pattern.compile("\\$\\{reference\\.([^.${}]+)\\.([^.${}]+)\\}"); // NOI18N
952
    private static final Pattern FOREIGN_FILE_REFERENCE = Pattern.compile("\\$\\{reference\\.([^.${}]+)\\.([^.${}]+)\\.([\\d&&[^.${}]]+)\\}"); // NOI18N
953
    private static final Pattern FOREIGN_FILE_REFERENCE_OLD = Pattern.compile("\\$\\{reference\\.([^.${}]+)\\.([^.${}]+)\\}"); // NOI18N
762
    private static final Pattern FOREIGN_PLAIN_FILE_REFERENCE = Pattern.compile("\\$\\{file\\.reference\\.([^${}]+)\\}"); // NOI18N
954
    private static final Pattern FOREIGN_PLAIN_FILE_REFERENCE = Pattern.compile("\\$\\{file\\.reference\\.([^${}]+)\\}"); // NOI18N
763
    
955
    
764
    /**
956
    /**
Lines 769-797 Link Here
769
     * <p>Acquires read access.
961
     * <p>Acquires read access.
770
     * @param reference a reference string as present in an Ant property
962
     * @param reference a reference string as present in an Ant property
771
     * @return a corresponding Ant artifact object if there is one, else null
963
     * @return a corresponding Ant artifact object if there is one, else null
964
     * @deprecated use {@link #findArtifactAndLocation} instead
772
     */
965
     */
773
    public AntArtifact getForeignFileReferenceAsArtifact(final String reference) {
966
    public AntArtifact getForeignFileReferenceAsArtifact(final String reference) {
774
        return (AntArtifact)ProjectManager.mutex().readAccess(new Mutex.Action() {
967
        Object ret[] = findArtifactAndLocation(reference);
968
        return (AntArtifact)ret[0];
969
    }
970
    
971
    /**
972
     * Try to find an <code>AntArtifact</code> object and location corresponding
973
     * to a given reference. If the supplied string is not a recognized 
974
     * reference to a build artifact, returns null.
975
     * <p>
976
     * Acquires read access.
977
     * @param reference a reference string as present in an Ant property and as
978
     *   created by {@link #addReference(AntArtifact, URI)}
979
     * @return always returns array of two items. The items may be null. First
980
     *   one is instance of AntArtifact and second is instance of URI and is 
981
     *   AntArtifact's location
982
     * @since X.XX
983
     */
984
    public Object[] findArtifactAndLocation(final String reference) {
985
        return ((List)ProjectManager.mutex().readAccess(new Mutex.Action() {
775
            public Object run() {
986
            public Object run() {
987
                ArrayList l = new ArrayList();
988
                AntArtifact aa = null;
776
                Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
989
                Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
777
                if (m.matches()) {
990
                boolean matches = m.matches();
991
                int index = 0;
992
                if (!matches) {
993
                    m = FOREIGN_FILE_REFERENCE_OLD.matcher(reference);
994
                    matches = m.matches();
995
                } else {
996
                    try {
997
                        index = Integer.parseInt(m.group(3));
998
                    } catch (NumberFormatException ex) {
999
                        ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, 
1000
                            "Could not parse reference ("+reference+") for the jar index. " + // NOI18N
1001
                            "Expected number: "+m.group(3)); // NOI18N
1002
                        matches = false;
1003
                    }
1004
                }
1005
                if (matches) {
778
                    RawReference ref = getRawReference(m.group(1), m.group(2), true);
1006
                    RawReference ref = getRawReference(m.group(1), m.group(2), true);
779
                    if (ref != null) {
1007
                    if (ref != null) {
780
                        return ref.toAntArtifact(ReferenceHelper.this);
1008
                        aa = ref.toAntArtifact(ReferenceHelper.this);
781
                    }
1009
                    }
782
                }
1010
                }
783
                return null;
1011
                if (aa == null) {
1012
                    l.add(null);
1013
                    l.add(null);
1014
                    return l;
784
            }
1015
            }
785
        });
1016
                assert index <= aa.getArtifactLocations().length;
1017
                URI uri = aa.getArtifactLocations()[index];
1018
                l.add(aa);
1019
                l.add(uri);
1020
                return l;
1021
            }
1022
        })).toArray(new Object[2]);
1023
    }
1024
    
1025
    /**
1026
     * Remove a reference to a foreign file from the project.
1027
     * See {@link #destroyReference} for more information.
1028
     * @param reference an Ant-interpretable foreign file reference as created e.g.
1029
     *                  by {@link #createForeignFileReference(File,String)} or
1030
     *                  by {@link #createForeignFileReference(AntArtifact)}
1031
     * @deprecated use {@link #destroyReference} instead which does exactly 
1032
     *   the same but has more appropriate name
1033
     */
1034
    public void destroyForeignFileReference(String reference) {
1035
        destroyReference(reference);
786
    }
1036
    }
787
    
1037
    
788
    /**
1038
    /**
789
     * Remove a reference to a foreign file from the project.
1039
     * Remove a reference to a foreign file from the project.
790
     * If the passed string consists of an Ant property reference corresponding to
1040
     * If the passed string consists of an Ant property reference corresponding to
791
     * a known inter-project reference created by 
1041
     * a known inter-project reference created by 
792
     * {@link #createForeignFileReference(AntArtifact)} or file reference created by
1042
     * {@link #addReference(AntArtifact, URI)} or file reference created by
793
     * {@link #createForeignFileReference(File, String)}, that reference is removed using
1043
     * {@link #createForeignFileReference(File, String)}, that reference is removed.
794
     * {@link #removeReference(String, String)} or {@link #removeReference(String)}.
795
     * Since this would break any other identical foreign
1044
     * Since this would break any other identical foreign
796
     * file references present in the project, you should first confirm that this
1045
     * file references present in the project, you should first confirm that this
797
     * reference was the last one of its kind (by string match).
1046
     * reference was the last one of its kind (by string match).
Lines 803-822 Link Here
803
     * @param reference an Ant-interpretable foreign file reference as created e.g.
1052
     * @param reference an Ant-interpretable foreign file reference as created e.g.
804
     *                  by {@link #createForeignFileReference(File,String)} or
1053
     *                  by {@link #createForeignFileReference(File,String)} or
805
     *                  by {@link #createForeignFileReference(AntArtifact)}
1054
     *                  by {@link #createForeignFileReference(AntArtifact)}
1055
     * @return true if reference was really destroyed or not
1056
     * @since X.XX
806
     */
1057
     */
807
    public void destroyForeignFileReference(String reference) {
1058
    public boolean destroyReference(String reference) {
808
        Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
1059
        Matcher m = FOREIGN_FILE_REFERENCE.matcher(reference);
809
        if (m.matches()) {
1060
        boolean matches = m.matches();
1061
        if (!matches) {
1062
            m = FOREIGN_FILE_REFERENCE_OLD.matcher(reference);
1063
            matches = m.matches();
1064
        }
1065
        if (matches) {
810
            String forProjName = m.group(1);
1066
            String forProjName = m.group(1);
811
            String id = m.group(2);
1067
            String id = m.group(2);
812
            removeReference(forProjName, id, true);
1068
            return removeReference(forProjName, id, true, reference.substring(2, reference.length()-1));
813
            return;
814
        }
1069
        }
815
        m = FOREIGN_PLAIN_FILE_REFERENCE.matcher(reference);
1070
        m = FOREIGN_PLAIN_FILE_REFERENCE.matcher(reference);
816
        if (m.matches()) {
1071
        if (m.matches()) {
817
            removeReference(reference);
1072
            return removeFileReference(reference);
818
            return;
819
        }
1073
        }
1074
        return false;
820
    }
1075
    }
821
    
1076
    
822
    /**
1077
    /**
Lines 847-856 Link Here
847
        
1102
        
848
        private final String foreignProjectName;
1103
        private final String foreignProjectName;
849
        private final String artifactType;
1104
        private final String artifactType;
850
        private final URI scriptLocation;
1105
        private URI scriptLocation;
1106
        // introduced in /2 version
1107
        private String newScriptLocation;
851
        private final String targetName;
1108
        private final String targetName;
852
        private final String cleanTargetName;
1109
        private final String cleanTargetName;
853
        private final String artifactID;
1110
        private final String artifactID;
1111
        private final Properties props;
854
        
1112
        
855
        /**
1113
        /**
856
         * Create a raw reference descriptor.
1114
         * Create a raw reference descriptor.
Lines 864-878 Link Here
864
         * @throws IllegalArgumentException if the script location is given an absolute URI
1122
         * @throws IllegalArgumentException if the script location is given an absolute URI
865
         */
1123
         */
866
        public RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String targetName, String cleanTargetName, String artifactID) throws IllegalArgumentException {
1124
        public RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String targetName, String cleanTargetName, String artifactID) throws IllegalArgumentException {
1125
           this(foreignProjectName, artifactType, scriptLocation, null, targetName, cleanTargetName, artifactID, new Properties());
1126
        }
1127
        
1128
        /**
1129
         * Create a raw reference descriptor.
1130
         * As this is basically just a struct, does no real work.
1131
         * @param foreignProjectName the name of the foreign project (usually its code name)
1132
         * @param artifactType the {@link AntArtifact#getType type} of the build artifact
1133
         * @param newScriptLocation absolute path to the build script; can contain Ant-like properties
1134
         * @param targetName the Ant target name
1135
         * @param cleanTargetName the Ant clean target name
1136
         * @param artifactID the {@link AntArtifact#getID ID} of the build artifact
1137
         * @param props optional properties to be used for target execution; never null
1138
         * @throws IllegalArgumentException if the script location is given an absolute URI
1139
         * @since X.XX
1140
         */
1141
        public RawReference(String foreignProjectName, String artifactType, String newScriptLocation, String targetName, String cleanTargetName, String artifactID, Properties props) throws IllegalArgumentException {
1142
           this(foreignProjectName, artifactType, null, newScriptLocation, targetName, cleanTargetName, artifactID, props);
1143
        }
1144
        
1145
        private RawReference(String foreignProjectName, String artifactType, URI scriptLocation, String newScriptLocation, String targetName, String cleanTargetName, String artifactID, Properties props) throws IllegalArgumentException {
867
            this.foreignProjectName = foreignProjectName;
1146
            this.foreignProjectName = foreignProjectName;
868
            this.artifactType = artifactType;
1147
            this.artifactType = artifactType;
869
            if (scriptLocation.isAbsolute()) {
1148
            if (scriptLocation != null && scriptLocation.isAbsolute()) {
870
                throw new IllegalArgumentException("Cannot use an absolute URI " + scriptLocation + " for script location"); // NOI18N
1149
                throw new IllegalArgumentException("Cannot use an absolute URI " + scriptLocation + " for script location"); // NOI18N
871
            }
1150
            }
872
            this.scriptLocation = scriptLocation;
1151
            this.scriptLocation = scriptLocation;
1152
            this.newScriptLocation = newScriptLocation;
873
            this.targetName = targetName;
1153
            this.targetName = targetName;
874
            this.cleanTargetName = cleanTargetName;
1154
            this.cleanTargetName = cleanTargetName;
875
            this.artifactID = artifactID;
1155
            this.artifactID = artifactID;
1156
            this.props = props;
876
        }
1157
        }
877
        
1158
        
878
        private static final List/*<String>*/ SUB_ELEMENT_NAMES = Arrays.asList(new String[] {
1159
        private static final List/*<String>*/ SUB_ELEMENT_NAMES = Arrays.asList(new String[] {
Lines 889-894 Link Here
889
         * @throws IllegalArgumentException if anything is missing or duplicated or malformed etc.
1170
         * @throws IllegalArgumentException if anything is missing or duplicated or malformed etc.
890
         */
1171
         */
891
        static RawReference create(Element xml) throws IllegalArgumentException {
1172
        static RawReference create(Element xml) throws IllegalArgumentException {
1173
            if (REFS_NS.equals(xml.getNamespaceURI())) {
1174
                return create1(xml);
1175
            } else {
1176
                return create2(xml);
1177
            }
1178
        }
1179
        
1180
        private static RawReference create1(Element xml) throws IllegalArgumentException {
892
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS.equals(xml.getNamespaceURI())) {
1181
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS.equals(xml.getNamespaceURI())) {
893
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1182
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
894
            }
1183
            }
Lines 921-947 Link Here
921
            return new RawReference(values[0], values[1], scriptLocation, values[3], values[4], values[5]);
1210
            return new RawReference(values[0], values[1], scriptLocation, values[3], values[4], values[5]);
922
        }
1211
        }
923
        
1212
        
1213
        private static RawReference create2(Element xml) throws IllegalArgumentException {
1214
            if (!REF_NAME.equals(xml.getLocalName()) || !REFS_NS2.equals(xml.getNamespaceURI())) {
1215
                throw new IllegalArgumentException("bad element name: " + xml); // NOI18N
1216
            }
1217
            List nl = Util.findSubElements(xml);
1218
            if (nl.size() < 6) {
1219
                throw new IllegalArgumentException("missing or extra data: " + xml); // NOI18N
1220
            }
1221
            String[] values = new String[6];
1222
            for (int i = 0; i < 6; i++) {
1223
                Element el = (Element)nl.get(i);
1224
                if (!REFS_NS2.equals(el.getNamespaceURI())) {
1225
                    throw new IllegalArgumentException("bad subelement ns: " + el); // NOI18N
1226
                }
1227
                String elName = el.getLocalName();
1228
                int idx = SUB_ELEMENT_NAMES.indexOf(elName);
1229
                if (idx == -1) {
1230
                    throw new IllegalArgumentException("bad subelement name: " + elName); // NOI18N
1231
                }
1232
                String val = Util.findText(el);
1233
                if (val == null) {
1234
                    throw new IllegalArgumentException("empty subelement: " + el); // NOI18N
1235
                }
1236
                if (values[idx] != null) {
1237
                    throw new IllegalArgumentException("duplicate " + elName + ": " + values[idx] + " and " + val); // NOI18N
1238
                }
1239
                values[idx] = val;
1240
            }
1241
            Properties props = new Properties();
1242
            if (nl.size() == 7) {
1243
                Element el = (Element)nl.get(6);
1244
                if (!REFS_NS2.equals(el.getNamespaceURI())) {
1245
                    throw new IllegalArgumentException("bad subelement ns: " + el); // NOI18N
1246
                }
1247
                if (!"properties".equals(el.getLocalName())) { // NOI18N
1248
                    throw new IllegalArgumentException("bad subelement. expected 'properties': " + el); // NOI18N
1249
                }
1250
                Iterator it = Util.findSubElements(el).iterator();
1251
                while (it.hasNext()) {
1252
                    el = (Element)it.next();
1253
                    String key = el.getAttribute("name");
1254
                    String value = Util.findText(el);
1255
                    props.setProperty(key, value);
1256
                }
1257
            }
1258
            assert !Arrays.asList(values).contains(null);
1259
            return new RawReference(values[0], values[1], values[2], values[3], values[4], values[5], props);
1260
        }
1261
        
924
        /**
1262
        /**
925
         * Write a RawReference as an XML &lt;reference&gt; fragment.
1263
         * Write a RawReference as an XML &lt;reference&gt; fragment.
926
         */
1264
         */
927
        Element toXml(Document ownerDocument) {
1265
        Element toXml(String namespace, Document ownerDocument) {
928
            Element el = ownerDocument.createElementNS(REFS_NS, REF_NAME);
1266
            Element el = ownerDocument.createElementNS(namespace, REF_NAME);
929
            String[] values = {
1267
            String[] values = {
930
                foreignProjectName,
1268
                foreignProjectName,
931
                artifactType,
1269
                artifactType,
932
                scriptLocation.toString(),
1270
                newScriptLocation != null ? newScriptLocation : scriptLocation.toString(),
933
                targetName,
1271
                targetName,
934
                cleanTargetName,
1272
                cleanTargetName,
935
                artifactID,
1273
                artifactID,
936
            };
1274
            };
937
            for (int i = 0; i < 6; i++) {
1275
            for (int i = 0; i < 6; i++) {
938
                Element subel = ownerDocument.createElementNS(REFS_NS, (String)SUB_ELEMENT_NAMES.get(i));
1276
                Element subel = ownerDocument.createElementNS(namespace, (String)SUB_ELEMENT_NAMES.get(i));
939
                subel.appendChild(ownerDocument.createTextNode(values[i]));
1277
                subel.appendChild(ownerDocument.createTextNode(values[i]));
940
                el.appendChild(subel);
1278
                el.appendChild(subel);
941
            }
1279
            }
1280
            if (props.keySet().size() > 0) {
1281
                assert namespace.equals(REFS_NS2) : "can happen only in /2"; // NOI18N
1282
                Element propEls = ownerDocument.createElementNS(namespace, "properties"); // NOI18N
1283
                el.appendChild(propEls);
1284
                List keys = new ArrayList(props.keySet());
1285
                Collections.sort(keys);
1286
                Iterator it = keys.iterator();
1287
                while (it.hasNext()) {
1288
                    String key = (String)it.next();
1289
                    Element propEl = ownerDocument.createElementNS(namespace, "property"); // NOI18N
1290
                    propEl.appendChild(ownerDocument.createTextNode(props.getProperty(key)));
1291
                    propEl.setAttribute("name", key); // NOI18N
1292
                    propEls.appendChild(propEl);
1293
                }
1294
            }
942
            return el;
1295
            return el;
943
        }
1296
        }
944
        
1297
        
1298
        private String getNS() {
1299
            if (newScriptLocation != null) {
1300
                return REFS_NS2;
1301
            } else {
1302
                return REFS_NS;
1303
            }
1304
        }
1305
        
945
        /**
1306
        /**
946
         * Get the name of the foreign project as referred to from this project.
1307
         * Get the name of the foreign project as referred to from this project.
947
         * Usually this will be the code name of the foreign project, but it may
1308
         * Usually this will be the code name of the foreign project, but it may
Lines 968-979 Link Here
968
         * project directory.
1329
         * project directory.
969
         * This is the script which would be called to build the desired artifact.
1330
         * This is the script which would be called to build the desired artifact.
970
         * @return the script location
1331
         * @return the script location
1332
         * @deprecated use {@link #getScriptLocationValue} instead; may return null now
971
         */
1333
         */
972
        public URI getScriptLocation() {
1334
        public URI getScriptLocation() {
973
            return scriptLocation;
1335
            return scriptLocation;
974
        }
1336
        }
975
        
1337
        
976
        /**
1338
        /**
1339
         * Get absolute path location of the foreign project's build script.
1340
         * This is the script which would be called to build the desired artifact.
1341
         * @return absolute path possibly containing Ant properties
1342
         */
1343
        public String getScriptLocationValue() {
1344
            if (newScriptLocation != null) {
1345
                return newScriptLocation;
1346
            } else {
1347
                return "${project."+foreignProjectName+"}/"+scriptLocation.toString();
1348
            }
1349
        }
1350
        
1351
        /**
977
         * Get the Ant target name to build the artifact.
1352
         * Get the Ant target name to build the artifact.
978
         * @return the target name
1353
         * @return the target name
979
         */
1354
         */
Lines 998-1003 Link Here
998
            return artifactID;
1373
            return artifactID;
999
        }
1374
        }
1000
        
1375
        
1376
        public Properties getProperties() {
1377
            return props;
1378
        }
1379
        
1001
        /**
1380
        /**
1002
         * Attempt to convert this reference to a live artifact object.
1381
         * Attempt to convert this reference to a live artifact object.
1003
         * This involves finding the referenced foreign project on disk
1382
         * This involves finding the referenced foreign project on disk
Lines 1046-1053 Link Here
1046
            });
1425
            });
1047
        }
1426
        }
1048
        
1427
        
1428
        private void upgrade() {
1429
            assert newScriptLocation == null && scriptLocation != null : "was already upgraded "+this;
1430
            newScriptLocation = "${project."+foreignProjectName+"}/" +scriptLocation.toString(); // NOI18N
1431
            scriptLocation = null;
1432
        }
1433
        
1049
        public String toString() {
1434
        public String toString() {
1050
            return "ReferenceHelper.RawReference<" + foreignProjectName + "," + artifactType + "," + scriptLocation + "," + targetName + "," + cleanTargetName + "," + artifactID + ">"; // NOI18N
1435
            return "ReferenceHelper.RawReference<" + foreignProjectName + "," + 
1436
                artifactType + "," + newScriptLocation != null ? newScriptLocation : scriptLocation + 
1437
                "," + targetName + "," + cleanTargetName + "," + artifactID + ">"; // NOI18N
1051
        }
1438
        }
1052
        
1439
        
1053
    }
1440
    }
(-)ant/project/src/org/netbeans/spi/project/support/ant/SimpleAntArtifact.java (-1 / +5 lines)
Lines 48-54 Link Here
48
        this.cleanTargetName = cleanTargetName;
48
        this.cleanTargetName = cleanTargetName;
49
    }
49
    }
50
    
50
    
51
    public URI getArtifactLocation() {
51
    private URI getArtifactLocation0() {
52
        String locationResolved = eval.getProperty(locationProperty);
52
        String locationResolved = eval.getProperty(locationProperty);
53
        if (locationResolved == null) {
53
        if (locationResolved == null) {
54
            return URI.create("file:/UNDEFINED"); // NOI18N
54
            return URI.create("file:/UNDEFINED"); // NOI18N
Lines 65-70 Link Here
65
                return URI.create("file:/BROKEN"); // NOI18N
65
                return URI.create("file:/BROKEN"); // NOI18N
66
            }
66
            }
67
        }
67
        }
68
    }
69
    
70
    public URI[] getArtifactLocations() {
71
        return new URI[]{getArtifactLocation0()};
68
    }
72
    }
69
    
73
    
70
    public String getCleanTargetName() {
74
    public String getCleanTargetName() {
(-)ant/project/test/unit/src/org/netbeans/api/project/ant/AntArtifactQueryTest.java (-1 / +1 lines)
Lines 88-94 Link Here
88
        AntArtifact art = AntArtifactQuery.findArtifactFromFile(proj2Jar);
88
        AntArtifact art = AntArtifactQuery.findArtifactFromFile(proj2Jar);
89
        assertNotNull("found an artifact matching " + proj2Jar, art);
89
        assertNotNull("found an artifact matching " + proj2Jar, art);
90
        assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject());
90
        assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject());
91
        assertEquals("correct artifact file", proj2JarFO, art.getArtifactFile());
91
        assertEquals("correct artifact file", proj2JarFO, art.getArtifactFiles()[0]);
92
        assertEquals("correct target name", "dojar", art.getTargetName());
92
        assertEquals("correct target name", "dojar", art.getTargetName());
93
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
93
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
94
        assertEquals("correct type", "jar", art.getType());
94
        assertEquals("correct type", "jar", art.getType());
(-)ant/project/test/unit/src/org/netbeans/spi/project/support/ant/ReferenceHelperTest.java (-32 / +61 lines)
Lines 18-23 Link Here
18
import java.util.Arrays;
18
import java.util.Arrays;
19
import java.util.Collections;
19
import java.util.Collections;
20
import java.util.Set;
20
import java.util.Set;
21
import java.util.TreeSet;
21
import org.netbeans.api.project.Project;
22
import org.netbeans.api.project.Project;
22
import org.netbeans.api.project.ProjectManager;
23
import org.netbeans.api.project.ProjectManager;
23
import org.netbeans.api.project.ProjectUtils;
24
import org.netbeans.api.project.ProjectUtils;
Lines 195-200 Link Here
195
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
196
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
196
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
197
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
197
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
198
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
199
        assertEquals("correct script location", "${project.otherproj}/build.xml", ref.getScriptLocationValue());
198
        assertEquals("correct target name", "dojar", ref.getTargetName());
200
        assertEquals("correct target name", "dojar", ref.getTargetName());
199
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
201
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
200
        assertEquals("correct ID name", "dojarID", ref.getID());
202
        assertEquals("correct ID name", "dojarID", ref.getID());
Lines 211-217 Link Here
211
        ref = refs[0];
213
        ref = refs[0];
212
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
214
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
213
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
215
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
214
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
216
        assertEquals("correct script location", "${project.otherproj}/build.xml", ref.getScriptLocationValue());
215
        assertEquals("correct target name", "dojar", ref.getTargetName());
217
        assertEquals("correct target name", "dojar", ref.getTargetName());
216
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
218
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
217
        assertEquals("correct ID name", "dojarID", ref.getID());
219
        assertEquals("correct ID name", "dojarID", ref.getID());
Lines 247-253 Link Here
247
        ref = r.getRawReference("otherproj", "dojarID");
249
        ref = r.getRawReference("otherproj", "dojarID");
248
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
250
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
249
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
251
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
250
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
252
        assertEquals("correct script location", "${project.otherproj}/build.xml", ref.getScriptLocationValue());
251
        assertEquals("correct target name", "dojar", ref.getTargetName());
253
        assertEquals("correct target name", "dojar", ref.getTargetName());
252
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
254
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
253
        assertEquals("correct ID name", "dojarID", ref.getID());
255
        assertEquals("correct ID name", "dojarID", ref.getID());
Lines 258-264 Link Here
258
        ref = r.getRawReference("otherproj", "dojarID");
260
        ref = r.getRawReference("otherproj", "dojarID");
259
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
261
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
260
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
262
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
261
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
263
        assertEquals("correct script location", "${project.otherproj}/build2.xml", ref.getScriptLocationValue());
262
        assertEquals("correct target name", "dojar", ref.getTargetName());
264
        assertEquals("correct target name", "dojar", ref.getTargetName());
263
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
265
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
264
        assertEquals("correct ID name", "dojarID", ref.getID());
266
        assertEquals("correct ID name", "dojarID", ref.getID());
Lines 278-298 Link Here
278
        ref = refs[0];
280
        ref = refs[0];
279
        assertEquals("correct foreign project name", "aardvark", ref.getForeignProjectName());
281
        assertEquals("correct foreign project name", "aardvark", ref.getForeignProjectName());
280
        assertEquals("correct modified artifact type", "jar", ref.getArtifactType());
282
        assertEquals("correct modified artifact type", "jar", ref.getArtifactType());
281
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
283
        assertEquals("correct script location", "${project.aardvark}/build.xml", ref.getScriptLocationValue());
282
        assertEquals("correct target name", "jar", ref.getTargetName());
284
        assertEquals("correct target name", "jar", ref.getTargetName());
283
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
285
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
284
        assertEquals("correct ID name", "jarID", ref.getID());
286
        assertEquals("correct ID name", "jarID", ref.getID());
285
        ref = refs[1];
287
        ref = refs[1];
286
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
288
        assertEquals("correct foreign project name", "otherproj", ref.getForeignProjectName());
287
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
289
        assertEquals("correct modified artifact type", "war", ref.getArtifactType());
288
        assertEquals("correct script location", URI.create("build2.xml"), ref.getScriptLocation());
290
        assertEquals("correct script location", "${project.otherproj}/build2.xml", ref.getScriptLocationValue());
289
        assertEquals("correct target name", "dojar", ref.getTargetName());
291
        assertEquals("correct target name", "dojar", ref.getTargetName());
290
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
292
        assertEquals("correct clean target name", "clean2", ref.getCleanTargetName());
291
        assertEquals("correct ID name", "dojarID", ref.getID());
293
        assertEquals("correct ID name", "dojarID", ref.getID());
292
        ref = refs[2];
294
        ref = refs[2];
293
        assertEquals("correct foreign project name", "otherproj2", ref.getForeignProjectName());
295
        assertEquals("correct foreign project name", "otherproj2", ref.getForeignProjectName());
294
        assertEquals("correct modified artifact type", "ear", ref.getArtifactType());
296
        assertEquals("correct modified artifact type", "ear", ref.getArtifactType());
295
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
297
        assertEquals("correct script location", "${project.otherproj2}/build.xml", ref.getScriptLocationValue());
296
        assertEquals("correct target name", "dojar", ref.getTargetName());
298
        assertEquals("correct target name", "dojar", ref.getTargetName());
297
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
299
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
298
        assertEquals("correct ID name", "dojarID", ref.getID());
300
        assertEquals("correct ID name", "dojarID", ref.getID());
Lines 359-372 Link Here
359
        // Add one artifact. Check that the raw reference is there.
361
        // Add one artifact. Check that the raw reference is there.
360
        assertFalse("project not initially modified", pm.isModified(p));
362
        assertFalse("project not initially modified", pm.isModified(p));
361
        AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
363
        AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
364
        assertFalse("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
362
        assertTrue("added a ref to proj2.dojar", r.addReference(art));
365
        assertTrue("added a ref to proj2.dojar", r.addReference(art));
366
        assertTrue("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
363
        assertTrue("project now modified", pm.isModified(p));
367
        assertTrue("project now modified", pm.isModified(p));
364
        ReferenceHelper.RawReference[] refs = r.getRawReferences();
368
        ReferenceHelper.RawReference[] refs = r.getRawReferences();
365
        assertEquals("one ref now", 1, refs.length);
369
        assertEquals("one ref now", 1, refs.length);
366
        ReferenceHelper.RawReference ref = refs[0];
370
        ReferenceHelper.RawReference ref = refs[0];
367
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
371
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
368
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
372
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
369
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
373
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
370
        assertEquals("correct target name", "dojar", ref.getTargetName());
374
        assertEquals("correct target name", "dojar", ref.getTargetName());
371
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
375
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
372
        // Check that the project properties are correct.
376
        // Check that the project properties are correct.
Lines 383-393 Link Here
383
            h.resolveFile(pev.getProperty("reference.proj2.dojar")));
387
            h.resolveFile(pev.getProperty("reference.proj2.dojar")));
384
        // Check no-op adds.
388
        // Check no-op adds.
385
        pm.saveProject(p);
389
        pm.saveProject(p);
390
        assertTrue("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
386
        assertFalse("no-op add", r.addReference(art));
391
        assertFalse("no-op add", r.addReference(art));
387
        assertFalse("project not modified by no-op add", pm.isModified(p));
392
        assertFalse("project not modified by no-op add", pm.isModified(p));
388
        // Try another artifact from the same project.
393
        // Try another artifact from the same project.
389
        art = sisterh.createSimpleAntArtifact("javadoc", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
394
        art = sisterh.createSimpleAntArtifact("javadoc", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
390
        assertTrue("added a ref to proj2.dojavadoc", r.addReference(art));
395
        assertFalse("reference does not exist", r.isReferenced(art, art.getArtifactLocations()[0]));
396
        assertNotNull("added a ref to proj2.dojavadoc", r.addReference(art, art.getArtifactLocations()[0]));
391
        assertTrue("project now modified", pm.isModified(p));
397
        assertTrue("project now modified", pm.isModified(p));
392
        refs = r.getRawReferences();
398
        refs = r.getRawReferences();
393
        assertEquals("two refs now", 2, refs.length);
399
        assertEquals("two refs now", 2, refs.length);
Lines 397-403 Link Here
397
        ref = refs[1];
403
        ref = refs[1];
398
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
404
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
399
        assertEquals("correct artifact type", "javadoc", ref.getArtifactType());
405
        assertEquals("correct artifact type", "javadoc", ref.getArtifactType());
400
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
406
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
401
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
407
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
402
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
408
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
403
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
409
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
Lines 412-444 Link Here
412
            new File(new File(FileUtil.toFile(sisterprojdir), "build"), "javadoc"),
418
            new File(new File(FileUtil.toFile(sisterprojdir), "build"), "javadoc"),
413
            h.resolveFile(pev.getProperty("reference.proj2.dojavadoc")));
419
            h.resolveFile(pev.getProperty("reference.proj2.dojavadoc")));
414
        pm.saveProject(p);
420
        pm.saveProject(p);
415
        assertFalse("no-op add", r.addReference(art));
421
        assertTrue("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
422
        r.addReference(art, art.getArtifactLocations()[0]);
416
        assertFalse("project not modified by no-op add", pm.isModified(p));
423
        assertFalse("project not modified by no-op add", pm.isModified(p));
417
        // Try modifying the second artifact in some way.
424
        // Try modifying the second artifact in some way.
418
        // Note that only changes in the type, clean target, and artifact path count as modifications.
425
        // Note that only changes in the type, clean target, and artifact path count as modifications.
419
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
426
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
420
        assertTrue("successful modification of proj2.dojavadoc by type", r.addReference(art));
427
        assertFalse("reference exist but needs to be updated", r.isReferenced(art, art.getArtifactLocations()[0]));
428
        r.addReference(art, art.getArtifactLocations()[0]);
421
        assertTrue("project modified by ref mod", pm.isModified(p));
429
        assertTrue("project modified by ref mod", pm.isModified(p));
422
        refs = r.getRawReferences();
430
        refs = r.getRawReferences();
423
        assertEquals("still two refs", 2, refs.length);
431
        assertEquals("still two refs", 2, refs.length);
424
        ref = refs[1];
432
        ref = refs[1];
425
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
433
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
426
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
434
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
427
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
435
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
428
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
436
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
429
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
437
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
430
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "realclean");
438
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "realclean");
431
        assertTrue("successful modification of proj2.dojavadoc by clean target", r.addReference(art));
439
        r.addReference(art, art.getArtifactLocations()[0]);
432
        pm.saveProject(p);
440
        pm.saveProject(p);
433
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc.complete", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "realclean");
441
        art = sisterh.createSimpleAntArtifact("javadoc.html", "build.javadoc.complete", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "realclean");
434
        assertTrue("successful modification of proj2.dojavadoc by artifact location property", r.addReference(art));
442
        r.addReference(art, art.getArtifactLocations()[0]);
435
        assertTrue("project modified by ref mod", pm.isModified(p));
443
        assertTrue("project modified by ref mod", pm.isModified(p));
436
        refs = r.getRawReferences();
444
        refs = r.getRawReferences();
437
        assertEquals("still two refs", 2, refs.length);
445
        assertEquals("still two refs", 2, refs.length);
438
        ref = refs[1];
446
        ref = refs[1];
439
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
447
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
440
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
448
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
441
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
449
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
442
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
450
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
443
        assertEquals("correct modified clean target name", "realclean", ref.getCleanTargetName());
451
        assertEquals("correct modified clean target name", "realclean", ref.getCleanTargetName());
444
        // Check that changing the artifact location property changed the reference property too.
452
        // Check that changing the artifact location property changed the reference property too.
Lines 456-467 Link Here
456
        // Check that changing the value of the artifact location property
464
        // Check that changing the value of the artifact location property
457
        // in the subproject modifies this project.
465
        // in the subproject modifies this project.
458
        pm.saveProject(p);
466
        pm.saveProject(p);
459
        assertFalse("no-op add", r.addReference(art));
467
        assertTrue("reference exist but needs to be updated", r.isReferenced(art, art.getArtifactLocations()[0]));
468
        r.addReference(art, art.getArtifactLocations()[0]);
460
        assertFalse("project not modified by no-op add", pm.isModified(p));
469
        assertFalse("project not modified by no-op add", pm.isModified(p));
461
        props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
470
        props = sisterh.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
462
        props.setProperty("build.javadoc.complete", "build/total-javadoc");
471
        props.setProperty("build.javadoc.complete", "build/total-javadoc");
463
        sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
472
        sisterh.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
464
        assertTrue("add ref modifying just because artifact location changed", r.addReference(art));
473
        r.addReference(art, art.getArtifactLocations()[0]);
465
        assertTrue("project modified by new ${reference.proj2.dojavadoc}", pm.isModified(p));
474
        assertTrue("project modified by new ${reference.proj2.dojavadoc}", pm.isModified(p));
466
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
475
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
467
        assertEquals("correct ${reference.proj2.dojavadoc}",
476
        assertEquals("correct ${reference.proj2.dojavadoc}",
Lines 472-485 Link Here
472
            h.resolveFile(pev.getProperty("reference.proj2.dojavadoc")));
481
            h.resolveFile(pev.getProperty("reference.proj2.dojavadoc")));
473
        // Now try removing first ref. Should remove raw ref, ref property, but not project property.
482
        // Now try removing first ref. Should remove raw ref, ref property, but not project property.
474
        pm.saveProject(p);
483
        pm.saveProject(p);
475
        assertTrue("remove proj2.dojar succeeded", r.removeReference("proj2", "dojar"));
484
        assertTrue("remove proj2.dojar succeeded", r.destroyReference("${reference.proj2.dojar}"));
476
        assertTrue("remove ref modified project", pm.isModified(p));
485
        assertTrue("remove ref modified project", pm.isModified(p));
477
        refs = r.getRawReferences();
486
        refs = r.getRawReferences();
478
        assertEquals("now have just one ref", 1, refs.length);
487
        assertEquals("now have just one ref", 1, refs.length);
479
        ref = refs[0];
488
        ref = refs[0];
480
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
489
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
481
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
490
        assertEquals("correct modified artifact type", "javadoc.html", ref.getArtifactType());
482
        assertEquals("correct script location", URI.create("build.xml"), ref.getScriptLocation());
491
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
483
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
492
        assertEquals("correct target name", "dojavadoc", ref.getTargetName());
484
        assertEquals("correct modified clean target name", "realclean", ref.getCleanTargetName());
493
        assertEquals("correct modified clean target name", "realclean", ref.getCleanTargetName());
485
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
494
        props = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
Lines 491-500 Link Here
491
            "${project.proj2}/build/total-javadoc",
500
            "${project.proj2}/build/total-javadoc",
492
            props.getProperty("reference.proj2.dojavadoc"));
501
            props.getProperty("reference.proj2.dojavadoc"));
493
        pm.saveProject(p);
502
        pm.saveProject(p);
494
        assertFalse("no-op remove proj2.dojar failed", r.removeReference("proj2", "dojar"));
503
        assertFalse("no-op remove proj2.dojar failed", r.destroyReference("${reference.proj2.dojar}"));
495
        assertFalse("no-op remove did not modify project", pm.isModified(p));
504
        assertFalse("no-op remove did not modify project", pm.isModified(p));
496
        // Try removing second ref. Should now remove project property.
505
        // Try removing second ref. Should now remove project property.
497
        assertTrue("remove proj2.dojavadoc succeeded", r.removeReference("proj2", "dojavadoc"));
506
        assertTrue("remove proj2.dojavadoc succeeded", r.destroyReference("${reference.proj2.dojavadoc}"));
498
        assertTrue("remove ref modified project", pm.isModified(p));
507
        assertTrue("remove ref modified project", pm.isModified(p));
499
        refs = r.getRawReferences();
508
        refs = r.getRawReferences();
500
        assertEquals("now have no refs", 0, refs.length);
509
        assertEquals("now have no refs", 0, refs.length);
Lines 517-523 Link Here
517
        Project p = pm.findProject(projdir);
526
        Project p = pm.findProject(projdir);
518
        ReferenceHelper referenceHelperProj4 = (ReferenceHelper)p.getLookup().lookup(ReferenceHelper.class);
527
        ReferenceHelper referenceHelperProj4 = (ReferenceHelper)p.getLookup().lookup(ReferenceHelper.class);
519
        AntArtifact art = proj4Helper.createSimpleAntArtifact("jar", "build.jar", proj4Helper.getStandardPropertyEvaluator(), "do.jar", "clean");
528
        AntArtifact art = proj4Helper.createSimpleAntArtifact("jar", "build.jar", proj4Helper.getStandardPropertyEvaluator(), "do.jar", "clean");
520
        String ref = referenceHelperProj4.createForeignFileReference(art);
529
        String ref = referenceHelperProj4.addReference(art, art.getArtifactLocations()[0]);
521
        assertEquals("Project reference was not correctly escaped", "${reference.pro-ject_4.do_jar}", ref);
530
        assertEquals("Project reference was not correctly escaped", "${reference.pro-ject_4.do_jar}", ref);
522
        
531
        
523
        // test that it can be found
532
        // test that it can be found
Lines 534-539 Link Here
534
        assertNull("Reference was not deleted", rr);
543
        assertNull("Reference was not deleted", rr);
535
    }
544
    }
536
        
545
        
546
    public void testArtifactProperties() throws Exception {
547
        assertFalse("project not initially modified", pm.isModified(p));
548
        AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
549
        art.getProperties().setProperty("configuration", "debug");
550
        assertFalse("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
551
        assertEquals("added a ref to proj2.dojar", "${reference.proj2.dojar}", r.addReference(art, art.getArtifactLocations()[0]));
552
        assertTrue("reference exist", r.isReferenced(art, art.getArtifactLocations()[0]));
553
        assertTrue("project now modified", pm.isModified(p));
554
        ProjectManager.getDefault().saveAllProjects();
555
        ReferenceHelper.RawReference[] refs = r.getRawReferences();
556
        assertEquals("one ref now", 1, refs.length);
557
        ReferenceHelper.RawReference ref = refs[0];
558
        assertEquals("correct foreign project name", "proj2", ref.getForeignProjectName());
559
        assertEquals("correct artifact type", "jar", ref.getArtifactType());
560
        assertEquals("correct script location", "${project.proj2}/build.xml", ref.getScriptLocationValue());
561
        assertEquals("correct target name", "dojar", ref.getTargetName());
562
        assertEquals("correct clean target name", "clean", ref.getCleanTargetName());
563
        assertEquals("correct property keys", new TreeSet(Arrays.asList(new String[]{"configuration"})), ref.getProperties().keySet());
564
        assertEquals("correct property values", new TreeSet(Arrays.asList(new String[]{"debug"})), new TreeSet(ref.getProperties().values()));
565
    }
537
566
538
    /**
567
    /**
539
     * Check that the {@link SubprojectProvider} implementation behaves correctly.
568
     * Check that the {@link SubprojectProvider} implementation behaves correctly.
Lines 541-551 Link Here
541
     */
570
     */
542
    public void testSubprojectProviderImpl() throws Exception {
571
    public void testSubprojectProviderImpl() throws Exception {
543
        AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
572
        AntArtifact art = sisterh.createSimpleAntArtifact("jar", "build.jar", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
544
        assertTrue("added a ref to proj2.dojar", r.addReference(art));
573
        assertNotNull("added a ref to proj2.dojar", r.addReference(art, art.getArtifactLocations()[0]));
545
        art = sisterh.createSimpleAntArtifact("javadoc", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
574
        art = sisterh.createSimpleAntArtifact("javadoc", "build.javadoc", sisterh.getStandardPropertyEvaluator(), "dojavadoc", "clean");
546
        assertTrue("added a ref to proj2.dojavadoc", r.addReference(art));
575
        assertNotNull("added a ref to proj2.dojavadoc", r.addReference(art, art.getArtifactLocations()[0]));
547
        art = seph.createSimpleAntArtifact("jar", "build.jar", seph.getStandardPropertyEvaluator(), "dojar", "clean");
576
        art = seph.createSimpleAntArtifact("jar", "build.jar", seph.getStandardPropertyEvaluator(), "dojar", "clean");
548
        assertTrue("added a ref to proj3.dojar", r.addReference(art));
577
        assertNotNull("added a ref to proj3.dojar", r.addReference(art, art.getArtifactLocations()[0]));
549
        SubprojectProvider sp = r.createSubprojectProvider();
578
        SubprojectProvider sp = r.createSubprojectProvider();
550
        Set/*<Project>*/ subprojs = sp.getSubprojects();
579
        Set/*<Project>*/ subprojs = sp.getSubprojects();
551
        assertEquals("two subprojects", 2, subprojs.size());
580
        assertEquals("two subprojects", 2, subprojs.size());
Lines 580-589 Link Here
580
        assertEquals("correct project", sisterprojdir, art.getProject().getProjectDirectory());
609
        assertEquals("correct project", sisterprojdir, art.getProject().getProjectDirectory());
581
        assertEquals("correct target name", "dojar", art.getTargetName());
610
        assertEquals("correct target name", "dojar", art.getTargetName());
582
        assertEquals("correct type", "jar", art.getType());
611
        assertEquals("correct type", "jar", art.getType());
583
        assertEquals("correct artifact location", URI.create("dist/proj2.jar"), art.getArtifactLocation());
612
        assertEquals("correct artifact location", URI.create("dist/proj2.jar"), art.getArtifactLocations()[0]);
584
        art = r.getForeignFileReferenceAsArtifact("reference.proj2.dojar");
613
        art = (AntArtifact)r.findArtifactAndLocation("reference.proj2.dojar")[0];
585
        assertNull("bad format", art);
614
        assertNull("bad format", art);
586
        art = r.getForeignFileReferenceAsArtifact("${reference.proj2.doojar}");
615
        art = (AntArtifact)r.findArtifactAndLocation("${reference.proj2.doojar}")[0];
587
        assertNull("wrong target name", art);
616
        assertNull("wrong target name", art);
588
        File f2 = new File(new File(FileUtil.toFile(sisterprojdir2), "dist"), "proj2.jar");
617
        File f2 = new File(new File(FileUtil.toFile(sisterprojdir2), "dist"), "proj2.jar");
589
        assertEquals("reference ID must be unique", "${reference.proj2-1.dojar}", r.createForeignFileReference(f2, "jar"));
618
        assertEquals("reference ID must be unique", "${reference.proj2-1.dojar}", r.createForeignFileReference(f2, "jar"));
Lines 609-615 Link Here
609
        assertEquals("reference correctly evaluated", f, h.resolveFile(refval));
638
        assertEquals("reference correctly evaluated", f, h.resolveFile(refval));
610
        val = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty("project.proj3");
639
        val = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty("project.proj3");
611
        assertEquals("reference correctly evaluated", FileUtil.toFile(sepprojdir).getAbsolutePath(), val);
640
        assertEquals("reference correctly evaluated", FileUtil.toFile(sepprojdir).getAbsolutePath(), val);
612
        art = r.getForeignFileReferenceAsArtifact("${reference.proj3.dojar}");
641
        art = (AntArtifact)r.findArtifactAndLocation("${reference.proj3.dojar}")[0];
613
        assertNotNull("got the reference back", art);
642
        assertNotNull("got the reference back", art);
614
        assertEquals("correct project", sepprojdir, art.getProject().getProjectDirectory());
643
        assertEquals("correct project", sepprojdir, art.getProject().getProjectDirectory());
615
        assertEquals("correct target name", "dojar", art.getTargetName());
644
        assertEquals("correct target name", "dojar", art.getTargetName());
Lines 644-651 Link Here
644
        assertEquals("Foreign file reference was not correctly created", "${file.reference.m_y_l_i_b.jar-2}", ref);
673
        assertEquals("Foreign file reference was not correctly created", "${file.reference.m_y_l_i_b.jar-2}", ref);
645
        refval = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(ref.substring(2, ref.length()-1));
674
        refval = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(ref.substring(2, ref.length()-1));
646
        assertEquals("Reference was not correctly evaluated", "../jars3/m y l i b.jar", refval);
675
        assertEquals("Reference was not correctly evaluated", "../jars3/m y l i b.jar", refval);
647
        assertTrue("Reference was not removed", r.removeReference(ref));
676
        assertTrue("Reference was not removed", r.destroyReference(ref));
648
        assertFalse("There should not be any reference", r.removeReference(ref));
677
        assertFalse("There should not be any reference", r.destroyReference(ref));
649
        refval = pev.evaluate(ref);
678
        refval = pev.evaluate(ref);
650
        assertEquals("Reference was not removed", ref, refval);
679
        assertEquals("Reference was not removed", ref, refval);
651
        
680
        
Lines 692-698 Link Here
692
        art = ref.toAntArtifact(r);
721
        art = ref.toAntArtifact(r);
693
        assertNotNull("now artifact will be found", art);
722
        assertNotNull("now artifact will be found", art);
694
        assertEquals("correct directory", sisterprojdir, art.getProject().getProjectDirectory());
723
        assertEquals("correct directory", sisterprojdir, art.getProject().getProjectDirectory());
695
        assertEquals("correct artifact location", URI.create("dist/proj2.jar"), art.getArtifactLocation());
724
        assertEquals("correct artifact location", URI.create("dist/proj2.jar"), art.getArtifactLocations()[0]);
696
        assertEquals("correct script location", new File(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
725
        assertEquals("correct script location", new File(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
697
        assertEquals("correct target name", "dojar", art.getTargetName());
726
        assertEquals("correct target name", "dojar", art.getTargetName());
698
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
727
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
(-)ant/project/test/unit/src/org/netbeans/spi/project/support/ant/SimpleAntArtifactTest.java (-4 / +4 lines)
Lines 73-82 Link Here
73
        assertEquals("correct type", "jar", art.getType());
73
        assertEquals("correct type", "jar", art.getType());
74
        assertEquals("correct target name", "dojar", art.getTargetName());
74
        assertEquals("correct target name", "dojar", art.getTargetName());
75
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
75
        assertEquals("correct clean target name", "clean", art.getCleanTargetName());
76
        assertEquals("correct artifact location", URI.create("build/proj2.jar"), art.getArtifactLocation());
76
        assertEquals("correct artifact location", URI.create("build/proj2.jar"), art.getArtifactLocations()[0]);
77
        assertEquals("no artifact file yet", null, art.getArtifactFile());
77
        assertEquals("no artifact file yet", 0, art.getArtifactFiles().length);
78
        FileObject artfile = FileUtil.createData(sisterprojdir, "build/proj2.jar");
78
        FileObject artfile = FileUtil.createData(sisterprojdir, "build/proj2.jar");
79
        assertEquals("now have an artifact file", artfile, art.getArtifactFile());
79
        assertEquals("now have an artifact file", artfile, art.getArtifactFiles()[0]);
80
        assertEquals("correct script location", new File(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
80
        assertEquals("correct script location", new File(FileUtil.toFile(sisterprojdir), "build.xml"), art.getScriptLocation());
81
        assertEquals("no script file yet", null, art.getScriptFile());
81
        assertEquals("no script file yet", null, art.getScriptFile());
82
        FileObject scriptfile = FileUtil.createData(sisterprojdir, "build.xml");
82
        FileObject scriptfile = FileUtil.createData(sisterprojdir, "build.xml");
Lines 84-90 Link Here
84
        assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject());
84
        assertEquals("correct project", pm.findProject(sisterprojdir), art.getProject());
85
        
85
        
86
        art = sisterh.createSimpleAntArtifact("jar", "build.jar.absolute", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
86
        art = sisterh.createSimpleAntArtifact("jar", "build.jar.absolute", sisterh.getStandardPropertyEvaluator(), "dojar", "clean");
87
        assertEquals("correct artifact location", (new File(getWorkDir().getAbsolutePath()+"/build/proj3.jar")).toURI(), art.getArtifactLocation());
87
        assertEquals("correct artifact location", (new File(getWorkDir().getAbsolutePath()+"/build/proj3.jar")).toURI(), art.getArtifactLocations()[0]);
88
    }
88
    }
89
    
89
    
90
}
90
}
(-)form/src/org/netbeans/modules/form/project/ClassPathUtils.java (-2 / +5 lines)
Lines 258-265 Link Here
258
                File jarFile = new File(name);
258
                File jarFile = new File(name);
259
                AntArtifact artifact =
259
                AntArtifact artifact =
260
                    AntArtifactQuery.findArtifactFromFile(jarFile);
260
                    AntArtifactQuery.findArtifactFromFile(jarFile);
261
                if (artifact.getProject() != project)
261
                if (artifact.getProject() != project) {
262
                    projectClassPath.addAntArtifact(artifact);
262
                    for (int y=0; y<artifact.getArtifactLocations().length; y++ ) {
263
                        projectClassPath.addAntArtifact(artifact, artifact.getArtifactLocations()[y]);
264
                    }
265
                }
263
            }
266
            }
264
        }
267
        }
265
268
(-)java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java (-9 lines)
Lines 472-486 Link Here
472
            TargetMapping tm = (TargetMapping)it.next();
472
            TargetMapping tm = (TargetMapping)it.next();
473
            if (tm.name.equals("build")) { // NOI18N
473
            if (tm.name.equals("build")) { // NOI18N
474
                if (tm.targets.size() == 1) {
474
                if (tm.targets.size() == 1) {
475
                    if (tm.script != null) {
476
                        String script = evaluator.evaluate(tm.script);
477
                        File f = new File(script);
478
                        if (f.isAbsolute()) {
479
                            // #50092 - no exports will be generated when build
480
                            // script does not lie within project directory
481
                            return new ArrayList();
482
                        }
483
                    }
484
                    targetName = (String)tm.targets.get(0);
475
                    targetName = (String)tm.targets.get(0);
485
                    scriptName = tm.script;
476
                    scriptName = tm.script;
486
                } else {
477
                } else {
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathExtender.java (-4 / +7 lines)
Lines 14-20 Link Here
14
14
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.io.File;
16
import java.io.File;
17
import java.net.URI;
17
import java.util.List;
18
import java.util.List;
19
import org.netbeans.modules.java.j2seproject.ui.customizer.AntArtifactChooser;
18
import org.openide.ErrorManager;
20
import org.openide.ErrorManager;
19
import org.openide.filesystems.FileObject;
21
import org.openide.filesystems.FileObject;
20
import org.openide.filesystems.FileUtil;
22
import org.openide.filesystems.FileUtil;
Lines 132-142 Link Here
132
        }
134
        }
133
    }
135
    }
134
136
135
    public boolean addAntArtifact(final AntArtifact artifact) throws IOException {
137
    public boolean addAntArtifact(final AntArtifact artifact, final URI location) throws IOException {
136
        return addAntArtifact(CP_CLASS_PATH,artifact);
138
        return addAntArtifact(CP_CLASS_PATH,artifact, location);
137
    }
139
    }
138
140
139
    public boolean addAntArtifact(final String classPathId, final AntArtifact artifact) throws IOException {
141
    public boolean addAntArtifact(final String classPathId, final AntArtifact artifact, final URI location) throws IOException {
140
        assert artifact != null : "Parameter can not be null";       //NOI18N
142
        assert artifact != null : "Parameter can not be null";       //NOI18N
141
        try {
143
        try {
142
            return ((Boolean)ProjectManager.mutex().writeAccess(
144
            return ((Boolean)ProjectManager.mutex().writeAccess(
Lines 146-152 Link Here
146
                            String raw = props.getProperty (classPathId);
148
                            String raw = props.getProperty (classPathId);
147
                            J2SEProjectProperties.PathParser parser = new J2SEProjectProperties.PathParser ();
149
                            J2SEProjectProperties.PathParser parser = new J2SEProjectProperties.PathParser ();
148
                            List resources = (List) parser.decode(raw, project, helper.getAntProjectHelper(), eval, refHelper);
150
                            List resources = (List) parser.decode(raw, project, helper.getAntProjectHelper(), eval, refHelper);
149
                            VisualClassPathItem item = VisualClassPathItem.create (artifact);
151
                            AntArtifactChooser.ArtifactItem ai = new AntArtifactChooser.ArtifactItem(artifact, location);
152
                            VisualClassPathItem item = VisualClassPathItem.create (ai);
150
                            if (!resources.contains(item)) {
153
                            if (!resources.contains(item)) {
151
                                resources.add (item);
154
                                resources.add (item);
152
                                raw = parser.encode (resources, project, helper.getAntProjectHelper(), refHelper);
155
                                raw = parser.encode (resources, project, helper.getAntProjectHelper(), refHelper);
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl (-1 / +36 lines)
Lines 27-33 Link Here
27
                xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1"   
27
                xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1"   
28
                xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2"
28
                xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2"
29
                xmlns:projdeps="http://www.netbeans.org/ns/ant-project-references/1"
29
                xmlns:projdeps="http://www.netbeans.org/ns/ant-project-references/1"
30
                exclude-result-prefixes="xalan p projdeps">
30
                xmlns:projdeps2="http://www.netbeans.org/ns/ant-project-references/2"
31
                exclude-result-prefixes="xalan p projdeps projdeps2">
31
<!-- XXX should use namespaces for NB in-VM tasks from ant/browsetask and debuggerjpda/ant (Ant 1.6.1 and higher only) -->
32
<!-- XXX should use namespaces for NB in-VM tasks from ant/browsetask and debuggerjpda/ant (Ant 1.6.1 and higher only) -->
32
    <xsl:output method="xml" indent="yes" encoding="UTF-8" xalan:indent-amount="4"/>
33
    <xsl:output method="xml" indent="yes" encoding="UTF-8" xalan:indent-amount="4"/>
33
    <xsl:template match="/">
34
    <xsl:template match="/">
Lines 1034-1039 Link Here
1034
        <target name="{$targetname}">
1035
        <target name="{$targetname}">
1035
            <xsl:attribute name="depends">init</xsl:attribute>
1036
            <xsl:attribute name="depends">init</xsl:attribute>
1036
            <xsl:attribute name="unless">no.deps</xsl:attribute>
1037
            <xsl:attribute name="unless">no.deps</xsl:attribute>
1038
            
1039
            <xsl:variable name="references2" select="/p:project/p:configuration/projdeps2:references"/>
1040
            <xsl:for-each select="$references2/projdeps2:reference[not($type) or projdeps2:artifact-type = $type]">
1041
                <xsl:variable name="subproj" select="projdeps2:foreign-project"/>
1042
                <xsl:variable name="subtarget">
1043
                    <xsl:choose>
1044
                        <xsl:when test="$type">
1045
                            <xsl:value-of select="projdeps2:target"/>
1046
                        </xsl:when>
1047
                        <xsl:otherwise>
1048
                            <xsl:value-of select="projdeps2:clean-target"/>
1049
                        </xsl:otherwise>
1050
                    </xsl:choose>
1051
                </xsl:variable>
1052
                <xsl:variable name="script" select="projdeps2:script"/>
1053
                <xsl:choose>
1054
                    <xsl:when test="projdeps2:properties">
1055
                        <ant target="{$subtarget}" inheritall="false" antfile="{$script}">
1056
                            <xsl:for-each select="projdeps2:properties/projdeps2:property">
1057
                                <xsl:variable name="value">
1058
                                    <xsl:value-of select="current()"/>
1059
                                </xsl:variable>
1060
                                <xsl:variable name="key" select="@name"/>
1061
                                <property name="{$key}" value="{$value}"/>
1062
                            </xsl:for-each>
1063
                        </ant>
1064
                    </xsl:when>
1065
                    <xsl:otherwise>
1066
                        <ant target="{$subtarget}" inheritall="false" antfile="{$script}"/>
1067
                    </xsl:otherwise>
1068
                </xsl:choose>
1069
            </xsl:for-each>
1070
            
1037
            <xsl:variable name="references" select="/p:project/p:configuration/projdeps:references"/>
1071
            <xsl:variable name="references" select="/p:project/p:configuration/projdeps:references"/>
1038
            <xsl:for-each select="$references/projdeps:reference[not($type) or projdeps:artifact-type = $type]">
1072
            <xsl:for-each select="$references/projdeps:reference[not($type) or projdeps:artifact-type = $type]">
1039
                <xsl:variable name="subproj" select="projdeps:foreign-project"/>
1073
                <xsl:variable name="subproj" select="projdeps:foreign-project"/>
Lines 1050-1055 Link Here
1050
                <xsl:variable name="script" select="projdeps:script"/>
1084
                <xsl:variable name="script" select="projdeps:script"/>
1051
                <ant target="{$subtarget}" inheritall="false" antfile="${{project.{$subproj}}}/{$script}"/>
1085
                <ant target="{$subtarget}" inheritall="false" antfile="${{project.{$subproj}}}/{$script}"/>
1052
            </xsl:for-each>
1086
            </xsl:for-each>
1087
            
1053
        </target>
1088
        </target>
1054
    </xsl:template>
1089
    </xsl:template>
1055
    
1090
    
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/LibrariesNode.java (-8 / +9 lines)
Lines 319-326 Link Here
319
                }
319
                }
320
                else if (prop.startsWith(ANT_ARTIFACT_PREFIX)) {
320
                else if (prop.startsWith(ANT_ARTIFACT_PREFIX)) {
321
                    //Project reference
321
                    //Project reference
322
                    AntArtifact artifact = refHelper.getForeignFileReferenceAsArtifact(prop);
322
                    Object ret[] = refHelper.findArtifactAndLocation(prop);
323
                    if ( artifact != null ) {
323
                    if ( ret[0] != null ) {
324
                        AntArtifact artifact = (AntArtifact)ret[0];
324
                        Project project = artifact.getProject();
325
                        Project project = artifact.getProject();
325
                        result.add (new Key(project,currentClassPath, propName));
326
                        result.add (new Key(project,currentClassPath, propName));
326
                    }
327
                    }
Lines 491-508 Link Here
491
        }
492
        }
492
493
493
        public void actionPerformed(ActionEvent e) {
494
        public void actionPerformed(ActionEvent e) {
494
            AntArtifact artifacts[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, project);
495
            AntArtifactChooser.ArtifactItem ai[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, project);
495
                if ( artifacts != null ) {
496
                if ( ai != null ) {
496
                    addArtifacts( artifacts );
497
                    addArtifacts( ai );
497
                }
498
                }
498
        }
499
        }
499
500
500
        private void addArtifacts (AntArtifact[] artifacts) {
501
        private void addArtifacts (AntArtifactChooser.ArtifactItem[] artifactItems) {
501
            J2SEProjectClassPathExtender cpExtender = (J2SEProjectClassPathExtender) project.getLookup().lookup(J2SEProjectClassPathExtender.class);
502
            J2SEProjectClassPathExtender cpExtender = (J2SEProjectClassPathExtender) project.getLookup().lookup(J2SEProjectClassPathExtender.class);
502
            if (cpExtender != null) {
503
            if (cpExtender != null) {
503
                for (int i=0; i<artifacts.length;i++) {
504
                for (int i=0; i<artifactItems.length;i++) {
504
                    try {
505
                    try {
505
                        cpExtender.addAntArtifact(classPathId, artifacts[i]);
506
                        cpExtender.addAntArtifact(classPathId, artifactItems[i].getArtifact(), artifactItems[i].getArtifactURI());
506
                    } catch (IOException ioe) {
507
                    } catch (IOException ioe) {
507
                        ErrorManager.getDefault().notify(ioe);
508
                        ErrorManager.getDefault().notify(ioe);
508
                    }
509
                    }
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/ProjectNode.java (-28 / +27 lines)
Lines 21-26 Link Here
21
import java.net.URL;
21
import java.net.URL;
22
import java.net.MalformedURLException;
22
import java.net.MalformedURLException;
23
import java.io.File;
23
import java.io.File;
24
import java.util.Arrays;
25
import java.util.HashSet;
26
import java.util.Set;
24
import javax.swing.Action;
27
import javax.swing.Action;
25
import javax.swing.Icon;
28
import javax.swing.Icon;
26
import javax.swing.ImageIcon;
29
import javax.swing.ImageIcon;
Lines 144-189 Link Here
144
147
145
148
146
        public boolean hasJavadoc() {
149
        public boolean hasJavadoc() {
147
            try {
150
            return findJavadoc().size() > 0;
151
        }
152
153
        public void showJavadoc() {
154
            Set us = findJavadoc();
155
            URL[] urls = (URL[])us.toArray(new URL[us.size()]);
156
            ProjectInformation info = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class);
157
            ShowJavadocAction.showJavaDoc (ShowJavadocAction.findJavadoc("index.html",urls),info == null ?
158
                NbBundle.getMessage (ProjectNode.class,"TXT_UnknownProjectName") : info.getDisplayName());
159
        }
160
        
161
        private Set findJavadoc() {
148
                AntArtifactProvider provider = (AntArtifactProvider) project.getLookup().lookup(AntArtifactProvider.class);
162
                AntArtifactProvider provider = (AntArtifactProvider) project.getLookup().lookup(AntArtifactProvider.class);
149
                if (provider == null) {
163
                if (provider == null) {
150
                    return false;
164
                return new HashSet();
151
                }
165
                }
152
                AntArtifact[] artifacts = provider.getBuildArtifacts();
166
                AntArtifact[] artifacts = provider.getBuildArtifacts();
153
                if (artifacts.length==0) {
167
                if (artifacts.length==0) {
154
                    return false;
168
                return new HashSet();
155
                }
169
                }
156
                URI artifactLocation = artifacts[0].getArtifactLocation();
157
                File scriptLocation = artifacts[0].getScriptLocation();
170
                File scriptLocation = artifacts[0].getScriptLocation();
158
                URL artifactURL = scriptLocation.toURI().resolve(artifactLocation).normalize().toURL();
171
            URI artifactLocations[] = artifacts[0].getArtifactLocations();
159
                if (FileUtil.isArchiveFile(artifactURL)) {
172
            Set urls = new HashSet();
160
                    artifactURL = FileUtil.getArchiveRoot(artifactURL);
173
            URL artifactURL;
161
                }
174
            for (int i=0; i<artifactLocations.length; i++) {
162
                URL[] urls = JavadocForBinaryQuery.findJavadoc(artifactURL).getRoots();
175
                try {
163
                return urls.length>0;
176
                    artifactURL = scriptLocation.toURI().resolve(artifactLocations[i]).normalize().toURL();
164
            } catch (MalformedURLException mue) {
177
            } catch (MalformedURLException mue) {
165
                return false;
178
                    continue;
166
            }
179
            }
167
        }
168
169
        public void showJavadoc() {
170
            try {
171
                AntArtifactProvider provider = (AntArtifactProvider) project.getLookup().lookup(AntArtifactProvider.class);
172
                AntArtifact[] artifacts = provider.getBuildArtifacts();
173
                //XXX: J2SEProject has a single artifact, if changed must return FileObject[]
174
                URI artifactLocation = artifacts[0].getArtifactLocation();
175
                File scriptLocation = artifacts[0].getScriptLocation();
176
                URL artifactURL = scriptLocation.toURI().resolve(artifactLocation).normalize().toURL();
177
                if (FileUtil.isArchiveFile(artifactURL)) {
180
                if (FileUtil.isArchiveFile(artifactURL)) {
178
                    artifactURL = FileUtil.getArchiveRoot(artifactURL);
181
                    artifactURL = FileUtil.getArchiveRoot(artifactURL);
179
                }
182
                }
180
                URL[] urls = JavadocForBinaryQuery.findJavadoc(artifactURL).getRoots();
183
                urls.addAll(Arrays.asList(JavadocForBinaryQuery.findJavadoc(artifactURL).getRoots()));
181
                ProjectInformation info = (ProjectInformation) project.getLookup().lookup(ProjectInformation.class);
182
                ShowJavadocAction.showJavaDoc (ShowJavadocAction.findJavadoc("index.html",urls),info == null ?
183
                    NbBundle.getMessage (ProjectNode.class,"TXT_UnknownProjectName") : info.getDisplayName());
184
            } catch (MalformedURLException mue) {
185
                ErrorManager.getDefault().notify (mue);
186
            }
184
            }
185
            return urls;
187
        }
186
        }
188
187
189
    }
188
    }
Lines 262-268 Link Here
262
                       if (!RemoveClassPathRootAction.isReferenced (new EditableProperties[] {
261
                       if (!RemoveClassPathRootAction.isReferenced (new EditableProperties[] {
263
                           props,
262
                           props,
264
                           helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH)}, ref)) {
263
                           helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH)}, ref)) {
265
                           refHelper.destroyForeignFileReference (ref);
264
                           refHelper.destroyReference(ref);
266
                       }
265
                       }
267
                   }
266
                   }
268
               }
267
               }
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/AntArtifactChooser.java (-16 / +31 lines)
Lines 18-23 Link Here
18
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyChangeListener;
19
import java.io.File;
19
import java.io.File;
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.net.URI;
21
import javax.swing.DefaultListModel;
22
import javax.swing.DefaultListModel;
22
import javax.swing.JFileChooser;
23
import javax.swing.JFileChooser;
23
import javax.swing.JPanel;
24
import javax.swing.JPanel;
Lines 152-160 Link Here
152
            AntArtifact artifacts[] = AntArtifactQuery.findArtifactsByType( project, artifactType );
153
            AntArtifact artifacts[] = AntArtifactQuery.findArtifactsByType( project, artifactType );
153
        
154
        
154
            for( int i = 0; i < artifacts.length; i++ ) {
155
            for( int i = 0; i < artifacts.length; i++ ) {
155
                model.addElement( new ArtifactItem( artifacts[i]));
156
                URI uris[] = artifacts[i].getArtifactLocations();
157
                for( int y = 0; y < uris.length; y++ ) {
158
                    model.addElement( new ArtifactItem(artifacts[i], uris[y]));
156
            }
159
            }
157
        }
160
        }
161
            jListArtifacts.setSelectionInterval(0, model.size());
162
        }
158
        
163
        
159
    }
164
    }
160
        
165
        
Lines 171-177 Link Here
171
    /** Shows dialog with the artifact chooser 
176
    /** Shows dialog with the artifact chooser 
172
     * @return null if canceled selected jars if some jars selected
177
     * @return null if canceled selected jars if some jars selected
173
     */
178
     */
174
    public static AntArtifact[] showDialog( String artifactType, Project master ) {
179
    public static ArtifactItem[] showDialog( String artifactType, Project master ) {
175
        
180
        
176
        JFileChooser chooser = ProjectChooser.projectChooser();
181
        JFileChooser chooser = ProjectChooser.projectChooser();
177
        chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
182
        chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
Lines 208-225 Link Here
208
                return null;
213
                return null;
209
            }
214
            }
210
            
215
            
211
            DefaultListModel model = (DefaultListModel)accessory.jListArtifacts.getModel();
212
            
213
            AntArtifact artifacts[] = new AntArtifact[ model.size() ];
214
            
215
            // XXX Adding references twice            
216
            for( int i = 0; i < artifacts.length; i++ ) {
217
                artifacts[i] = ((ArtifactItem)model.getElementAt( i )).getArtifact();
218
            }
219
            
220
            FoldersListSettings.getDefault().setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
216
            FoldersListSettings.getDefault().setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
221
            return artifacts;
222
            
217
            
218
            Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
219
            int count = 0;
220
            for(int i = 0; i < tmp.length; i++) {
221
                if (accessory.jListArtifacts.isSelectedIndex(i)) {
222
                    tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
223
                    count++;
224
                }
225
            }
226
            ArtifactItem artifactItems[] = new ArtifactItem[count];
227
            System.arraycopy(tmp, 0, artifactItems, 0, count);
228
            return artifactItems;
223
        }
229
        }
224
        else {
230
        else {
225
            return null; 
231
            return null; 
Lines 227-246 Link Here
227
                
233
                
228
    }
234
    }
229
       
235
       
230
    private static class ArtifactItem {
236
    /**
237
     * Pair of AntArtifact and one of jars it produces.
238
     */
239
    public static class ArtifactItem {
231
        
240
        
232
        private AntArtifact artifact;
241
        private AntArtifact artifact;
242
        private URI artifactURI;
233
        
243
        
234
        ArtifactItem( AntArtifact artifact ) {
244
        public ArtifactItem(AntArtifact artifact, URI artifactURI) {
235
            this.artifact = artifact;
245
            this.artifact = artifact;
246
            this.artifactURI = artifactURI;
236
        }
247
        }
237
        
248
        
238
        AntArtifact getArtifact() {
249
        public AntArtifact getArtifact() {
239
            return artifact;
250
            return artifact;
240
        }
251
        }
241
        
252
        
253
        public URI getArtifactURI() {
254
            return artifactURI;
255
        }
256
        
242
        public String toString() {
257
        public String toString() {
243
            return artifact.getArtifactLocation().toString();
258
            return artifactURI.toString();
244
        }
259
        }
245
        
260
        
246
    }
261
    }
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEProjectProperties.java (-7 / +8 lines)
Lines 507-513 Link Here
507
            VisualClassPathItem vcpi = (VisualClassPathItem)it.next();
507
            VisualClassPathItem vcpi = (VisualClassPathItem)it.next();
508
            if ( vcpi.getType() == VisualClassPathItem.TYPE_ARTIFACT ||
508
            if ( vcpi.getType() == VisualClassPathItem.TYPE_ARTIFACT ||
509
                    vcpi.getType() == VisualClassPathItem.TYPE_JAR ) {
509
                    vcpi.getType() == VisualClassPathItem.TYPE_JAR ) {
510
                refHelper.destroyForeignFileReference(vcpi.getRaw());
510
                refHelper.destroyReference(vcpi.getRaw());
511
            }
511
            }
512
        }
512
        }
513
        
513
        
Lines 749-759 Link Here
749
                        cpItem = new VisualClassPathItem(null, VisualClassPathItem.TYPE_LIBRARY, pe[i], eval);
749
                        cpItem = new VisualClassPathItem(null, VisualClassPathItem.TYPE_LIBRARY, pe[i], eval);
750
                    }
750
                    }
751
                } else if (pe[i].startsWith(ANT_ARTIFACT_PREFIX)) {
751
                } else if (pe[i].startsWith(ANT_ARTIFACT_PREFIX)) {
752
                    AntArtifact artifact = refHelper.getForeignFileReferenceAsArtifact(pe[i]);
752
                    Object ret[] = refHelper.findArtifactAndLocation(pe[i]);
753
                    if ( artifact != null ) {
753
                    if ( ret[0] != null ) {
754
                        // Sub project artifact
754
                        // Sub project artifact
755
                        String eval = artifact.getArtifactLocation().toString();
755
                        AntArtifactChooser.ArtifactItem ai = new  AntArtifactChooser.ArtifactItem((AntArtifact)ret[0], (URI)ret[1]);
756
                        cpItem = new VisualClassPathItem( artifact, VisualClassPathItem.TYPE_ARTIFACT, pe[i], eval );
756
                        String eval = ai.getArtifactURI().toString();
757
                        cpItem = new VisualClassPathItem( ai, VisualClassPathItem.TYPE_ARTIFACT, pe[i], eval );
757
                    } else {
758
                    } else {
758
                        cpItem = new VisualClassPathItem(null, VisualClassPathItem.TYPE_ARTIFACT, pe[i], null);
759
                        cpItem = new VisualClassPathItem(null, VisualClassPathItem.TYPE_ARTIFACT, pe[i], null);
759
                    }
760
                    }
Lines 808-815 Link Here
808
                        break;    
809
                        break;    
809
                    case VisualClassPathItem.TYPE_ARTIFACT:
810
                    case VisualClassPathItem.TYPE_ARTIFACT:
810
                        if (vcpi.getObject() != null) {
811
                        if (vcpi.getObject() != null) {
811
                            AntArtifact aa = (AntArtifact)vcpi.getObject();
812
                            AntArtifactChooser.ArtifactItem ai = (AntArtifactChooser.ArtifactItem)vcpi.getObject();
812
                            String reference = refHelper.createForeignFileReference( aa );
813
                            String reference = refHelper.addReference(ai.getArtifact(), ai.getArtifactURI());
813
                            sb.append( reference );
814
                            sb.append( reference );
814
                        } else {
815
                        } else {
815
                            sb.append(vcpi.getRaw());
816
                            sb.append(vcpi.getRaw());
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/VisualClassPathItem.java (-15 / +14 lines)
Lines 18-24 Link Here
18
import java.io.File;
18
import java.io.File;
19
import javax.swing.Icon;
19
import javax.swing.Icon;
20
import javax.swing.ImageIcon;
20
import javax.swing.ImageIcon;
21
import org.netbeans.api.project.ant.AntArtifact;
22
import org.netbeans.api.project.libraries.Library;
21
import org.netbeans.api.project.libraries.Library;
23
import org.openide.filesystems.FileObject;
22
import org.openide.filesystems.FileObject;
24
23
Lines 81-88 Link Here
81
                    }
80
                    }
82
                    break;
81
                    break;
83
                case TYPE_ARTIFACT:
82
                case TYPE_ARTIFACT:
84
                    if (!(cpElement instanceof AntArtifact)) {
83
                    if (!(cpElement instanceof AntArtifactChooser.ArtifactItem)) {
85
                        throw new IllegalArgumentException("AntArtifact instance must be " + // NOI18N
84
                        throw new IllegalArgumentException("AntArtifactChooser.ArtifactItem instance must be " + // NOI18N
86
                            "passed as object for TYPE_ARTIFACT. Was: "+cpElement.getClass()); // NOI18N
85
                            "passed as object for TYPE_ARTIFACT. Was: "+cpElement.getClass()); // NOI18N
87
                    }
86
                    }
88
                    break;
87
                    break;
Lines 195-205 Link Here
195
        switch ( getType() ) {
194
        switch ( getType() ) {
196
            case TYPE_ARTIFACT:
195
            case TYPE_ARTIFACT:
197
                if (getObject() != null) {
196
                if (getObject() != null) {
198
                    AntArtifact aa = (AntArtifact)getObject();
197
                    AntArtifactChooser.ArtifactItem ai = (AntArtifactChooser.ArtifactItem)getObject();
199
198
200
                    hash += aa.getType().hashCode();                
199
                    hash += ai.getArtifact().getType().hashCode();                
201
                    hash += aa.getScriptLocation().hashCode();
200
                    hash += ai.getArtifact().getScriptLocation().hashCode();
202
                    hash += aa.getArtifactLocation().hashCode();
201
                    hash += ai.getArtifactURI().hashCode();
203
                } else {
202
                } else {
204
                    hash += getRaw().hashCode();
203
                    hash += getRaw().hashCode();
205
                }
204
                }
Lines 230-247 Link Here
230
        switch ( getType() ) {
229
        switch ( getType() ) {
231
            case TYPE_ARTIFACT:
230
            case TYPE_ARTIFACT:
232
                if (getObject() != null) {
231
                if (getObject() != null) {
233
                    AntArtifact aa1 = (AntArtifact)getObject();
232
                    AntArtifactChooser.ArtifactItem ai1 = (AntArtifactChooser.ArtifactItem)getObject();
234
                    AntArtifact aa2 = (AntArtifact)vcpi.getObject();
233
                    AntArtifactChooser.ArtifactItem ai2 = (AntArtifactChooser.ArtifactItem)vcpi.getObject();
235
234
236
                    if ( aa1.getType() != aa2.getType() ) {
235
                    if ( ai1.getArtifact().getType() != ai2.getArtifact().getType() ) {
237
                        return false;
236
                        return false;
238
                    }
237
                    }
239
238
240
                    if ( !aa1.getScriptLocation().equals( aa2.getScriptLocation() ) ) {
239
                    if ( !ai1.getArtifact().getScriptLocation().equals( ai2.getArtifact().getScriptLocation() ) ) {
241
                        return false;
240
                        return false;
242
                    }
241
                    }
243
242
244
                    if ( !aa1.getArtifactLocation().equals( aa2.getArtifactLocation() ) ) {
243
                    if ( !ai1.getArtifactURI().equals( ai2.getArtifactURI() ) ) {
245
                        return false;
244
                        return false;
246
                    }
245
                    }
247
246
Lines 272-282 Link Here
272
                    archiveFile.getPath());
271
                    archiveFile.getPath());
273
    }
272
    }
274
273
275
    public static VisualClassPathItem create (AntArtifact artifact) {
274
    public static VisualClassPathItem create(AntArtifactChooser.ArtifactItem artifactItem) {
276
        return new VisualClassPathItem( artifact,
275
        return new VisualClassPathItem(artifactItem,
277
                    VisualClassPathItem.TYPE_ARTIFACT,
276
                    VisualClassPathItem.TYPE_ARTIFACT,
278
                    null,
277
                    null,
279
                    artifact.getArtifactLocation().toString() );
278
                    artifactItem.toString());
280
    }
279
    }
281
    
280
    
282
    private static Icon getFolderIcon() {
281
    private static Icon getFolderIcon() {
(-)java/j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/VisualClasspathSupport.java (-8 / +7 lines)
Lines 29-35 Link Here
29
import org.netbeans.api.java.project.JavaProjectConstants;
29
import org.netbeans.api.java.project.JavaProjectConstants;
30
import org.netbeans.api.project.Project;
30
import org.netbeans.api.project.Project;
31
31
32
import org.netbeans.api.project.ant.AntArtifact;
33
import org.netbeans.api.project.libraries.Library;
32
import org.netbeans.api.project.libraries.Library;
34
import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings;
33
import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings;
35
import org.openide.DialogDisplayer;
34
import org.openide.DialogDisplayer;
Lines 190-204 Link Here
190
        fireActionPerformed();
189
        fireActionPerformed();
191
    }
190
    }
192
    
191
    
193
    private void addArtifacts( AntArtifact artifacts[] ) {
192
    private void addArtifacts(AntArtifactChooser.ArtifactItem artifactItems[]) {
194
        
193
        
195
        int[] si = classpathList.getSelectedIndices();
194
        int[] si = classpathList.getSelectedIndices();
196
        
195
        
197
        int lastIndex = si == null || si.length == 0 ? -1 : si[si.length - 1];
196
        int lastIndex = si == null || si.length == 0 ? -1 : si[si.length - 1];
198
        int[] indexes = new int[artifacts.length];
197
        int[] indexes = new int[artifactItems.length];
199
        for( int i = 0; i < artifacts.length; i++ ) {
198
        for( int i = 0; i < artifactItems.length; i++ ) {
200
            int current = lastIndex + 1 + i;
199
            int current = lastIndex + 1 + i;
201
            classpathModel.add(current,VisualClassPathItem.create(artifacts[i]));
200
            classpathModel.add(current,VisualClassPathItem.create(artifactItems[i]));
202
            indexes[i] = current;
201
            indexes[i] = current;
203
        }
202
        }
204
        this.classpathList.setSelectedIndices(indexes);
203
        this.classpathList.setSelectedIndices(indexes);
Lines 345-353 Link Here
345
                dlg.dispose();
344
                dlg.dispose();
346
            }
345
            }
347
            else if ( source == addArtifactButton ) { 
346
            else if ( source == addArtifactButton ) { 
348
                AntArtifact artifacts[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, master);
347
                AntArtifactChooser.ArtifactItem artifactItems[] = AntArtifactChooser.showDialog(JavaProjectConstants.ARTIFACT_TYPE_JAR, master);
349
                if ( artifacts != null ) {
348
                if (artifactItems != null) {
350
                    addArtifacts( artifacts );
349
                    addArtifacts(artifactItems);
351
                }
350
                }
352
            }
351
            }
353
            else if ( source == removeButton ) { 
352
            else if ( source == removeButton ) { 
(-)java/project/src/org/netbeans/modules/java/project/ProjectClassPathExtender.java (-1 / +3 lines)
Lines 13-18 Link Here
13
package org.netbeans.modules.java.project;
13
package org.netbeans.modules.java.project;
14
14
15
import java.io.IOException;
15
import java.io.IOException;
16
import java.net.URI;
16
import org.openide.filesystems.FileObject;
17
import org.openide.filesystems.FileObject;
17
import org.netbeans.api.project.libraries.Library;
18
import org.netbeans.api.project.libraries.Library;
18
import org.netbeans.api.project.ant.AntArtifact;
19
import org.netbeans.api.project.ant.AntArtifact;
Lines 49-57 Link Here
49
     * Adds AntArtifact into project's compile classpath if the
50
     * Adds AntArtifact into project's compile classpath if the
50
     * artifact is not already on it.
51
     * artifact is not already on it.
51
     * @param artifact the ant artifact to be added, not null
52
     * @param artifact the ant artifact to be added, not null
53
     * @param location the ant artifact's location to be added, not null
52
     * @return true in the case when the classpath was changed
54
     * @return true in the case when the classpath was changed
53
     * @exception IOException
55
     * @exception IOException
54
     */
56
     */
55
    public boolean addAntArtifact (AntArtifact artifact) throws IOException;
57
    public boolean addAntArtifact (AntArtifact artifact, URI location) throws IOException;
56
58
57
}
59
}

Return to bug 52886