Lines 20-25
Link Here
|
20 |
package org.netbeans.modules.java.freeform; |
20 |
package org.netbeans.modules.java.freeform; |
21 |
|
21 |
|
22 |
import java.io.File; |
22 |
import java.io.File; |
|
|
23 |
import java.net.MalformedURLException; |
23 |
import java.util.ArrayList; |
24 |
import java.util.ArrayList; |
24 |
import java.util.HashSet; |
25 |
import java.util.HashSet; |
25 |
import java.util.Iterator; |
26 |
import java.util.Iterator; |
Lines 35-40
Link Here
|
35 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
36 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
36 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
37 |
import org.netbeans.spi.project.support.ant.PropertyUtils; |
37 |
import org.openide.filesystems.FileUtil; |
38 |
import org.openide.filesystems.FileUtil; |
|
|
39 |
import org.openide.util.Exceptions; |
38 |
import org.w3c.dom.Document; |
40 |
import org.w3c.dom.Document; |
39 |
import org.w3c.dom.Element; |
41 |
import org.w3c.dom.Element; |
40 |
|
42 |
|
Lines 52-58
Link Here
|
52 |
private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N |
54 |
private static final String[] viewElementsOrder = new String[]{"items", "context-menu"}; // NOI18N |
53 |
|
55 |
|
54 |
// this order is not required by schema, but follow it to minimize randomness a bit |
56 |
// this order is not required by schema, but follow it to minimize randomness a bit |
55 |
private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder"}; // NOI18N |
57 |
private static final String[] folderElementsOrder = new String[]{"source-folder", "build-folder", "build-file"}; // NOI18N |
56 |
private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N |
58 |
private static final String[] viewItemElementsOrder = new String[]{"source-folder", "source-file"}; // NOI18N |
57 |
|
59 |
|
58 |
/** |
60 |
/** |
Lines 695-723
Link Here
|
695 |
*/ |
697 |
*/ |
696 |
public static List<String> guessBuildFolders(PropertyEvaluator evaluator, |
698 |
public static List<String> guessBuildFolders(PropertyEvaluator evaluator, |
697 |
List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) { |
699 |
List<JavaCompilationUnit> javaCompilationUnits, File projectBase, File freeformBase) { |
698 |
//assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess(); |
700 |
|
699 |
List<String> buildFolders = new ArrayList<String>(); |
701 |
List<String> buildFolders = new ArrayList<String>(); |
700 |
for (JavaCompilationUnit cu : javaCompilationUnits) { |
702 |
for (JavaCompilationUnit cu : javaCompilationUnits) { |
701 |
if (cu.output != null) { |
703 |
if (cu.output != null) { |
702 |
for (String output : cu.output) { |
704 |
for (String output : cu.output) { |
703 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
705 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
704 |
if (f.exists()) { |
706 |
// include only directories |
705 |
if (f.isFile()) { |
707 |
if (!f.isDirectory()) { |
706 |
f = f.getParentFile(); |
708 |
continue; |
707 |
} |
|
|
708 |
} else { |
709 |
// guess: if name contains dot then it is probably file |
710 |
if (f.getName().indexOf('.') != -1) { |
711 |
f = f.getParentFile(); |
712 |
} |
713 |
} |
709 |
} |
714 |
output = f.getAbsolutePath(); |
710 |
String absOutput = f.getAbsolutePath(); |
715 |
if (!output.endsWith(File.separator)) { |
711 |
if (!absOutput.endsWith(File.separator)) { |
716 |
output += File.separatorChar; |
712 |
absOutput += File.separatorChar; |
717 |
} |
713 |
} |
718 |
|
714 |
|
719 |
if (output.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || |
715 |
if (absOutput.startsWith(projectBase.getAbsolutePath()+File.separatorChar) || |
720 |
output.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { |
716 |
absOutput.startsWith(freeformBase.getAbsolutePath()+File.separatorChar)) { |
721 |
// ignore output which lies below project base or freeform base |
717 |
// ignore output which lies below project base or freeform base |
722 |
continue; |
718 |
continue; |
723 |
} |
719 |
} |
Lines 728-747
Link Here
|
728 |
if (!path.endsWith(File.separator)) { |
724 |
if (!path.endsWith(File.separator)) { |
729 |
path += File.separatorChar; |
725 |
path += File.separatorChar; |
730 |
} |
726 |
} |
731 |
if (path.equals(output)) { |
727 |
if (path.equals(absOutput)) { |
732 |
// such a path is already there |
728 |
// such a path is already there |
733 |
add = false; |
729 |
add = false; |
734 |
break; |
730 |
break; |
735 |
} else if (output.startsWith(path)) { |
731 |
} else if (absOutput.startsWith(path)) { |
736 |
// such a patch is already there |
732 |
// such a patch is already there |
737 |
add = false; |
733 |
add = false; |
738 |
break; |
734 |
break; |
739 |
} else if (path.startsWith(output)) { |
735 |
} else if (path.startsWith(absOutput)) { |
740 |
it.remove(); |
736 |
it.remove(); |
741 |
} |
737 |
} |
742 |
} |
738 |
} |
743 |
if (add) { |
739 |
if (add) { |
744 |
buildFolders.add(f.getAbsolutePath()); |
740 |
buildFolders.add(output); |
745 |
} |
741 |
} |
746 |
} |
742 |
} |
747 |
} |
743 |
} |
Lines 756-763
Link Here
|
756 |
* @param buildFolders list of build folder locations |
752 |
* @param buildFolders list of build folder locations |
757 |
*/ |
753 |
*/ |
758 |
public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) { |
754 |
public static void putBuildFolders(AntProjectHelper helper, List<String> buildFolders) { |
759 |
//assert ProjectManager.mutex().isWriteAccess(); |
755 |
putBuildElement(helper, buildFolders, "build-folder"); |
760 |
ArrayList list = new ArrayList(); |
756 |
} |
|
|
757 |
|
758 |
private static void putBuildElement(AntProjectHelper helper, List<String> buildFolders, String elemName) { |
761 |
Element data = Util.getPrimaryConfigurationData(helper); |
759 |
Element data = Util.getPrimaryConfigurationData(helper); |
762 |
Document doc = data.getOwnerDocument(); |
760 |
Document doc = data.getOwnerDocument(); |
763 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
761 |
Element foldersEl = Util.findElement(data, "folders", Util.NAMESPACE); // NOI18N |
Lines 769-775
Link Here
|
769 |
Iterator it = folders.iterator(); |
767 |
Iterator it = folders.iterator(); |
770 |
while (it.hasNext()) { |
768 |
while (it.hasNext()) { |
771 |
Element buildFolderEl = (Element)it.next(); |
769 |
Element buildFolderEl = (Element)it.next(); |
772 |
if (!buildFolderEl.getLocalName().equals("build-folder")) { // NOI18N |
770 |
if (!buildFolderEl.getLocalName().equals(elemName)) { // NOI18N |
773 |
continue; |
771 |
continue; |
774 |
} |
772 |
} |
775 |
foldersEl.removeChild(buildFolderEl); |
773 |
foldersEl.removeChild(buildFolderEl); |
Lines 778-784
Link Here
|
778 |
Iterator it = buildFolders.iterator(); |
776 |
Iterator it = buildFolders.iterator(); |
779 |
while (it.hasNext()) { |
777 |
while (it.hasNext()) { |
780 |
String location = (String)it.next(); |
778 |
String location = (String)it.next(); |
781 |
Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, "build-folder"); // NOI18N |
779 |
Element buildFolderEl = doc.createElementNS(Util.NAMESPACE, elemName); // NOI18N |
782 |
Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N |
780 |
Element locationEl = doc.createElementNS(Util.NAMESPACE, "location"); // NOI18N |
783 |
locationEl.appendChild(doc.createTextNode(location)); |
781 |
locationEl.appendChild(doc.createTextNode(location)); |
784 |
buildFolderEl.appendChild(locationEl); |
782 |
buildFolderEl.appendChild(locationEl); |
Lines 786-792
Link Here
|
786 |
} |
784 |
} |
787 |
Util.putPrimaryConfigurationData(helper, data); |
785 |
Util.putPrimaryConfigurationData(helper, data); |
788 |
} |
786 |
} |
789 |
|
787 |
|
|
|
788 |
public static List<String> getBuildFiles(PropertyEvaluator evaluator, |
789 |
List<JavaCompilationUnit> compUnits, File projectBase, File freeformBase) { |
790 |
|
791 |
List<String> buildFiles = new ArrayList<String>(); |
792 |
for (JavaCompilationUnit cu : compUnits) { |
793 |
if (cu.output != null) { |
794 |
for (String output : cu.output) { |
795 |
File f = Util.resolveFile(evaluator, freeformBase, output); |
796 |
try { |
797 |
if (f.exists() && !FileUtil.isArchiveFile(f.toURL())) { |
798 |
continue; |
799 |
} |
800 |
} catch (MalformedURLException murle) { |
801 |
Exceptions.printStackTrace(murle); |
802 |
} |
803 |
String absOutput = f.getAbsolutePath(); |
804 |
if (absOutput.startsWith(projectBase.getAbsolutePath() + File.separatorChar) || |
805 |
absOutput.startsWith(freeformBase.getAbsolutePath() + File.separatorChar)) { |
806 |
// ignore output which lies below project base or freeform base |
807 |
continue; |
808 |
} |
809 |
boolean add = true; |
810 |
Iterator<String> it = buildFiles.iterator(); |
811 |
while (it.hasNext()) { |
812 |
String path = it.next(); |
813 |
if (path.equals(absOutput)) { |
814 |
// such a path is already there |
815 |
add = false; |
816 |
break; |
817 |
} |
818 |
} |
819 |
if (add) { |
820 |
buildFiles.add(output); |
821 |
} |
822 |
} |
823 |
} |
824 |
} |
825 |
return buildFiles; |
826 |
} |
827 |
|
828 |
public static void putBuildFiles(AntProjectHelper helper, List<String> buildFiles) { |
829 |
putBuildElement(helper, buildFiles, "build-file"); |
830 |
} |
831 |
|
790 |
// XXX: copy&pasted from FreeformProjectGenerator |
832 |
// XXX: copy&pasted from FreeformProjectGenerator |
791 |
/** |
833 |
/** |
792 |
* Read target mappings from project. |
834 |
* Read target mappings from project. |