Lines 19-27
Link Here
|
19 |
import java.net.URISyntaxException; |
19 |
import java.net.URISyntaxException; |
20 |
import java.util.ArrayList; |
20 |
import java.util.ArrayList; |
21 |
import java.util.Arrays; |
21 |
import java.util.Arrays; |
|
|
22 |
import java.util.HashSet; |
22 |
import java.util.Iterator; |
23 |
import java.util.Iterator; |
23 |
import java.util.List; |
24 |
import java.util.List; |
24 |
import java.util.Map; |
25 |
import java.util.Map; |
|
|
26 |
import java.util.Set; |
25 |
import java.util.regex.Matcher; |
27 |
import java.util.regex.Matcher; |
26 |
import java.util.regex.Pattern; |
28 |
import java.util.regex.Pattern; |
27 |
import org.netbeans.api.project.Project; |
29 |
import org.netbeans.api.project.Project; |
Lines 84-89
Link Here
|
84 |
*/ |
86 |
*/ |
85 |
static final String REFS_NS = "http://www.netbeans.org/ns/ant-project-references/1"; // NOI18N |
87 |
static final String REFS_NS = "http://www.netbeans.org/ns/ant-project-references/1"; // NOI18N |
86 |
|
88 |
|
|
|
89 |
/** Set of property names which values can be used as additional base |
90 |
* directories. */ |
91 |
private Set/*<String>*/ extraBaseDirectories = new HashSet(); |
92 |
|
87 |
private final AntProjectHelper h; |
93 |
private final AntProjectHelper h; |
88 |
final PropertyEvaluator eval; |
94 |
final PropertyEvaluator eval; |
89 |
private final AuxiliaryConfiguration aux; |
95 |
private final AuxiliaryConfiguration aux; |
Lines 218-226
Link Here
|
218 |
assert forProjPath != null : "These dirs are not really collocated: " + myProjDir + " & " + forProjDir; |
224 |
assert forProjPath != null : "These dirs are not really collocated: " + myProjDir + " & " + forProjDir; |
219 |
propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH; |
225 |
propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH; |
220 |
} else { |
226 |
} else { |
221 |
// Use an absolute path. |
227 |
forProjPath = relativizeFileToExtraBaseFolders(forProjDir); |
222 |
forProjPath = forProjDir.getAbsolutePath(); |
228 |
if (forProjPath != null) { |
223 |
propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH; |
229 |
propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH; |
|
|
230 |
} else { |
231 |
// Use an absolute path. |
232 |
forProjPath = forProjDir.getAbsolutePath(); |
233 |
propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH; |
234 |
} |
224 |
} |
235 |
} |
225 |
EditableProperties props = h.getProperties(propertiesFile); |
236 |
EditableProperties props = h.getProperties(propertiesFile); |
226 |
String forProjPathProp = "project." + forProjName; // NOI18N |
237 |
String forProjPathProp = "project." + forProjName; // NOI18N |
Lines 643-650
Link Here
|
643 |
path = PropertyUtils.relativizeFile(myProjDir, file); |
654 |
path = PropertyUtils.relativizeFile(myProjDir, file); |
644 |
assert path != null : "expected relative path from " + myProjDir + " to " + file; |
655 |
assert path != null : "expected relative path from " + myProjDir + " to " + file; |
645 |
} else { |
656 |
} else { |
646 |
propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH; |
657 |
path = relativizeFileToExtraBaseFolders(file); |
647 |
path = file.getAbsolutePath(); |
658 |
if (path != null) { |
|
|
659 |
propertiesFile = AntProjectHelper.PROJECT_PROPERTIES_PATH; |
660 |
} else { |
661 |
propertiesFile = AntProjectHelper.PRIVATE_PROPERTIES_PATH; |
662 |
path = file.getAbsolutePath(); |
663 |
} |
648 |
} |
664 |
} |
649 |
EditableProperties props = h.getProperties(propertiesFile); |
665 |
EditableProperties props = h.getProperties(propertiesFile); |
650 |
String fileID = file.getName(); |
666 |
String fileID = file.getName(); |
Lines 669-675
Link Here
|
669 |
} |
685 |
} |
670 |
}); |
686 |
}); |
671 |
} |
687 |
} |
|
|
688 |
|
689 |
/** |
690 |
* Test whether file does not lie under an extra base folder and if it does |
691 |
* then return string in form of "${extra.base}/remaining/path"; or null. |
692 |
*/ |
693 |
private String relativizeFileToExtraBaseFolders(File f) { |
694 |
File base = FileUtil.toFile(h.getProjectDirectory()); |
695 |
String fileToRelativize = f.getAbsolutePath(); |
696 |
synchronized (extraBaseDirectories) { |
697 |
Iterator it = extraBaseDirectories.iterator(); |
698 |
while (it.hasNext()) { |
699 |
String prop = (String)it.next(); |
700 |
String path = eval.getProperty(prop); |
701 |
File extraBase = PropertyUtils.resolveFile(base, path); |
702 |
path = extraBase.getAbsolutePath(); |
703 |
if (!path.endsWith(File.separator)) { |
704 |
path += File.separator; |
705 |
} |
706 |
if (fileToRelativize.startsWith(path)) { |
707 |
return "${"+prop+"}/"+fileToRelativize.substring(path.length()).replace('\\', '/'); // NOI18N |
708 |
} |
709 |
} |
710 |
} |
711 |
return null; |
712 |
} |
672 |
|
713 |
|
|
|
714 |
/** |
715 |
* Add extra folder which can be used as base directory (in addition to |
716 |
* project base folder) for creating references. Duplicate property names |
717 |
* are not allowed. Any newly created reference to a file lying under an |
718 |
* extra base directory will be based on that property and will be stored in |
719 |
* shared project proeprties. |
720 |
* @param propertyName property name which value is path to folder which |
721 |
* can be used as alternative project's base directory |
722 |
* @since 1.3 |
723 |
*/ |
724 |
public void addExtraBaseDirectory(String propertyName) { |
725 |
assert propertyName != null && eval.getProperty(propertyName) != null; |
726 |
synchronized (extraBaseDirectories) { |
727 |
if (!extraBaseDirectories.add(propertyName)) { |
728 |
throw new IllegalArgumentException("Already extra base directory property: "+propertyName); // NOI18N |
729 |
} |
730 |
} |
731 |
} |
732 |
|
733 |
/** |
734 |
* Remove extra base directory. The base directory property had to be added |
735 |
* by {@link #addExtraBaseDirectory} method call. At the time when this |
736 |
* method is called the property must still exist and must be valid. This |
737 |
* method will replace all references of the extra base directory property |
738 |
* with its current value and if needed it may move such a property from |
739 |
* shared project properties into the private properties. |
740 |
* @param propertyName property name which was added by |
741 |
* {@link #addExtraBaseDirectory} method. |
742 |
* @since 1.3 |
743 |
*/ |
744 |
public void removeExtraBaseDirectory(String propertyName) { |
745 |
synchronized (extraBaseDirectories) { |
746 |
if (!extraBaseDirectories.remove(propertyName)) { |
747 |
throw new IllegalArgumentException("Non-existing extra base directory property: "+propertyName); // NOI18N |
748 |
} |
749 |
// substitute all references of removed extra base folder property with its value |
750 |
String tag = "${"+propertyName+"}"; // NOI18N |
751 |
// was extra base property defined in shared file or not: |
752 |
boolean shared = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH).containsKey(propertyName); |
753 |
String value = eval.getProperty(propertyName); |
754 |
EditableProperties propProj = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); |
755 |
EditableProperties propPriv = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); |
756 |
boolean modifiedProj = false; |
757 |
boolean modifiedPriv = false; |
758 |
Iterator it = propProj.entrySet().iterator(); |
759 |
while (it.hasNext()) { |
760 |
Map.Entry entry = (Map.Entry)it.next(); |
761 |
String val = (String)entry.getValue(); |
762 |
int index; |
763 |
if ((index = val.indexOf(tag)) != -1) { |
764 |
val = val.substring(0, index) +value + val.substring(index+tag.length()); |
765 |
if (shared) { |
766 |
// substitute extra base folder property with its value |
767 |
entry.setValue(val); |
768 |
modifiedProj = true; |
769 |
} else { |
770 |
// move property to private properties file |
771 |
it.remove(); |
772 |
propPriv.put(entry.getKey(), val); |
773 |
modifiedPriv = true; |
774 |
modifiedProj = true; |
775 |
} |
776 |
} |
777 |
} |
778 |
if (modifiedProj) { |
779 |
h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, propProj); |
780 |
} |
781 |
if (modifiedPriv) { |
782 |
h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, propPriv); |
783 |
} |
784 |
} |
785 |
} |
786 |
|
673 |
/** |
787 |
/** |
674 |
* Find reference ID (e.g. something you can then pass to RawReference |
788 |
* Find reference ID (e.g. something you can then pass to RawReference |
675 |
* as foreignProjectName) for the given property base name, prefix and path. |
789 |
* as foreignProjectName) for the given property base name, prefix and path. |