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

(-)j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathProviderImpl.java (-5 / +11 lines)
Lines 20-25 Link Here
20
import org.netbeans.api.java.classpath.ClassPath;
20
import org.netbeans.api.java.classpath.ClassPath;
21
import org.netbeans.spi.java.classpath.ClassPathFactory;
21
import org.netbeans.spi.java.classpath.ClassPathFactory;
22
import org.netbeans.spi.java.classpath.ClassPathProvider;
22
import org.netbeans.spi.java.classpath.ClassPathProvider;
23
import org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport;
23
import org.netbeans.spi.project.support.ant.AntProjectHelper;
24
import org.netbeans.spi.project.support.ant.AntProjectHelper;
24
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
25
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
25
import org.netbeans.modules.java.j2seproject.SourceRoots;
26
import org.netbeans.modules.java.j2seproject.SourceRoots;
Lines 143-153 Link Here
143
        if ( cp == null) {
144
        if ( cp == null) {
144
            if (type == 0) {
145
            if (type == 0) {
145
                cp = ClassPathFactory.createClassPath(
146
                cp = ClassPathFactory.createClassPath(
146
                new ProjectClassPathImplementation(helper, "javac.classpath", evaluator)); // NOI18N
147
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
148
                    helper, evaluator, new String[] {"javac.classpath"})); // NOI18N
147
            }
149
            }
148
            else {
150
            else {
149
                cp = ClassPathFactory.createClassPath(
151
                cp = ClassPathFactory.createClassPath(
150
                new ProjectClassPathImplementation(helper, "javac.test.classpath", evaluator)); // NOI18N
152
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
153
                    helper, evaluator, new String[] {"javac.test.classpath"})); // NOI18N
151
            }
154
            }
152
            cache[2+type] = cp;
155
            cache[2+type] = cp;
153
        }
156
        }
Lines 169-185 Link Here
169
        if ( cp == null) {
172
        if ( cp == null) {
170
            if (type == 0) {
173
            if (type == 0) {
171
                cp = ClassPathFactory.createClassPath(
174
                cp = ClassPathFactory.createClassPath(
172
                new ProjectClassPathImplementation(helper, "run.classpath", evaluator)); // NOI18N
175
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
176
                    helper, evaluator, new String[] {"run.classpath"})); // NOI18N
173
            }
177
            }
174
            else if (type == 1) {
178
            else if (type == 1) {
175
                cp = ClassPathFactory.createClassPath(
179
                cp = ClassPathFactory.createClassPath(
176
                new ProjectClassPathImplementation(helper, "run.test.classpath", evaluator)); // NOI18N
180
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
181
                    helper, evaluator, new String[] {"run.test.classpath"})); // NOI18N
177
            }
182
            }
178
            else if (type == 2) {
183
            else if (type == 2) {
179
                //Only to make the CompiledDataNode hapy
184
                //Only to make the CompiledDataNode hapy
180
                //Todo: Strictly it should return ${run.classpath} - ${build.classes.dir} + ${dist.jar}
185
                //Todo: Strictly it should return ${run.classpath} - ${build.classes.dir} + ${dist.jar}
181
                cp = ClassPathFactory.createClassPath(
186
                cp = ClassPathFactory.createClassPath(
182
                new ProjectClassPathImplementation(helper, DIST_JAR, evaluator)); // NOI18N
187
                    ProjectClassPathSupport.createPropertyBasedClassPathImplementation(
188
                    helper, evaluator, new String[] {DIST_JAR})); // NOI18N
183
            }
189
            }
184
            cache[4+type] = cp;
190
            cache[4+type] = cp;
185
        }
191
        }
(-)j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ProjectClassPathImplementation.java (-132 lines)
Removed 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-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.java.j2seproject.classpath;
15
16
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyChangeSupport;
19
import java.io.File;
20
import java.net.MalformedURLException;
21
import java.net.URL;
22
import java.util.ArrayList;
23
import java.util.Collections;
24
import java.util.List;
25
import org.netbeans.api.project.ProjectManager;
26
import org.netbeans.spi.java.classpath.ClassPathImplementation;
27
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
28
import org.netbeans.spi.project.support.ant.AntProjectHelper;
29
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
30
import org.netbeans.spi.project.support.ant.PropertyUtils;
31
import org.openide.filesystems.FileUtil;
32
import org.openide.util.WeakListeners;
33
34
// XXX needs unit test!
35
36
/**
37
 * Implementation of a single classpath that is derived from one Ant property.
38
 */
39
final class ProjectClassPathImplementation implements ClassPathImplementation, PropertyChangeListener, Runnable {
40
    
41
    private PropertyChangeSupport support = new PropertyChangeSupport(this);
42
    private AntProjectHelper helper;
43
    private String propertyName;
44
    private List resources;
45
    private final PropertyEvaluator evaluator;
46
    private boolean dirty = false;
47
48
    /**
49
     * Construct the implementation.
50
     * @param helper an Ant project, used to resolve file paths
51
     * @param propertyName the name of an Ant property which will supply the classpath
52
     * @param evaluator a property evaluator used to find the value of the classpath
53
     */
54
    public ProjectClassPathImplementation(AntProjectHelper helper, String propertyName, PropertyEvaluator evaluator) {
55
        assert helper != null && propertyName != null;
56
        this.helper = helper;
57
        this.evaluator = evaluator;
58
        this.propertyName = propertyName;
59
        evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator));
60
    }
61
62
    public synchronized List /*<PathResourceImplementation>*/ getResources() {
63
        if (this.resources == null) {
64
            this.resources = this.getPath ();
65
        }
66
        return this.resources;
67
    }
68
69
    public void addPropertyChangeListener(PropertyChangeListener listener) {
70
        support.addPropertyChangeListener (listener);
71
    }
72
73
    public void removePropertyChangeListener(PropertyChangeListener listener) {
74
        support.removePropertyChangeListener (listener);
75
    }
76
77
78
    public void propertyChange(PropertyChangeEvent evt) {
79
        if (!evt.getPropertyName().equals(propertyName)) {
80
            // Not interesting to us.
81
            return;
82
        }
83
        // Coalesce changes; can come in fast after huge CP changes (#47910):
84
        if (!dirty) {
85
            dirty = true;
86
            ProjectManager.mutex().postReadRequest(this);
87
        }
88
    }
89
    
90
    public void run() {
91
        dirty = false;
92
        List newRoots = getPath ();
93
        boolean fire = false;
94
        synchronized (this) {
95
            if (this.resources != null && !this.resources.equals(newRoots)) {
96
                this.resources = newRoots;
97
                fire = true;
98
            }
99
        }
100
        if (fire) {
101
            support.firePropertyChange (PROP_RESOURCES,null,null);
102
        }
103
    }
104
    
105
    private List getPath() {
106
        List result = new ArrayList ();
107
        String prop = evaluator.getProperty(propertyName);
108
        if (prop != null) {
109
            String[] pieces = PropertyUtils.tokenizePath(prop);
110
            for (int i = 0; i < pieces.length; i++) {
111
                File f = helper.resolveFile(pieces[i]);
112
                try {
113
                    URL entry = f.toURI().toURL();
114
                    if (FileUtil.isArchiveFile(entry) || (f.isFile() && f.length()<4)) {    //XXX: Not yet closed archive file
115
                        entry = FileUtil.getArchiveRoot(entry);
116
                    } else if (!f.exists()) {
117
                        // if file does not exist (e.g. build/classes folder
118
                        // was not created yet) then corresponding File will
119
                        // not be ended with slash. Fix that.
120
                        assert !entry.toExternalForm().endsWith("/") : f; // NOI18N
121
                        entry = new URL(entry.toExternalForm() + "/"); // NOI18N
122
                    }
123
                    result.add(ClassPathSupport.createResource(entry));
124
                } catch (MalformedURLException mue) {
125
                    assert false : mue;
126
                }
127
            }
128
        }
129
        return Collections.unmodifiableList(result);
130
    }
131
132
}
(-)project/apichanges.xml (-1 / +17 lines)
Lines 69-80 Link Here
69
    <!-- First, a list of API names you may use: -->
69
    <!-- First, a list of API names you may use: -->
70
    <apidefs>
70
    <apidefs>
71
        <apidef name="general">Java Project API</apidef>
71
        <apidef name="general">Java Project API</apidef>
72
        <apidef name="classpath">Classpath Support SPI</apidef>
72
        <!-- etc. -->
73
        <!-- etc. -->
73
    </apidefs>
74
    </apidefs>
74
75
75
    <!-- ACTUAL CHANGES BEGIN HERE: -->
76
    <!-- ACTUAL CHANGES BEGIN HERE: -->
76
77
77
    <changes>
78
       <change>
79
            <api name="Classpath"/>
80
            <summary>Added helper method for creating ClassPathImplementation based on the ant property</summary>
81
            <version major="1" minor="3"/>
82
            <date day="6" month="1" year="2005"/>
83
            <author login="tzezula"/>
84
            <compatibility addition="yes"/>
85
            <description>
86
                <p>
87
                Added new helper class org.netbeans.spi.java.project.classpath.support.ProjectClassPathSupport
88
                with a static method createPropertyBasedClassPathImplementation (AntProjectHelper, PropertyEvaluator, String[]).
89
                This method creates a live classpath based on the list of Ant properties holding the path. The classpath
90
                implementation listens on changes of properties, updates state and fires events to clients.
91
                </p>
92
            </description>
93
        </change>    
78
94
79
        <change id="rel-vers-1">
95
        <change id="rel-vers-1">
80
            <api name="general"/>
96
            <api name="general"/>
(-)project/arch.xml (+6 lines)
Lines 57-62 Link Here
57
    classpath of a J2SE project automatically.
57
    classpath of a J2SE project automatically.
58
   </p>
58
   </p>
59
  </api>
59
  </api>
60
  <api group="java" name="ProjectClassPathSupport" type="export" category="devel">
61
   <p>
62
    Support class containg helper method for creating ClassPathImplementation based
63
    on the Ant properies.
64
   </p>
65
  </api>
60
   </li>
66
   </li>
61
  </ul>
67
  </ul>
62
 </answer>
68
 </answer>
(-)project/nbproject/project.properties (-2 / +5 lines)
Lines 17-27 Link Here
17
javadoc.arch=${basedir}/arch.xml
17
javadoc.arch=${basedir}/arch.xml
18
javadoc.apichanges=${basedir}/apichanges.xml
18
javadoc.apichanges=${basedir}/apichanges.xml
19
19
20
test.unit.cp.extra=${nb_all}/projects/projectapi/build/test/unit/classes
20
test.unit.cp.extra=${nb_all}/projects/projectapi/build/test/unit/classes:\
21
    ${nb_all}/ant/project/build/test/unit/classes
21
# masterfs needed for the usual reasons; tools.jar needed for Ant's <javac> to work
22
# masterfs needed for the usual reasons; tools.jar needed for Ant's <javac> to work
22
test.unit.run.cp.extra=\
23
test.unit.run.cp.extra=\
23
    ${openide/masterfs.dir}/${nb.modules.dir}/org-netbeans-modules-masterfs.jar:\
24
    ${openide/masterfs.dir}/${nb.modules.dir}/org-netbeans-modules-masterfs.jar:\
24
    ${jdkhome}/lib/tools.jar
25
    ${jdkhome}/lib/tools.jar:\
26
    ${diff.dir}/${nb.modules.dir}/org-netbeans-modules-diff.jar:\
27
    ${libs/xerces.dir}/${nb.modules/autoload.dir}/ext/xerces-2.6.2.jar
25
test-unit-sys-prop.test.data.dir=${nb_all}/java/project/test/unit/data
28
test-unit-sys-prop.test.data.dir=${nb_all}/java/project/test/unit/data
26
test-unit-sys-prop.test.bridge.jar=${ant.dir}/ant/nblib/bridge.jar
29
test-unit-sys-prop.test.bridge.jar=${ant.dir}/ant/nblib/bridge.jar
27
# May be overridden to e.g. test against a different version of Ant:
30
# May be overridden to e.g. test against a different version of Ant:
(-)project/nbproject/project.xml (+1 lines)
Lines 134-139 Link Here
134
                <package>org.netbeans.api.java.project</package>
134
                <package>org.netbeans.api.java.project</package>
135
                <package>org.netbeans.spi.java.project.support.ui</package>
135
                <package>org.netbeans.spi.java.project.support.ui</package>
136
                <package>org.netbeans.spi.java.project.support.ui.templates</package>
136
                <package>org.netbeans.spi.java.project.support.ui.templates</package>
137
		<package>org.netbeans.spi.java.project.classpath.support</package>
137
            </public-packages>
138
            </public-packages>
138
            <javadoc/>
139
            <javadoc/>
139
        </data>
140
        </data>
(-)project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementation.java (+138 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-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.java.project.classpath.support;
15
16
import java.beans.PropertyChangeEvent;
17
import java.beans.PropertyChangeListener;
18
import java.beans.PropertyChangeSupport;
19
import java.io.File;
20
import java.net.MalformedURLException;
21
import java.net.URL;
22
import java.util.ArrayList;
23
import java.util.Arrays;
24
import java.util.Collections;
25
import java.util.HashSet;
26
import java.util.List;
27
import java.util.Set;
28
import org.netbeans.api.project.ProjectManager;
29
import org.netbeans.spi.java.classpath.ClassPathImplementation;
30
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
31
import org.netbeans.spi.project.support.ant.AntProjectHelper;
32
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
33
import org.netbeans.spi.project.support.ant.PropertyUtils;
34
import org.openide.filesystems.FileUtil;
35
import org.openide.util.WeakListeners;
36
37
38
/**
39
 * Implementation of a single classpath that is derived from list of Ant properties.
40
 */
41
final class ProjectClassPathImplementation implements ClassPathImplementation, PropertyChangeListener, Runnable {
42
    
43
    private final PropertyChangeSupport support = new PropertyChangeSupport(this);
44
    private final AntProjectHelper helper;
45
    private final String[] propertyNames;
46
    private List resources;
47
    private final PropertyEvaluator evaluator;
48
    private boolean dirty = false;
49
    private final Set/*<String>*/ propertyNamesSet = new HashSet ();
50
51
    /**
52
     * Construct the implementation.
53
     * @param helper an Ant project, used to resolve file paths
54
     * @param propertyNames the names of an Ant properties which will supply the classpath
55
     * @param evaluator a property evaluator used to find the value of the classpath
56
     */
57
    public ProjectClassPathImplementation(AntProjectHelper helper, String[] propertyNames, PropertyEvaluator evaluator) {
58
        assert helper != null && propertyNames != null && evaluator != null;
59
        this.helper = helper;
60
        this.evaluator = evaluator;
61
        this.propertyNames = propertyNames;
62
        this.propertyNamesSet.addAll(Arrays.asList(propertyNames));
63
        evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, evaluator));
64
    }
65
66
    public synchronized List /*<PathResourceImplementation>*/ getResources() {
67
        if (this.resources == null) {
68
            this.resources = this.getPath ();
69
        }
70
        return this.resources;
71
    }
72
73
    public void addPropertyChangeListener(PropertyChangeListener listener) {
74
        support.addPropertyChangeListener (listener);
75
    }
76
77
    public void removePropertyChangeListener(PropertyChangeListener listener) {
78
        support.removePropertyChangeListener (listener);
79
    }
80
81
82
    public void propertyChange(PropertyChangeEvent evt) {        
83
        if (!this.propertyNamesSet.contains(evt.getPropertyName())) {
84
            // Not interesting to us.
85
            return;
86
        }
87
        // Coalesce changes; can come in fast after huge CP changes (#47910):
88
        if (!dirty) {
89
            dirty = true;
90
            ProjectManager.mutex().postReadRequest(this);
91
        }
92
    }
93
    
94
    public void run() {
95
        dirty = false;
96
        List newRoots = getPath ();
97
        boolean fire = false;
98
        synchronized (this) {
99
            if (this.resources != null && !this.resources.equals(newRoots)) {
100
                this.resources = newRoots;
101
                fire = true;
102
            }
103
        }
104
        if (fire) {
105
            support.firePropertyChange (PROP_RESOURCES,null,null);
106
        }
107
    }
108
    
109
    private List getPath() {
110
        List result = new ArrayList ();
111
        for (int j=0; j< propertyNames.length; j++) {
112
            String prop = evaluator.getProperty(propertyNames[j]);
113
            if (prop != null) {
114
                String[] pieces = PropertyUtils.tokenizePath(prop);
115
                for (int i = 0; i < pieces.length; i++) {
116
                    File f = helper.resolveFile(pieces[i]);
117
                    try {
118
                        URL entry = f.toURI().toURL();
119
                        if (FileUtil.isArchiveFile(entry) || (f.isFile() && f.length()<4)) {    //XXX: Not yet closed archive file
120
                            entry = FileUtil.getArchiveRoot(entry);
121
                        } else if (!f.exists()) {
122
                            // if file does not exist (e.g. build/classes folder
123
                            // was not created yet) then corresponding File will
124
                            // not be ended with slash. Fix that.
125
                            assert !entry.toExternalForm().endsWith("/") : f; // NOI18N
126
                            entry = new URL(entry.toExternalForm() + "/"); // NOI18N
127
                        }
128
                        result.add(ClassPathSupport.createResource(entry));
129
                    } catch (MalformedURLException mue) {
130
                        assert false : mue;
131
                    }
132
                }
133
            }
134
        }
135
        return Collections.unmodifiableList(result);
136
    }
137
138
}
(-)project/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathSupport.java (+47 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.netbeans.spi.java.project.classpath.support;
14
15
import org.netbeans.spi.java.classpath.ClassPathImplementation;
16
import org.netbeans.spi.project.support.ant.AntProjectHelper;
17
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
18
19
/**
20
 * ProjectClassPathSupport is a support class for creating classpath based
21
 * on the list of ant properties.
22
 * @since org.netbeans.modules.java.project 1.3 
23
 * @author Tomas Zezula
24
 */
25
public class ProjectClassPathSupport {
26
        
27
    /** Creates a new instance of NewClass */
28
    private ProjectClassPathSupport() {
29
    }
30
    
31
    
32
    /**
33
     * Creates new classpath based on the ant property. The returned classpath
34
     * listens on changes of property value.
35
     * @param helper {@link AntProjectHelper} used to resolve files
36
     * @param evaluator {@link PropertyEvaluator} used for obtaining the value of
37
     * given property and listening on value changes.
38
     * @param propertyNames the names of ant properties the classpath will be build on,
39
     * can't be or contain null. It can contain duplicates, in this case the duplicated property
40
     * is used multiple times.
41
     */
42
    public static ClassPathImplementation createPropertyBasedClassPathImplementation (AntProjectHelper helper,
43
            PropertyEvaluator evaluator, String[] propertyNames) {
44
        return new ProjectClassPathImplementation (helper, propertyNames, evaluator);
45
    }
46
    
47
}
(-)project/test/unit/src/org/netbeans/spi/java/project/classpath/support/ProjectClassPathImplementationTest.java (+151 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-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.spi.java.project.classpath.support;
15
16
17
import java.io.File;
18
import java.io.IOException;
19
import java.net.URL;
20
import java.util.ArrayList;
21
import java.util.Arrays;
22
import java.util.Collection;
23
import java.util.Collections;
24
import java.util.List;
25
import java.util.Map;
26
import java.util.Properties;
27
import org.netbeans.api.java.classpath.ClassPath;
28
import org.netbeans.api.project.Project;
29
import org.netbeans.api.project.ProjectManager;
30
import org.netbeans.junit.NbTestCase;
31
import org.netbeans.spi.java.classpath.ClassPathFactory;
32
import org.netbeans.spi.java.classpath.ClassPathImplementation;
33
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
34
import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
35
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
36
import org.netbeans.spi.project.support.ant.PropertyUtils;
37
import org.openide.filesystems.FileObject;
38
import org.netbeans.api.project.TestUtil;
39
import org.netbeans.spi.project.support.ant.AntProjectHelper;
40
import org.netbeans.spi.project.support.ant.EditableProperties;
41
import org.netbeans.spi.project.support.ant.ProjectGenerator;
42
import org.openide.filesystems.FileUtil;
43
import org.openide.filesystems.Repository;
44
import org.openide.util.Lookup;
45
46
/**
47
 * Tests for {@link ProjectClassPathImplementation}.
48
 * @author Tomas Zezula
49
 */
50
public class ProjectClassPathImplementationTest extends NbTestCase {
51
    
52
    private static final String PROP_NAME_1 = "classpath1"; //NOI18N
53
    private static final String PROP_NAME_2 = "classpath2"; //NOI18N
54
    
55
    public ProjectClassPathImplementationTest(String testName) {
56
        super(testName);
57
    }
58
    
59
    private FileObject scratch;
60
    private FileObject projdir;
61
    private FileObject[] cpRoots1;
62
    private FileObject[] cpRoots2;
63
    private AntProjectHelper helper;
64
    private PropertyEvaluator evaluator;
65
    
66
    protected void setUp() throws Exception {
67
        super.setUp();
68
        TestUtil.setLookup(new Object[] {
69
            new org.netbeans.modules.projectapi.SimpleFileOwnerQueryImplementation(),
70
            AntBasedTestUtil.testAntBasedProjectType(),
71
        }, ProjectClassPathImplementation.class.getClassLoader());
72
    }
73
74
    protected void tearDown() throws Exception {
75
        scratch = null;
76
        projdir = null;
77
        cpRoots1 = null;
78
        cpRoots2 = null;
79
        helper = null;
80
        evaluator = null;
81
        TestUtil.setLookup(Lookup.EMPTY);
82
        super.tearDown();
83
    }
84
    
85
    
86
    private void prepareProject () throws IOException {
87
        scratch = TestUtil.makeScratchDir(this);
88
        projdir = scratch.createFolder("proj"); //NOI18N
89
        cpRoots1 = new FileObject[2];
90
        cpRoots1[0] = scratch.createFolder("cpRoot1"); //NOI18N
91
        cpRoots1[1] = scratch.createFolder("cpRoot2"); //NOI18N
92
        cpRoots2[0] = scratch.createFolder("cpRoot3"); //NOI18N
93
        cpRoots2[1] = scratch.createFolder("cpRoot4"); //NOI18N
94
        helper = ProjectGenerator.createProject(projdir, "test"); //NOI18N                
95
        evaluator = helper.getStandardPropertyEvaluator();
96
        setClassPath(new String[] {}, new FileObject[][] {cpRoots1, cpRoots2});
97
    }
98
    
99
    public void testBootClassPathImplementation () throws Exception {
100
        prepareProject();
101
        ClassPathImplementation cpImpl = ProjectClassPathSupport.createPropertyBasedClassPathImplementation(helper, evaluator, new String[] {PROP_NAME_1, PROP_NAME_2});
102
        ClassPath cp = ClassPathFactory.createClassPath(cpImpl);
103
        FileObject[] fo = cp.getRoots();
104
        List expected = new ArrayList ();
105
        expected.addAll(Arrays.asList(cpRoots1));
106
        expected.addAll(Arrays.asList(cpRoots2));
107
        assertEquals ("Wrong ClassPath roots",expected, Arrays.asList(fo));   //NOI18N
108
        cpRoots1 = new FileObject[] {cpRoots1[0]};
109
        setClassPath(new String[] {PROP_NAME_1}, new FileObject[][]{cpRoots1});
110
        fo = cp.getRoots();
111
        expected = new ArrayList ();
112
        expected.addAll(Arrays.asList(cpRoots1));
113
        expected.addAll(Arrays.asList(cpRoots2));
114
        assertEquals ("Wrong ClassPath roots",expected, Arrays.asList(fo));   //NOI18N
115
        cpRoots2 = new FileObject[] {cpRoots2[0]};
116
        setClassPath(new String[] {PROP_NAME_2}, new FileObject[][]{cpRoots2});
117
        fo = cp.getRoots();
118
        expected = new ArrayList ();
119
        expected.addAll(Arrays.asList(cpRoots1));
120
        expected.addAll(Arrays.asList(cpRoots2));
121
        assertEquals ("Wrong ClassPath roots",expected, Arrays.asList(fo));   //NOI18N
122
    }        
123
    
124
    
125
    
126
    private void setClassPath (String[] propNames, FileObject[][] cpRoots) {
127
        EditableProperties props = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
128
        for (int i=0; i< propNames.length; i++) {
129
            props.setProperty (propNames[i],toPath(cpRoots[i]));
130
        }                
131
        helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, props);
132
    }
133
    
134
    
135
    private static String toPath (FileObject[] cpRoots) {
136
        StringBuffer result = new StringBuffer ();
137
        for (int i=0; i<cpRoots.length; i++) {
138
            if (i>0) {
139
                result.append(':'); //NOI18N
140
            }
141
            File f = FileUtil.toFile (cpRoots[i]);
142
            result.append (f.getAbsolutePath());
143
        }
144
        return result.toString();
145
    }
146
    
147
    
148
    
149
    
150
    
151
}

Return to bug 53056