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

(-)a/java.project/apichanges.xml (+17 lines)
Lines 106-111 Link Here
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
107
108
    <changes>
108
    <changes>
109
110
        <change id="source-group-modifier-constants">
111
            <api name="general"/>
112
            <summary>Constants for SourceGroupModifier</summary>
113
            <version major="1" minor="24"/>
114
            <date day="18" month="2" year="2009"/>
115
            <author login="mkleint"/>
116
            <compatibility addition="yes"/>
117
            <description>
118
                <p>
119
                    Added a few constants to <code>JavaProjectConstants</code> for use by <code>SourceGroupModifier</code> with relation
120
                    to java projects.
121
                </p>
122
            </description>
123
            <class package="org.netbeans.api.java.project" name="JavaProjectConstants"/>
124
            <issue number="102711"/>
125
        </change>
109
        
126
        
110
        <change id="javadoc-root-and-source-root-detection">
127
        <change id="javadoc-root-and-source-root-detection">
111
            <api name="general"/>
128
            <api name="general"/>
(-)a/java.project/manifest.mf (-1 / +1 lines)
Lines 3-9 Link Here
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/modules/java/project/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/project/Bundle.properties
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
5
OpenIDE-Module-Needs: javax.script.ScriptEngine.freemarker
6
OpenIDE-Module-Specification-Version: 1.23
6
OpenIDE-Module-Specification-Version: 1.24
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
7
OpenIDE-Module-Recommends: org.netbeans.spi.java.project.runner.JavaRunnerImplementation
8
AutoUpdate-Show-In-Client: false
8
AutoUpdate-Show-In-Client: false
9
9
(-)a/java.project/src/org/netbeans/api/java/project/JavaProjectConstants.java (+17 lines)
Lines 62-67 Link Here
62
     */
62
     */
63
    public static final String SOURCES_TYPE_RESOURCES = "resources"; // NOI18N
63
    public static final String SOURCES_TYPE_RESOURCES = "resources"; // NOI18N
64
64
65
66
    /**
67
     * Hint for <code>SourceGroupModifier</code> to create a <code>SourceGroup</code>
68
     * for main project codebase.
69
     * @see org.netbeans.api.project.SourceGroupModifier
70
     * @since org.netbeans.modules.java.project/1 1.24
71
     */
72
    public static final String SOURCES_HINT_MAIN = "main"; //NOI18N
73
74
    /**
75
     * Hint for <code>SourceGroupModifier</code> to create a <code>SourceGroup</code>
76
     * for project's tests.
77
     * @see org.netbeans.api.project.SourceGroupModifier
78
     * @since org.netbeans.modules.java.project/1 1.24
79
     */
80
    public static final String SOURCES_HINT_TEST = "test"; //NOI18N
81
65
    /**
82
    /**
66
     * Standard artifact type representing a JAR file, presumably
83
     * Standard artifact type representing a JAR file, presumably
67
     * used as a Java library of some kind.
84
     * used as a Java library of some kind.
(-)a/maven/nbproject/project.xml (-2 / +2 lines)
Lines 123-129 Link Here
123
                    <compile-dependency/>
123
                    <compile-dependency/>
124
                    <run-dependency>
124
                    <run-dependency>
125
                        <release-version>1</release-version>
125
                        <release-version>1</release-version>
126
                        <specification-version>1.18</specification-version>
126
                        <specification-version>1.24</specification-version>
127
                    </run-dependency>
127
                    </run-dependency>
128
                </dependency>
128
                </dependency>
129
                <dependency>
129
                <dependency>
Lines 194-200 Link Here
194
                    <compile-dependency/>
194
                    <compile-dependency/>
195
                    <run-dependency>
195
                    <run-dependency>
196
                        <release-version>1</release-version>
196
                        <release-version>1</release-version>
197
                        <specification-version>1.22</specification-version>
197
                        <specification-version>1.24</specification-version>
198
                    </run-dependency>
198
                    </run-dependency>
199
                </dependency>
199
                </dependency>
200
                <dependency>
200
                <dependency>
(-)a/maven/src/org/netbeans/modules/maven/MavenSourcesImpl.java (-1 / +32 lines)
Lines 70-75 Link Here
70
import org.netbeans.api.project.Sources;
70
import org.netbeans.api.project.Sources;
71
import org.netbeans.api.queries.SharabilityQuery;
71
import org.netbeans.api.queries.SharabilityQuery;
72
import org.netbeans.modules.maven.spi.nodes.NodeUtils;
72
import org.netbeans.modules.maven.spi.nodes.NodeUtils;
73
import org.netbeans.spi.project.SourceGroupModifierImplementation;
73
import org.netbeans.spi.project.support.GenericSources;
74
import org.netbeans.spi.project.support.GenericSources;
74
import org.openide.filesystems.FileObject;
75
import org.openide.filesystems.FileObject;
75
import org.openide.filesystems.FileUtil;
76
import org.openide.filesystems.FileUtil;
Lines 85-91 Link Here
85
 * IMHO at least..
86
 * IMHO at least..
86
 * @author  Milos Kleint
87
 * @author  Milos Kleint
87
 */
88
 */
88
public class MavenSourcesImpl implements Sources {
89
public class MavenSourcesImpl implements Sources, SourceGroupModifierImplementation {
89
    public static final String TYPE_OTHER = "Resources"; //NOI18N
90
    public static final String TYPE_OTHER = "Resources"; //NOI18N
90
    public static final String TYPE_TEST_OTHER = "TestResources"; //NOI18N
91
    public static final String TYPE_TEST_OTHER = "TestResources"; //NOI18N
91
    public static final String TYPE_GEN_SOURCES = "GeneratedSources"; //NOI18N
92
    public static final String TYPE_GEN_SOURCES = "GeneratedSources"; //NOI18N
Lines 378-383 Link Here
378
        }
379
        }
379
        return changed;
380
        return changed;
380
    }
381
    }
382
383
    public SourceGroup createSourceGroup(String type, String hint) {
384
        assert type != null;
385
        MavenProject mp = project.getOriginalMavenProject();
386
        File folder = null;
387
        if (JavaProjectConstants.SOURCES_TYPE_JAVA.equals(type)) {
388
            if (JavaProjectConstants.SOURCES_HINT_MAIN.equals(hint)) {
389
                folder = FileUtilities.convertStringToFile(mp.getBuild().getSourceDirectory());
390
            }
391
            if (JavaProjectConstants.SOURCES_HINT_TEST.equals(hint)) {
392
                folder = FileUtilities.convertStringToFile(mp.getBuild().getTestSourceDirectory());
393
            }
394
        }
395
        if (folder != null) {
396
            folder.mkdirs();
397
            FileUtil.refreshFor(folder);
398
            checkChanges(false);
399
            FileObject fo = FileUtil.toFileObject(folder);
400
            assert fo != null;
401
            SourceGroup[] grps = getSourceGroups(type);
402
            for (SourceGroup sg : grps) {
403
                if (fo.equals(sg.getRootFolder())) {
404
                    return sg;
405
                }
406
            }
407
            //shall we somehow report it?
408
        }
409
410
        return null;
411
    }
381
    
412
    
382
    
413
    
383
    public static final class OtherGroup implements SourceGroup {
414
    public static final class OtherGroup implements SourceGroup {
(-)a/projectapi/apichanges.xml (+19 lines)
Lines 104-109 Link Here
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
104
    <!-- ACTUAL CHANGES BEGIN HERE: -->
105
105
106
    <changes>
106
    <changes>
107
        <change id="source-group-modifier">
108
            <api name="general"/>
109
            <summary>introduction of SourceGroupModifier, a way to create SourceGroup if missing</summary>
110
            <version major="1" minor="24"/>
111
            <date day="18" month="2" year="2009"/>
112
            <author login="mkleint"/>
113
            <compatibility addition="yes"/>
114
            <description>
115
                <p>
116
                    <code>SourceGroupModifier</code> provides ways of create specific folders (<code>SourceGroup</code> root folders)
117
                    in case they don't exist, eg. cannot be retrieved from <code>Sources</code>.
118
                    The project supporting automated creation of SourceGroup root folders needs to
119
                    provide <code>SourceGroupModifierImplementation</code> in the project's lookup.
120
                </p>
121
            </description>
122
            <class package="org.netbeans.api.project" name="SourceGroupModifier"/>
123
            <class package="org.netbeans.spi.project" name="SourceGroupModifierImplementation"/>
124
            <issue number="102711"/>
125
        </change>
107
126
108
        <change id="projectfactory2">
127
        <change id="projectfactory2">
109
            <api name="general"/>
128
            <api name="general"/>
(-)a/projectapi/manifest.mf (-1 / +1 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
2
OpenIDE-Module: org.netbeans.modules.projectapi/1
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
3
OpenIDE-Module-Install: org/netbeans/modules/projectapi/Installer.class
4
OpenIDE-Module-Specification-Version: 1.23
4
OpenIDE-Module-Specification-Version: 1.24
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
5
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
6
OpenIDE-Module-Layer: org/netbeans/modules/projectapi/layer.xml
7
7
(-)82fe84a414e3 (+131 lines)
Added 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.api.project;
41
42
import org.netbeans.spi.project.SourceGroupModifierImplementation;
43
44
/**
45
 * <code>SourceGroupModifier</code> provides ways of create specific folders ({@link org.netbeans.api.project.SourceGroup} root folders)
46
 * in case they don't exist, eg. cannot be retrieved from {@link org.netbeans.api.project.Sources}
47
 * The project type supporting automated creation of {@link org.netbeans.api.project.SourceGroup} root folders needs to
48
 * provide {@link org.netbeans.spi.project.SourceGroupModifierImplementation} in the project's lookup.
49
 *
50
 * @since org.netbeans.modules.projectapi 1.24
51
 * @author mkleint
52
 */
53
public final class SourceGroupModifier {
54
55
    private SourceGroupModifier() {
56
    }
57
58
    /**
59
     * Creates a {@link org.netbeans.api.project.SourceGroup} in the given {@link org.netbeans.api.project.Project} of the given type and hint.
60
     * Typically a type is a constant for java/groovy/ruby source roots and hint is a constant for main sources or test sources.
61
     * Please consult specific APIs fro the supported types/hints. Eg. <code>JavaProjectConstants</code> for java related project sources.
62
     *
63
     * @param project
64
     * @param type constant for type of sources
65
     * @param hint
66
     * @return the created SourceGroup or null
67
     */
68
    public static final SourceGroup createSourceGroup(Project project, String type, String hint) {
69
        assert project != null;
70
        SourceGroupModifierImplementation impl = project.getLookup().lookup(SourceGroupModifierImplementation.class);
71
        if (impl == null) {
72
            return null;
73
        }
74
        return impl.createSourceGroup(type, hint);
75
    }
76
77
    /**
78
     * Creates a {@link org.netbeans.api.project.SourceGroupModifier.Future} object
79
     * that is capable of lazily creating {@link org.netbeans.api.project.SourceGroup} in the given {@link org.netbeans.api.project.Project} of the given type and hint.
80
     * Typically a type is a constant for java/groovy/ruby source roots and hint is a constant for main sources or test sources.
81
     * Please consult specific APIs fro the supported types/hints. Eg. <code>JavaProjectConstants</code> for java related project sources.
82
     * @param project
83
     * @param type
84
     * @param hint
85
     * @return Future instance that is capable of creating a SourceGroup or null
86
     */
87
    public static final SourceGroupModifier.Future createSourceGroupFuture(Project project, String type, String hint) {
88
        assert project != null;
89
        SourceGroupModifierImplementation impl = project.getLookup().lookup(SourceGroupModifierImplementation.class);
90
        if (impl == null) {
91
            return null;
92
        }
93
        return new Future(impl, type, hint);
94
    }
95
96
    /**
97
     * A wrapper class that is capable of lazily creating a {@link org.netbeans.api.project.SourceGroup} instance.
98
     */
99
    public static final class Future {
100
101
        SourceGroupModifierImplementation impl;
102
        private String hint;
103
        private String type;
104
105
        private Future(SourceGroupModifierImplementation im, String type, String hint) {
106
            this.impl = im;
107
            this.hint = hint;
108
            this.type = type;
109
        }
110
111
        /**
112
         * Create the instance of {@link org.netbeans.api.project.SourceGroup} wrapped by
113
         * this object.
114
         * @param type
115
         * @param hint
116
         * @return
117
         */
118
        public final SourceGroup createSourceGroup() {
119
            return impl.createSourceGroup(type, hint);
120
        }
121
122
123
        public String getType() {
124
            return type;
125
        }
126
127
        public String getHint() {
128
            return hint;
129
        }
130
    }
131
}
(-)82fe84a414e3 (+67 lines)
Added 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.spi.project;
41
42
import org.netbeans.api.project.SourceGroup;
43
44
/**
45
 * The SPI side of {@link org.netbeans.api.project.SourceGroupModifier}.
46
 * Expected to be present in project lookup of project types supporting automated creation
47
 * of {@link org.netbeans.api.project.SourceGroup} root folders.
48
 * @since org.netbeans.modules.projectapi 1.24
49
 * @author mkleint
50
 */
51
public interface SourceGroupModifierImplementation {
52
    /**
53
     * Creates a {@link org.netbeans.api.project.SourceGroup} of the given type and hint.
54
     * Typically a type is a constant for java/groovy/ruby source roots and hint is a constant for main sources or test sources.
55
     * Please consult specific APIs fro the supported types/hints. Eg. <code>JavaProjectConstants</code> for java related project sources.
56
     * If the SourceGroup's type/hint is not supported, the implementation shall silently return null and not throw any exceptions.
57
     * If the SourceGroup of given type/hint already exists it shall be returned as well.
58
     *
59
     * @param project
60
     * @param type constant for type of sources
61
     * @param hint
62
     * @return the created or existing SourceGroup or null
63
     */
64
65
    public SourceGroup createSourceGroup(String type, String hint);
66
67
}

Return to bug 102711