View | Details | Raw Unified | Return to bug 105645
Collapse All | Expand All

(-)a/java.api.common/nbproject/project.xml (-1 / +6 lines)
 Lines 123-129    Link Here 
123
                    <build-prerequisite/>
123
                    <build-prerequisite/>
124
                    <compile-dependency/>
124
                    <compile-dependency/>
125
                    <run-dependency>
125
                    <run-dependency>
126
                        <specification-version>7.19</specification-version>
126
                        <specification-version>7.20</specification-version>
127
                    </run-dependency>
127
                    </run-dependency>
128
                </dependency>
128
                </dependency>
129
                <dependency>
129
                <dependency>
 Lines 187-192    Link Here 
187
                        <test/>
187
                        <test/>
188
                    </test-dependency>
188
                    </test-dependency>
189
                    <test-dependency>
189
                    <test-dependency>
190
                        <code-name-base>org.openide.filesystems</code-name-base>
191
                        <compile-dependency/>
192
                        <test/>
193
                    </test-dependency>
194
                    <test-dependency>
190
                        <code-name-base>org.openide.util</code-name-base>
195
                        <code-name-base>org.openide.util</code-name-base>
191
                        <compile-dependency/>
196
                        <compile-dependency/>
192
                        <test/>
197
                        <test/>
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/ClassPathProviderImpl.java (-1 / +10 lines)
 Lines 66-71    Link Here 
66
public final class ClassPathProviderImpl implements ClassPathProvider {
66
public final class ClassPathProviderImpl implements ClassPathProvider {
67
67
68
    private String buildClassesDir = "build.classes.dir"; // NOI18N
68
    private String buildClassesDir = "build.classes.dir"; // NOI18N
69
    private static final String buildGeneratedDir = "build.generated.dir"; // NOI18N
69
    private String distJar = "dist.jar"; // NOI18N
70
    private String distJar = "dist.jar"; // NOI18N
70
    private String buildTestClassesDir = "build.test.classes.dir"; // NOI18N
71
    private String buildTestClassesDir = "build.test.classes.dir"; // NOI18N
71
    private String[] javacClasspath = new String[]{"javac.classpath"};    //NOI18N
72
    private String[] javacClasspath = new String[]{"javac.classpath"};    //NOI18N
 Lines 147-153    Link Here 
147
    private FileObject getBuildClassesDir() {
148
    private FileObject getBuildClassesDir() {
148
        return getDir(buildClassesDir);
149
        return getDir(buildClassesDir);
149
    }
150
    }
150
    
151
152
    private FileObject getBuildGeneratedDir() {
153
        return getDir(buildGeneratedDir);
154
    }
155
151
    private FileObject getDistJar() {
156
    private FileObject getDistJar() {
152
        return getDir(distJar);
157
        return getDir(distJar);
153
    }
158
    }
 Lines 196-201    Link Here 
196
        if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir,file))) {
201
        if (dir != null && (dir.equals(file) || FileUtil.isParentOf(dir,file))) {
197
            return 3;
202
            return 3;
198
        }
203
        }
204
        dir = getBuildGeneratedDir();
205
        if (dir != null && FileUtil.isParentOf(dir, file) /* but dir != file */) { // #105645
206
            return 0;
207
        }
199
        return -1;
208
        return -1;
200
    }
209
    }
201
    
210
    
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/classpath/SourcePathImplementation.java (+34 lines)
 Lines 66-71    Link Here 
66
import org.openide.filesystems.FileChangeListener;
66
import org.openide.filesystems.FileChangeListener;
67
import org.openide.filesystems.FileEvent;
67
import org.openide.filesystems.FileEvent;
68
import org.openide.filesystems.FileObject;
68
import org.openide.filesystems.FileObject;
69
import org.openide.filesystems.FileRenameEvent;
69
import org.openide.filesystems.FileUtil;
70
import org.openide.filesystems.FileUtil;
70
import org.openide.util.Exceptions;
71
import org.openide.util.Exceptions;
71
import org.openide.util.RequestProcessor;
72
import org.openide.util.RequestProcessor;
 Lines 78-83    Link Here 
78
79
79
    // TODO: if needed these parameters can be configurable via constructor parameter:
80
    // TODO: if needed these parameters can be configurable via constructor parameter:
80
    private static final String BUILD_DIR = "build.dir"; // NOI18N
81
    private static final String BUILD_DIR = "build.dir"; // NOI18N
82
    private static final String BUILD_GENERATED_DIR = "build.generated.dir"; // NOI18N
81
83
82
    private static final String DIR_GEN_BINDINGS = "generated/addons"; // NOI18N
84
    private static final String DIR_GEN_BINDINGS = "generated/addons"; // NOI18N
83
    private static RequestProcessor REQ_PROCESSOR = new RequestProcessor(); // No I18N
85
    private static RequestProcessor REQ_PROCESSOR = new RequestProcessor(); // No I18N
 Lines 89-94    Link Here 
89
    private FileChangeListener fcl = null;      
91
    private FileChangeListener fcl = null;      
90
    private PropertyEvaluator evaluator;
92
    private PropertyEvaluator evaluator;
91
    private boolean canHaveWebServices;
93
    private boolean canHaveWebServices;
94
    private File buildGeneratedDir = null;
95
    private final FileChangeListener buildGeneratedDirListener = new FileChangeAdapter() {
96
        public @Override void fileFolderCreated(FileEvent fe) {
97
            // XXX could do this asynch like SourceRootScannerTask, but would need to do synch during unit test
98
            invalidate();
99
        }
100
        public @Override void fileDeleted(FileEvent fe) {
101
            invalidate();
102
        }
103
        public @Override void fileRenamed(FileRenameEvent fe) {
104
            invalidate();
105
        }
106
    };
92
    
107
    
93
    /**
108
    /**
94
     * Construct the implementation.
109
     * Construct the implementation.
 Lines 246-251    Link Here 
246
                        createListener(buildDir,
261
                        createListener(buildDir,
247
                                new String[] {DIR_GEN_BINDINGS});
262
                                new String[] {DIR_GEN_BINDINGS});
248
                    }
263
                    }
264
                    String buildGeneratedDirS = evaluator.getProperty(BUILD_GENERATED_DIR);
265
                    if (buildGeneratedDirS != null) {
266
                        File _buildGeneratedDir = projectHelper.resolveFile(buildGeneratedDirS);
267
                        if (!_buildGeneratedDir.equals(buildGeneratedDir)) {
268
                            if (buildGeneratedDir != null) {
269
                                FileUtil.removeFileChangeListener(buildGeneratedDirListener, buildGeneratedDir);
270
                            }
271
                            buildGeneratedDir = _buildGeneratedDir;
272
                            FileUtil.addFileChangeListener(buildGeneratedDirListener, buildGeneratedDir);
273
                        }
274
                        if (buildGeneratedDir.isDirectory()) { // #105645
275
                            for (File root : buildGeneratedDir.listFiles()) {
276
                                if (!root.isDirectory()) {
277
                                    continue;
278
                                }
279
                                result.add(ClassPathSupport.createResource(root.toURI().toURL()));
280
                            }
281
                        }
282
                    }
249
                    } catch (MalformedURLException ex) {
283
                    } catch (MalformedURLException ex) {
250
                        Exceptions.printStackTrace(ex);
284
                        Exceptions.printStackTrace(ex);
251
                    }
285
                    }
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/Bundle.properties (-1 / +2 lines)
 Lines 66-69    Link Here 
66
66
67
#JavaSourceNodeFactory
67
#JavaSourceNodeFactory
68
LBL_Properties_Action=Properties
68
LBL_Properties_Action=Properties
69
69
# {0} - folder name
70
JavaSourceNodeFactory.gensrc=Generated Sources ({0})
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/project/ui/JavaSourceNodeFactory.java (-27 / +83 lines)
 Lines 42-52    Link Here 
42
package org.netbeans.modules.java.api.common.project.ui;
42
package org.netbeans.modules.java.api.common.project.ui;
43
43
44
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionEvent;
45
import java.beans.PropertyChangeListener;
46
import java.io.File;
45
import java.util.ArrayList;
47
import java.util.ArrayList;
48
import java.util.Arrays;
46
import java.util.Collections;
49
import java.util.Collections;
50
import java.util.Iterator;
47
import java.util.List;
51
import java.util.List;
48
import javax.swing.AbstractAction;
52
import javax.swing.AbstractAction;
49
import javax.swing.Action;
53
import javax.swing.Action;
54
import javax.swing.Icon;
50
import javax.swing.SwingUtilities;
55
import javax.swing.SwingUtilities;
51
import javax.swing.event.ChangeEvent;
56
import javax.swing.event.ChangeEvent;
52
import javax.swing.event.ChangeListener;
57
import javax.swing.event.ChangeListener;
 Lines 60-66    Link Here 
60
import org.netbeans.spi.project.ui.CustomizerProvider;
65
import org.netbeans.spi.project.ui.CustomizerProvider;
61
import org.netbeans.spi.project.ui.support.NodeFactory;
66
import org.netbeans.spi.project.ui.support.NodeFactory;
62
import org.netbeans.spi.project.ui.support.NodeList;
67
import org.netbeans.spi.project.ui.support.NodeList;
68
import org.openide.filesystems.FileChangeAdapter;
69
import org.openide.filesystems.FileChangeListener;
70
import org.openide.filesystems.FileEvent;
63
import org.openide.filesystems.FileObject;
71
import org.openide.filesystems.FileObject;
72
import org.openide.filesystems.FileRenameEvent;
73
import org.openide.filesystems.FileUtil;
64
import org.openide.nodes.FilterNode;
74
import org.openide.nodes.FilterNode;
65
import org.openide.nodes.Node;
75
import org.openide.nodes.Node;
66
import org.openide.util.ChangeSupport;
76
import org.openide.util.ChangeSupport;
 Lines 83-119    Link Here 
83
    private static class SourcesNodeList implements NodeList<SourceGroupKey>, ChangeListener {
93
    private static class SourcesNodeList implements NodeList<SourceGroupKey>, ChangeListener {
84
        
94
        
85
        private final Project project;
95
        private final Project project;
86
        
96
        private final File genSrcDir;
97
        private final FileChangeListener genSrcDirListener;
87
        private final ChangeSupport changeSupport = new ChangeSupport(this);
98
        private final ChangeSupport changeSupport = new ChangeSupport(this);
88
        
99
89
        public SourcesNodeList(Project proj) {
100
        public SourcesNodeList(Project proj) {
90
            project = proj;
101
            project = proj;
102
            genSrcDirListener = new FileChangeAdapter() {
103
                public @Override void fileFolderCreated(FileEvent fe) {
104
                    stateChanged(null);
105
                }
106
                public @Override void fileDeleted(FileEvent fe) {
107
                    stateChanged(null);
108
                }
109
                public @Override void fileRenamed(FileRenameEvent fe) {
110
                    stateChanged(null);
111
                }
112
            };
113
            File d = FileUtil.toFile(proj.getProjectDirectory());
114
            // XXX hardcodes the value of ${build.generated.dir}, since we have no access to evaluator
115
            genSrcDir = d != null ? new File(d, "build/generated-sources") : null;
91
        }
116
        }
92
        
117
        
93
        public List<SourceGroupKey> keys() {
118
        public List<SourceGroupKey> keys() {
94
            if (this.project.getProjectDirectory() == null || !this.project.getProjectDirectory().isValid()) {
119
            if (this.project.getProjectDirectory() == null || !this.project.getProjectDirectory().isValid()) {
95
                return Collections.<SourceGroupKey>emptyList();
120
                return Collections.<SourceGroupKey>emptyList();
96
            }
121
            }
97
            Sources sources = getSources();
122
            List<SourceGroupKey> result =  new ArrayList<SourceGroupKey>();
98
            SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
123
            for (SourceGroup group : getSources().getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) {
99
            
124
                result.add(new SourceGroupKey(group, true));
100
            List<SourceGroupKey> result =  new ArrayList<SourceGroupKey>(groups.length);
125
            }
101
            for( int i = 0; i < groups.length; i++ ) {
126
            FileObject genSrc = FileUtil.toFileObject(genSrcDir);
102
                result.add(new SourceGroupKey(groups[i]));
127
            if (genSrc != null) {
128
                for (final FileObject child : genSrc.getChildren()) {
129
                    if (!child.isFolder()) {
130
                        continue;
131
                    }
132
                    result.add(new SourceGroupKey(new SourceGroup() {
133
                        public FileObject getRootFolder() {
134
                            return child;
135
                        }
136
                        public String getName() {
137
                            return child.getNameExt();
138
                        }
139
                        public String getDisplayName() {
140
                            return NbBundle.getMessage(JavaSourceNodeFactory.class, "JavaSourceNodeFactory.gensrc", child.getNameExt());
141
                        }
142
                        public Icon getIcon(boolean opened) {
143
                            return null;
144
                        }
145
                        public boolean contains(FileObject file) throws IllegalArgumentException {
146
                            return true;
147
                        }
148
                        public void addPropertyChangeListener(PropertyChangeListener listener) {}
149
                        public void removePropertyChangeListener(PropertyChangeListener listener) {}
150
                    }, false));
151
                }
103
            }
152
            }
104
            return result;
153
            return result;
105
        }
154
        }
106
        
155
        
107
        public void addChangeListener(ChangeListener l) {
156
        public void addChangeListener(ChangeListener l) {
108
            changeSupport.addChangeListener(l);
157
            changeSupport.addChangeListener(l);
158
            FileUtil.addFileChangeListener(genSrcDirListener, genSrcDir);
109
        }
159
        }
110
        
160
        
111
        public void removeChangeListener(ChangeListener l) {
161
        public void removeChangeListener(ChangeListener l) {
112
            changeSupport.removeChangeListener(l);
162
            changeSupport.removeChangeListener(l);
163
            FileUtil.removeFileChangeListener(genSrcDirListener, genSrcDir);
113
        }
164
        }
114
        
165
        
115
        public Node node(SourceGroupKey key) {
166
        public Node node(SourceGroupKey key) {
116
            return new PackageViewFilterNode(key.group, project);
167
            return new PackageViewFilterNode(key, project);
117
        }
168
        }
118
        
169
        
119
        public void addNotify() {
170
        public void addNotify() {
 Lines 144-153    Link Here 
144
        
195
        
145
        public final SourceGroup group;
196
        public final SourceGroup group;
146
        public final FileObject fileObject;
197
        public final FileObject fileObject;
198
        public final boolean trueSource;
147
        
199
        
148
        SourceGroupKey(SourceGroup group) {
200
        SourceGroupKey(SourceGroup group, boolean trueSource) {
149
            this.group = group;
201
            this.group = group;
150
            this.fileObject = group.getRootFolder();
202
            this.fileObject = group.getRootFolder();
203
            this.trueSource = trueSource;
151
        }
204
        }
152
        
205
        
153
        @Override
206
        @Override
 Lines 182-216    Link Here 
182
        
235
        
183
    }
236
    }
184
    
237
    
185
    /** Yet another cool filter node just to add properties action
238
    /**
239
     * Adjusts context menu of source group root node.
186
     */
240
     */
187
    private static class PackageViewFilterNode extends FilterNode {
241
    private static class PackageViewFilterNode extends FilterNode {
188
        
242
        
189
        private final String nodeName;
243
        private final String nodeName;
190
        private final Project project;
244
        private final Project project;
245
        private final boolean trueSource;
191
        
246
        
192
        Action[] actions;
247
        public PackageViewFilterNode(SourceGroupKey sourceGroupKey, Project project) {
193
        
248
            super(PackageView.createPackageView(sourceGroupKey.group));
194
        public PackageViewFilterNode(SourceGroup sourceGroup, Project project) {
195
            super(PackageView.createPackageView(sourceGroup));
196
            this.project = project;
249
            this.project = project;
197
            this.nodeName = "Sources";
250
            this.nodeName = "Sources";
251
            trueSource = sourceGroupKey.trueSource;
198
        }
252
        }
199
        
253
        
200
        
254
        public @Override Action[] getActions(boolean context) {
201
        public Action[] getActions(boolean context) {
255
            List<Action> actions = new ArrayList<Action>(Arrays.asList(super.getActions(context)));
202
            if (!context) {
256
            if (trueSource) {
203
                if (actions == null) {
257
                actions.add(null);
204
                    Action superActions[] = super.getActions(context);
258
                actions.add(new PreselectPropertiesAction(project, nodeName));
205
                    actions = new Action[superActions.length + 2];
259
            } else {
206
                    System.arraycopy(superActions, 0, actions, 0, superActions.length);
260
                // Just take out "New File..." as this would be misleading.
207
                    actions[superActions.length] = null;
261
                Iterator<Action> scan = actions.iterator();
208
                    actions[superActions.length + 1] = new PreselectPropertiesAction(project, nodeName);
262
                while (scan.hasNext()) {
263
                    Action a = scan.next();
264
                    if (a != null && a.getClass().getName().equals("org.netbeans.modules.project.ui.actions.NewFile$WithSubMenu")) { // NOI18N
265
                        scan.remove();
266
                    }
209
                }
267
                }
210
                return actions;
211
            } else {
212
                return super.getActions(context);
213
            }
268
            }
269
            return actions.toArray(new Action[actions.size()]);
214
        }
270
        }
215
        
271
        
216
    }
272
    }
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/BinaryForSourceQueryImpl.java (-13 / +13 lines)
 Lines 43-50    Link Here 
43
43
44
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeEvent;
45
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeListener;
46
import java.io.File;
47
import java.net.MalformedURLException;
48
import java.net.URL;
46
import java.net.URL;
49
import java.util.ArrayList;
47
import java.util.ArrayList;
50
import java.util.HashMap;
48
import java.util.HashMap;
 Lines 57-64    Link Here 
57
import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation;
55
import org.netbeans.spi.java.queries.BinaryForSourceQueryImplementation;
58
import org.netbeans.spi.project.support.ant.AntProjectHelper;
56
import org.netbeans.spi.project.support.ant.AntProjectHelper;
59
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
58
import org.openide.filesystems.FileUtil;
60
import org.openide.util.ChangeSupport;
59
import org.openide.util.ChangeSupport;
61
import org.openide.util.Exceptions;
62
60
63
/**
61
/**
64
 *
62
 *
 Lines 100-113    Link Here 
100
                if (root.equals(sourceRoot)) {
98
                if (root.equals(sourceRoot)) {
101
                    result = new R (sourceProps);
99
                    result = new R (sourceProps);
102
                    cache.put (sourceRoot,result);
100
                    cache.put (sourceRoot,result);
103
                    break;
101
                    return result;
104
                }
102
                }
105
            }
103
            }
106
            for (URL root : this.test.getRootURLs()) {
104
            for (URL root : this.test.getRootURLs()) {
107
                if (root.equals(sourceRoot)) {
105
                if (root.equals(sourceRoot)) {
108
                    result = new R (testProps);
106
                    result = new R (testProps);
109
                    cache.put (sourceRoot,result);
107
                    cache.put (sourceRoot,result);
110
                    break;
108
                    return result;
109
                }
110
            }
111
            String buildGeneratedDirS = eval.getProperty("build.generated.dir");
112
            if (buildGeneratedDirS != null) { // #105645
113
                String parent = helper.resolveFile(buildGeneratedDirS).toURI().toString();
114
                if (sourceRoot.toString().startsWith(parent)) {
115
                    result = new R(sourceProps);
116
                    cache.put(sourceRoot, result);
117
                    return result;
111
                }
118
                }
112
            }
119
            }
113
        }
120
        }
 Lines 130-143    Link Here 
130
            for (String propName : propNames) {
137
            for (String propName : propNames) {
131
                String val = eval.getProperty(propName);
138
                String val = eval.getProperty(propName);
132
                if (val != null) {                
139
                if (val != null) {                
133
                    File f = helper.resolveFile(val);
140
                    urls.add(FileUtil.urlForArchiveOrDir(helper.resolveFile(val)));
134
                    if (f != null) {
135
                        try {
136
                            urls.add(f.toURI().toURL());
137
                        } catch (MalformedURLException e) {
138
                            Exceptions.printStackTrace(e);
139
                        }
140
                    }
141
                }
141
                }
142
            }
142
            }
143
            return urls.toArray(new URL[urls.size()]);
143
            return urls.toArray(new URL[urls.size()]);
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/CompiledSourceForBinaryQueryImpl.java (-2 / +22 lines)
 Lines 50-57    Link Here 
50
import java.net.MalformedURLException;
50
import java.net.MalformedURLException;
51
import java.beans.PropertyChangeListener;
51
import java.beans.PropertyChangeListener;
52
import java.beans.PropertyChangeEvent;
52
import java.beans.PropertyChangeEvent;
53
import java.util.ArrayList;
54
import java.util.Arrays;
53
import java.util.Map;
55
import java.util.Map;
54
import java.util.HashMap;
56
import java.util.HashMap;
57
import java.util.List;
55
import javax.swing.event.ChangeListener;
58
import javax.swing.event.ChangeListener;
56
import org.netbeans.api.java.queries.SourceForBinaryQuery;
59
import org.netbeans.api.java.queries.SourceForBinaryQuery;
57
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
60
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
 Lines 116-122    Link Here 
116
        if (src == null) {
119
        if (src == null) {
117
            return null;
120
            return null;
118
        }
121
        }
119
        res = new Result(src);
122
        res = new Result(src, src == sourceRoots);
120
        cache.put(binaryRoot, res);
123
        cache.put(binaryRoot, res);
121
        return res;
124
        return res;
122
    }
125
    }
 Lines 146-158    Link Here 
146
149
147
        private final ChangeSupport changeSupport = new ChangeSupport(this);
150
        private final ChangeSupport changeSupport = new ChangeSupport(this);
148
        private SourceRoots sourceRoots;
151
        private SourceRoots sourceRoots;
152
        private final boolean gensrc;
149
153
150
        public Result(SourceRoots sourceRoots) {
154
        public Result(SourceRoots sourceRoots, boolean gensrc) {
151
            this.sourceRoots = sourceRoots;
155
            this.sourceRoots = sourceRoots;
152
            this.sourceRoots.addPropertyChangeListener(this);
156
            this.sourceRoots.addPropertyChangeListener(this);
157
            this.gensrc = gensrc;
153
        }
158
        }
154
159
155
        public FileObject[] getRoots() {
160
        public FileObject[] getRoots() {
161
            if (gensrc) { // #105645
162
                String buildGeneratedDirS = evaluator.getProperty("build.generated.dir"); // NOI18N
163
                if (buildGeneratedDirS != null) {
164
                    FileObject buildGeneratedDir = helper.resolveFileObject(buildGeneratedDirS);
165
                    if (buildGeneratedDir != null) {
166
                        List<FileObject> roots = new ArrayList<FileObject>(Arrays.asList(sourceRoots.getRoots()));
167
                        for (FileObject root : buildGeneratedDir.getChildren()) {
168
                            if (root.isFolder()) {
169
                                roots.add(root);
170
                            }
171
                        }
172
                        return roots.toArray(new FileObject[roots.size()]);
173
                    }
174
                }
175
            }
156
            return this.sourceRoots.getRoots(); // no need to cache it, SourceRoots does
176
            return this.sourceRoots.getRoots(); // no need to cache it, SourceRoots does
157
        }
177
        }
158
178
(-)a/java.api.common/src/org/netbeans/modules/java/api/common/queries/FileBuiltQueryImpl.java (-15 / +58 lines)
 Lines 42-47    Link Here 
42
42
43
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeListener;
44
import java.beans.PropertyChangeListener;
45
import java.io.File;
46
import java.util.ArrayList;
47
import java.util.List;
45
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.api.project.ProjectManager;
46
import org.openide.filesystems.FileObject;
49
import org.openide.filesystems.FileObject;
47
import org.netbeans.api.queries.FileBuiltQuery;
50
import org.netbeans.api.queries.FileBuiltQuery;
 Lines 49-54    Link Here 
49
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
52
import org.netbeans.spi.queries.FileBuiltQueryImplementation;
50
import org.netbeans.spi.project.support.ant.AntProjectHelper;
53
import org.netbeans.spi.project.support.ant.AntProjectHelper;
51
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
54
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
55
import org.openide.filesystems.FileChangeAdapter;
56
import org.openide.filesystems.FileChangeListener;
57
import org.openide.filesystems.FileEvent;
58
import org.openide.filesystems.FileRenameEvent;
59
import org.openide.filesystems.FileUtil;
52
import org.openide.util.Mutex.Action;
60
import org.openide.util.Mutex.Action;
53
61
54
62
 Lines 63-68    Link Here 
63
    private final PropertyEvaluator evaluator;
71
    private final PropertyEvaluator evaluator;
64
    private final SourceRoots sourceRoots;
72
    private final SourceRoots sourceRoots;
65
    private final SourceRoots testRoots;
73
    private final SourceRoots testRoots;
74
    private File buildGeneratedDir = null;
75
    private final FileChangeListener buildGeneratedDirListener = new FileChangeAdapter() {
76
        public @Override void fileFolderCreated(FileEvent fe) {
77
            invalidate();
78
        }
79
        public @Override void fileDeleted(FileEvent fe) {
80
            invalidate();
81
        }
82
        public @Override void fileRenamed(FileRenameEvent fe) {
83
            invalidate();
84
        }
85
    };
66
86
67
    FileBuiltQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots,
87
    FileBuiltQueryImpl(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots,
68
            SourceRoots testRoots) {
88
            SourceRoots testRoots) {
 Lines 96-122    Link Here 
96
116
97
117
98
    private FileBuiltQueryImplementation createDelegate() {
118
    private FileBuiltQueryImplementation createDelegate() {
99
        String[] srcRoots = sourceRoots.getRootProperties();
119
        List<String> from = new ArrayList<String>();
100
        String[] tstRoots = testRoots.getRootProperties();
120
        List<String> to = new ArrayList<String>();
101
        String[] from = new String [srcRoots.length + tstRoots.length];
121
        for (String r : sourceRoots.getRootProperties()) {
102
        String[] to = new String [srcRoots.length + tstRoots.length];
122
            from.add("${" + r + "}/*.java"); // NOI18N
103
        for (int i = 0; i < srcRoots.length; i++) {
123
            to.add("${build.classes.dir}/*.class"); // NOI18N
104
            from[i] = "${" + srcRoots[i] + "}/*.java"; // NOI18N
105
            to[i] = "${build.classes.dir}/*.class"; // NOI18N
106
        }
124
        }
107
        for (int i = 0; i < tstRoots.length; i++) {
125
        for (String r : testRoots.getRootProperties()) {
108
            from[srcRoots.length + i] = "${" + tstRoots[i] + "}/*.java"; // NOI18N
126
            from.add("${" + r + "}/*.java"); // NOI18N
109
            to[srcRoots.length + i] = "${build.test.classes.dir}/*.class"; // NOI18N
127
            to.add("${build.test.classes.dir}/*.class"); // NOI18N
110
        }
128
        }
111
        return helper.createGlobFileBuiltQuery(evaluator, from, to); // save to pass APH
129
        String buildGeneratedDirS = evaluator.getProperty("build.generated.dir"); // NOI18N
130
        if (buildGeneratedDirS != null) { // #105645
131
            File _buildGeneratedDir = helper.resolveFile(buildGeneratedDirS);
132
            if (!_buildGeneratedDir.equals(buildGeneratedDir)) {
133
                if (buildGeneratedDir != null) {
134
                    FileUtil.removeFileChangeListener(buildGeneratedDirListener, buildGeneratedDir);
135
                }
136
                buildGeneratedDir = _buildGeneratedDir;
137
                FileUtil.addFileChangeListener(buildGeneratedDirListener, buildGeneratedDir);
138
            }
139
            if (buildGeneratedDir.isDirectory()) {
140
                for (File root : buildGeneratedDir.listFiles()) {
141
                    if (!root.isDirectory()) {
142
                        continue;
143
                    }
144
                    from.add(root + "/*.java"); // NOI18N
145
                    to.add("${build.classes.dir}/*.class"); // NOI18N
146
                }
147
            }
148
        }
149
        return helper.createGlobFileBuiltQuery(evaluator,
150
                from.toArray(new String[from.size()]),
151
                to.toArray(new String[to.size()]));
112
    }
152
    }
113
153
114
    public void propertyChange(PropertyChangeEvent evt) {
154
    public void propertyChange(PropertyChangeEvent evt) {
115
        if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) {
155
        if (SourceRoots.PROP_ROOT_PROPERTIES.equals(evt.getPropertyName())) {
116
            synchronized (this) {
156
            invalidate();
117
                delegate = null;
118
                // XXX: what to do with already returned Statuses
119
            }
120
        }
157
        }
121
    }
158
    }
159
160
    private synchronized void invalidate() {
161
        delegate = null;
162
        // XXX: what to do with already returned Statuses
163
    }
164
122
}
165
}
(-)a/java.api.common/test/unit/src/org/netbeans/modules/java/api/common/queries/GeneratedSourceRootTest.java (+364 lines)
Line 0    Link Here 
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.java.api.common.queries;
41
42
import java.beans.PropertyChangeEvent;
43
import java.beans.PropertyChangeListener;
44
import java.io.IOException;
45
import java.net.URL;
46
import java.util.Arrays;
47
import java.util.Collections;
48
import javax.swing.event.ChangeEvent;
49
import javax.swing.event.ChangeListener;
50
import org.netbeans.api.java.classpath.ClassPath;
51
import org.netbeans.api.java.project.JavaProjectConstants;
52
import org.netbeans.api.java.queries.BinaryForSourceQuery;
53
import org.netbeans.api.java.queries.SourceForBinaryQuery;
54
import org.netbeans.api.java.queries.SourceLevelQuery;
55
import org.netbeans.api.java.queries.UnitTestForSourceQuery;
56
import org.netbeans.api.project.Project;
57
import org.netbeans.api.project.ProjectManager;
58
import org.netbeans.api.project.ProjectUtils;
59
import org.netbeans.api.project.SourceGroup;
60
import org.netbeans.api.project.Sources;
61
import org.netbeans.api.queries.FileBuiltQuery;
62
import org.netbeans.api.queries.FileEncodingQuery;
63
import org.netbeans.junit.NbTestCase;
64
import org.netbeans.modules.java.api.common.SourceRoots;
65
import org.netbeans.modules.java.api.common.ant.UpdateHelper;
66
import org.netbeans.modules.java.api.common.ant.UpdateImplementation;
67
import org.netbeans.modules.java.api.common.classpath.ClassPathProviderImpl;
68
import org.netbeans.spi.project.AuxiliaryConfiguration;
69
import org.netbeans.spi.project.support.ant.AntBasedProjectType;
70
import org.netbeans.spi.project.support.ant.AntProjectHelper;
71
import org.netbeans.spi.project.support.ant.EditableProperties;
72
import org.netbeans.spi.project.support.ant.ProjectGenerator;
73
import org.netbeans.spi.project.support.ant.PropertyEvaluator;
74
import org.netbeans.spi.project.support.ant.ReferenceHelper;
75
import org.netbeans.spi.project.support.ant.SourcesHelper;
76
import org.openide.filesystems.FileObject;
77
import org.openide.filesystems.FileUtil;
78
import org.openide.filesystems.test.TestFileUtils;
79
import org.openide.util.ChangeSupport;
80
import org.openide.util.Lookup;
81
import org.openide.util.Mutex;
82
import org.openide.util.lookup.Lookups;
83
import org.openide.util.test.MockLookup;
84
import org.w3c.dom.Document;
85
import org.w3c.dom.Element;
86
87
/**
88
 * Test for #105645 functionality: build/generated-sources/NAME/ roots.
89
 */
90
public class GeneratedSourceRootTest extends NbTestCase {
91
92
    public GeneratedSourceRootTest(String n) {
93
        super(n);
94
    }
95
96
    public void testSourceRoots() throws Exception {
97
        Project p = createTestProject(true);
98
        FileObject d = p.getProjectDirectory();
99
        FileObject src = d.getFileObject("src");
100
        FileObject stuff = d.getFileObject("build/generated-sources/stuff");
101
        SourceGroup[] groups = ProjectUtils.getSources(p).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
102
        assertEquals(2, groups.length);
103
        assertEquals(src, groups[0].getRootFolder());
104
        assertEquals(d.getFileObject("test"), groups[1].getRootFolder());
105
        ClassPath sourcePath = ClassPath.getClassPath(src, ClassPath.SOURCE);
106
        assertEquals(Arrays.asList(src, stuff), Arrays.asList(sourcePath.getRoots()));
107
        FileObject moreStuff = FileUtil.createFolder(d, "build/generated-sources/morestuff");
108
        assertEquals(Arrays.asList(src, stuff, moreStuff), Arrays.asList(sourcePath.getRoots()));
109
        ClassPath compile = ClassPath.getClassPath(src, ClassPath.COMPILE);
110
        assertEquals(compile, ClassPath.getClassPath(stuff, ClassPath.COMPILE));
111
        assertEquals(compile, ClassPath.getClassPath(moreStuff, ClassPath.COMPILE));
112
        assertEquals(ClassPath.getClassPath(src, ClassPath.EXECUTE), ClassPath.getClassPath(stuff, ClassPath.EXECUTE));
113
        assertEquals(ClassPath.getClassPath(src, ClassPath.BOOT), ClassPath.getClassPath(stuff, ClassPath.BOOT));
114
        d.getFileObject("build").delete();
115
        assertEquals(Arrays.asList(src), Arrays.asList(sourcePath.getRoots()));
116
    }
117
118
    public void testMiscellaneousQueries() throws Exception {
119
        Project p = createTestProject(true);
120
        FileObject d = p.getProjectDirectory();
121
        FileObject src = d.getFileObject("src");
122
        FileObject test = d.getFileObject("test");
123
        FileObject stuff = d.getFileObject("build/generated-sources/stuff");
124
        URL classes = new URL(d.getURL(), "build/classes/");
125
        URL testClasses = new URL(d.getURL(), "build/test/classes/");
126
        FileObject xgen = stuff.getFileObject("net/nowhere/XGen.java");
127
        assertEquals(Arrays.asList(src, stuff), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
128
        assertEquals(Arrays.asList(test), Arrays.asList(SourceForBinaryQuery.findSourceRoots(testClasses).getRoots()));
129
        assertEquals(Collections.singletonList(classes), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(src.getURL()).getRoots()));
130
        assertEquals(Collections.singletonList(testClasses), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(test.getURL()).getRoots()));
131
        assertEquals(Collections.singletonList(classes), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(stuff.getURL()).getRoots()));
132
        assertEquals(Collections.singletonList(src.getURL()), Arrays.asList(UnitTestForSourceQuery.findSources(test)));
133
        assertEquals(Collections.singletonList(test.getURL()), Arrays.asList(UnitTestForSourceQuery.findUnitTests(src)));
134
        assertEquals("1.5", SourceLevelQuery.getSourceLevel(stuff));
135
        FileBuiltQuery.Status status = FileBuiltQuery.getStatus(xgen);
136
        assertNotNull(status);
137
        assertFalse(status.isBuilt());
138
        FileUtil.createData(d, "build/classes/net/nowhere/XGen.class");
139
        assertTrue(status.isBuilt());
140
        assertEquals("ISO-8859-2", FileEncodingQuery.getEncoding(xgen).name());
141
        // check also dynamic changes in set of gensrc roots:
142
        FileObject moreStuff = FileUtil.createFolder(d, "build/generated-sources/morestuff");
143
        FileObject ygen = FileUtil.createData(moreStuff, "net/nowhere/YGen.java");
144
        assertEquals(Arrays.asList(src, stuff, moreStuff), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
145
        assertEquals(Collections.singletonList(classes), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(moreStuff.getURL()).getRoots()));
146
        // XXX should previously created Result objects fire changes? ideally yes, but probably unnecessary
147
        assertEquals("1.5", SourceLevelQuery.getSourceLevel(moreStuff));
148
        status = FileBuiltQuery.getStatus(ygen);
149
        assertNotNull(status);
150
        assertFalse(status.isBuilt());
151
        FileUtil.createData(d, "build/classes/net/nowhere/YGen.class");
152
        assertTrue(status.isBuilt());
153
        assertEquals("ISO-8859-2", FileEncodingQuery.getEncoding(ygen).name());
154
        d.getFileObject("build").delete();
155
        assertEquals(Arrays.asList(src), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
156
    }
157
158
    public void testFirstGenSrcAddedDynamically() throws Exception {
159
        Project p = createTestProject(false);
160
        FileObject d = p.getProjectDirectory();
161
        FileObject src = d.getFileObject("src");
162
        URL classes = new URL(d.getURL(), "build/classes/");
163
        ClassPath sourcePath = ClassPath.getClassPath(src, ClassPath.SOURCE);
164
        assertEquals(Arrays.asList(src), Arrays.asList(sourcePath.getRoots()));
165
        assertEquals(Arrays.asList(src), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
166
        // now add the first gensrc root:
167
        FileObject stuff = FileUtil.createFolder(d, "build/generated-sources/stuff");
168
        FileObject xgen = FileUtil.createData(stuff, "net/nowhere/XGen.java");
169
        assertEquals(Arrays.asList(src, stuff), Arrays.asList(sourcePath.getRoots()));
170
        assertEquals(ClassPath.getClassPath(src, ClassPath.COMPILE), ClassPath.getClassPath(stuff, ClassPath.COMPILE));
171
        assertEquals(Arrays.asList(src, stuff), Arrays.asList(SourceForBinaryQuery.findSourceRoots(classes).getRoots()));
172
        assertEquals(Collections.singletonList(classes), Arrays.asList(BinaryForSourceQuery.findBinaryRoots(stuff.getURL()).getRoots()));
173
        FileBuiltQuery.Status status = FileBuiltQuery.getStatus(xgen);
174
        assertNotNull(status);
175
        assertFalse(status.isBuilt());
176
        FileUtil.createData(d, "build/classes/net/nowhere/XGen.class");
177
        assertTrue(status.isBuilt());
178
    }
179
180
    protected @Override void setUp() throws Exception {
181
        clearWorkDir();
182
        MockLookup.setInstances(new TestAntBasedProjectType());
183
    }
184
185
    private Project createTestProject(boolean initGenRoot) throws Exception {
186
        final FileObject dir = FileUtil.toFileObject(getWorkDir());
187
        TestFileUtils.writeFile(dir, "src/net/nowhere/X.java",
188
                "package net.nowhere; public class X {}");
189
        TestFileUtils.writeFile(dir, "test/net/nowhere/XTest.java",
190
                "package net.nowhere; public class XTest {}");
191
        if (initGenRoot) {
192
            TestFileUtils.writeFile(dir, "build/generated-sources/stuff/net/nowhere/XGen.java",
193
                    "package net.nowhere; public class XGen {}");
194
        }
195
        return ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Project>() {
196
            public Project run() throws Exception {
197
                AntProjectHelper h = ProjectGenerator.createProject(dir, "test");
198
                EditableProperties pp = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH);
199
                pp.setProperty("src.dir", "src");
200
                pp.setProperty("test.src.dir", "test");
201
                pp.setProperty("build.dir", "build");
202
                pp.setProperty("build.classes.dir", "${build.dir}/classes");
203
                pp.setProperty("build.test.classes.dir", "${build.dir}/test/classes");
204
                pp.setProperty("build.generated.dir", "${build.dir}/generated-sources");
205
                pp.setProperty("javac.classpath", "lib.jar");
206
                pp.setProperty("javac.test.classpath", "${javac.classpath}:junit.jar");
207
                pp.setProperty("run.classpath", "${javac.classpath}:${build.classes.dir}:runlib.jar");
208
                pp.setProperty("run.test.classpath", "${javac.test.classpath}:${build.test.classes.dir}:runlib.jar");
209
                pp.setProperty("dist.dir", "dist");
210
                pp.setProperty("dist.jar", "${dist.dir}/x.jar");
211
                pp.setProperty("javac.source", "1.5");
212
                pp.setProperty("encoding", "ISO-8859-2");
213
                h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, pp);
214
                Element data = h.getPrimaryConfigurationData(true);
215
                Document doc = data.getOwnerDocument();
216
                ((Element) data.appendChild(doc.createElementNS(NS, "source-roots")).
217
                        appendChild(doc.createElementNS(NS, "root"))).
218
                        setAttribute("id", "src.dir");
219
                ((Element) data.appendChild(doc.createElementNS(NS, "test-roots")).
220
                        appendChild(doc.createElementNS(NS, "root"))).
221
                        setAttribute("id", "test.src.dir");
222
                h.putPrimaryConfigurationData(data, true);
223
                Project p = ProjectManager.getDefault().findProject(dir);
224
                assertEquals(TestProject.class, p.getClass());
225
                ProjectManager.getDefault().saveProject(p);
226
                return p;
227
            }
228
        });
229
    }
230
231
    private static final String NS = "urn:test";
232
    private static class TestAntBasedProjectType implements AntBasedProjectType {
233
        public String getType() {
234
            return "test";
235
        }
236
        public Project createProject(AntProjectHelper helper) throws IOException {
237
            return new TestProject(helper);
238
        }
239
        public String getPrimaryConfigurationDataElementName(boolean shared) {
240
            return "data";
241
        }
242
        public String getPrimaryConfigurationDataElementNamespace(boolean shared) {
243
            return NS;
244
        }
245
    }
246
    private static class TestProject implements Project {
247
        private final AntProjectHelper helper;
248
        private Lookup lookup;
249
        TestProject(AntProjectHelper helper) {
250
            this.helper = helper;
251
        }
252
        public FileObject getProjectDirectory() {
253
            return helper.getProjectDirectory();
254
        }
255
        public synchronized Lookup getLookup() {
256
            if (lookup == null) {
257
                PropertyEvaluator evaluator = helper.getStandardPropertyEvaluator();
258
                AuxiliaryConfiguration aux = helper.createAuxiliaryConfiguration();
259
                ReferenceHelper refHelper = new ReferenceHelper(helper, aux, evaluator);
260
                UpdateHelper upHelper = new UpdateHelper(new UpdateImplementation() {
261
                    public boolean isCurrent() {return true;}
262
                    public boolean canUpdate() {throw new AssertionError();}
263
                    public void saveUpdate(EditableProperties props) throws IOException {throw new AssertionError();}
264
                    public Element getUpdatedSharedConfigurationData() {throw new AssertionError();}
265
                    public EditableProperties getUpdatedProjectProperties() {throw new AssertionError();}
266
                }, helper);
267
                SourceRoots src = SourceRoots.create(upHelper, evaluator, refHelper, NS,
268
                        "source-roots", false, "src.{0}{1}.dir");
269
                SourceRoots test = SourceRoots.create(upHelper, evaluator, refHelper, NS,
270
                        "test-roots", false, "test.{0}{1}.dir");
271
                lookup = Lookups.fixed(
272
                    aux,
273
                    new TestSources(helper, evaluator, src, test),
274
                    new ClassPathProviderImpl(this.helper, evaluator, src, test),
275
                    QuerySupport.createCompiledSourceForBinaryQuery(helper, evaluator, src, test),
276
                    QuerySupport.createBinaryForSourceQueryImplementation(src, test, helper, evaluator),
277
                    QuerySupport.createUnitTestForSourceQuery(src, test),
278
                    QuerySupport.createSourceLevelQuery(evaluator),
279
                    QuerySupport.createFileBuiltQuery(helper, evaluator, src, test),
280
                    QuerySupport.createFileEncodingQuery(evaluator, "encoding")
281
                );
282
            }
283
            return lookup;
284
        }
285
    }
286
    /** Simplified copy of J2SESources. */
287
    private static class TestSources implements Sources, PropertyChangeListener, ChangeListener {
288
        private final AntProjectHelper helper;
289
        private final PropertyEvaluator evaluator;
290
        private final SourceRoots sourceRoots;
291
        private final SourceRoots testRoots;
292
        private SourcesHelper sourcesHelper;
293
        private Sources delegate;
294
        private final ChangeSupport changeSupport = new ChangeSupport(this);
295
        TestSources(AntProjectHelper helper, PropertyEvaluator evaluator, SourceRoots sourceRoots, SourceRoots testRoots) {
296
            this.helper = helper;
297
            this.evaluator = evaluator;
298
            this.evaluator.addPropertyChangeListener(this);
299
            this.sourceRoots = sourceRoots;
300
            this.sourceRoots.addPropertyChangeListener(this);
301
            this.testRoots = testRoots;
302
            this.testRoots.addPropertyChangeListener(this);
303
            initSources();
304
        }
305
        public SourceGroup[] getSourceGroups(final String type) {
306
            return ProjectManager.mutex().readAccess(new Mutex.Action<SourceGroup[]>() {
307
                public SourceGroup[] run() {
308
                    Sources _delegate;
309
                    synchronized (TestSources.this) {
310
                        if (delegate == null) {
311
                            delegate = initSources();
312
                            delegate.addChangeListener(TestSources.this);
313
                        }
314
                        _delegate = delegate;
315
                    }
316
                    return _delegate.getSourceGroups(type);
317
                }
318
            });
319
        }
320
        private Sources initSources() {
321
            sourcesHelper = new SourcesHelper(helper, evaluator);
322
            register(sourceRoots);
323
            register(testRoots);
324
            sourcesHelper.addNonSourceRoot("${build.dir}");
325
            return sourcesHelper.createSources();
326
        }
327
        private void register(SourceRoots roots) {
328
            String[] propNames = roots.getRootProperties();
329
            String[] rootNames = roots.getRootNames();
330
            for (int i = 0; i < propNames.length; i++) {
331
                String prop = propNames[i];
332
                String displayName = roots.getRootDisplayName(rootNames[i], prop);
333
                String loc = "${" + prop + "}";
334
                sourcesHelper.addPrincipalSourceRoot(loc, displayName, null, null);
335
                sourcesHelper.addTypedSourceRoot(loc, JavaProjectConstants.SOURCES_TYPE_JAVA, displayName, null, null);
336
            }
337
        }
338
        public void addChangeListener(ChangeListener changeListener) {
339
            changeSupport.addChangeListener(changeListener);
340
        }
341
        public void removeChangeListener(ChangeListener changeListener) {
342
            changeSupport.removeChangeListener(changeListener);
343
        }
344
        private void fireChange() {
345
            synchronized (this) {
346
                if (delegate != null) {
347
                    delegate.removeChangeListener(this);
348
                    delegate = null;
349
                }
350
            }
351
            changeSupport.fireChange();
352
        }
353
        public void propertyChange(PropertyChangeEvent evt) {
354
            String propName = evt.getPropertyName();
355
            if (SourceRoots.PROP_ROOT_PROPERTIES.equals(propName) || "build.dir".equals(propName)) {
356
                this.fireChange();
357
            }
358
        }
359
        public void stateChanged(ChangeEvent event) {
360
            this.fireChange();
361
        }
362
    }
363
364
}
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProject.java (+3 lines)
 Lines 584-589    Link Here 
584
                                if (!ep.containsKey(ProjectProperties.EXCLUDES)) {
584
                                if (!ep.containsKey(ProjectProperties.EXCLUDES)) {
585
                                    ep.setProperty(ProjectProperties.EXCLUDES, ""); // NOI18N
585
                                    ep.setProperty(ProjectProperties.EXCLUDES, ""); // NOI18N
586
                                }
586
                                }
587
                                if (!ep.containsKey("build.generated.dir")) { // NOI18N
588
                                    ep.setProperty("build.generated.dir", "${build.dir}/generated-sources"); // NOI18N
589
                                }
587
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
590
                                helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
588
                                try {
591
                                try {
589
                                    ProjectManager.getDefault().saveProject(J2SEProject.this);
592
                                    ProjectManager.getDefault().saveProject(J2SEProject.this);
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/J2SEProjectGenerator.java (+1 lines)
 Lines 297-302    Link Here 
297
        ep.setProperty("build.dir", "build"); // NOI18N
297
        ep.setProperty("build.dir", "build"); // NOI18N
298
        ep.setComment("build.dir", new String[] {"# " + NbBundle.getMessage(J2SEProjectGenerator.class, "COMMENT_build.dir")}, false); // NOI18N
298
        ep.setComment("build.dir", new String[] {"# " + NbBundle.getMessage(J2SEProjectGenerator.class, "COMMENT_build.dir")}, false); // NOI18N
299
        ep.setProperty("build.classes.dir", "${build.dir}/classes"); // NOI18N
299
        ep.setProperty("build.classes.dir", "${build.dir}/classes"); // NOI18N
300
        ep.setProperty("build.generated.dir", "${build.dir}/generated-sources"); // NOI18N
300
        ep.setProperty("build.test.classes.dir", "${build.dir}/test/classes"); // NOI18N
301
        ep.setProperty("build.test.classes.dir", "${build.dir}/test/classes"); // NOI18N
301
        ep.setProperty("build.test.results.dir", "${build.dir}/test/results"); // NOI18N
302
        ep.setProperty("build.test.results.dir", "${build.dir}/test/results"); // NOI18N
302
        ep.setProperty("build.classes.excludes", "**/*.java,**/*.form"); // NOI18N
303
        ep.setProperty("build.classes.excludes", "**/*.java,**/*.form"); // NOI18N
(-)a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/resources/build-impl.xsl (-2 / +28 lines)
 Lines 337-342    Link Here 
337
                        <xsl:attribute name="name">sourcepath</xsl:attribute>
337
                        <xsl:attribute name="name">sourcepath</xsl:attribute>
338
                        <xsl:attribute name="default">/does/not/exist</xsl:attribute>
338
                        <xsl:attribute name="default">/does/not/exist</xsl:attribute>
339
                    </attribute>
339
                    </attribute>
340
                    <attribute>
341
                        <xsl:attribute name="name">gensrcdir</xsl:attribute>
342
                        <xsl:attribute name="default">/does/not/exist</xsl:attribute>
343
                    </attribute>
340
                    <element>
344
                    <element>
341
                        <xsl:attribute name="name">customize</xsl:attribute>
345
                        <xsl:attribute name="name">customize</xsl:attribute>
342
                        <xsl:attribute name="optional">true</xsl:attribute>
346
                        <xsl:attribute name="optional">true</xsl:attribute>
 Lines 361-366    Link Here 
361
                                <xsl:attribute name="tempdir">${java.io.tmpdir}</xsl:attribute> <!-- XXX cf. #51482, Ant #29391 -->
365
                                <xsl:attribute name="tempdir">${java.io.tmpdir}</xsl:attribute> <!-- XXX cf. #51482, Ant #29391 -->
362
                            </xsl:if>
366
                            </xsl:if>
363
                            <xsl:attribute name="includeantruntime">false</xsl:attribute>
367
                            <xsl:attribute name="includeantruntime">false</xsl:attribute>
368
                            <src>
369
                                <dirset dir="@{{gensrcdir}}">
370
                                    <include name="*"/>
371
                                </dirset>
372
                            </src>
364
                            <classpath>
373
                            <classpath>
365
                                <path path="@{{classpath}}"/>
374
                                <path path="@{{classpath}}"/>
366
                            </classpath>
375
                            </classpath>
 Lines 775-786    Link Here 
775
            </target>
784
            </target>
776
            
785
            
777
            <target name="-compile-depend" if="do.depend.true">
786
            <target name="-compile-depend" if="do.depend.true">
778
                <j2seproject3:depend/>
787
                <pathconvert property="build.generated.subdirs">
788
                    <dirset dir="${{build.generated.dir}}">
789
                        <include name="*"/>
790
                    </dirset>
791
                </pathconvert>
792
                <j2seproject3:depend>
793
                    <xsl:attribute name="srcdir">
794
                        <xsl:call-template name="createPath">
795
                            <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
796
                        </xsl:call-template>
797
                        <xsl:text>:${build.generated.subdirs}</xsl:text>
798
                    </xsl:attribute>
799
                </j2seproject3:depend>
779
            </target>
800
            </target>
780
            <target name="-do-compile">
801
            <target name="-do-compile">
781
                <xsl:attribute name="depends">init,deps-jar,-pre-pre-compile,-pre-compile<xsl:if test="/p:project/p:configuration/jaxrpc:web-service-clients/jaxrpc:web-service-client">,web-service-client-compile</xsl:if>,-compile-depend</xsl:attribute>
802
                <xsl:attribute name="depends">init,deps-jar,-pre-pre-compile,-pre-compile<xsl:if test="/p:project/p:configuration/jaxrpc:web-service-clients/jaxrpc:web-service-client">,web-service-client-compile</xsl:if>,-compile-depend</xsl:attribute>
782
                <xsl:attribute name="if">have.sources</xsl:attribute>
803
                <xsl:attribute name="if">have.sources</xsl:attribute>
783
                <j2seproject3:javac/>
804
                <j2seproject3:javac gensrcdir="${{build.generated.dir}}"/>
784
                <copy todir="${{build.classes.dir}}">
805
                <copy todir="${{build.classes.dir}}">
785
                    <xsl:call-template name="createFilesets">
806
                    <xsl:call-template name="createFilesets">
786
                        <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
807
                        <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
 Lines 817-822    Link Here 
817
                            <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
838
                            <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
818
                        </xsl:call-template>
839
                        </xsl:call-template>
819
                    </xsl:attribute>
840
                    </xsl:attribute>
841
                    <xsl:attribute name="gensrcdir">${build.generated.dir}</xsl:attribute>
820
                </xsl:element>
842
                </xsl:element>
821
            </target>
843
            </target>
822
            
844
            
 Lines 1089-1094    Link Here 
1089
                        <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
1111
                        <xsl:with-param name="roots" select="/p:project/p:configuration/j2seproject3:data/j2seproject3:source-roots"/>
1090
                        <xsl:with-param name="includes2">**/*.java</xsl:with-param>
1112
                        <xsl:with-param name="includes2">**/*.java</xsl:with-param>
1091
                    </xsl:call-template>
1113
                    </xsl:call-template>
1114
                    <fileset>
1115
                        <xsl:attribute name="dir">${build.generated.dir}</xsl:attribute>
1116
                        <include name="**/*.java"/>
1117
                    </fileset>
1092
                </javadoc>
1118
                </javadoc>
1093
            </target>
1119
            </target>
1094
            
1120
            

Return to bug 105645
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo