Lines 196-201
Link Here
|
196 |
* A constant indicating an output location. |
196 |
* A constant indicating an output location. |
197 |
*/ |
197 |
*/ |
198 |
public static final int K_OUTPUT = 10; |
198 |
public static final int K_OUTPUT = 10; |
|
|
199 |
|
200 |
public static final String DOT_DOT = ".."; //$NON-NLS-1$ |
199 |
|
201 |
|
200 |
/** |
202 |
/** |
201 |
* The export flag |
203 |
* The export flag |
Lines 625-631
Link Here
|
625 |
IPath path = new Path(pathAttr); |
627 |
IPath path = new Path(pathAttr); |
626 |
int kind = kindFromString(kindAttr); |
628 |
int kind = kindFromString(kindAttr); |
627 |
if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { |
629 |
if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { |
628 |
path = projectPath.append(path); |
630 |
if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) { |
|
|
631 |
path = projectPath.append(path); |
632 |
} |
629 |
} |
633 |
} |
630 |
// source attachment info (optional) |
634 |
// source attachment info (optional) |
631 |
IPath sourceAttachmentPath = |
635 |
IPath sourceAttachmentPath = |
Lines 705-722
Link Here
|
705 |
|
709 |
|
706 |
case IClasspathEntry.CPE_PROJECT : |
710 |
case IClasspathEntry.CPE_PROJECT : |
707 |
entry = new ClasspathEntry( |
711 |
entry = new ClasspathEntry( |
708 |
IPackageFragmentRoot.K_SOURCE, |
712 |
IPackageFragmentRoot.K_SOURCE, |
709 |
IClasspathEntry.CPE_PROJECT, |
713 |
IClasspathEntry.CPE_PROJECT, |
710 |
path, |
714 |
path, |
711 |
ClasspathEntry.INCLUDE_ALL, // inclusion patterns |
715 |
ClasspathEntry.INCLUDE_ALL, // inclusion patterns |
712 |
ClasspathEntry.EXCLUDE_NONE, // exclusion patterns |
716 |
ClasspathEntry.EXCLUDE_NONE, // exclusion patterns |
713 |
null, // source attachment |
717 |
null, // source attachment |
714 |
null, // source attachment root |
718 |
null, // source attachment root |
715 |
null, // specific output folder |
719 |
null, // specific output folder |
716 |
isExported, |
720 |
isExported, |
717 |
accessRules, |
721 |
accessRules, |
718 |
combineAccessRestrictions, |
722 |
combineAccessRestrictions, |
719 |
extraAttributes); |
723 |
extraAttributes); |
720 |
break; |
724 |
break; |
721 |
case IClasspathEntry.CPE_LIBRARY : |
725 |
case IClasspathEntry.CPE_LIBRARY : |
722 |
entry = JavaCore.newLibraryEntry( |
726 |
entry = JavaCore.newLibraryEntry( |
Lines 731-737
Link Here
|
731 |
// must be an entry in this project or specify another project |
735 |
// must be an entry in this project or specify another project |
732 |
String projSegment = path.segment(0); |
736 |
String projSegment = path.segment(0); |
733 |
if (projSegment != null && projSegment.equals(project.getElementName())) { // this project |
737 |
if (projSegment != null && projSegment.equals(project.getElementName())) { // this project |
734 |
entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); |
738 |
entry = JavaCore.newSourceEntry( |
|
|
739 |
path, |
740 |
inclusionPatterns, |
741 |
exclusionPatterns, |
742 |
outputLocation, |
743 |
extraAttributes); |
735 |
} else { |
744 |
} else { |
736 |
if (path.segmentCount() == 1) { |
745 |
if (path.segmentCount() == 1) { |
737 |
// another project |
746 |
// another project |
Lines 743-783
Link Here
|
743 |
isExported); |
752 |
isExported); |
744 |
} else { |
753 |
} else { |
745 |
// an invalid source folder |
754 |
// an invalid source folder |
746 |
entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); |
755 |
entry = JavaCore.newSourceEntry( |
|
|
756 |
path, |
757 |
inclusionPatterns, |
758 |
exclusionPatterns, |
759 |
outputLocation, |
760 |
extraAttributes); |
747 |
} |
761 |
} |
748 |
} |
762 |
} |
749 |
break; |
763 |
break; |
750 |
case IClasspathEntry.CPE_VARIABLE : |
764 |
case IClasspathEntry.CPE_VARIABLE : |
751 |
entry = JavaCore.newVariableEntry( |
765 |
entry = JavaCore.newVariableEntry( |
752 |
path, |
766 |
path, |
753 |
sourceAttachmentPath, |
767 |
sourceAttachmentPath, |
754 |
sourceAttachmentRootPath, |
768 |
sourceAttachmentRootPath, |
755 |
accessRules, |
769 |
accessRules, |
756 |
extraAttributes, |
770 |
extraAttributes, |
757 |
isExported); |
771 |
isExported); |
758 |
break; |
772 |
break; |
759 |
case IClasspathEntry.CPE_CONTAINER : |
773 |
case IClasspathEntry.CPE_CONTAINER : |
760 |
entry = JavaCore.newContainerEntry( |
774 |
entry = JavaCore.newContainerEntry( |
761 |
path, |
775 |
path, |
762 |
accessRules, |
776 |
accessRules, |
763 |
extraAttributes, |
777 |
extraAttributes, |
764 |
isExported); |
778 |
isExported); |
765 |
break; |
779 |
break; |
766 |
case ClasspathEntry.K_OUTPUT : |
780 |
case ClasspathEntry.K_OUTPUT : |
767 |
if (!path.isAbsolute()) return null; |
781 |
if (!path.isAbsolute()) return null; |
768 |
entry = new ClasspathEntry( |
782 |
entry = new ClasspathEntry( |
769 |
ClasspathEntry.K_OUTPUT, |
783 |
ClasspathEntry.K_OUTPUT, |
770 |
IClasspathEntry.CPE_LIBRARY, |
784 |
IClasspathEntry.CPE_LIBRARY, |
771 |
path, |
785 |
path, |
772 |
INCLUDE_ALL, |
786 |
INCLUDE_ALL, |
773 |
EXCLUDE_NONE, |
787 |
EXCLUDE_NONE, |
774 |
null, // source attachment |
788 |
null, // source attachment |
775 |
null, // source attachment root |
789 |
null, // source attachment root |
776 |
null, // custom output location |
790 |
null, // custom output location |
777 |
false, |
791 |
false, |
778 |
null, // no access rules |
792 |
null, // no access rules |
779 |
false, // no accessible files to combine |
793 |
false, // no accessible files to combine |
780 |
NO_EXTRA_ATTRIBUTES); |
794 |
NO_EXTRA_ATTRIBUTES); |
781 |
break; |
795 |
break; |
782 |
default : |
796 |
default : |
783 |
throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); |
797 |
throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); |
Lines 792-797
Link Here
|
792 |
|
806 |
|
793 |
return entry; |
807 |
return entry; |
794 |
} |
808 |
} |
|
|
809 |
|
810 |
/* |
811 |
* Returns whether the given path as a ".." segment |
812 |
*/ |
813 |
public static boolean hasDotDot(IPath path) { |
814 |
for (int i = 0, length = path.segmentCount(); i < length; i++) { |
815 |
if (DOT_DOT.equals(path.segment(i))) |
816 |
return true; |
817 |
} |
818 |
return false; |
819 |
} |
795 |
|
820 |
|
796 |
public static NodeList getChildAttributes(String childName, NodeList children, boolean[] foundChildren) { |
821 |
public static NodeList getChildAttributes(String childName, NodeList children, boolean[] foundChildren) { |
797 |
for (int i = 0, length = foundChildren.length; i < length; i++) { |
822 |
for (int i = 0, length = foundChildren.length; i < length; i++) { |
Lines 822-827
Link Here
|
822 |
} |
847 |
} |
823 |
} |
848 |
} |
824 |
|
849 |
|
|
|
850 |
/* |
851 |
* Resolves the ".." in the given path. Returns the given path if it contains no ".." segment. |
852 |
*/ |
853 |
public static IPath resolveDotDot(IPath path) { |
854 |
IPath newPath = null; |
855 |
IWorkspaceRoot root = null; |
856 |
IPath workspaceLocation = null; |
857 |
for (int i = 0, length = path.segmentCount(); i < length; i++) { |
858 |
String segment = path.segment(i); |
859 |
if (DOT_DOT.equals(segment)) { |
860 |
if (newPath == null) { |
861 |
if (i == 0) { |
862 |
workspaceLocation = (root = ResourcesPlugin.getWorkspace().getRoot()).getLocation(); |
863 |
newPath = workspaceLocation; |
864 |
} else { |
865 |
newPath = path.removeFirstSegments(i); |
866 |
} |
867 |
} else { |
868 |
if (newPath.segmentCount() > 0) { |
869 |
newPath = newPath.removeLastSegments(1); |
870 |
} else { |
871 |
workspaceLocation = (root = ResourcesPlugin.getWorkspace().getRoot()).getLocation(); |
872 |
newPath = workspaceLocation; |
873 |
} |
874 |
} |
875 |
} else if (newPath != null) { |
876 |
if (newPath.equals(workspaceLocation) && root.getProject(segment).isAccessible()) { |
877 |
newPath = new Path(segment).makeAbsolute(); |
878 |
} else { |
879 |
newPath = newPath.append(segment); |
880 |
} |
881 |
} |
882 |
} |
883 |
if (newPath == null) |
884 |
return path; |
885 |
return newPath; |
886 |
} |
887 |
|
825 |
/** |
888 |
/** |
826 |
* Encode some patterns into XML parameter tag |
889 |
* Encode some patterns into XML parameter tag |
827 |
*/ |
890 |
*/ |
Lines 1195-1201
Link Here
|
1195 |
} |
1258 |
} |
1196 |
return buffer.toString(); |
1259 |
return buffer.toString(); |
1197 |
} |
1260 |
} |
1198 |
|
1261 |
|
|
|
1262 |
public ClasspathEntry resolvedDotDot() { |
1263 |
IPath resolvedPath = resolveDotDot(this.path); |
1264 |
if (resolvedPath == this.path) |
1265 |
return this; |
1266 |
return new ClasspathEntry( |
1267 |
getContentKind(), |
1268 |
getEntryKind(), |
1269 |
resolvedPath, |
1270 |
this.inclusionPatterns, |
1271 |
this.exclusionPatterns, |
1272 |
getSourceAttachmentPath(), |
1273 |
getSourceAttachmentRootPath(), |
1274 |
getOutputLocation(), |
1275 |
this.isExported, |
1276 |
getAccessRules(), |
1277 |
this.combineAccessRules, |
1278 |
this.extraAttributes); |
1279 |
} |
1280 |
|
1199 |
/** |
1281 |
/** |
1200 |
* Answers an ID which is used to distinguish entries during package |
1282 |
* Answers an ID which is used to distinguish entries during package |
1201 |
* fragment root computations |
1283 |
* fragment root computations |
Lines 1636-1641
Link Here
|
1636 |
|
1718 |
|
1637 |
// library entry check |
1719 |
// library entry check |
1638 |
case IClasspathEntry.CPE_LIBRARY : |
1720 |
case IClasspathEntry.CPE_LIBRARY : |
|
|
1721 |
path = ClasspathEntry.resolveDotDot(path); |
1639 |
if (path.isAbsolute() && !path.isEmpty()) { |
1722 |
if (path.isAbsolute() && !path.isEmpty()) { |
1640 |
IPath sourceAttachment = entry.getSourceAttachmentPath(); |
1723 |
IPath sourceAttachment = entry.getSourceAttachmentPath(); |
1641 |
Object target = JavaModel.getTarget(path, true); |
1724 |
Object target = JavaModel.getTarget(path, true); |