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

(-)freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java (-3 / +13 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
13
Lines 126-139 Link Here
126
        if (getAsFile(projectFolder.getText() + File.separatorChar + "nbproject").exists()){ // NOI18N
126
        if (getAsFile(projectFolder.getText() + File.separatorChar + "nbproject").exists()){ // NOI18N
127
            return org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_8");
127
            return org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_8");
128
        }
128
        }
129
        
129
        Project p;
130
        Project p;
130
        if ((p=FileOwnerQuery.getOwner(getProjectFolder().toURI()))!=null) {
131
        File projectFolder = getProjectFolder();
132
        
133
        assert projectFolder != null;
134
        
135
        if ((p = FileOwnerQuery.getOwner(projectFolder.toURI())) != null && projectFolder.equals(FileUtil.toFile(p.getProjectDirectory()))) {
131
            ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
136
            ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
132
            String displayName = (pi == null ? "" : pi.getDisplayName());   //NOI18N
137
            String displayName = (pi == null ? "" : pi.getDisplayName());   //NOI18N
133
            return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
138
            return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
134
                new Object[] {displayName});
139
                new Object[] {displayName});
135
        }
140
        }
136
        if ((p=FileOwnerQuery.getOwner(getProjectLocation().toURI()))!=null) {
141
        
142
        File projectLocation = getProjectLocation();
143
        
144
        assert projectLocation != null;
145
        
146
        if ((p = FileOwnerQuery.getOwner(projectLocation.toURI())) != null && projectLocation.equals(FileUtil.toFile(p.getProjectDirectory()))) {
137
            ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
147
            ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
138
            String displayName = (pi == null ? "" : pi.getDisplayName());   //NOI18N
148
            String displayName = (pi == null ? "" : pi.getDisplayName());   //NOI18N
139
            return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
149
            return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
(-)freeform/test/unit/data/example-projects/freeforminside/build.xml (+4 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="dist" name="simple-freeform-project">
3
    <target name="dist" />
4
</project>
(-)freeform/test/unit/data/example-projects/freeforminside/FreeForm/build.xml (+4 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="dist" name="simple-freeform-project">
3
    <target name="dist" />
4
</project>
(-)freeform/test/unit/data/example-projects/freeforminside/FreeForm/src/javaapplication1/Main.java (+4 lines)
Line 0 Link Here
1
package javaapplication1;
2
3
public class Main {
4
}
(-)freeform/test/unit/data/example-projects/freeforminside/nbproject/project.xml (+149 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.ant.freeform</type>
4
    <configuration>
5
        <general-data xmlns="http://www.netbeans.org/ns/freeform-project/1">
6
            <name>Simple Freeform Project</name>
7
            <properties>
8
                <property name="build.properties">build.properties</property>
9
                <property-file>${build.properties}</property-file>
10
            </properties>
11
            <folders>
12
                <source-folder>
13
                    <label>Main Sources</label>
14
                    <type>java</type>
15
                    <location>${src.dir}</location>
16
                </source-folder>
17
                <source-folder>
18
                    <label>Ant Task Sources</label>
19
                    <type>java</type>
20
                    <location>${ant.src.dir}</location>
21
                </source-folder>
22
                <!--
23
                <build-folder>
24
                    <location>${build.dir}</location>
25
                </build-folder>
26
                <build-folder>
27
                    <location>${dist.dir}</location>
28
                </build-folder>
29
                -->
30
            </folders>
31
            <ide-actions>
32
                <action name="build">
33
                    <target>jar</target>
34
                </action>
35
                <action name="clean">
36
                    <target>clean</target>
37
                </action>
38
                <action name="rebuild">
39
                    <target>clean</target>
40
                    <target>jar</target>
41
                </action>
42
                <action name="run">
43
                    <target>start</target>
44
                </action>
45
                <action name="javadoc">
46
                    <target>build-javadoc</target>
47
                    <property name="from-ide">true</property>
48
                </action>
49
                <action name="compile.single">
50
                    <target>compile-some-files</target>
51
                    <context>
52
                        <property>files</property>
53
                        <folder>${src.dir}</folder>
54
                        <pattern>\.java$</pattern>
55
                        <format>relative-path</format>
56
                        <arity>
57
                            <separated-files>,</separated-files>
58
                        </arity>
59
                    </context>
60
                </action>
61
                <action name="compile.single">
62
                    <target>ant-compile-some-files</target>
63
                    <context>
64
                        <property>files</property>
65
                        <folder>${ant.src.dir}</folder>
66
                        <pattern>\.java$</pattern>
67
                        <format>relative-path</format>
68
                        <arity>
69
                            <separated-files>,</separated-files>
70
                        </arity>
71
                    </context>
72
                </action>
73
                <action name="run.single">
74
                    <target>start-with-specified-class</target>
75
                    <context>
76
                        <property>class</property>
77
                        <folder>${src.dir}</folder>
78
                        <pattern>\.java$</pattern>
79
                        <format>java-name</format>
80
                        <arity>
81
                            <one-file-only/>
82
                        </arity>
83
                    </context>
84
                </action>
85
            </ide-actions>
86
            <export>
87
                <type>jar</type>
88
                <location>${main.jar}</location>
89
                <build-target>jar</build-target>
90
            </export>
91
            <view>
92
                <items>
93
                    <source-folder style="packages">
94
                        <label>Main Sources</label>
95
                        <location>${src.dir}</location>
96
                    </source-folder>
97
                    <source-folder style="packages">
98
                        <label>Ant Task Sources</label>
99
                        <location>${ant.src.dir}</location>
100
                    </source-folder>
101
                    <source-folder style="tree">
102
                        <label>XML Documents</label>
103
                        <location>xdocs</location>
104
                    </source-folder>
105
                    <source-file>
106
                        <location>build.xml</location>
107
                    </source-file>
108
                    <source-file>
109
                        <location>build.properties</location>
110
                    </source-file>
111
                </items>
112
                <context-menu>
113
                    <ide-action name="build"/>
114
                    <ide-action name="clean"/>
115
                    <ide-action name="rebuild"/>
116
                    <separator/>
117
                    <ide-action name="run"/>
118
                    <separator/>
119
                    <ide-action name="javadoc"/>
120
                    <action>
121
                        <label>Generate XDocs</label>
122
                        <target>generate-xdocs</target>
123
                        <property name="from-ide">true</property>
124
                    </action>
125
                    <separator/>
126
                    <action>
127
                        <label>Create Distribution</label>
128
                        <target>dist</target>
129
                    </action>
130
                </context-menu>
131
            </view>
132
        </general-data>
133
        <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/1">
134
            <compilation-unit>
135
                <package-root>${src.dir}</package-root>
136
                <classpath mode="compile">${src.cp}</classpath>
137
                <built-to>${classes.dir}</built-to>
138
                <built-to>${main.jar}</built-to>
139
                <source-level>1.4</source-level>
140
            </compilation-unit>
141
            <compilation-unit>
142
                <package-root>${ant.src.dir}</package-root>
143
                <classpath mode="compile">${ant.src.cp}</classpath>
144
                <built-to>${ant.classes.dir}</built-to>
145
                <source-level>1.4</source-level>
146
            </compilation-unit>
147
        </java-data>
148
    </configuration>
149
</project>
(-)freeform/test/unit/data/example-projects/freeforminside/src/javaapplication1/Main.java (+4 lines)
Line 0 Link Here
1
package javaapplication1;
2
3
public class Main {
4
}
(-)freeform/test/unit/data/example-projects/simple3/build.xml (+4 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="dist" name="simple-freeform-project">
3
    <target name="dist" />
4
</project>
(-)freeform/test/unit/data/example-projects/simple3/src/javaapplication1/Main.java (+4 lines)
Line 0 Link Here
1
package javaapplication1;
2
3
public class Main {
4
}
(-)freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanelTest.java (+157 lines)
Line 0 Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.netbeans.modules.ant.freeform.ui;
15
16
import java.io.IOException;
17
import java.text.MessageFormat;
18
import junit.framework.*;
19
import java.io.File;
20
import org.netbeans.api.project.Project;
21
import org.netbeans.api.project.ProjectManager;
22
import org.netbeans.modules.ant.freeform.TestBase;
23
import org.openide.filesystems.FileObject;
24
import org.openide.filesystems.FileUtil;
25
26
/**
27
 *
28
 * @author Jan Lahoda
29
 */
30
public class BasicProjectInfoPanelTest extends TestBase {
31
    
32
    private File outterProjectDir;
33
    private FileObject outterProjectDirFO;
34
    private Project outterProject;
35
    private File innerProjectDir;
36
    private File innerAntScript;
37
    private File simple3Dir;
38
    private File simple3AntScript;
39
    private File outterProjectNBProjectDir;
40
        
41
    public BasicProjectInfoPanelTest(String testName) {
42
        super(testName);
43
    }
44
45
    protected void setUp() throws Exception {
46
        super.setUp();
47
        File outterProjectDirOriginal = FileUtil.normalizeFile(new File(egdir, "freeforminside"));
48
        File simple3DirOriginal = FileUtil.normalizeFile(new File(egdir, "simple3"));
49
        
50
        assertTrue("freeforminside directory (" + outterProjectDirOriginal + ") exists", outterProjectDirOriginal.exists());
51
        assertTrue("simple3 directory (" + simple3DirOriginal + ") exists", simple3DirOriginal.exists());
52
        
53
        outterProjectDir = copyFolder(outterProjectDirOriginal);
54
        simple3Dir       = copyFolder(simple3DirOriginal);
55
        
56
        assertTrue("freeforminside directory copy exists", outterProjectDir.exists());
57
        assertTrue("simple3 directory copy exists", simple3Dir.exists());
58
        
59
        outterProjectDirFO = FileUtil.toFileObject(outterProjectDir);
60
        assertNotNull("have FileObject for " + outterProjectDir, outterProjectDirFO);
61
        outterProject = ProjectManager.getDefault().findProject(outterProjectDirFO);
62
        assertNotNull("have a project", outterProject);
63
        outterProjectNBProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "nbproject"));
64
        assertNotNull("found nbproject directory", outterProjectNBProjectDir);
65
        innerProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "FreeForm"));
66
        assertTrue("inner directory (" + innerProjectDir + ") exists", innerProjectDir.exists());
67
        innerAntScript = FileUtil.normalizeFile(new File(innerProjectDir, "build.xml"));
68
        assertTrue("inner ant script (" + innerAntScript + ") exists", innerAntScript.exists());
69
        simple3AntScript = FileUtil.normalizeFile(new File(simple3Dir, "build.xml"));
70
        assertTrue("simple3 ant script (" + simple3AntScript + ") exists", simple3AntScript.exists());
71
    }
72
73
    public static Test suite() {
74
        TestSuite suite = new TestSuite(BasicProjectInfoPanelTest.class);
75
        
76
        return suite;
77
    }
78
79
    private boolean deepDelete(File f) throws IOException {
80
        if (f.isDirectory()) {
81
            File[] children = f.listFiles();
82
            
83
            for (int cntr = 0; cntr < children.length; cntr++) {
84
                if (!deepDelete(children[cntr]))
85
                    return false;
86
            }
87
        }
88
        
89
        return f.delete();
90
    }
91
    
92
    /**The BasicProjectInfoPanel should allow creation of a freeform project in the directory hierarchy under
93
     * another project, but should refuse to create a project in place of another (loaded, but deleted)
94
     * project. See issues #58467 and #55533.
95
     */
96
    public void testGetError1() throws Exception {
97
        BasicProjectInfoPanel panel;
98
        String                error;
99
        
100
        panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null);
101
        
102
        assertNull("allow creation (#58467)", panel.getError());
103
        
104
        //delete the outter/nbproject directory and try to create a new project here:
105
        assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
106
        
107
        panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null);
108
        
109
        error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
110
                new Object[] {"Simple Freeform Project"});
111
                
112
        assertEquals("do not allow creation (#55533)", error, panel.getError());
113
    }
114
    
115
    public void testGetError2() throws Exception {
116
        BasicProjectInfoPanel panel;
117
        String                error;
118
        
119
        panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null);
120
        
121
        assertNull("allow creation (#58467)", panel.getError());
122
        
123
        //delete the outter/nbproject directory and try to create a new project here:
124
        assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
125
        
126
        panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null);
127
        
128
        error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
129
                new Object[] {"Simple Freeform Project"});
130
                
131
        assertEquals("do not allow creation (#55533)", error, panel.getError());
132
    }
133
    
134
    public void testGetError3() throws Exception {
135
        BasicProjectInfoPanel panel;
136
        String                error;
137
        
138
        panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null);
139
        
140
        assertNull("allow creation (#58467)", panel.getError());
141
        
142
        //delete the outter/nbproject directory and try to create a new project here:
143
        assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
144
        
145
        panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null);
146
        
147
        error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
148
                new Object[] {"Simple Freeform Project"});
149
                
150
        assertEquals("do not allow creation (#55533)", error, panel.getError());
151
    }
152
153
    protected boolean runInEQ() {
154
        return true;
155
    }
156
    
157
}

Return to bug 58467