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

(-)j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (-1 / +4 lines)
Lines 28-33 Link Here
28
import org.netbeans.api.project.ant.AntArtifact;
28
import org.netbeans.api.project.ant.AntArtifact;
29
import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl;
29
import org.netbeans.modules.java.j2seproject.classpath.ClassPathProviderImpl;
30
import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathExtender;
30
import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathExtender;
31
import org.netbeans.modules.java.j2seproject.classpath.J2SEProjectClassPathModifier;
31
import org.netbeans.modules.java.j2seproject.queries.CompiledSourceForBinaryQuery;
32
import org.netbeans.modules.java.j2seproject.queries.CompiledSourceForBinaryQuery;
32
import org.netbeans.modules.java.j2seproject.queries.JavadocForBinaryQueryImpl;
33
import org.netbeans.modules.java.j2seproject.queries.JavadocForBinaryQueryImpl;
33
import org.netbeans.modules.java.j2seproject.queries.SourceLevelQueryImpl;
34
import org.netbeans.modules.java.j2seproject.queries.SourceLevelQueryImpl;
Lines 144-149 Link Here
144
145
145
    private Lookup createLookup(AuxiliaryConfiguration aux) {
146
    private Lookup createLookup(AuxiliaryConfiguration aux) {
146
        SubprojectProvider spp = refHelper.createSubprojectProvider();
147
        SubprojectProvider spp = refHelper.createSubprojectProvider();
148
        final J2SEProjectClassPathModifier cpMod = new J2SEProjectClassPathModifier(this, this.updateHelper, eval, refHelper);
147
        return Lookups.fixed(new Object[] {
149
        return Lookups.fixed(new Object[] {
148
            new Info(),
150
            new Info(),
149
            aux,
151
            aux,
Lines 165-171 Link Here
165
            new J2SESharabilityQuery (this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
167
            new J2SESharabilityQuery (this.helper, evaluator(), getSourceRoots(), getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
166
            new J2SEFileBuiltQuery (this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
168
            new J2SEFileBuiltQuery (this.helper, evaluator(),getSourceRoots(),getTestSourceRoots()), //Does not use APH to get/put properties/cfgdata
167
            new RecommendedTemplatesImpl (this.updateHelper),
169
            new RecommendedTemplatesImpl (this.updateHelper),
168
            new J2SEProjectClassPathExtender(this, this.updateHelper, eval,refHelper),
170
            new J2SEProjectClassPathExtender(cpMod),
171
            cpMod,
169
            this, // never cast an externally obtained Project to J2SEProject - use lookup instead
172
            this, // never cast an externally obtained Project to J2SEProject - use lookup instead
170
            new J2SEProjectOperations(this),
173
            new J2SEProjectOperations(this),
171
            new J2SEProjectWebServicesSupportProvider()
174
            new J2SEProjectWebServicesSupportProvider()
(-)j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java (-4 / +44 lines)
Lines 19-24 Link Here
19
import java.util.HashMap;
19
import java.util.HashMap;
20
20
21
import org.netbeans.api.java.classpath.ClassPath;
21
import org.netbeans.api.java.classpath.ClassPath;
22
import org.netbeans.api.project.SourceGroup;
22
import org.netbeans.spi.java.classpath.ClassPathFactory;
23
import org.netbeans.spi.java.classpath.ClassPathFactory;
23
import org.netbeans.spi.java.classpath.ClassPathProvider;
24
import org.netbeans.spi.java.classpath.ClassPathProvider;
24
import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
25
import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
Lines 38-43 Link Here
38
    private static final String DIST_JAR = "dist.jar"; // NOI18N
39
    private static final String DIST_JAR = "dist.jar"; // NOI18N
39
    private static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N
40
    private static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N
40
    
41
    
42
    private static final String JAVAC_CLASSPATH = "javac.classpath";    //NOI18N
43
    private static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath";  //NOI18N
44
    private static final String RUN_CLASSPATH = "run.classpath";    //NOI18N
45
    private static final String RUN_TEST_CLASSPATH = "run.test.classpath";  //NOI18N
46
    
47
    
41
    private final AntProjectHelper helper;
48
    private final AntProjectHelper helper;
42
    private final File projectDirectory;
49
    private final File projectDirectory;
43
    private final PropertyEvaluator evaluator;
50
    private final PropertyEvaluator evaluator;
Lines 149-160 Link Here
149
            if (type == 0) {
156
            if (type == 0) {
150
                cp = ClassPathFactory.createClassPath(
157
                cp = ClassPathFactory.createClassPath(
151
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
158
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
152
                    projectDirectory, evaluator, new String[] {"javac.classpath"})); // NOI18N
159
                    projectDirectory, evaluator, new String[] {JAVAC_CLASSPATH})); // NOI18N
153
            }
160
            }
154
            else {
161
            else {
155
                cp = ClassPathFactory.createClassPath(
162
                cp = ClassPathFactory.createClassPath(
156
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
163
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
157
                    projectDirectory, evaluator, new String[] {"javac.test.classpath"})); // NOI18N
164
                    projectDirectory, evaluator, new String[] {JAVAC_TEST_CLASSPATH})); // NOI18N
158
            }
165
            }
159
            cache[2+type] = cp;
166
            cache[2+type] = cp;
160
        }
167
        }
Lines 177-188 Link Here
177
            if (type == 0) {
184
            if (type == 0) {
178
                cp = ClassPathFactory.createClassPath(
185
                cp = ClassPathFactory.createClassPath(
179
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
186
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
180
                    projectDirectory, evaluator, new String[] {"run.classpath"})); // NOI18N
187
                    projectDirectory, evaluator, new String[] {RUN_CLASSPATH})); // NOI18N
181
            }
188
            }
182
            else if (type == 1) {
189
            else if (type == 1) {
183
                cp = ClassPathFactory.createClassPath(
190
                cp = ClassPathFactory.createClassPath(
184
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
191
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
185
                    projectDirectory, evaluator, new String[] {"run.test.classpath"})); // NOI18N
192
                    projectDirectory, evaluator, new String[] {RUN_TEST_CLASSPATH})); // NOI18N
186
            }
193
            }
187
            else if (type == 2) {
194
            else if (type == 2) {
188
                //Only to make the CompiledDataNode hapy
195
                //Only to make the CompiledDataNode hapy
Lines 269-274 Link Here
269
276
270
    public synchronized void propertyChange(PropertyChangeEvent evt) {
277
    public synchronized void propertyChange(PropertyChangeEvent evt) {
271
        dirCache.remove(evt.getPropertyName());
278
        dirCache.remove(evt.getPropertyName());
279
    }
280
    
281
    public String getPropertyName (SourceGroup sg, String classPathId) {
282
        FileObject root = sg.getRootFolder();
283
        FileObject[] path = getPrimarySrcPath();
284
        for (int i=0; i<path.length; i++) {
285
            if (root.equals(path[i])) {
286
                if (ClassPath.COMPILE.equals(classPathId)) {
287
                    return JAVAC_CLASSPATH;
288
                }
289
                else if (ClassPath.EXECUTE.equals(classPathId)) {
290
                    return RUN_CLASSPATH;
291
                }
292
                else {
293
                    return null;
294
                }
295
            }
296
        }
297
        path = getTestSrcDir();
298
        for (int i=0; i<path.length; i++) {
299
            if (root.equals(path[i])) {
300
                if (ClassPath.COMPILE.equals(classPathId)) {
301
                    return JAVAC_TEST_CLASSPATH;
302
                }
303
                else if (ClassPath.EXECUTE.equals(classPathId)) {
304
                    return RUN_TEST_CLASSPATH;
305
                }
306
                else {
307
                    return null;
308
                }
309
            }
310
        }
311
        return null;
272
    }
312
    }
273
    
313
    
274
}
314
}
(-)j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathExtender.java (-114 / +11 lines)
Lines 39-63 Link Here
39
    
39
    
40
    private static final String CP_CLASS_PATH = "javac.classpath"; //NOI18N
40
    private static final String CP_CLASS_PATH = "javac.classpath"; //NOI18N
41
41
42
    private Project project;
42
    private final J2SEProjectClassPathModifier delegate;
43
    private UpdateHelper helper;
43
44
    private ReferenceHelper refHelper;
44
    public J2SEProjectClassPathExtender (final J2SEProjectClassPathModifier delegate) {
45
    private PropertyEvaluator eval;
45
        assert delegate != null;
46
    
46
        this.delegate = delegate;
47
    
48
    private ClassPathSupport cs;
49
50
    public J2SEProjectClassPathExtender (Project project, UpdateHelper helper, PropertyEvaluator eval, ReferenceHelper refHelper) {
51
        this.project = project;
52
        this.helper = helper;
53
        this.eval = eval;
54
        this.refHelper = refHelper;
55
        
56
        this.cs = new ClassPathSupport( eval, refHelper, helper.getAntProjectHelper(), 
57
                                        J2SEProjectProperties.WELL_KNOWN_PATHS, 
58
                                        J2SEProjectProperties.LIBRARY_PREFIX, 
59
                                        J2SEProjectProperties.LIBRARY_SUFFIX, 
60
                                        J2SEProjectProperties.ANT_ARTIFACT_PREFIX );        
61
    }
47
    }
62
48
63
    public boolean addLibrary(final Library library) throws IOException {
49
    public boolean addLibrary(final Library library) throws IOException {
Lines 65-141 Link Here
65
    }
51
    }
66
52
67
    public boolean addLibrary(final String classPathId, final Library library) throws IOException {
53
    public boolean addLibrary(final String classPathId, final Library library) throws IOException {
68
        assert library != null : "Parameter cannot be null";       //NOI18N
54
        return this.delegate.handleLibrary (library,classPathId, J2SEProjectClassPathModifier.ADD);
69
        try {
70
            return ((Boolean)ProjectManager.mutex().writeAccess(
71
                    new Mutex.ExceptionAction () {
72
                        public Object run() throws IOException {
73
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
74
                            String raw = props.getProperty(classPathId);
75
                            List resources = cs.itemsList( raw );
76
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( library, null );
77
                            if (!resources.contains(item)) {
78
                                resources.add (item);                                
79
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );                                
80
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);    //PathParser may change the EditableProperties                                
81
                                props.setProperty(classPathId, itemRefs);                                
82
                                String prop = cs.getLibraryReference( item );
83
                                prop = prop.substring(2, prop.length()-1); // XXX make a PropertyUtils method for this!
84
                                ClassPathSupport.relativizeLibraryClassPath(props, helper.getAntProjectHelper(), prop);                                
85
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
86
                                ProjectManager.getDefault().saveProject(project);
87
                                return Boolean.TRUE;
88
                            }
89
                            return Boolean.FALSE;
90
                        }
91
                    }
92
            )).booleanValue();
93
        } catch (MutexException e) {
94
            throw (IOException) e.getException();
95
        }
96
    }
55
    }
97
56
98
    public boolean addArchiveFile(final FileObject archiveFile) throws IOException {
57
    public boolean addArchiveFile(final FileObject archiveFile) throws IOException {
99
        return addArchiveFile(CP_CLASS_PATH,archiveFile);
58
        return addArchiveFile(CP_CLASS_PATH,archiveFile);
100
    }
59
    }
101
60
102
    public boolean addArchiveFile(final String classPathId, final FileObject archiveFile) throws IOException {
61
    public boolean addArchiveFile(final String classPathId, FileObject archiveFile) throws IOException {
103
        assert archiveFile != null : "Parameter cannot be null";       //NOI18N
62
        if (FileUtil.isArchiveFile(archiveFile)) {
104
        try {
63
            archiveFile = FileUtil.getArchiveRoot (archiveFile);
105
            return ((Boolean)ProjectManager.mutex().writeAccess(
106
                    new Mutex.ExceptionAction () {
107
                        public Object run() throws Exception {
108
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
109
                            String raw = props.getProperty(classPathId);                            
110
                            List resources = cs.itemsList( raw );                                                        
111
                            File f = FileUtil.toFile (archiveFile);
112
                            if (f == null ) {
113
                                throw new IllegalArgumentException ("The file must exist on disk");     //NOI18N
114
                            }
115
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( f, null );
116
117
                            if (!resources.contains(item)) {
118
                                resources.add (item);
119
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );
120
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);  //PathParser may change the EditableProperties
121
                                props.setProperty(classPathId, itemRefs);
122
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
123
                                ProjectManager.getDefault().saveProject(project);
124
                                return Boolean.TRUE;
125
                            }
126
                            return Boolean.FALSE;
127
                        }
128
                    }
129
            )).booleanValue();
130
        } catch (Exception e) {
131
            if (e instanceof IOException) {
132
                throw (IOException) e;
133
            }
134
            else {
135
                Exception t = new IOException ();
136
                throw (IOException) ErrorManager.getDefault().annotate(t,e);
137
            }
138
        }
64
        }
65
        return this.delegate.handleRoot(archiveFile.getURL(),classPathId,J2SEProjectClassPathModifier.ADD);
139
    }
66
    }
140
67
141
    public boolean addAntArtifact(final AntArtifact artifact, final URI artifactElement) throws IOException {
68
    public boolean addAntArtifact(final AntArtifact artifact, final URI artifactElement) throws IOException {
Lines 143-179 Link Here
143
    }
70
    }
144
71
145
    public boolean addAntArtifact(final String classPathId, final AntArtifact artifact, final URI artifactElement) throws IOException {
72
    public boolean addAntArtifact(final String classPathId, final AntArtifact artifact, final URI artifactElement) throws IOException {
146
        assert artifact != null : "Parameter cannot be null";       //NOI18N
73
        return this.delegate.handleAntArtifact(artifact, artifactElement,classPathId,J2SEProjectClassPathModifier.ADD);
147
        try {
148
            return ((Boolean)ProjectManager.mutex().writeAccess(
149
                    new Mutex.ExceptionAction () {
150
                        public Object run() throws Exception {
151
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
152
                            String raw = props.getProperty (classPathId);
153
                            List resources = cs.itemsList( raw );
154
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( artifact, artifactElement, null );                            
155
                            if (!resources.contains(item)) {
156
                                resources.add (item);
157
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );                                
158
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);    //Reread the properties, PathParser changes them
159
                                props.setProperty (classPathId, itemRefs);
160
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
161
                                ProjectManager.getDefault().saveProject(project);
162
                                return Boolean.TRUE;
163
                            }
164
                            return Boolean.FALSE;
165
                        }
166
                    }
167
            )).booleanValue();
168
        } catch (Exception e) {
169
            if (e instanceof IOException) {
170
                throw (IOException) e;
171
            }
172
            else {
173
                Exception t = new IOException ();
174
                throw (IOException) ErrorManager.getDefault().annotate(t,e);
175
            }
176
        }
177
    }
74
    }
178
75
179
}
76
}
(-)j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java (+241 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.java.j2seproject.classpath;
15
16
import java.io.File;
17
import java.io.IOException;
18
import java.net.URI;
19
import java.net.URL;
20
import java.util.List;
21
import org.netbeans.api.project.Project;
22
import org.netbeans.api.project.ProjectManager;
23
import org.netbeans.api.project.SourceGroup;
24
import org.netbeans.api.project.ant.AntArtifact;
25
import org.netbeans.api.project.libraries.Library;
26
import org.netbeans.modules.java.j2seproject.UpdateHelper;
27
import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties;
28
import org.netbeans.spi.java.project.classpath.ProjectClassPathModifier;
29
import org.netbeans.spi.project.support.ant.AntProjectHelper;
30
import org.netbeans.spi.project.support.ant.EditableProperties;
31
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
32
import org.netbeans.spi.project.support.ant.ReferenceHelper;
33
import org.openide.ErrorManager;
34
import org.openide.filesystems.FileObject;
35
import org.openide.filesystems.FileUtil;
36
import org.openide.util.Mutex;
37
import org.openide.util.MutexException;
38
39
/**
40
 *
41
 * @author Tomas Zezula
42
 */
43
public class J2SEProjectClassPathModifier implements ProjectClassPathModifier {
44
    
45
    static final int ADD = 1;
46
    static final int REMOVE = 2;
47
    
48
    private final Project project;
49
    private final UpdateHelper helper;
50
    private final ReferenceHelper refHelper;
51
    private final PropertyEvaluator eval;    
52
    private final ClassPathSupport cs;    
53
    
54
    /** Creates a new instance of J2SEProjectClassPathModifier */
55
    public J2SEProjectClassPathModifier(final Project project, final UpdateHelper helper, final PropertyEvaluator eval, final ReferenceHelper refHelper) {
56
        assert project != null;
57
        assert helper != null;
58
        assert eval != null;
59
        assert refHelper != null;
60
        this.project = project;
61
        this.helper = helper;
62
        this.eval = eval;
63
        this.refHelper = refHelper;        
64
        this.cs = new ClassPathSupport( eval, refHelper, helper.getAntProjectHelper(), 
65
                                        J2SEProjectProperties.WELL_KNOWN_PATHS, 
66
                                        J2SEProjectProperties.LIBRARY_PREFIX, 
67
                                        J2SEProjectProperties.LIBRARY_SUFFIX, 
68
                                        J2SEProjectProperties.ANT_ARTIFACT_PREFIX );
69
    }
70
71
    public boolean removeRoot(final URL classPathRoot, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {
72
        return handleRoot (classPathRoot, getClassPathProperty(sourceGroup, classPathId), REMOVE);
73
    }
74
75
    public boolean addRoot(final URL classPathRoot, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {        
76
        return handleRoot (classPathRoot, getClassPathProperty(sourceGroup, classPathId), ADD);
77
    }
78
    
79
    boolean handleRoot (final URL classPathRoot, final String classPathProperty, final int operation) throws IOException, UnsupportedOperationException {
80
        assert classPathRoot != null : "The classPathRoot cannot be null";      //NOI18N
81
        assert classPathRoot.toExternalForm().endsWith("/") : "The classPathRoot must be a folder"; //NOI18N
82
        assert classPathProperty != null;
83
        try {
84
            return ((Boolean)ProjectManager.mutex().writeAccess(
85
                    new Mutex.ExceptionAction () {
86
                        public Object run() throws Exception {
87
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
88
                            String raw = props.getProperty(classPathProperty);                            
89
                            List resources = cs.itemsList( raw );
90
                            URL toAdd = FileUtil.getArchiveFile(classPathRoot);
91
                            if (toAdd == null) {
92
                                toAdd = classPathRoot;
93
                            }
94
                            File f = FileUtil.normalizeFile( new File (URI.create(toAdd.toExternalForm())));
95
                            if (f == null ) {
96
                                throw new IllegalArgumentException ("The file must exist on disk");     //NOI18N
97
                            }
98
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( f, null );
99
                            boolean changed = false;
100
                            if (operation == ADD && !resources.contains(item)) {
101
                                resources.add (item);
102
                                changed = true;
103
                            }                            
104
                            else if (operation == REMOVE && resources.contains(item)) {
105
                                resources.remove(item);
106
                                changed = true;
107
                            }
108
                            if (changed) {
109
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );
110
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);  //PathParser may change the EditableProperties
111
                                props.setProperty(classPathProperty, itemRefs);
112
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
113
                                ProjectManager.getDefault().saveProject(project);
114
                                return Boolean.TRUE;
115
                            }
116
                            return Boolean.FALSE;
117
                        }
118
                    }
119
            )).booleanValue();
120
        } catch (Exception e) {
121
            if (e instanceof IOException) {
122
                throw (IOException) e;
123
            }
124
            else {
125
                Exception t = new IOException ();
126
                throw (IOException) ErrorManager.getDefault().annotate(t,e);
127
            }
128
        }
129
    }
130
131
    public boolean removeAntArtifact(final AntArtifact artifact, final URI artifactElement, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {
132
        return handleAntArtifact (artifact, artifactElement, getClassPathProperty(sourceGroup, classPathId), REMOVE);
133
    }
134
135
    public boolean addAntArtifact(final AntArtifact artifact, final URI artifactElement, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {
136
        return handleAntArtifact (artifact, artifactElement, getClassPathProperty(sourceGroup, classPathId), ADD);
137
    }
138
    
139
    boolean handleAntArtifact (final AntArtifact artifact, final URI artifactElement, final String classPathProperty, final int operation) throws IOException, UnsupportedOperationException {
140
        assert artifact != null : "Artifact cannot be null";    //NOI18N
141
        assert artifactElement != null : "ArtifactElement cannot be null";  //NOI18N
142
        assert classPathProperty != null;
143
        try {
144
            return ((Boolean)ProjectManager.mutex().writeAccess(
145
                    new Mutex.ExceptionAction () {
146
                        public Object run() throws Exception {
147
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
148
                            String raw = props.getProperty (classPathProperty);
149
                            List resources = cs.itemsList( raw );
150
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( artifact, artifactElement, null );
151
                            boolean changed = false;                            
152
                            if (operation == ADD && !resources.contains(item)) {
153
                                resources.add (item);
154
                                changed = true;
155
                            }
156
                            else if (operation == REMOVE && resources.contains(item)) {
157
                                resources.remove(item);
158
                                changed = true;
159
                            }
160
                            if (changed) {
161
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );                                
162
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);    //Reread the properties, PathParser changes them
163
                                props.setProperty (classPathProperty, itemRefs);
164
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
165
                                ProjectManager.getDefault().saveProject(project);
166
                                return Boolean.TRUE;
167
                            }
168
                            return Boolean.FALSE;
169
                        }
170
                    }
171
            )).booleanValue();
172
        } catch (Exception e) {
173
            if (e instanceof IOException) {
174
                throw (IOException) e;
175
            }
176
            else {
177
                Exception t = new IOException ();
178
                throw (IOException) ErrorManager.getDefault().annotate(t,e);
179
            }
180
        }
181
    }
182
    
183
    
184
    public boolean removeLibrary(final Library library, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {
185
        return handleLibrary (library, getClassPathProperty(sourceGroup, classPathId), REMOVE);
186
    }
187
188
    public boolean addLibrary(final Library library, final SourceGroup sourceGroup, final String classPathId) throws IOException, UnsupportedOperationException {
189
        return handleLibrary (library, getClassPathProperty(sourceGroup, classPathId), ADD);
190
    }
191
    
192
    boolean handleLibrary (final Library library, final String classPathProperty, final int operation) throws IOException, UnsupportedOperationException {
193
        assert library != null : "Library cannot be null";  //NOI18N
194
        assert classPathProperty != null;
195
        try {
196
            return ((Boolean)ProjectManager.mutex().writeAccess(
197
                    new Mutex.ExceptionAction () {
198
                        public Object run() throws IOException {
199
                            EditableProperties props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);
200
                            String raw = props.getProperty(classPathProperty);
201
                            List resources = cs.itemsList( raw );
202
                            ClassPathSupport.Item item = ClassPathSupport.Item.create( library, null );
203
                            boolean changed = false;
204
                            if (operation == ADD && !resources.contains(item)) {
205
                                resources.add (item);                                
206
                                changed = true;
207
                            }
208
                            else if (operation == REMOVE && resources.contains(item)) {
209
                                resources.remove(item);
210
                                changed = true;
211
                            }                            
212
                            if (changed) {
213
                                String itemRefs[] = cs.encodeToStrings( resources.iterator() );                                
214
                                props = helper.getProperties (AntProjectHelper.PROJECT_PROPERTIES_PATH);    //PathParser may change the EditableProperties                                
215
                                props.setProperty(classPathProperty, itemRefs);                                
216
                                String prop = cs.getLibraryReference( item );
217
                                prop = prop.substring(2, prop.length()-1); // XXX make a PropertyUtils method for this!
218
                                ClassPathSupport.relativizeLibraryClassPath(props, helper.getAntProjectHelper(), prop);                                
219
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
220
                                ProjectManager.getDefault().saveProject(project);
221
                                return Boolean.TRUE;
222
                            }
223
                            return Boolean.FALSE;
224
                        }
225
                    }
226
            )).booleanValue();
227
        } catch (MutexException e) {
228
            throw (IOException) e.getException();
229
        }
230
    }
231
    
232
    private String getClassPathProperty (final SourceGroup sg, final String classPathId) throws UnsupportedOperationException {
233
        assert sg != null : "SourceGroup cannot be null";  //NOI18N
234
        assert classPathId != null : "ClassPathId cannot be null";  //NOI18N
235
        final String classPathProperty = ((ClassPathProviderImpl)project.getLookup().lookup(ClassPathProviderImpl.class)).getPropertyName (sg, classPathId);
236
        if (classPathProperty == null) {
237
            throw new UnsupportedOperationException ("Modification of [" + sg.getRootFolder().getPath() +", " + classPathId + "] is not supported"); //NOI8N
238
        }
239
        return classPathProperty;
240
    }
241
}
(-)j2seproject/test/unit/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifierTest.java (+360 lines)
Added Link Here
1
/*
2
 * J2SEProjectClassPathModifierTest.java
3
 * JUnit based test
4
 *
5
 * Created on May 2, 2006, 9:45 PM
6
 */
7
8
package org.netbeans.modules.java.j2seproject.classpath;
9
10
import java.beans.Customizer;
11
import java.beans.PropertyChangeListener;
12
import java.io.OutputStream;
13
import java.net.URL;
14
import java.util.Arrays;
15
import java.util.Collections;
16
import java.util.jar.JarFile;
17
import java.util.jar.JarOutputStream;
18
import java.util.zip.ZipEntry;
19
import java.util.zip.ZipOutputStream;
20
import junit.framework.*;
21
import java.io.File;
22
import java.io.IOException;
23
import java.net.URI;
24
import java.util.List;
25
import org.netbeans.api.java.classpath.ClassPath;
26
import org.netbeans.api.java.project.JavaProjectConstants;
27
import org.netbeans.api.project.FileOwnerQuery;
28
import org.netbeans.api.project.Project;
29
import org.netbeans.api.project.ProjectManager;
30
import org.netbeans.api.project.SourceGroup;
31
import org.netbeans.api.project.Sources;
32
import org.netbeans.api.project.TestUtil;
33
import org.netbeans.api.project.ant.AntArtifact;
34
import org.netbeans.api.project.libraries.Library;
35
import org.netbeans.api.project.libraries.LibraryManager;
36
import org.netbeans.junit.NbTestCase;
37
import org.netbeans.modules.java.j2seproject.J2SEProjectGenerator;
38
import org.netbeans.modules.java.j2seproject.UpdateHelper;
39
import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties;
40
import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
41
import org.netbeans.spi.java.project.classpath.ProjectClassPathModifier;
42
import org.netbeans.spi.project.ant.AntArtifactProvider;
43
import org.netbeans.spi.project.libraries.LibraryImplementation;
44
import org.netbeans.spi.project.libraries.LibraryProvider;
45
import org.netbeans.spi.project.libraries.LibraryTypeProvider;
46
import org.netbeans.spi.project.support.ant.AntProjectHelper;
47
import org.netbeans.spi.project.support.ant.EditableProperties;
48
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
49
import org.netbeans.spi.project.support.ant.PropertyUtils;
50
import org.netbeans.spi.project.support.ant.ReferenceHelper;
51
import org.openide.ErrorManager;
52
import org.openide.filesystems.FileLock;
53
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileUtil;
55
import org.openide.modules.SpecificationVersion;
56
import org.openide.util.Lookup;
57
import org.openide.util.Mutex;
58
import org.openide.util.MutexException;
59
60
/**
61
 *
62
 * @author tom
63
 */
64
public class J2SEProjectClassPathModifierTest extends NbTestCase {
65
    
66
    private FileObject scratch;
67
    private AntProjectHelper helper;
68
    private PropertyEvaluator eval;
69
    private Project prj;
70
    
71
    public J2SEProjectClassPathModifierTest(String testName) {
72
        super(testName);
73
    }       
74
    
75
    protected void setUp() throws Exception {
76
        super.setUp();
77
        TestUtil.setLookup(new Object[] {
78
            new org.netbeans.modules.java.j2seproject.J2SEProjectType(),
79
            new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation(),
80
            new TestLibraryProvider (),
81
        });
82
        this.scratch = TestUtil.makeScratchDir(this);
83
        FileObject projdir = scratch.createFolder("proj");  //NOI18N
84
        J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4"));   //NOI18N    
85
        this.helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"proj",null,null); //NOI18N
86
        this.eval = this.helper.getStandardPropertyEvaluator();
87
        J2SEProjectGenerator.setDefaultSourceLevel(null);
88
        this.prj = FileOwnerQuery.getOwner(projdir);
89
        assertNotNull (this.prj);
90
    }
91
92
    protected void tearDown() throws Exception {
93
    }
94
    
95
    public void testAddRemoveRoot () throws Exception {        
96
        final FileObject rootFolder = this.scratch.createFolder("Root");
97
        final FileObject jarFile = this.scratch.createData("archive","jar");
98
        FileLock lck = jarFile.lock();
99
        try {
100
            ZipOutputStream jf = new ZipOutputStream (jarFile.getOutputStream(lck));            
101
            try {
102
                jf.putNextEntry(new ZipEntry("Test.properties"));
103
            }finally {
104
                jf.close();
105
            }
106
        } finally {
107
            lck.releaseLock();
108
        }
109
        final FileObject jarRoot = FileUtil.getArchiveRoot(jarFile);
110
        ProjectClassPathModifier modifier = (ProjectClassPathModifier) this.prj.getLookup().lookup(ProjectClassPathModifier.class);
111
        assertNotNull (modifier);
112
        Sources sources = (Sources) this.prj.getLookup().lookup(Sources.class);
113
        assertNotNull (sources);
114
        SourceGroup[] sgs = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
115
        assertNotNull (sgs);
116
        assertEquals(2,sgs.length);
117
        SourceGroup srcSg=null, testSg = null;
118
        for (int i=0; i<sgs.length; i++) {
119
            if ("src".equals(sgs[i].getRootFolder().getName())) {
120
                srcSg = sgs[i];
121
            }
122
            if ("test".equals(sgs[i].getRootFolder().getName())) {
123
                testSg = sgs[i];
124
            }
125
        }
126
        assertNotNull (srcSg);
127
        assertNotNull (testSg);
128
        modifier.addRoot (rootFolder.getURL(),srcSg,ClassPath.COMPILE);
129
        String cp = this.eval.getProperty("javac.classpath");
130
        assertNotNull (cp);
131
        String[] cpRoots = PropertyUtils.tokenizePath (cp);
132
        assertNotNull (cpRoots);
133
        assertEquals(1,cpRoots.length);
134
        assertEquals(rootFolder,this.helper.resolveFileObject(cpRoots[0]));
135
        modifier.removeRoot (rootFolder.getURL(),srcSg,ClassPath.COMPILE);
136
        cp = this.eval.getProperty("javac.classpath");
137
        assertNotNull (cp);
138
        cpRoots = PropertyUtils.tokenizePath (cp);
139
        assertNotNull (cpRoots);
140
        assertEquals(0,cpRoots.length);
141
        modifier.addRoot(jarRoot.getURL(),testSg,ClassPath.EXECUTE);
142
        cp = this.eval.getProperty("run.test.classpath");
143
        assertNotNull (cp);
144
        cpRoots = PropertyUtils.tokenizePath (cp);
145
        assertNotNull (cpRoots);
146
        assertEquals(4,cpRoots.length);
147
        assertEquals(this.helper.resolveFileObject(cpRoots[3]),jarFile);
148
    }
149
    
150
    public void testAddRemoveArtifact () throws Exception {
151
        FileObject projdir = scratch.createFolder("libPrj");  //NOI18N
152
        J2SEProjectGenerator.setDefaultSourceLevel(new SpecificationVersion ("1.4"));   //NOI18N    
153
        AntProjectHelper helper = J2SEProjectGenerator.createProject(FileUtil.toFile(projdir),"libProj",null,null); //NOI18N        
154
        J2SEProjectGenerator.setDefaultSourceLevel(null);
155
        Project libPrj = FileOwnerQuery.getOwner(projdir);
156
        assertNotNull (this.prj);
157
        AntArtifactProvider ap = (AntArtifactProvider) libPrj.getLookup().lookup(AntArtifactProvider.class);
158
        AntArtifact[] aas = ap.getBuildArtifacts();
159
        AntArtifact output = null;
160
        for (int i=0; i<aas.length; i++) {
161
            if (JavaProjectConstants.ARTIFACT_TYPE_JAR.equals(aas[i].getType())) {
162
                output = aas[i];
163
                break;
164
            }
165
        }
166
        assertNotNull (output);        
167
        ProjectClassPathModifier modifier = (ProjectClassPathModifier) this.prj.getLookup().lookup(ProjectClassPathModifier.class);
168
        assertNotNull (modifier);
169
        Sources sources = (Sources) this.prj.getLookup().lookup(Sources.class);
170
        assertNotNull (sources);
171
        SourceGroup[] sgs = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
172
        assertNotNull (sgs);
173
        assertEquals(2,sgs.length);
174
        SourceGroup srcSg=null;
175
        for (int i=0; i<sgs.length; i++) {
176
            if ("src".equals(sgs[i].getRootFolder().getName())) {
177
                srcSg = sgs[i];
178
                break;
179
            }
180
        }
181
        assertNotNull (srcSg);
182
        modifier.addAntArtifact(output,output.getArtifactLocations()[0],srcSg,ClassPath.COMPILE);
183
        String cp = this.eval.getProperty("javac.classpath");
184
        assertNotNull (cp);
185
        String[] cpRoots = PropertyUtils.tokenizePath (cp);
186
        assertNotNull (cpRoots);
187
        assertEquals(1,cpRoots.length);
188
        URI projectURI = URI.create(output.getProject().getProjectDirectory().getURL().toExternalForm());
189
        URI expected = projectURI.resolve(output.getArtifactLocations()[0]);
190
        assertEquals(expected,this.helper.resolveFile(cpRoots[0]).toURI());
191
        modifier.removeAntArtifact(output,output.getArtifactLocations()[0],srcSg,ClassPath.COMPILE);
192
        cp = this.eval.getProperty("javac.classpath");
193
        assertNotNull (cp);
194
        cpRoots = PropertyUtils.tokenizePath (cp);
195
        assertNotNull (cpRoots);
196
        assertEquals(0,cpRoots.length);
197
    }
198
    
199
    public void testAddRemoveLibrary () throws Exception {
200
        LibraryProvider lp = (LibraryProvider) Lookup.getDefault().lookup(LibraryProvider.class);
201
        assertNotNull (lp);
202
        LibraryImplementation[] impls = lp.getLibraries();
203
        assertNotNull (impls);
204
        assertEquals(1,impls.length);
205
        FileObject libRoot = this.scratch.createFolder("libRoot");
206
        impls[0].setContent("classpath",Collections.singletonList(libRoot.getURL()));
207
        Library[] libs =LibraryManager.getDefault().getLibraries();
208
        assertNotNull (libs);
209
        assertEquals(1,libs.length);        
210
        ProjectClassPathModifier modifier = (ProjectClassPathModifier) this.prj.getLookup().lookup(ProjectClassPathModifier.class);
211
        assertNotNull (modifier);
212
        Sources sources = (Sources) this.prj.getLookup().lookup(Sources.class);
213
        assertNotNull (sources);
214
        SourceGroup[] sgs = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
215
        assertNotNull (sgs);
216
        assertEquals(2,sgs.length);
217
        SourceGroup srcSg=null;
218
        for (int i=0; i<sgs.length; i++) {
219
            if ("src".equals(sgs[i].getRootFolder().getName())) {
220
                srcSg = sgs[i];
221
                break;
222
            }
223
        }
224
        assertNotNull (srcSg);
225
        modifier.addLibrary(libs[0],srcSg,ClassPath.COMPILE);
226
        String cp = this.eval.getProperty("javac.classpath");
227
        assertNotNull (cp);
228
        String[] cpRoots = PropertyUtils.tokenizePath (cp);
229
        assertNotNull (cpRoots);
230
        assertEquals(1,cpRoots.length);
231
        assertEquals("${libs.Test.classpath}",cpRoots[0]);    //There is no build.properties filled, the libraries are not resolved
232
        modifier.removeLibrary(libs[0],srcSg,ClassPath.COMPILE);
233
        cp = this.eval.getProperty("javac.classpath");
234
        assertNotNull (cp);
235
        cpRoots = PropertyUtils.tokenizePath (cp);
236
        assertNotNull (cpRoots);
237
        assertEquals(0,cpRoots.length);
238
    }
239
    
240
    public void testClassPathExtenderCompatibility () throws Exception {
241
        final FileObject rootFolder = this.scratch.createFolder("Root");
242
        final FileObject jarFile = this.scratch.createData("archive","jar");
243
        FileLock lck = jarFile.lock();
244
        try {
245
            ZipOutputStream jf = new ZipOutputStream (jarFile.getOutputStream(lck));            
246
            try {
247
                jf.putNextEntry(new ZipEntry("Test.properties"));
248
            }finally {
249
                jf.close();
250
            }
251
        } finally {
252
            lck.releaseLock();
253
        }
254
        final FileObject jarRoot = FileUtil.getArchiveRoot(jarFile);
255
        ProjectClassPathExtender extender = (ProjectClassPathExtender) this.prj.getLookup().lookup(ProjectClassPathExtender.class);
256
        assertNotNull (extender);
257
        extender.addArchiveFile(rootFolder);
258
        extender.addArchiveFile(jarFile);
259
        String cp = this.eval.getProperty("javac.classpath");
260
        assertNotNull (cp);
261
        String[] cpRoots = PropertyUtils.tokenizePath (cp);
262
        assertNotNull (cpRoots);
263
        assertEquals(2,cpRoots.length);
264
        assertEquals(rootFolder,this.helper.resolveFileObject(cpRoots[0]));
265
        assertEquals(jarFile,this.helper.resolveFileObject(cpRoots[1]));
266
    }
267
    
268
    
269
    private static class TestLibraryProvider implements LibraryProvider {
270
        
271
        private LibraryImplementation[] libs;
272
        
273
        public void removePropertyChangeListener(PropertyChangeListener listener) {
274
        }
275
276
        public void addPropertyChangeListener(PropertyChangeListener listener) {
277
        }
278
279
        public LibraryImplementation[] getLibraries() {
280
            if (libs == null) {
281
                this.libs = new LibraryImplementation[] { new TestLibrary ("Test")};
282
            }
283
            return this.libs;
284
        }
285
        
286
    }    
287
    
288
    private static class TestLibrary implements LibraryImplementation {
289
        
290
        private String name;
291
        private List cp = Collections.EMPTY_LIST;
292
        private List src = Collections.EMPTY_LIST;
293
        private List jdoc = Collections.EMPTY_LIST;
294
        
295
        public TestLibrary (String name) {
296
            this.name = name;
297
        }
298
        
299
        public void setName(String name) {
300
        }
301
302
        public void setLocalizingBundle(String resourceName) {
303
        }
304
305
        public void setDescription(String text) {
306
        }
307
308
        public List getContent(String volumeType) throws IllegalArgumentException {
309
            if ("classpath".equals(volumeType)) {
310
                return this.cp; 
311
            }
312
            else if ("src".equals(volumeType)) {
313
                return this.src;
314
            }
315
            else if ("jdoc".equals(volumeType)) {
316
                return this.jdoc;
317
            }
318
            throw new IllegalArgumentException ();
319
        }
320
321
        public void removePropertyChangeListener(PropertyChangeListener l) {
322
        }
323
324
        public void addPropertyChangeListener(PropertyChangeListener l) {
325
        }
326
327
        public void setContent(String volumeType, List path) throws IllegalArgumentException {
328
            if ("classpath".equals(volumeType)) {
329
                this.cp = path;
330
            }
331
            else if ("src".equals(volumeType)) {
332
                this.src = path;
333
            }
334
            else if ("jdoc".equals(volumeType)) {
335
                this.jdoc = path;
336
            }
337
            else {
338
                throw new IllegalArgumentException ();
339
            }
340
        }
341
342
        public String getType() {
343
            return "j2se";
344
        }
345
346
        public String getName() {
347
            return this.name;
348
        }
349
350
        public String getLocalizingBundle() {
351
            return null;
352
        }
353
354
        public String getDescription() {
355
            return null;
356
        }
357
        
358
    }
359
    
360
}
(-)project/apichanges.xml (+18 lines)
Lines 77-82 Link Here
77
    <!-- ACTUAL CHANGES BEGIN HERE: -->
77
    <!-- ACTUAL CHANGES BEGIN HERE: -->
78
78
79
    <changes>
79
    <changes>
80
    <change id="ProjectClassPathModifier">
81
        <api name="classpath"/>
82
        <summary>New ProjectClassPathModifier SPI for modification of project's classpath</summary>
83
        <version major="1" minor="10"/>
84
        <date day="3" month="5" year="2006"/>
85
        <author login="tzezula"/>
86
        <compatibility addition="yes"/>
87
        <description>
88
        The new SPI interface ProjectClassPathModifier was created to allow extension modules to
89
        add or remove classpath elements (archive files, folders, libraries, subprojects) from the
90
        project's classpath.
91
        </description>
92
        <class package="org.netbeans.spi.java.project.classpath" name="ProjectClassPathModifier"/>
93
         <issue number="74356"/>
94
         <issue number="75469"/>
95
         <issue number="60852"/>
96
    </change>
97
                                                                                                                                
80
    <change id="BrokenReferencesModel.updateReference">
98
    <change id="BrokenReferencesModel.updateReference">
81
        <api name="general"/>
99
        <api name="general"/>
82
        <summary>Semantic changes in the BrokenReferencesModel.updateReference behavior</summary>
100
        <summary>Semantic changes in the BrokenReferencesModel.updateReference behavior</summary>
(-)project/manifest.mf (-1 / +1 lines)
Lines 2-7 Link Here
2
OpenIDE-Module: org.netbeans.modules.java.project/1
2
OpenIDE-Module: org.netbeans.modules.java.project/1
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.9
5
OpenIDE-Module-Specification-Version: 1.10
6
OpenIDE-Module-Requires: org.netbeans.modules.project.uiapi.ActionsFactory
6
OpenIDE-Module-Requires: org.netbeans.modules.project.uiapi.ActionsFactory
7
7
(-)project/nbproject/project.properties (+1 lines)
Lines 11-16 Link Here
11
11
12
is.autoload=true
12
is.autoload=true
13
13
14
javac.source=1.5
14
javadoc.title=Java Project API
15
javadoc.title=Java Project API
15
javadoc.overview=${basedir}/overview.html
16
javadoc.overview=${basedir}/overview.html
16
javadoc.arch=${basedir}/arch.xml
17
javadoc.arch=${basedir}/arch.xml
(-)project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathExtender.java (-2 / +6 lines)
Lines 24-32 Link Here
24
 * A project can provide this interface in its {@link org.netbeans.api.project.Project#getLookup lookup} to
24
 * A project can provide this interface in its {@link org.netbeans.api.project.Project#getLookup lookup} to
25
 * allow clients to extend its compilation classpath
25
 * allow clients to extend its compilation classpath
26
 * by a new classpath element (JAR, folder, dependent project, or library).
26
 * by a new classpath element (JAR, folder, dependent project, or library).
27
 * @since org.netbeans.modules.java.project/1 1.3 
27
 * @since org.netbeans.modules.java.project/1 1.3
28
 * @deprecated Please use the {@link ProjectClassPathModifier} instead.
28
 */
29
 */
29
public interface ProjectClassPathExtender {
30
public @Deprecated interface ProjectClassPathExtender {
30
31
31
    /**
32
    /**
32
     * Adds a library into the project's compile classpath if the
33
     * Adds a library into the project's compile classpath if the
Lines 34-39 Link Here
34
     * @param library to be added
35
     * @param library to be added
35
     * @return true in case the classpath was changed
36
     * @return true in case the classpath was changed
36
     * @exception IOException in case the project metadata cannot be changed
37
     * @exception IOException in case the project metadata cannot be changed
38
     * @deprecated Please use {@link ProjectClassPathModifier#addLibrary} instead.
37
     */
39
     */
38
    boolean addLibrary(Library library) throws IOException;
40
    boolean addLibrary(Library library) throws IOException;
39
41
Lines 43-48 Link Here
43
     * @param archiveFile ZIP/JAR file to be added
45
     * @param archiveFile ZIP/JAR file to be added
44
     * @return true in case the classpath was changed
46
     * @return true in case the classpath was changed
45
     * @exception IOException in case the project metadata cannot be changed
47
     * @exception IOException in case the project metadata cannot be changed
48
     * @deprecated Please use {@link ProjectClassPathModifier#addArchive} instead.
46
     */
49
     */
47
    boolean addArchiveFile(FileObject archiveFile) throws IOException;
50
    boolean addArchiveFile(FileObject archiveFile) throws IOException;
48
51
Lines 54-59 Link Here
54
     *                        (must be owned by the artifact and be relative to it)
57
     *                        (must be owned by the artifact and be relative to it)
55
     * @return true in case the classpath was changed
58
     * @return true in case the classpath was changed
56
     * @exception IOException in case the project metadata cannot be changed
59
     * @exception IOException in case the project metadata cannot be changed
60
     * @deprecated Please use {@link ProjectClassPathModifier#addAntArtifact} instead.
57
     */
61
     */
58
    boolean addAntArtifact(AntArtifact artifact, URI artifactElement) throws IOException;
62
    boolean addAntArtifact(AntArtifact artifact, URI artifactElement) throws IOException;
59
63
(-)project/src/org/netbeans/spi/java/project/classpath/ProjectClassPathModifier.java (+128 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.java.project.classpath;
15
16
import java.io.IOException;
17
import java.net.URI;
18
import java.net.URL;
19
import org.netbeans.api.project.SourceGroup;
20
import org.netbeans.api.project.ant.AntArtifact;
21
import org.netbeans.api.project.libraries.Library;
22
import org.openide.filesystems.FileObject;
23
24
/**
25
 * Interface for project's classpaths modification.
26
 * A project can provide this interface in its {@link org.netbeans.api.project.Project#getLookup lookup} to
27
 * allow clients to add or remove new classpath elements (JAR, folder, dependent project, or library) to its 
28
 * classpaths.
29
 * @since org.netbeans.modules.java.project/1 1.10
30
 */
31
public interface ProjectClassPathModifier {
32
    
33
    /**
34
     * Adds a library into the project's classpath if the
35
     * library is not already included.
36
     * @param library to be added
37
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
38
     * identifying the compilation unit to change
39
     * @param classPathId the id of the classpath the library should be added to,
40
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
41
     * @return true in case the classpath was changed
42
     * @exception IOException in case the project metadata cannot be changed
43
     * @exception UnsupportedOperationException is thrown when the project does not support
44
     * adding of a library to the classpath of the given id.
45
     */
46
    boolean addLibrary (Library library, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
47
    
48
    
49
    /**
50
     * Removes a library from the project's classpath if the
51
     * library is included on it.
52
     * @param library to be removed
53
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
54
     * identifying the compilation unit to change
55
     * @param classPathId the id of the classpath the library should be removed from,
56
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
57
     * @return true in case the classpath was changed
58
     * @exception IOException in case the project metadata cannot be changed
59
     * @exception UnsupportedOperationException is thrown when the project does not support
60
     * removing of a library from the classpath of the given id.
61
     */
62
    boolean removeLibrary (Library library, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
63
    
64
    /**
65
     * Adds an archive file or folder into the project's classpath if the
66
     * entry is not already there.
67
     * @param classPathRoot root to be added, either root of an archive or folder
68
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
69
     * identifying the compilation unit to change
70
     * @param classPathId the id of the classpath the root should be added to,
71
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
72
     * @return true in case the classpath was changed
73
     * @exception IOException in case the project metadata cannot be changed
74
     * @exception UnsupportedOperationException is thrown when the project does not support
75
     * adding of a root to the classpath of the given id.
76
     */
77
    boolean addRoot (URL classPathRoot, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
78
    
79
    /**
80
     * Removes an archive file or folder from the project's classpath if the
81
     * entry is included on it.
82
     * @param classPathRoot root to be removed, either root of an archive or folder
83
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
84
     * identifying the compilation unit to change
85
     * @param classPathId the id of the classpath the root should be removed from,
86
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
87
     * @return true in case the classpath was changed
88
     * @exception IOException in case the project metadata cannot be changed
89
     * @exception UnsupportedOperationException is thrown when the project does not support
90
     * removing of a root from the classpath of the given id.
91
     */
92
    boolean removeRoot (URL classPathRoot, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
93
    
94
    /**
95
     * Adds an artifact (e.g. subproject) into project's classpath if the
96
     * artifact is not already on it.
97
     * @param artifact to be added
98
     * @param artifactElement the URI of the build output
99
     * (must be owned by the artifact and be relative to it)
100
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
101
     * identifying the compilation unit to change
102
     * @param classPathId the id of the classpath the artifact should be added to,
103
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
104
     * @return true in case the classpath was changed
105
     * @exception IOException in case the project metadata cannot be changed
106
     * @exception UnsupportedOperationException is thrown when the project does not support
107
     * adding of an artifact to the classpath of the given id.
108
     */
109
    boolean addAntArtifact (AntArtifact artifact, URI artifactElement, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
110
    
111
    /**
112
     * Removes an artifact (e.g. subproject) from project's classpath if the
113
     * artifact is not already on it.
114
     * @param artifact to be added
115
     * @param artifactElement the URI of the build output
116
     * (must be owned by the artifact and be relative to it)
117
     * @param sourceGroup of type {@link org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA}
118
     * identifying the compilation unit to change
119
     * @param classPathId the id of the classpath the artifact should be removed from,
120
     * eg {@link org.netbeans.api.java.classpath.ClassPath.COMPILE}
121
     * @return true in case the classpath was changed
122
     * @exception IOException in case the project metadata cannot be changed
123
     * @exception UnsupportedOperationException is thrown when the project does not support
124
     * removing of an artifact from the classpath of the given id.
125
     */
126
    boolean removeAntArtifact (AntArtifact artifact, URI artifactElement, SourceGroup sourceGroup, String classPathId) throws IOException, UnsupportedOperationException;
127
128
}

Return to bug 75471