Lines 18-23
Link Here
|
18 |
import java.util.Hashtable; |
18 |
import java.util.Hashtable; |
19 |
import java.util.Iterator; |
19 |
import java.util.Iterator; |
20 |
import java.util.LinkedHashSet; |
20 |
import java.util.LinkedHashSet; |
|
|
21 |
import java.util.List; |
21 |
import java.util.Map; |
22 |
import java.util.Map; |
22 |
|
23 |
|
23 |
import javax.xml.parsers.DocumentBuilder; |
24 |
import javax.xml.parsers.DocumentBuilder; |
Lines 45-50
Link Here
|
45 |
import org.eclipse.core.runtime.content.IContentDescription; |
46 |
import org.eclipse.core.runtime.content.IContentDescription; |
46 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
47 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
47 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
48 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
|
|
49 |
import org.eclipse.jdt.core.IClasspathAttribute; |
48 |
import org.eclipse.jdt.core.IClasspathContainer; |
50 |
import org.eclipse.jdt.core.IClasspathContainer; |
49 |
import org.eclipse.jdt.core.IClasspathEntry; |
51 |
import org.eclipse.jdt.core.IClasspathEntry; |
50 |
import org.eclipse.jdt.core.ICompilationUnit; |
52 |
import org.eclipse.jdt.core.ICompilationUnit; |
Lines 260-265
Link Here
|
260 |
return false; |
262 |
return false; |
261 |
return true; |
263 |
return true; |
262 |
} |
264 |
} |
|
|
265 |
|
266 |
private static boolean areClasspathEqual(IClasspathEntry[] first, IClasspathEntry[] second) { |
267 |
if (first != second){ |
268 |
if (first == null) return false; |
269 |
int length = first.length; |
270 |
if (second == null || second.length != length) |
271 |
return false; |
272 |
for (int i = 0; i < length; i++) { |
273 |
if (!first[i].equals(second[i])) |
274 |
return false; |
275 |
} |
276 |
} |
277 |
return true; |
278 |
} |
263 |
|
279 |
|
264 |
/** |
280 |
/** |
265 |
* Returns a canonicalized path from the given external path. |
281 |
* Returns a canonicalized path from the given external path. |
Lines 848-854
Link Here
|
848 |
/* |
864 |
/* |
849 |
* Reads and decode an XML classpath string |
865 |
* Reads and decode an XML classpath string |
850 |
*/ |
866 |
*/ |
851 |
public IClasspathEntry[] decodeClasspath(String xmlClasspath, Map unknownElements) throws IOException, ClasspathEntry.AssertionFailedException { |
867 |
public IClasspathEntry[][] decodeClasspath(String xmlClasspath, Map unknownElements) throws IOException, ClasspathEntry.AssertionFailedException { |
852 |
|
868 |
|
853 |
ArrayList paths = new ArrayList(); |
869 |
ArrayList paths = new ArrayList(); |
854 |
IClasspathEntry defaultOutput = null; |
870 |
IClasspathEntry defaultOutput = null; |
Lines 868-874
Link Here
|
868 |
if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$ |
884 |
if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$ |
869 |
throw new IOException(Messages.file_badFormat); |
885 |
throw new IOException(Messages.file_badFormat); |
870 |
} |
886 |
} |
871 |
NodeList list = cpElement.getElementsByTagName("classpathentry"); //$NON-NLS-1$ |
887 |
NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY); |
872 |
int length = list.getLength(); |
888 |
int length = list.getLength(); |
873 |
|
889 |
|
874 |
for (int i = 0; i < length; ++i) { |
890 |
for (int i = 0; i < length; ++i) { |
Lines 880-894
Link Here
|
880 |
defaultOutput = entry; // separate output |
896 |
defaultOutput = entry; // separate output |
881 |
} else { |
897 |
} else { |
882 |
paths.add(entry); |
898 |
paths.add(entry); |
|
|
899 |
} |
900 |
} |
883 |
} |
901 |
} |
884 |
} |
902 |
} |
|
|
903 |
int pathSize = paths.size(); |
904 |
IClasspathEntry[][] entries = new IClasspathEntry[2][]; |
905 |
entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)]; |
906 |
paths.toArray(entries[0]); |
907 |
if (defaultOutput != null) entries[0][pathSize] = defaultOutput; // ensure output is last item |
908 |
|
909 |
paths.clear(); |
910 |
list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY); |
911 |
length = list.getLength(); |
912 |
|
913 |
for (int i = 0; i < length; ++i) { |
914 |
Node node = list.item(i); |
915 |
if (node.getNodeType() == Node.ELEMENT_NODE) { |
916 |
IClasspathEntry entry = ClasspathEntry.elementDecode((Element)node, this, unknownElements); |
917 |
if (entry != null){ |
918 |
paths.add(entry); |
919 |
} |
885 |
} |
920 |
} |
886 |
} |
921 |
} |
887 |
// return a new empty classpath is it size is 0, to differenciate from an INVALID_CLASSPATH |
922 |
entries[1] = new IClasspathEntry[paths.size()]; |
888 |
int pathSize = paths.size(); |
923 |
paths.toArray(entries[1]); |
889 |
IClasspathEntry[] entries = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)]; |
924 |
|
890 |
paths.toArray(entries); |
|
|
891 |
if (defaultOutput != null) entries[pathSize] = defaultOutput; // ensure output is last item |
892 |
return entries; |
925 |
return entries; |
893 |
} |
926 |
} |
894 |
|
927 |
|
Lines 911-917
Link Here
|
911 |
reader.close(); |
944 |
reader.close(); |
912 |
} |
945 |
} |
913 |
|
946 |
|
914 |
if (!node.getNodeName().equalsIgnoreCase("classpathentry") //$NON-NLS-1$ |
947 |
if (!node.getNodeName().equalsIgnoreCase(ClasspathEntry.TAG_CLASSPATHENTRY) |
915 |
|| node.getNodeType() != Node.ELEMENT_NODE) { |
948 |
|| node.getNodeType() != Node.ELEMENT_NODE) { |
916 |
return null; |
949 |
return null; |
917 |
} |
950 |
} |
Lines 956-962
Link Here
|
956 |
/** |
989 |
/** |
957 |
* Returns the XML String encoding of the class path. |
990 |
* Returns the XML String encoding of the class path. |
958 |
*/ |
991 |
*/ |
959 |
protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException { |
992 |
protected String encodeClasspath(IClasspathEntry[] classpath, IClasspathEntry[] referencedEntries, IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException { |
960 |
try { |
993 |
try { |
961 |
ByteArrayOutputStream s = new ByteArrayOutputStream(); |
994 |
ByteArrayOutputStream s = new ByteArrayOutputStream(); |
962 |
OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$ |
995 |
OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$ |
Lines 964-970
Link Here
|
964 |
|
997 |
|
965 |
xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent); |
998 |
xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent); |
966 |
for (int i = 0; i < classpath.length; ++i) { |
999 |
for (int i = 0; i < classpath.length; ++i) { |
967 |
((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements); |
1000 |
((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements, false); |
968 |
} |
1001 |
} |
969 |
|
1002 |
|
970 |
if (outputLocation != null) { |
1003 |
if (outputLocation != null) { |
Lines 976-981
Link Here
|
976 |
xmlWriter.printTag(ClasspathEntry.TAG_CLASSPATHENTRY, parameters, indent, true, true); |
1009 |
xmlWriter.printTag(ClasspathEntry.TAG_CLASSPATHENTRY, parameters, indent, true, true); |
977 |
} |
1010 |
} |
978 |
|
1011 |
|
|
|
1012 |
if (referencedEntries != null) { |
1013 |
for (int i = 0; i < referencedEntries.length; ++i) { |
1014 |
((ClasspathEntry) referencedEntries[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements, true); |
1015 |
} |
1016 |
} |
1017 |
|
979 |
xmlWriter.endTag(ClasspathEntry.TAG_CLASSPATH, indent, true/*insert new line*/); |
1018 |
xmlWriter.endTag(ClasspathEntry.TAG_CLASSPATH, indent, true/*insert new line*/); |
980 |
writer.flush(); |
1019 |
writer.flush(); |
981 |
writer.close(); |
1020 |
writer.close(); |
Lines 991-997
Link Here
|
991 |
OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$ |
1030 |
OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$ |
992 |
XMLWriter xmlWriter = new XMLWriter(writer, this, false/*don't print XML version*/); |
1031 |
XMLWriter xmlWriter = new XMLWriter(writer, this, false/*don't print XML version*/); |
993 |
|
1032 |
|
994 |
((ClasspathEntry)classpathEntry).elementEncode(xmlWriter, this.project.getFullPath(), true/*indent*/, true/*insert new line*/, null/*not interested in unknown elements*/); |
1033 |
((ClasspathEntry)classpathEntry).elementEncode(xmlWriter, this.project.getFullPath(), true/*indent*/, true/*insert new line*/, null/*not interested in unknown elements*/, (classpathEntry.getReferencingEntry() != null)); |
995 |
|
1034 |
|
996 |
writer.flush(); |
1035 |
writer.flush(); |
997 |
writer.close(); |
1036 |
writer.close(); |
Lines 1841-1847
Link Here
|
1841 |
IClasspathEntry[] classpath = perProjectInfo.rawClasspath; |
1880 |
IClasspathEntry[] classpath = perProjectInfo.rawClasspath; |
1842 |
if (classpath != null) return classpath; |
1881 |
if (classpath != null) return classpath; |
1843 |
|
1882 |
|
1844 |
classpath = perProjectInfo.readAndCacheClasspath(this); |
1883 |
classpath = perProjectInfo.readAndCacheClasspath(this)[0]; |
1845 |
|
1884 |
|
1846 |
if (classpath == JavaProject.INVALID_CLASSPATH) |
1885 |
if (classpath == JavaProject.INVALID_CLASSPATH) |
1847 |
return defaultClasspath(); |
1886 |
return defaultClasspath(); |
Lines 1850-1855
Link Here
|
1850 |
} |
1889 |
} |
1851 |
|
1890 |
|
1852 |
/** |
1891 |
/** |
|
|
1892 |
* @see IJavaProject |
1893 |
*/ |
1894 |
public IClasspathEntry[] getReferencedClasspathEntries() throws JavaModelException { |
1895 |
return getPerProjectInfo().referencedEntries; |
1896 |
} |
1897 |
|
1898 |
/** |
1853 |
* @see IJavaProject#getRequiredProjectNames() |
1899 |
* @see IJavaProject#getRequiredProjectNames() |
1854 |
*/ |
1900 |
*/ |
1855 |
public String[] getRequiredProjectNames() throws JavaModelException { |
1901 |
public String[] getRequiredProjectNames() throws JavaModelException { |
Lines 2384-2390
Link Here
|
2384 |
* As a side effect, unknown elements are stored in the given map (if not null) |
2430 |
* As a side effect, unknown elements are stored in the given map (if not null) |
2385 |
* Throws exceptions if the file cannot be accessed or is malformed. |
2431 |
* Throws exceptions if the file cannot be accessed or is malformed. |
2386 |
*/ |
2432 |
*/ |
2387 |
public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException { |
2433 |
public IClasspathEntry[][] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException { |
2388 |
IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME); |
2434 |
IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME); |
2389 |
byte[] bytes; |
2435 |
byte[] bytes; |
2390 |
if (rscFile.exists()) { |
2436 |
if (rscFile.exists()) { |
Lines 2403-2409
Link Here
|
2403 |
bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file); |
2449 |
bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file); |
2404 |
} catch (IOException e) { |
2450 |
} catch (IOException e) { |
2405 |
if (!file.exists()) |
2451 |
if (!file.exists()) |
2406 |
return defaultClasspath(); |
2452 |
return new IClasspathEntry[][]{defaultClasspath(), ClasspathEntry.NO_ENTRIES}; |
2407 |
throw e; |
2453 |
throw e; |
2408 |
} |
2454 |
} |
2409 |
} |
2455 |
} |
Lines 2427-2444
Link Here
|
2427 |
* This includes the output entry. |
2473 |
* This includes the output entry. |
2428 |
* As a side effect, unknown elements are stored in the given map (if not null) |
2474 |
* As a side effect, unknown elements are stored in the given map (if not null) |
2429 |
*/ |
2475 |
*/ |
2430 |
private IClasspathEntry[] readFileEntries(Map unkwownElements) { |
2476 |
private IClasspathEntry[][] readFileEntries(Map unkwownElements) { |
2431 |
try { |
2477 |
try { |
2432 |
return readFileEntriesWithException(unkwownElements); |
2478 |
return readFileEntriesWithException(unkwownElements); |
2433 |
} catch (CoreException e) { |
2479 |
} catch (CoreException e) { |
2434 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2480 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2435 |
return JavaProject.INVALID_CLASSPATH; |
2481 |
return new IClasspathEntry[][]{JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES}; |
2436 |
} catch (IOException e) { |
2482 |
} catch (IOException e) { |
2437 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2483 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2438 |
return JavaProject.INVALID_CLASSPATH; |
2484 |
return new IClasspathEntry[][]{JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES}; |
2439 |
} catch (ClasspathEntry.AssertionFailedException e) { |
2485 |
} catch (ClasspathEntry.AssertionFailedException e) { |
2440 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2486 |
Util.log(e, "Exception while reading " + getPath().append(JavaProject.CLASSPATH_FILENAME)); //$NON-NLS-1$ |
2441 |
return JavaProject.INVALID_CLASSPATH; |
2487 |
return new IClasspathEntry[][]{JavaProject.INVALID_CLASSPATH, ClasspathEntry.NO_ENTRIES}; |
2442 |
} |
2488 |
} |
2443 |
} |
2489 |
} |
2444 |
|
2490 |
|
Lines 2447-2460
Link Here
|
2447 |
*/ |
2493 |
*/ |
2448 |
public IPath readOutputLocation() { |
2494 |
public IPath readOutputLocation() { |
2449 |
// Read classpath file without creating markers nor logging problems |
2495 |
// Read classpath file without creating markers nor logging problems |
2450 |
IClasspathEntry[] classpath = readFileEntries(null/*not interested in unknown elements*/); |
2496 |
IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/); |
2451 |
if (classpath == JavaProject.INVALID_CLASSPATH) |
2497 |
if (classpath[0] == JavaProject.INVALID_CLASSPATH) |
2452 |
return defaultOutputLocation(); |
2498 |
return defaultOutputLocation(); |
2453 |
|
2499 |
|
2454 |
// extract the output location |
2500 |
// extract the output location |
2455 |
IPath outputLocation = null; |
2501 |
IPath outputLocation = null; |
2456 |
if (classpath.length > 0) { |
2502 |
if (classpath[0].length > 0) { |
2457 |
IClasspathEntry entry = classpath[classpath.length - 1]; |
2503 |
IClasspathEntry entry = classpath[0][classpath[0].length - 1]; |
2458 |
if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { |
2504 |
if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { |
2459 |
outputLocation = entry.getPath(); |
2505 |
outputLocation = entry.getPath(); |
2460 |
} |
2506 |
} |
Lines 2467-2486
Link Here
|
2467 |
*/ |
2513 |
*/ |
2468 |
public IClasspathEntry[] readRawClasspath() { |
2514 |
public IClasspathEntry[] readRawClasspath() { |
2469 |
// Read classpath file without creating markers nor logging problems |
2515 |
// Read classpath file without creating markers nor logging problems |
2470 |
IClasspathEntry[] classpath = readFileEntries(null/*not interested in unknown elements*/); |
2516 |
IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/); |
2471 |
if (classpath == JavaProject.INVALID_CLASSPATH) |
2517 |
if (classpath[0] == JavaProject.INVALID_CLASSPATH) |
2472 |
return defaultClasspath(); |
2518 |
return defaultClasspath(); |
2473 |
|
2519 |
|
2474 |
// discard the output location |
2520 |
// discard the output location |
2475 |
if (classpath.length > 0) { |
2521 |
if (classpath[0].length > 0) { |
2476 |
IClasspathEntry entry = classpath[classpath.length - 1]; |
2522 |
IClasspathEntry entry = classpath[0][classpath[0].length - 1]; |
2477 |
if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { |
2523 |
if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { |
2478 |
IClasspathEntry[] copy = new IClasspathEntry[classpath.length - 1]; |
2524 |
IClasspathEntry[] copy = new IClasspathEntry[classpath[0].length - 1]; |
2479 |
System.arraycopy(classpath, 0, copy, 0, copy.length); |
2525 |
System.arraycopy(classpath[0], 0, copy, 0, copy.length); |
2480 |
classpath = copy; |
2526 |
classpath[0] = copy; |
2481 |
} |
2527 |
} |
2482 |
} |
2528 |
} |
2483 |
return classpath; |
2529 |
return classpath[0]; |
2484 |
} |
2530 |
} |
2485 |
|
2531 |
|
2486 |
/** |
2532 |
/** |
Lines 2533-2546
Link Here
|
2533 |
IJavaModelStatus unresolvedEntryStatus = JavaModelStatus.VERIFIED_OK; |
2579 |
IJavaModelStatus unresolvedEntryStatus = JavaModelStatus.VERIFIED_OK; |
2534 |
HashMap rawReverseMap = new HashMap(); |
2580 |
HashMap rawReverseMap = new HashMap(); |
2535 |
Map rootPathToResolvedEntries = new HashMap(); |
2581 |
Map rootPathToResolvedEntries = new HashMap(); |
|
|
2582 |
IClasspathEntry[] referencedEntries = null; |
2536 |
} |
2583 |
} |
2537 |
|
2584 |
|
2538 |
public ResolvedClasspath resolveClasspath(IClasspathEntry[] rawClasspath, boolean usePreviousSession, boolean resolveChainedLibraries) throws JavaModelException { |
2585 |
public ResolvedClasspath resolveClasspath(IClasspathEntry[] rawClasspath, boolean usePreviousSession, boolean resolveChainedLibraries) throws JavaModelException { |
|
|
2586 |
return resolveClasspath(rawClasspath, null, usePreviousSession, resolveChainedLibraries); |
2587 |
} |
2588 |
|
2589 |
public ResolvedClasspath resolveClasspath(IClasspathEntry[] rawClasspath, IClasspathEntry[] referencedEntries, boolean usePreviousSession, boolean resolveChainedLibraries) throws JavaModelException { |
2539 |
JavaModelManager manager = JavaModelManager.getJavaModelManager(); |
2590 |
JavaModelManager manager = JavaModelManager.getJavaModelManager(); |
2540 |
ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager(); |
2591 |
ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager(); |
2541 |
ResolvedClasspath result = new ResolvedClasspath(); |
2592 |
ResolvedClasspath result = new ResolvedClasspath(); |
2542 |
|
2593 |
|
|
|
2594 |
Map referencedEntriesMap = new HashMap(); |
2595 |
List rawLibrariesPath = new ArrayList(); |
2543 |
LinkedHashSet resolvedEntries = new LinkedHashSet(); |
2596 |
LinkedHashSet resolvedEntries = new LinkedHashSet(); |
|
|
2597 |
|
2598 |
if(resolveChainedLibraries) { |
2599 |
for (int index = 0; index < rawClasspath.length; index++) { |
2600 |
IClasspathEntry currentEntry = rawClasspath[index]; |
2601 |
if (currentEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
2602 |
rawLibrariesPath.add(ClasspathEntry.resolveDotDot(currentEntry.getPath())); |
2603 |
} |
2604 |
} |
2605 |
if (referencedEntries != null) { |
2606 |
// The Set is required to keep the order intact while the referencedEntriesMap (Map) |
2607 |
// is used to map the referenced entries with path |
2608 |
LinkedHashSet referencedEntriesSet = new LinkedHashSet(); |
2609 |
for (int index = 0; index < referencedEntries.length; index++) { |
2610 |
IPath path = referencedEntries[index].getPath(); |
2611 |
if (!rawLibrariesPath.contains(path) && referencedEntriesMap.get(path) == null) { |
2612 |
referencedEntriesMap.put(path, referencedEntries[index]); |
2613 |
referencedEntriesSet.add(referencedEntries[index]); |
2614 |
} |
2615 |
} |
2616 |
result.referencedEntries = new IClasspathEntry[referencedEntriesSet.size()]; |
2617 |
referencedEntriesSet.toArray(result.referencedEntries); |
2618 |
} |
2619 |
} |
2620 |
|
2544 |
int length = rawClasspath.length; |
2621 |
int length = rawClasspath.length; |
2545 |
for (int i = 0; i < length; i++) { |
2622 |
for (int i = 0; i < length; i++) { |
2546 |
|
2623 |
|
Lines 2561-2574
Link Here
|
2561 |
if (resolvedEntry == null) { |
2638 |
if (resolvedEntry == null) { |
2562 |
result.unresolvedEntryStatus = new JavaModelStatus(IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND, this, rawEntry.getPath()); |
2639 |
result.unresolvedEntryStatus = new JavaModelStatus(IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND, this, rawEntry.getPath()); |
2563 |
} else { |
2640 |
} else { |
2564 |
if (resolveChainedLibraries && resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
2641 |
// If the entry is already present in the rawReversetMap, it means the entry and the chained libraries |
|
|
2642 |
// have already been processed. So, skip it. |
2643 |
if (resolveChainedLibraries && resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY |
2644 |
&& result.rawReverseMap.get(resolvedEntry.getPath()) == null) { |
2565 |
// resolve Class-Path: in manifest |
2645 |
// resolve Class-Path: in manifest |
2566 |
ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); |
2646 |
ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); |
2567 |
for (int j = 0, length2 = extraEntries.length; j < length2; j++) { |
2647 |
for (int j = 0, length2 = extraEntries.length; j < length2; j++) { |
2568 |
addToResult(rawEntry, extraEntries[j], result, resolvedEntries, externalFoldersManager); |
2648 |
if (!rawLibrariesPath.contains(extraEntries[j].getPath())) { |
|
|
2649 |
addToResult(rawEntry, extraEntries[j], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, true); |
2650 |
} |
2569 |
} |
2651 |
} |
2570 |
} |
2652 |
} |
2571 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager); |
2653 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false); |
2572 |
} |
2654 |
} |
2573 |
break; |
2655 |
break; |
2574 |
|
2656 |
|
Lines 2603-2617
Link Here
|
2603 |
// resolve ".." in library path |
2685 |
// resolve ".." in library path |
2604 |
cEntry = cEntry.resolvedDotDot(); |
2686 |
cEntry = cEntry.resolvedDotDot(); |
2605 |
|
2687 |
|
2606 |
if (resolveChainedLibraries) { |
2688 |
if (resolveChainedLibraries && result.rawReverseMap.get(cEntry.getPath()) == null) { |
2607 |
// resolve Class-Path: in manifest |
2689 |
// resolve Class-Path: in manifest |
2608 |
ClasspathEntry[] extraEntries = cEntry.resolvedChainedLibraries(); |
2690 |
ClasspathEntry[] extraEntries = cEntry.resolvedChainedLibraries(); |
2609 |
for (int k = 0, length2 = extraEntries.length; k < length2; k++) { |
2691 |
for (int k = 0, length2 = extraEntries.length; k < length2; k++) { |
2610 |
addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager); |
2692 |
if (!rawLibrariesPath.contains(extraEntries[k].getPath())) { |
|
|
2693 |
addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, true); |
2694 |
} |
2611 |
} |
2695 |
} |
2612 |
} |
2696 |
} |
2613 |
} |
2697 |
} |
2614 |
addToResult(rawEntry, cEntry, result, resolvedEntries, externalFoldersManager); |
2698 |
addToResult(rawEntry, cEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false); |
2615 |
} |
2699 |
} |
2616 |
break; |
2700 |
break; |
2617 |
|
2701 |
|
Lines 2619-2636
Link Here
|
2619 |
// resolve ".." in library path |
2703 |
// resolve ".." in library path |
2620 |
resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(); |
2704 |
resolvedEntry = ((ClasspathEntry) rawEntry).resolvedDotDot(); |
2621 |
|
2705 |
|
2622 |
if (resolveChainedLibraries) { |
2706 |
if (resolveChainedLibraries && result.rawReverseMap.get(resolvedEntry.getPath()) == null) { |
2623 |
// resolve Class-Path: in manifest |
2707 |
// resolve Class-Path: in manifest |
2624 |
ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); |
2708 |
ClasspathEntry[] extraEntries = ((ClasspathEntry) resolvedEntry).resolvedChainedLibraries(); |
2625 |
for (int k = 0, length2 = extraEntries.length; k < length2; k++) { |
2709 |
for (int k = 0, length2 = extraEntries.length; k < length2; k++) { |
2626 |
addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager); |
2710 |
if (!rawLibrariesPath.contains(extraEntries[k].getPath())) { |
|
|
2711 |
addToResult(rawEntry, extraEntries[k], result, resolvedEntries, externalFoldersManager, referencedEntriesMap, true); |
2712 |
} |
2627 |
} |
2713 |
} |
2628 |
} |
2714 |
} |
2629 |
|
2715 |
|
2630 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager); |
2716 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false); |
2631 |
break; |
2717 |
break; |
2632 |
default : |
2718 |
default : |
2633 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager); |
2719 |
addToResult(rawEntry, resolvedEntry, result, resolvedEntries, externalFoldersManager, referencedEntriesMap, false); |
2634 |
break; |
2720 |
break; |
2635 |
} |
2721 |
} |
2636 |
} |
2722 |
} |
Lines 2639-2656
Link Here
|
2639 |
return result; |
2725 |
return result; |
2640 |
} |
2726 |
} |
2641 |
|
2727 |
|
2642 |
private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager) { |
2728 |
private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, |
|
|
2729 |
LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager, |
2730 |
Map oldChainedEntriesMap, boolean addAsChainedEntry) { |
2731 |
|
2643 |
IPath resolvedPath; |
2732 |
IPath resolvedPath; |
|
|
2733 |
// If it's already been resolved, do not add to resolvedEntries or newChainedEntries lists |
2644 |
if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) { |
2734 |
if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) { |
2645 |
result.rawReverseMap.put(resolvedPath, rawEntry); |
2735 |
result.rawReverseMap.put(resolvedPath, rawEntry); |
2646 |
result.rootPathToResolvedEntries.put(resolvedPath, resolvedEntry); |
2736 |
result.rootPathToResolvedEntries.put(resolvedPath, resolvedEntry); |
2647 |
resolvedEntries.add(resolvedEntry); |
2737 |
resolvedEntries.add(resolvedEntry); |
|
|
2738 |
if (addAsChainedEntry) { |
2739 |
IClasspathEntry chainedEntry = null; |
2740 |
if (rawEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
2741 |
|
2742 |
chainedEntry = (ClasspathEntry) oldChainedEntriesMap.get(resolvedPath); |
2743 |
if (chainedEntry != null) { |
2744 |
// This is required to keep the attributes if any added by the user in |
2745 |
// the previous session such as source attachment path etc. |
2746 |
copyFromOldChainedEntry((ClasspathEntry) resolvedEntry, (ClasspathEntry) chainedEntry); |
2747 |
} |
2748 |
} |
2749 |
} |
2648 |
} |
2750 |
} |
2649 |
if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) { |
2751 |
if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) { |
2650 |
externalFoldersManager.addFolder(resolvedPath); // no-op if not an external folder or if already registered |
2752 |
externalFoldersManager.addFolder(resolvedPath); // no-op if not an external folder or if already registered |
2651 |
} |
2753 |
} |
2652 |
} |
2754 |
} |
2653 |
|
2755 |
|
|
|
2756 |
private void copyFromOldChainedEntry(ClasspathEntry resolvedEntry, ClasspathEntry chainedEntry) { |
2757 |
IPath path = chainedEntry.getSourceAttachmentPath(); |
2758 |
if ( path != null) { |
2759 |
resolvedEntry.sourceAttachmentPath = path; |
2760 |
} |
2761 |
path = chainedEntry.getSourceAttachmentRootPath(); |
2762 |
if (path != null) { |
2763 |
resolvedEntry.sourceAttachmentRootPath = path; |
2764 |
} |
2765 |
IClasspathAttribute[] attributes = chainedEntry.getExtraAttributes(); |
2766 |
if (attributes != null) { |
2767 |
resolvedEntry.extraAttributes = attributes; |
2768 |
} |
2769 |
} |
2770 |
|
2654 |
/* |
2771 |
/* |
2655 |
* Resolve the given perProjectInfo's raw classpath and store the resolved classpath in the perProjectInfo. |
2772 |
* Resolve the given perProjectInfo's raw classpath and store the resolved classpath in the perProjectInfo. |
2656 |
*/ |
2773 |
*/ |
Lines 2665-2686
Link Here
|
2665 |
} |
2782 |
} |
2666 |
|
2783 |
|
2667 |
// get raw info inside a synchronized block to ensure that it is consistent |
2784 |
// get raw info inside a synchronized block to ensure that it is consistent |
2668 |
IClasspathEntry[] rawClasspath; |
2785 |
IClasspathEntry[][] classpath = new IClasspathEntry[2][]; |
2669 |
int timeStamp; |
2786 |
int timeStamp; |
2670 |
synchronized (perProjectInfo) { |
2787 |
synchronized (perProjectInfo) { |
2671 |
rawClasspath= perProjectInfo.rawClasspath; |
2788 |
classpath[0] = perProjectInfo.rawClasspath; |
2672 |
if (rawClasspath == null) |
2789 |
classpath[1] = perProjectInfo.referencedEntries; |
2673 |
rawClasspath = perProjectInfo.readAndCacheClasspath(this); |
2790 |
// Checking null only for rawClasspath enough |
|
|
2791 |
if (classpath[0] == null) |
2792 |
classpath = perProjectInfo.readAndCacheClasspath(this); |
2674 |
timeStamp = perProjectInfo.rawTimeStamp; |
2793 |
timeStamp = perProjectInfo.rawTimeStamp; |
2675 |
} |
2794 |
} |
2676 |
|
|
|
2677 |
ResolvedClasspath result = resolveClasspath(rawClasspath, usePreviousSession, true/*resolve chained libraries*/); |
2678 |
|
2795 |
|
|
|
2796 |
ResolvedClasspath result = resolveClasspath(classpath[0], classpath[1], usePreviousSession, true/*resolve chained libraries*/); |
2797 |
|
2679 |
if (CP_RESOLUTION_BP_LISTENERS != null) |
2798 |
if (CP_RESOLUTION_BP_LISTENERS != null) |
2680 |
breakpoint(2, this); |
2799 |
breakpoint(2, this); |
2681 |
|
2800 |
|
2682 |
// store resolved info along with the raw info to ensure consistency |
2801 |
// store resolved info along with the raw info to ensure consistency |
2683 |
perProjectInfo.setResolvedClasspath(result.resolvedClasspath, result.rawReverseMap, result.rootPathToResolvedEntries, usePreviousSession ? PerProjectInfo.NEED_RESOLUTION : result.unresolvedEntryStatus, timeStamp, addClasspathChange); |
2802 |
perProjectInfo.setResolvedClasspath(result.resolvedClasspath, result.referencedEntries, result.rawReverseMap, result.rootPathToResolvedEntries, usePreviousSession ? PerProjectInfo.NEED_RESOLUTION : result.unresolvedEntryStatus, timeStamp, addClasspathChange); |
2684 |
} finally { |
2803 |
} finally { |
2685 |
if (!isClasspathBeingResolved) { |
2804 |
if (!isClasspathBeingResolved) { |
2686 |
manager.setClasspathBeingResolved(this, false); |
2805 |
manager.setClasspathBeingResolved(this, false); |
Lines 2708-2732
Link Here
|
2708 |
* @return boolean Return whether the .classpath file was modified. |
2827 |
* @return boolean Return whether the .classpath file was modified. |
2709 |
* @throws JavaModelException |
2828 |
* @throws JavaModelException |
2710 |
*/ |
2829 |
*/ |
2711 |
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IPath newOutputLocation) throws JavaModelException { |
2830 |
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation) throws JavaModelException { |
2712 |
|
2831 |
|
2713 |
if (!this.project.isAccessible()) return false; |
2832 |
if (!this.project.isAccessible()) return false; |
2714 |
|
2833 |
|
2715 |
Map unknownElements = new HashMap(); |
2834 |
Map unknownElements = new HashMap(); |
2716 |
IClasspathEntry[] fileEntries = readFileEntries(unknownElements); |
2835 |
IClasspathEntry[][] fileEntries = readFileEntries(unknownElements); |
2717 |
if (fileEntries != JavaProject.INVALID_CLASSPATH && areClasspathsEqual(newClasspath, newOutputLocation, fileEntries)) { |
2836 |
if (fileEntries[0] != JavaProject.INVALID_CLASSPATH && |
|
|
2837 |
areClasspathsEqual(newClasspath, newOutputLocation, fileEntries[0]) |
2838 |
&& areClasspathEqual(referencedEntries, fileEntries[1])) { |
2718 |
// no need to save it, it is the same |
2839 |
// no need to save it, it is the same |
2719 |
return false; |
2840 |
return false; |
2720 |
} |
2841 |
} |
2721 |
|
2842 |
|
2722 |
// actual file saving |
2843 |
// actual file saving |
2723 |
try { |
2844 |
try { |
2724 |
setSharedProperty(JavaProject.CLASSPATH_FILENAME, encodeClasspath(newClasspath, newOutputLocation, true, unknownElements)); |
2845 |
setSharedProperty(JavaProject.CLASSPATH_FILENAME, encodeClasspath(newClasspath, referencedEntries, newOutputLocation, true, unknownElements)); |
2725 |
return true; |
2846 |
return true; |
2726 |
} catch (CoreException e) { |
2847 |
} catch (CoreException e) { |
2727 |
throw new JavaModelException(e); |
2848 |
throw new JavaModelException(e); |
2728 |
} |
2849 |
} |
2729 |
} |
2850 |
} |
|
|
2851 |
public boolean writeFileEntries(IClasspathEntry[] newClasspath, IPath newOutputLocation) throws JavaModelException { |
2852 |
return writeFileEntries(newClasspath, ClasspathEntry.NO_ENTRIES, newOutputLocation); |
2853 |
} |
2730 |
|
2854 |
|
2731 |
/** |
2855 |
/** |
2732 |
* Update the Java command in the build spec (replace existing one if present, |
2856 |
* Update the Java command in the build spec (replace existing one if present, |
Lines 2874-2895
Link Here
|
2874 |
boolean canModifyResources, |
2998 |
boolean canModifyResources, |
2875 |
IProgressMonitor monitor) |
2999 |
IProgressMonitor monitor) |
2876 |
throws JavaModelException { |
3000 |
throws JavaModelException { |
2877 |
|
3001 |
setRawClasspath(newRawClasspath, null, newOutputLocation, canModifyResources, monitor); |
2878 |
try { |
|
|
2879 |
if (newRawClasspath == null) //are we already with the default classpath |
2880 |
newRawClasspath = defaultClasspath(); |
2881 |
|
2882 |
SetClasspathOperation op = |
2883 |
new SetClasspathOperation( |
2884 |
this, |
2885 |
newRawClasspath, |
2886 |
newOutputLocation, |
2887 |
canModifyResources); |
2888 |
op.runOperation(monitor); |
2889 |
} catch (JavaModelException e) { |
2890 |
JavaModelManager.getJavaModelManager().getDeltaProcessor().flush(); |
2891 |
throw e; |
2892 |
} |
2893 |
} |
3002 |
} |
2894 |
|
3003 |
|
2895 |
/** |
3004 |
/** |
Lines 2907-2912
Link Here
|
2907 |
true/*can change resource (as per API contract)*/, |
3016 |
true/*can change resource (as per API contract)*/, |
2908 |
monitor); |
3017 |
monitor); |
2909 |
} |
3018 |
} |
|
|
3019 |
|
3020 |
public void setRawClasspath(IClasspathEntry[] entries, IClasspathEntry[] referencedEntries, IPath outputLocation, |
3021 |
IProgressMonitor monitor) throws JavaModelException { |
3022 |
setRawClasspath(entries, referencedEntries, outputLocation, true, monitor); |
3023 |
} |
3024 |
|
3025 |
protected void setRawClasspath(IClasspathEntry[] newRawClasspath, IClasspathEntry[] referencedEntries, IPath newOutputLocation, |
3026 |
boolean canModifyResources, IProgressMonitor monitor) throws JavaModelException { |
3027 |
|
3028 |
try { |
3029 |
if (newRawClasspath == null) //are we already with the default classpath |
3030 |
newRawClasspath = defaultClasspath(); |
3031 |
|
3032 |
SetClasspathOperation op = |
3033 |
new SetClasspathOperation( |
3034 |
this, |
3035 |
newRawClasspath, |
3036 |
referencedEntries, |
3037 |
newOutputLocation, |
3038 |
canModifyResources); |
3039 |
op.runOperation(monitor); |
3040 |
} catch (JavaModelException e) { |
3041 |
JavaModelManager.getJavaModelManager().getDeltaProcessor().flush(); |
3042 |
throw e; |
3043 |
} |
3044 |
} |
2910 |
|
3045 |
|
2911 |
/** |
3046 |
/** |
2912 |
* @see IJavaProject |
3047 |
* @see IJavaProject |