---------------------
PatchSet 1782
Date: 2005/05/02 09:58:18
Author: jlahoda
Log:
Fix for #58467: Cannot create a new freeform project inside of another project
Members:
freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java:1.19->1.20
freeform/test/unit/data/example-projects/freeforminside/build.xml:INITIAL->1.1
freeform/test/unit/data/example-projects/freeforminside/FreeForm/build.xml:INITIAL->1.1
freeform/test/unit/data/example-projects/freeforminside/FreeForm/src/javaapplication1/Main.java:INITIAL->1.1
freeform/test/unit/data/example-projects/freeforminside/nbproject/project.xml:INITIAL->1.1
freeform/test/unit/data/example-projects/freeforminside/src/javaapplication1/Main.java:INITIAL->1.1
freeform/test/unit/data/example-projects/simple3/build.xml:INITIAL->1.1
freeform/test/unit/data/example-projects/simple3/src/javaapplication1/Main.java:INITIAL->1.1
freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanelTest.java:INITIAL->1.1
Index: freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java
===================================================================
RCS file: /cvs/ant/freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java 28 Feb 2005 14:10:53 -0000 1.19
+++ freeform/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanel.java 2 May 2005 08:58:18 -0000 1.20
@@ -7,7 +7,7 @@
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
- * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
* Microsystems, Inc. All Rights Reserved.
*/
@@ -126,14 +126,24 @@
if (getAsFile(projectFolder.getText() + File.separatorChar + "nbproject").exists()){ // NOI18N
return org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_8");
}
+
Project p;
- if ((p=FileOwnerQuery.getOwner(getProjectFolder().toURI()))!=null) {
+ File projectFolder = getProjectFolder();
+
+ assert projectFolder != null;
+
+ if ((p = FileOwnerQuery.getOwner(projectFolder.toURI())) != null && projectFolder.equals(FileUtil.toFile(p.getProjectDirectory()))) {
ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
String displayName = (pi == null ? "" : pi.getDisplayName()); //NOI18N
return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
new Object[] {displayName});
}
- if ((p=FileOwnerQuery.getOwner(getProjectLocation().toURI()))!=null) {
+
+ File projectLocation = getProjectLocation();
+
+ assert projectLocation != null;
+
+ if ((p = FileOwnerQuery.getOwner(projectLocation.toURI())) != null && projectLocation.equals(FileUtil.toFile(p.getProjectDirectory()))) {
ProjectInformation pi = (ProjectInformation) p.getLookup().lookup(ProjectInformation.class);
String displayName = (pi == null ? "" : pi.getDisplayName()); //NOI18N
return MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
--- freeform/test/unit/data/example-projects/freeforminside/build.xml 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/freeforminside/build.xml 2005-05-02 13:47:09.079754000 +0200
@@ -0,0 +1,4 @@
+
+
+
+
--- freeform/test/unit/data/example-projects/freeforminside/FreeForm/build.xml 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/freeforminside/FreeForm/build.xml 2005-05-02 13:47:10.866142000 +0200
@@ -0,0 +1,4 @@
+
+
+
+
--- freeform/test/unit/data/example-projects/freeforminside/FreeForm/src/javaapplication1/Main.java 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/freeforminside/FreeForm/src/javaapplication1/Main.java 2005-05-02 13:47:12.911359000 +0200
@@ -0,0 +1,4 @@
+package javaapplication1;
+
+public class Main {
+}
--- freeform/test/unit/data/example-projects/freeforminside/nbproject/project.xml 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/freeforminside/nbproject/project.xml 2005-05-02 13:47:14.953925000 +0200
@@ -0,0 +1,149 @@
+
+
+ org.netbeans.modules.ant.freeform
+
+
+ Simple Freeform Project
+
+ build.properties
+ ${build.properties}
+
+
+
+
+ java
+ ${src.dir}
+
+
+
+ java
+ ${ant.src.dir}
+
+
+
+
+
+ jar
+
+
+ clean
+
+
+ clean
+ jar
+
+
+ start
+
+
+ build-javadoc
+ true
+
+
+ compile-some-files
+
+ files
+ ${src.dir}
+ \.java$
+ relative-path
+
+ ,
+
+
+
+
+ ant-compile-some-files
+
+ files
+ ${ant.src.dir}
+ \.java$
+ relative-path
+
+ ,
+
+
+
+
+ start-with-specified-class
+
+ class
+ ${src.dir}
+ \.java$
+ java-name
+
+
+
+
+
+
+
+ jar
+ ${main.jar}
+ jar
+
+
+
+
+
+ ${src.dir}
+
+
+
+ ${ant.src.dir}
+
+
+
+ xdocs
+
+
+ build.xml
+
+
+ build.properties
+
+
+
+
+
+
+
+
+
+
+
+
+ generate-xdocs
+ true
+
+
+
+
+ dist
+
+
+
+
+
+
+ ${src.dir}
+ ${src.cp}
+ ${classes.dir}
+ ${main.jar}
+ 1.4
+
+
+ ${ant.src.dir}
+ ${ant.src.cp}
+ ${ant.classes.dir}
+ 1.4
+
+
+
+
--- freeform/test/unit/data/example-projects/freeforminside/src/javaapplication1/Main.java 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/freeforminside/src/javaapplication1/Main.java 2005-05-02 13:47:17.044696000 +0200
@@ -0,0 +1,4 @@
+package javaapplication1;
+
+public class Main {
+}
--- freeform/test/unit/data/example-projects/simple3/build.xml 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/simple3/build.xml 2005-05-02 13:47:19.179063000 +0200
@@ -0,0 +1,4 @@
+
+
+
+
--- freeform/test/unit/data/example-projects/simple3/src/javaapplication1/Main.java 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/data/example-projects/simple3/src/javaapplication1/Main.java 2005-05-02 13:47:21.222462000 +0200
@@ -0,0 +1,4 @@
+package javaapplication1;
+
+public class Main {
+}
--- freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanelTest.java 2005-04-28 09:57:16.121354296 +0200
+++ freeform/test/unit/src/org/netbeans/modules/ant/freeform/ui/BasicProjectInfoPanelTest.java 2005-05-02 13:47:23.261378000 +0200
@@ -0,0 +1,157 @@
+/*
+ * Sun Public License Notice
+ *
+ * The contents of this file are subject to the Sun Public License
+ * Version 1.0 (the "License"). You may not use this file except in
+ * compliance with the License. A copy of the License is available at
+ * http://www.sun.com/
+ *
+ * The Original Code is NetBeans. The Initial Developer of the Original
+ * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+
+package org.netbeans.modules.ant.freeform.ui;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import junit.framework.*;
+import java.io.File;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.modules.ant.freeform.TestBase;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+
+/**
+ *
+ * @author Jan Lahoda
+ */
+public class BasicProjectInfoPanelTest extends TestBase {
+
+ private File outterProjectDir;
+ private FileObject outterProjectDirFO;
+ private Project outterProject;
+ private File innerProjectDir;
+ private File innerAntScript;
+ private File simple3Dir;
+ private File simple3AntScript;
+ private File outterProjectNBProjectDir;
+
+ public BasicProjectInfoPanelTest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ File outterProjectDirOriginal = FileUtil.normalizeFile(new File(egdir, "freeforminside"));
+ File simple3DirOriginal = FileUtil.normalizeFile(new File(egdir, "simple3"));
+
+ assertTrue("freeforminside directory (" + outterProjectDirOriginal + ") exists", outterProjectDirOriginal.exists());
+ assertTrue("simple3 directory (" + simple3DirOriginal + ") exists", simple3DirOriginal.exists());
+
+ outterProjectDir = copyFolder(outterProjectDirOriginal);
+ simple3Dir = copyFolder(simple3DirOriginal);
+
+ assertTrue("freeforminside directory copy exists", outterProjectDir.exists());
+ assertTrue("simple3 directory copy exists", simple3Dir.exists());
+
+ outterProjectDirFO = FileUtil.toFileObject(outterProjectDir);
+ assertNotNull("have FileObject for " + outterProjectDir, outterProjectDirFO);
+ outterProject = ProjectManager.getDefault().findProject(outterProjectDirFO);
+ assertNotNull("have a project", outterProject);
+ outterProjectNBProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "nbproject"));
+ assertNotNull("found nbproject directory", outterProjectNBProjectDir);
+ innerProjectDir = FileUtil.normalizeFile(new File(outterProjectDir, "FreeForm"));
+ assertTrue("inner directory (" + innerProjectDir + ") exists", innerProjectDir.exists());
+ innerAntScript = FileUtil.normalizeFile(new File(innerProjectDir, "build.xml"));
+ assertTrue("inner ant script (" + innerAntScript + ") exists", innerAntScript.exists());
+ simple3AntScript = FileUtil.normalizeFile(new File(simple3Dir, "build.xml"));
+ assertTrue("simple3 ant script (" + simple3AntScript + ") exists", simple3AntScript.exists());
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(BasicProjectInfoPanelTest.class);
+
+ return suite;
+ }
+
+ private boolean deepDelete(File f) throws IOException {
+ if (f.isDirectory()) {
+ File[] children = f.listFiles();
+
+ for (int cntr = 0; cntr < children.length; cntr++) {
+ if (!deepDelete(children[cntr]))
+ return false;
+ }
+ }
+
+ return f.delete();
+ }
+
+ /**The BasicProjectInfoPanel should allow creation of a freeform project in the directory hierarchy under
+ * another project, but should refuse to create a project in place of another (loaded, but deleted)
+ * project. See issues #58467 and #55533.
+ */
+ public void testGetError1() throws Exception {
+ BasicProjectInfoPanel panel;
+ String error;
+
+ panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null);
+
+ assertNull("allow creation (#58467)", panel.getError());
+
+ //delete the outter/nbproject directory and try to create a new project here:
+ assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
+
+ panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null);
+
+ error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
+ new Object[] {"Simple Freeform Project"});
+
+ assertEquals("do not allow creation (#55533)", error, panel.getError());
+ }
+
+ public void testGetError2() throws Exception {
+ BasicProjectInfoPanel panel;
+ String error;
+
+ panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", innerProjectDir.getAbsolutePath(), null);
+
+ assertNull("allow creation (#58467)", panel.getError());
+
+ //delete the outter/nbproject directory and try to create a new project here:
+ assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
+
+ panel = new BasicProjectInfoPanel(simple3Dir.getAbsolutePath(), simple3AntScript.getAbsolutePath(), "NAME", outterProjectDir.getAbsolutePath(), null);
+
+ error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_9"),
+ new Object[] {"Simple Freeform Project"});
+
+ assertEquals("do not allow creation (#55533)", error, panel.getError());
+ }
+
+ public void testGetError3() throws Exception {
+ BasicProjectInfoPanel panel;
+ String error;
+
+ panel = new BasicProjectInfoPanel(innerProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null);
+
+ assertNull("allow creation (#58467)", panel.getError());
+
+ //delete the outter/nbproject directory and try to create a new project here:
+ assertTrue("nbproject deleted succesfully", deepDelete(outterProjectNBProjectDir));
+
+ panel = new BasicProjectInfoPanel(outterProjectDir.getAbsolutePath(), innerAntScript.getAbsolutePath(), "NAME", simple3Dir.getAbsolutePath(), null);
+
+ error = MessageFormat.format(org.openide.util.NbBundle.getMessage(BasicProjectInfoPanel.class, "LBL_BasicProjectInfoPanel_Error_10"),
+ new Object[] {"Simple Freeform Project"});
+
+ assertEquals("do not allow creation (#55533)", error, panel.getError());
+ }
+
+ protected boolean runInEQ() {
+ return true;
+ }
+
+}