Lines 42-47
Link Here
|
42 |
package org.netbeans.modules.java.freeform; |
42 |
package org.netbeans.modules.java.freeform; |
43 |
|
43 |
|
44 |
import java.io.File; |
44 |
import java.io.File; |
|
|
45 |
import java.net.MalformedURLException; |
45 |
import java.util.ArrayList; |
46 |
import java.util.ArrayList; |
46 |
import java.util.HashSet; |
47 |
import java.util.HashSet; |
47 |
import java.util.Iterator; |
48 |
import java.util.Iterator; |
Lines 57-62
Link Here
|
57 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
58 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
58 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
59 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
59 |
import org.openide.filesystems.FileUtil; |
60 |
import org.openide.filesystems.FileUtil; |
|
|
61 |
import org.openide.util.Exceptions; |
60 |
import org.w3c.dom.Document; |
62 |
import org.w3c.dom.Document; |
61 |
import org.w3c.dom.Element; |
63 |
import org.w3c.dom.Element; |
62 |
|
64 |
|
Lines 74-80
Link Here
|
74 |
private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N |
76 |
private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N |
75 |
|
77 |
|
76 |
// this order is not required by schema, but follow it to minimize randomness a bit |
78 |
// this order is not required by schema, but follow it to minimize randomness a bit |
77 |
private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder"}; // NOI18N |
79 |
private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder", "build-file"}; // NOI18N |
78 |
private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N |
80 |
private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N |
79 |
|
81 |
|
80 |
/** |
82 |
/** |
Lines 717-745
Link Here
|
717 |
*/ |
719 |
*/ |
718 |
public static List<String> guessBuildFolders(PropertyEvaluator evaluator, |
720 |
public static List<String> guessBuildFolders(PropertyEvaluator evaluator, |
719 |
List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) { |
721 |
List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) { |
720 |
//assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); |
722 |
|
721 |
List<String> buildFolders = new ArrayList<String>(); |
723 |
List<String> buildFolders = new ArrayList<String>(); |
722 |
for (JavaCompilationUnit cu : javaCompilationUnits) { |
724 |
for (JavaCompilationUnit cu : javaCompilationUnits) { |
723 |
if (cu.output != null) { |
725 |
if (cu.output != null) { |
724 |
for (String output : cu.output) { |
726 |
for (String output : cu.output) { |
725 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
727 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
726 |
if (f.exists()) { |
728 |
// include only directories |
727 |
if (f.isFile()) { |
729 |
if (!f.isDirectory()) { |
728 |
f = f.getParentFile(); |
730 |
continue; |
729 |
} |
|
|
730 |
} else { |
731 |
// guess: if name contains dot then it is probably file |
732 |
if (f.getName().indexOf('.') != -1) { |
733 |
f = f.getParentFile(); |
734 |
} |
735 |
} |
731 |
} |
736 |
output = f.getAbsolutePath(); |
732 |
String absOutput = f.getAbsolutePath(); |
737 |
if (!output.endsWith(File.separator)) { |
733 |
if (!absOutput.endsWith(File.separator)) { |
738 |
output += File.separatorChar; |
734 |
absOutput += File.separatorChar; |
739 |
} |
735 |
} |
740 |
|
736 |
|
741 |
if (output.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || |
737 |
if (absOutput.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || |
742 |
output.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { |
738 |
absOutput.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { |
743 |
// ignore output which lies below project base or freeform base |
739 |
// ignore output which lies below project base or freeform base |
744 |
continue; |
740 |
continue; |
745 |
} |
741 |
} |
Lines 750-769
Link Here
|
750 |
if (!path.endsWith(File.separator)) { |
746 |
if (!path.endsWith(File.separator)) { |
751 |
path += File.separatorChar; |
747 |
path += File.separatorChar; |
752 |
} |
748 |
} |
753 |
if (path.equals(output)) { |
749 |
if (path.equals(absOutput)) { |
754 |
// such a path is already there |
750 |
// such a path is already there |
755 |
add = false; |
751 |
add = false; |
756 |
break; |
752 |
break; |
757 |
} else if (output.startsWith(path)) { |
753 |
} else if (absOutput.startsWith(path)) { |
758 |
// such a patch is already there |
754 |
// such a patch is already there |
759 |
add = false; |
755 |
add = false; |
760 |
break; |
756 |
break; |
761 |
} else if (path.startsWith(output)) { |
757 |
} else if (path.startsWith(absOutput)) { |
762 |
it.remove(); |
758 |
it.remove(); |
763 |
} |
759 |
} |
764 |
} |
760 |
} |
765 |
if (add) { |
761 |
if (add) { |
766 |
buildFolders.add(f.getAbsolutePath()); |
762 |
buildFolders.add(output); |
767 |
} |
763 |
} |
768 |
} |
764 |
} |
769 |
} |
765 |
} |
Lines 778-785
Link Here
|
778 |
* @param buildFolders list of build folder locations |
774 |
* @param buildFolders list of build folder locations |
779 |
*/ |
775 |
*/ |
780 |
public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) { |
776 |
public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) { |
781 |
//assert ProjectManager.mutex().isWriteAccess(); |
777 |
putBuildElement(helper, buildFolders, "build-folder"); |
782 |
ArrayList list = new ArrayList(); |
778 |
} |
|
|
779 |
|
780 |
private static void putBuildElement(AntProjectHelper helper, List<String> buildFolders, String elemName) { |
783 |
Element data = Util.getPrimaryConfigurationData(helper); |
781 |
Element data = Util.getPrimaryConfigurationData(helper); |
784 |
Document doc = data.getOwnerDocument(); |
782 |
Document doc = data.getOwnerDocument(); |
785 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
783 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
Lines 791-797
Link Here
|
791 |
Iterator it = folders.iterator(); |
789 |
Iterator it = folders.iterator(); |
792 |
while (it.hasNext()) { |
790 |
while (it.hasNext()) { |
793 |
Element buildFolderEl = (Element)it.next(); |
791 |
Element buildFolderEl = (Element)it.next(); |
794 |
if (!buildFolderEl.getLocalName().equals("build-folder")) { // NOI18N |
792 |
if (!buildFolderEl.getLocalName().equals(elemName)) { // NOI18N |
795 |
continue; |
793 |
continue; |
796 |
} |
794 |
} |
797 |
foldersEl.removeChild(buildFolderEl); |
795 |
foldersEl.removeChild(buildFolderEl); |
Lines 800-806
Link Here
|
800 |
Iterator it = buildFolders.iterator(); |
798 |
Iterator it = buildFolders.iterator(); |
801 |
while (it.hasNext()) { |
799 |
while (it.hasNext()) { |
802 |
String location = (String)it.next(); |
800 |
String location = (String)it.next(); |
803 |
Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, "build-folder"); // NOI18N |
801 |
Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, elemName); // NOI18N |
804 |
Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N |
802 |
Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N |
805 |
locationEl.appendChild(doc.createTextNode(location)); |
803 |
locationEl.appendChild(doc.createTextNode(location)); |
806 |
buildFolderEl.appendChild(locationEl); |
804 |
buildFolderEl.appendChild(locationEl); |
Lines 808-814
Link Here
|
808 |
} |
806 |
} |
809 |
Util.putPrimaryConfigurationData(helper, data); |
807 |
Util.putPrimaryConfigurationData(helper, data); |
810 |
} |
808 |
} |
811 |
|
809 |
|
|
|
810 |
public static List<String> getBuildFiles(PropertyEvaluator evaluator, |
811 |
List<JavaCompilationUnit> compUnits, File projectBase, File freeformBase) { |
812 |
|
813 |
List<String> buildFiles = new ArrayList<String>(); |
814 |
for (JavaCompilationUnit cu : compUnits) { |
815 |
if (cu.output != null) { |
816 |
for (String output : cu.output) { |
817 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
818 |
try { |
819 |
if (f.exists() && !FileUtil.isArchiveFile(f.toURL())) { |
820 |
continue; |
821 |
} |
822 |
} catch (MalformedURLException murle) { |
823 |
Exceptions.printStackTrace(murle); |
824 |
} |
825 |
String absOutput = f.getAbsolutePath(); |
826 |
if (absOutput.startsWith(projectBase.getAbsolutePath() + File.separatorChar) || |
827 |
absOutput.startsWith(freeformBase.getAbsolutePath() + File.separatorChar)) { |
828 |
// ignore output which lies below project base or freeform base |
829 |
continue; |
830 |
} |
831 |
boolean add = true; |
832 |
Iterator<String> it = buildFiles.iterator(); |
833 |
while (it.hasNext()) { |
834 |
String path = it.next(); |
835 |
if (path.equals(absOutput)) { |
836 |
// such a path is already there |
837 |
add = false; |
838 |
break; |
839 |
} |
840 |
} |
841 |
if (add) { |
842 |
buildFiles.add(output); |
843 |
} |
844 |
} |
845 |
} |
846 |
} |
847 |
return buildFiles; |
848 |
} |
849 |
|
850 |
public static void putBuildFiles(AntProjectHelper helper, List<String> buildFiles) { |
851 |
putBuildElement(helper, buildFiles, "build-file"); |
852 |
} |
853 |
|
812 |
// XXX: copy&pasted from FreeformProjectGenerator |
854 |
// XXX: copy&pasted from FreeformProjectGenerator |
813 |
/** |
855 |
/** |
814 |
* Read target mappings from project. |
856 |
* Read target mappings from project. |