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

(-)a/ide.kit/test/qa-functional/data/blacklist.txt (+3 lines)
Lines 550-552 Link Here
550
org.netbeans.modules.project.ui.groups.GroupOptionProcessor
550
org.netbeans.modules.project.ui.groups.GroupOptionProcessor
551
org.netbeans.modules.project.ui.groups.Bundle
551
org.netbeans.modules.project.ui.groups.Bundle
552
org.netbeans.modules.openfile.Handler
552
org.netbeans.modules.openfile.Handler
553
554
#193549
555
org.netbeans.modules.maven.NbMavenProjectFactory
(-)a/ide.kit/test/qa-functional/data/whitelist_3.txt (-1 lines)
Lines 1517-1523 Link Here
1517
org.netbeans.modules.ide.ergonomics.fod.FeatureProjectFactory$Data
1517
org.netbeans.modules.ide.ergonomics.fod.FeatureProjectFactory$Data
1518
org.netbeans.modules.localhistory.store.LocalHistoryStoreImpl$StoreDataFile
1518
org.netbeans.modules.localhistory.store.LocalHistoryStoreImpl$StoreDataFile
1519
org.netbeans.modules.localhistory.utils.FileUtils
1519
org.netbeans.modules.localhistory.utils.FileUtils
1520
org.netbeans.modules.maven.NbMavenProjectFactory
1521
org.netbeans.modules.maven.hints.pom.TaskListBridge
1520
org.netbeans.modules.maven.hints.pom.TaskListBridge
1522
org.netbeans.modules.maven.queries.MavenFileOwnerQueryImpl
1521
org.netbeans.modules.maven.queries.MavenFileOwnerQueryImpl
1523
org.netbeans.modules.maven.queries.RepositorySourceForBinaryQueryImpl
1522
org.netbeans.modules.maven.queries.RepositorySourceForBinaryQueryImpl
(-)a/maven/src/org/netbeans/modules/maven/NbMavenProjectFactory.java (-14 / +6 lines)
Lines 45-65 Link Here
45
import java.io.File;
45
import java.io.File;
46
import java.io.IOException;
46
import java.io.IOException;
47
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.Project;
48
import org.netbeans.api.project.ProjectManager;
49
import org.netbeans.spi.project.ProjectFactory;
48
import org.netbeans.spi.project.ProjectFactory;
50
import org.netbeans.spi.project.ProjectFactory2;
51
import org.netbeans.spi.project.ProjectState;
49
import org.netbeans.spi.project.ProjectState;
52
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.FileObject;
53
import org.openide.filesystems.FileUtil;
51
import org.openide.filesystems.FileUtil;
54
import org.openide.util.ImageUtilities;
55
import org.openide.util.lookup.ServiceProvider;
56
52
57
/**
53
/**
58
 * factory of maven projects
54
 * factory of maven projects
59
 * @author  Milos Kleint
55
 * @author  Milos Kleint
60
 */
56
 */
61
@ServiceProvider(service=ProjectFactory.class, position=666)
57
@ProjectFactory.Registration(
62
public class NbMavenProjectFactory implements ProjectFactory2 {
58
    requiredFile="pom.xml",
59
    iconBase="org/netbeans/modules/maven/resources/Maven2Icon.gif",
60
    position=666
61
)
62
public class NbMavenProjectFactory implements ProjectFactory {
63
    
63
    
64
    public @Override boolean isProject(FileObject fileObject) {
64
    public @Override boolean isProject(FileObject fileObject) {
65
        File projectDir = FileUtil.toFile(fileObject);
65
        File projectDir = FileUtil.toFile(fileObject);
Lines 84-97 Link Here
84
        return true;
84
        return true;
85
    }
85
    }
86
86
87
    public @Override ProjectManager.Result isProject2(FileObject projectDirectory) {
88
        if (isProject(projectDirectory)) {
89
            return new ProjectManager.Result(ImageUtilities.loadImageIcon("org/netbeans/modules/maven/resources/Maven2Icon.gif", true)); //NOI18N
90
        }
91
        return null;
92
    }
93
94
    
95
    public @Override Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException {
87
    public @Override Project loadProject(FileObject fileObject, ProjectState projectState) throws IOException {
96
        if (!isProject(fileObject)) {
88
        if (!isProject(fileObject)) {
97
            return null;
89
            return null;
(-)a/projectapi/apichanges.xml (+15 lines)
Lines 108-113 Link Here
108
108
109
    <changes>
109
    <changes>
110
110
111
        <change id="ProjectFactory.Registration">
112
            <api name="general"/>
113
            <summary>Register ProjectFactory lazily</summary>
114
            <version major="1" minor="43"/>
115
            <date day="24" month="1" year="2012"/>
116
            <author login="jtulach"/>
117
            <compatibility source="compatible" binary="compatible" addition="yes" semantic="compatible"/>
118
            <description>
119
                <p>
120
                    New lazy annotation to register <code>ProjectFactory</code>.
121
                </p>
122
            </description>
123
            <class package="org.netbeans.spi.project" name="ProjectFactory"/>
124
            <issue number="193549"/>
125
        </change>
111
        <change id="SourceGroup.contains.IAE">
126
        <change id="SourceGroup.contains.IAE">
112
            <api name="general"/>
127
            <api name="general"/>
113
            <summary><code>SourceGroup.contains</code> no longer throws <code>IllegalArgumentException</code></summary>
128
            <summary><code>SourceGroup.contains</code> no longer throws <code>IllegalArgumentException</code></summary>
(-)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.42
4
OpenIDE-Module-Specification-Version: 1.43
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
(-)acea8f51d3d5 (+130 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.projectapi;
44
45
import java.io.IOException;
46
import java.util.ArrayList;
47
import java.util.List;
48
import java.util.Map;
49
import org.netbeans.api.project.Project;
50
import org.netbeans.api.project.ProjectManager.Result;
51
import org.netbeans.spi.project.ProjectFactory;
52
import org.netbeans.spi.project.ProjectFactory2;
53
import org.netbeans.spi.project.ProjectState;
54
import org.openide.filesystems.FileObject;
55
import org.openide.util.ImageUtilities;
56
57
/**
58
 *
59
 * @author Jaroslav Tulach <jtulach@netbeans.org>
60
 */
61
public final class GenericProjectFactory implements ProjectFactory2 {
62
    private final List<String> relativeFiles;
63
    private final Map<?,?> map;
64
    private volatile ProjectFactory delegate;
65
66
    private GenericProjectFactory(Map<?,?> map) {
67
        this.map = map;
68
        List<String> arr = new ArrayList<String>();
69
        for (int cnt = 0;; cnt++) {
70
            Object attr = map.get("relativeFile." + cnt); // NOI18N
71
            if (attr instanceof String) {
72
                arr.add((String) attr);
73
            } else {
74
                break;
75
            }
76
        }
77
        this.relativeFiles = arr;
78
    }
79
    
80
    synchronized ProjectFactory delegate() {
81
        if (delegate == null) {
82
            delegate = (ProjectFactory)map.get("delegate"); // NOI18N
83
        }
84
        return delegate;
85
    }
86
    
87
    public static GenericProjectFactory create(Map fo) {
88
        return new GenericProjectFactory(fo);
89
    }
90
    
91
    @Override
92
    public Result isProject2(FileObject projectDirectory) {
93
        if (isProject(projectDirectory)) {
94
            if (delegate instanceof ProjectFactory2) {
95
                return ((ProjectFactory2)delegate).isProject2(projectDirectory);
96
            }
97
            String iconBase = (String)map.get("iconBase"); // NOI18N
98
            return new Result(ImageUtilities.loadImageIcon(iconBase, true));
99
        }
100
        return null;
101
    }
102
103
    @Override
104
    public boolean isProject(FileObject projectDirectory) {
105
        for (String rp: relativeFiles) {
106
            FileObject fo = projectDirectory.getFileObject(rp);
107
            if (fo != null) {
108
                return true;
109
            }
110
        }
111
        return false;
112
    }
113
114
    @Override
115
    public Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException {
116
        if (isProject(projectDirectory)) {
117
            return delegate().loadProject(projectDirectory, state);
118
        } else {
119
            return null;
120
        }
121
    }
122
123
    @Override
124
    public void saveProject(Project project) throws IOException, ClassCastException {
125
        if (delegate != null) {
126
            delegate.saveProject(project);
127
        }
128
    }
129
130
}
(-)acea8f51d3d5 (+95 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.projectapi;
44
45
import java.util.Collections;
46
import java.util.Set;
47
import javax.annotation.processing.Processor;
48
import javax.annotation.processing.RoundEnvironment;
49
import javax.annotation.processing.SupportedAnnotationTypes;
50
import javax.annotation.processing.SupportedSourceVersion;
51
import javax.lang.model.SourceVersion;
52
import javax.lang.model.element.Element;
53
import javax.lang.model.element.TypeElement;
54
import org.netbeans.spi.project.ProjectFactory;
55
import org.netbeans.spi.project.ProjectFactory.Registration;
56
import org.openide.filesystems.annotations.LayerBuilder.File;
57
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
58
import org.openide.filesystems.annotations.LayerGenerationException;
59
import org.openide.util.lookup.ServiceProvider;
60
61
/**
62
 *
63
 * @author Jaroslav Tulach <jtulach@netbeans.org>
64
 */
65
@SupportedSourceVersion(SourceVersion.RELEASE_6)
66
@ServiceProvider(service=Processor.class)
67
public final class GenericProjectProcessor extends LayerGeneratingProcessor {
68
69
    @Override
70
    public Set<String> getSupportedAnnotationTypes() {
71
        return Collections.singleton(Registration.class.getCanonicalName());
72
    }
73
    
74
    
75
    
76
    @Override
77
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
78
        for (Element e : roundEnv.getElementsAnnotatedWith(Registration.class)) {
79
            Registration pr = e.getAnnotation(Registration.class);
80
            File f = layer(e).instanceFile("Services/ProjectFactories", null, ProjectFactory.class); // NOI18N
81
            f.methodvalue("instanceCreate", GenericProjectFactory.class.getName(), "create"); // NOI18N
82
            f.instanceAttribute("delegate", ProjectFactory.class); // NOI18N
83
            if (!pr.iconBase().isEmpty()) {
84
                f.stringvalue("iconBase", pr.iconBase()); // NOI18N
85
            }
86
            f.position(pr.position());
87
            int cnt = 0;
88
            for (String p : pr.requiredFile()) {
89
                f.stringvalue("relativeFile." + cnt++, p); // NOI18N
90
            }
91
            f.write();
92
        }
93
        return true;
94
    }
95
}
(-)a/projectapi/src/org/netbeans/spi/project/ProjectFactory.java (+29 lines)
Lines 45-50 Link Here
45
package org.netbeans.spi.project;
45
package org.netbeans.spi.project;
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.lang.annotation.ElementType;
49
import java.lang.annotation.Retention;
50
import java.lang.annotation.RetentionPolicy;
51
import java.lang.annotation.Target;
48
import org.netbeans.api.project.Project;
52
import org.netbeans.api.project.Project;
49
import org.netbeans.api.project.ProjectManager;
53
import org.netbeans.api.project.ProjectManager;
50
import org.openide.filesystems.FileObject;
54
import org.openide.filesystems.FileObject;
Lines 96-99 Link Here
96
     */
100
     */
97
    void saveProject(Project project) throws IOException, ClassCastException;
101
    void saveProject(Project project) throws IOException, ClassCastException;
98
    
102
    
103
    /** Registers a project factory in a lazy way. The factory instance creation
104
     * is delayed until one of files specified by {@link #requiredFile()} appears
105
     * on the disk. As soon as the real factory is created all operations are
106
     * delegated to it. The factory may implement {@link ProjectFactory2} or
107
     * directly specify path to icon via {@link #iconBase} attribute.
108
     * 
109
     * @since 1.43
110
     */
111
    @Retention(RetentionPolicy.SOURCE)
112
    @Target({ ElementType.METHOD, ElementType.TYPE })
113
    public @interface Registration {
114
        /** Relative path(s) to file under the project directory which
115
         * must be present to activate this factory. If more than one path
116
         * is specified, then presence of any of these files activates the
117
         * factory.
118
         * @return relative path(s) to files that trigger this registration
119
         */
120
        public String[] requiredFile();
121
        /** Path to icon to represent the project. 
122
         */
123
        public String iconBase() default "";
124
125
        /** The relative position of the registration */
126
        public int position() default Integer.MAX_VALUE;
127
    }
99
}
128
}
(-)acea8f51d3d5 (+117 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.spi.project;
43
44
import java.io.IOException;
45
import javax.swing.Icon;
46
import org.netbeans.api.project.Project;
47
import org.netbeans.api.project.ProjectManager;
48
import org.netbeans.api.project.ProjectManager.Result;
49
import org.netbeans.junit.NbTestCase;
50
import org.openide.filesystems.FileObject;
51
import org.openide.filesystems.FileUtil;
52
import org.openide.modules.ModuleInfo;
53
import org.openide.util.ImageUtilities;
54
import org.openide.util.Lookup;
55
56
public class ProjectFactoryTest extends NbTestCase {
57
    private FileObject dir;
58
    static boolean created;
59
    
60
    public ProjectFactoryTest(String n) {
61
        super(n);
62
    }
63
64
    @Override
65
    protected void setUp() throws Exception {
66
        clearWorkDir();
67
        Lookup.getDefault().lookup(ModuleInfo.class);
68
        FileObject root = FileUtil.toFileObject(getWorkDir());
69
        FileObject fo = FileUtil.createData(root, "dir/project/mark");
70
        dir = fo.getParent();
71
    }
72
73
    public void testRecognizeDirectory() throws Exception {
74
        Project r1 = ProjectManager.getDefault().findProject(dir.getParent());
75
        assertNull("Not a project", r1);
76
        assertFalse("Not created yet", created);
77
        
78
        assertTrue("Project recognized", ProjectManager.getDefault().isProject(dir));
79
        Result r3 = ProjectManager.getDefault().isProject2(dir);
80
        assertNotNull("Project found", r3);
81
        assertEquals("Icons are the same", icon(), r3.getIcon());
82
        assertFalse("Factory not yet created", created);
83
        
84
        Project r2 = ProjectManager.getDefault().findProject(dir);
85
        assertNull("Again not recognized, but via factory", r2);
86
        assertTrue("Factory created", created);
87
    }
88
    
89
    private static final String PATH = "org/netbeans.api/project/resources/icon-1.png";
90
    private static Icon icon() {
91
        return ImageUtilities.loadImageIcon(PATH, true);
92
    }
93
94
    @ProjectFactory.Registration(
95
        iconBase=PATH,
96
        requiredFile="mark"
97
    )
98
    public static final class Fact implements ProjectFactory {
99
        public Fact() {
100
            created = true;
101
        }
102
        
103
        @Override
104
        public boolean isProject(FileObject projectDirectory) {
105
            return projectDirectory.getFileObject("mark") != null;
106
        }
107
108
        @Override
109
        public Project loadProject(FileObject projectDirectory, ProjectState state) throws IOException {
110
            return null;
111
        }
112
113
        @Override
114
        public void saveProject(Project project) throws IOException, ClassCastException {
115
        }
116
    }
117
}

Return to bug 193549