Index: src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java,v retrieving revision 1.12 diff -u -r1.12 JavaProjectGenerator.java --- src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java 12 Apr 2007 13:18:37 -0000 1.12 +++ src/org/netbeans/modules/java/freeform/JavaProjectGenerator.java 2 Oct 2007 08:40:08 -0000 @@ -20,6 +20,7 @@ package org.netbeans.modules.java.freeform; import java.io.File; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -35,6 +36,7 @@ import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; import org.openide.filesystems.FileUtil; +import org.openide.util.Exceptions; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -52,7 +54,7 @@ private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N // this order is not required by schema, but follow it to minimize randomness a bit - private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder"}; // NOI18N + private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder", "build-file"}; // NOI18N private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N /** @@ -695,29 +697,23 @@ */ public static List guessBuildFolders(PropertyEvaluator evaluator, List javaCompilationUnits, File projectBase, File freeformBase) { - //assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); + List buildFolders = new ArrayList(); for (JavaCompilationUnit cu : javaCompilationUnits) { if (cu.output != null) { for (String output : cu.output) { File f = Util.resolveFile(evaluator, freeformBase, output); - if (f.exists()) { - if (f.isFile()) { - f = f.getParentFile(); - } - } else { - // guess: if name contains dot then it is probably file - if (f.getName().indexOf('.') != -1) { - f = f.getParentFile(); - } + // include only directories + if (!f.isDirectory()) { + continue; } - output = f.getAbsolutePath(); - if (!output.endsWith(File.separator)) { - output += File.separatorChar; + String absOutput = f.getAbsolutePath(); + if (!absOutput.endsWith(File.separator)) { + absOutput += File.separatorChar; } - if (output.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || - output.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { + if (absOutput.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || + absOutput.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { // ignore output which lies below project base or freeform base continue; } @@ -728,20 +724,20 @@ if (!path.endsWith(File.separator)) { path += File.separatorChar; } - if (path.equals(output)) { + if (path.equals(absOutput)) { // such a path is already there add = false; break; - } else if (output.startsWith(path)) { + } else if (absOutput.startsWith(path)) { // such a patch is already there add = false; break; - } else if (path.startsWith(output)) { + } else if (path.startsWith(absOutput)) { it.remove(); } } if (add) { - buildFolders.add(f.getAbsolutePath()); + buildFolders.add(output); } } } @@ -756,8 +752,10 @@ * @param buildFolders list of build folder locations */ public static void putBuildFolders(AntProjectHelper helper, List buildFolders) { - //assert ProjectManager.mutex().isWriteAccess(); - ArrayList list = new ArrayList(); + putBuildElement(helper, buildFolders, "build-folder"); + } + + private static void putBuildElement(AntProjectHelper helper, List buildFolders, String elemName) { Element data = Util.getPrimaryConfigurationData(helper); Document doc = data.getOwnerDocument(); Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N @@ -769,7 +767,7 @@ Iterator it = folders.iterator(); while (it.hasNext()) { Element buildFolderEl = (Element)it.next(); - if (!buildFolderEl.getLocalName().equals("build-folder")) { // NOI18N + if (!buildFolderEl.getLocalName().equals(elemName)) { // NOI18N continue; } foldersEl.removeChild(buildFolderEl); @@ -778,7 +776,7 @@ Iterator it = buildFolders.iterator(); while (it.hasNext()) { String location = (String)it.next(); - Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, "build-folder"); // NOI18N + Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, elemName); // NOI18N Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N locationEl.appendChild(doc.createTextNode(location)); buildFolderEl.appendChild(locationEl); @@ -786,7 +784,51 @@ } Util.putPrimaryConfigurationData(helper, data); } - + + public static List getBuildFiles(PropertyEvaluator evaluator, + List compUnits, File projectBase, File freeformBase) { + + List buildFiles = new ArrayList(); + for (JavaCompilationUnit cu : compUnits) { + if (cu.output != null) { + for (String output : cu.output) { + File f = Util.resolveFile(evaluator, freeformBase, output); + try { + if (f.exists() && !FileUtil.isArchiveFile(f.toURL())) { + continue; + } + } catch (MalformedURLException murle) { + Exceptions.printStackTrace(murle); + } + String absOutput = f.getAbsolutePath(); + if (absOutput.startsWith(projectBase.getAbsolutePath() + File.separatorChar) || + absOutput.startsWith(freeformBase.getAbsolutePath() + File.separatorChar)) { + // ignore output which lies below project base or freeform base + continue; + } + boolean add = true; + Iterator it = buildFiles.iterator(); + while (it.hasNext()) { + String path = it.next(); + if (path.equals(absOutput)) { + // such a path is already there + add = false; + break; + } + } + if (add) { + buildFiles.add(output); + } + } + } + } + return buildFiles; + } + + public static void putBuildFiles(AntProjectHelper helper, List buildFiles) { + putBuildElement(helper, buildFiles, "build-file"); + } + // XXX: copy&pasted from FreeformProjectGenerator /** * Read target mappings from project. Index: src/org/netbeans/modules/java/freeform/ui/ProjectModel.java =================================================================== RCS file: /cvs/java/freeform/src/org/netbeans/modules/java/freeform/ui/ProjectModel.java,v retrieving revision 1.14 diff -u -r1.14 ProjectModel.java --- src/org/netbeans/modules/java/freeform/ui/ProjectModel.java 12 Apr 2007 13:18:38 -0000 1.14 +++ src/org/netbeans/modules/java/freeform/ui/ProjectModel.java 1 Oct 2007 13:52:29 -0000 @@ -200,6 +200,10 @@ model.javaCompilationUnitsList, model.baseFolder, model.nbProjectFolder); JavaProjectGenerator.putBuildFolders(helper, buildFolders); + List buildFiles = JavaProjectGenerator.getBuildFiles(model.getEvaluator(), + model.javaCompilationUnitsList, model.baseFolder, model.nbProjectFolder); + JavaProjectGenerator.putBuildFiles(helper, buildFiles); + return null; } });