Lines 5972-5975
Link Here
|
5972 |
} |
5972 |
} |
5973 |
} |
5973 |
} |
5974 |
|
5974 |
|
|
|
5975 |
/** |
5976 |
* @bug 281551:[build path] Source attachments wrong for automatically added libraries |
5977 |
* @test that chained libraries that are already in the raw classpath are not added to the resolved |
5978 |
* classpath again |
5979 |
* |
5980 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281551" |
5981 |
*/ |
5982 |
public void test281551() throws Exception { |
5983 |
try { |
5984 |
IJavaProject p = createJavaProject("P"); |
5985 |
addLibrary(p, "lib1.jar", "lib1src.zip", new String[0], |
5986 |
new String[] { |
5987 |
"META-INF/MANIFEST.MF", |
5988 |
"Manifest-Version: 1.0\n" + |
5989 |
"Class-Path: lib2.jar\n", |
5990 |
}, |
5991 |
JavaCore.VERSION_1_4); |
5992 |
addLibrary(p, "lib2.jar", "lib2src.zip", new String[0], |
5993 |
new String[] { |
5994 |
"META-INF/MANIFEST.MF", |
5995 |
"Manifest-Version: 1.0\n" + |
5996 |
"Class-Path: \n", |
5997 |
}, |
5998 |
JavaCore.VERSION_1_4); |
5999 |
|
6000 |
ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID); |
6001 |
String libraryName = "SWT"; |
6002 |
IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID); |
6003 |
UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName); |
6004 |
initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion); |
6005 |
|
6006 |
IFile jarFile = getFile("/P/lib1.jar"); |
6007 |
|
6008 |
// Modify user library |
6009 |
IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID); |
6010 |
String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"SWT"; |
6011 |
String jarFullPath = getWorkspaceRoot().getLocation().append(jarFile.getFullPath()).toString(); |
6012 |
|
6013 |
StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive"); |
6014 |
propertyValue.append(" path=\""+jarFullPath); |
6015 |
propertyValue.append("\"/>\r\n</userlibrary>\r\n"); |
6016 |
preferences.put(propertyName, propertyValue.toString()); |
6017 |
preferences.flush(); |
6018 |
|
6019 |
IClasspathEntry[] entries = p.getRawClasspath(); |
6020 |
int length = entries.length; |
6021 |
System.arraycopy(entries, 0, entries = new IClasspathEntry[length+1], 0, length); |
6022 |
entries[length] = JavaCore.newContainerEntry(containerSuggestion.getPath()); |
6023 |
p.setRawClasspath(entries, null); |
6024 |
|
6025 |
assertClasspathEquals( |
6026 |
p.getResolvedClasspath(true), |
6027 |
"/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" + |
6028 |
""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" + |
6029 |
"/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/lib1src.zip][isExported:true]\n" + |
6030 |
"/P/lib2.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/lib2src.zip][isExported:true]\n" + |
6031 |
""+ getWorkspacePath() + "P\\lib1.jar[CPE_LIBRARY][K_BINARY][isExported:false]" |
6032 |
); |
6033 |
|
6034 |
} finally { |
6035 |
deleteProject("P"); |
6036 |
} |
6037 |
} |
6038 |
/** |
6039 |
* @bug 281551:[build path] Source attachments wrong for automatically added libraries |
6040 |
* @test that jars directly added to a container are added to the raw classpath even when |
6041 |
* they are referenced in other jar files |
6042 |
* |
6043 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281551" |
6044 |
*/ |
6045 |
public void test281551a() throws Exception { |
6046 |
try { |
6047 |
IJavaProject p = createJavaProject("P"); |
6048 |
addLibrary(p, "lib1.jar", "lib1src.zip", new String[0], |
6049 |
new String[] { |
6050 |
"META-INF/MANIFEST.MF", |
6051 |
"Manifest-Version: 1.0\n" + |
6052 |
"Class-Path: lib2.jar\n", |
6053 |
}, |
6054 |
JavaCore.VERSION_1_4); |
6055 |
addLibrary(p, "lib2.jar", "lib2src.zip", new String[0], |
6056 |
new String[] { |
6057 |
"META-INF/MANIFEST.MF", |
6058 |
"Manifest-Version: 1.0\n" + |
6059 |
"Class-Path: \n", |
6060 |
}, |
6061 |
JavaCore.VERSION_1_4); |
6062 |
|
6063 |
ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID); |
6064 |
String libraryName = "SWT"; |
6065 |
IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID); |
6066 |
UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName); |
6067 |
initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion); |
6068 |
|
6069 |
|
6070 |
IFile jarFile = getFile("/P/lib1.jar"); |
6071 |
|
6072 |
// Modify user library |
6073 |
IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID); |
6074 |
String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"SWT"; |
6075 |
String jarFullPath = getWorkspaceRoot().getLocation().append(jarFile.getFullPath()).toString(); |
6076 |
|
6077 |
StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n"); |
6078 |
propertyValue.append("<archive path=\""+jarFullPath+"\" />\r\n"); |
6079 |
|
6080 |
jarFile = getFile("/P/lib2.jar"); |
6081 |
jarFullPath = getWorkspaceRoot().getLocation().append(jarFile.getFullPath()).toString(); |
6082 |
|
6083 |
propertyValue.append("<archive path=\""+jarFullPath+"\"/>\r\n</userlibrary>\r\n"); |
6084 |
System.out.println(propertyValue.toString()); |
6085 |
preferences.put(propertyName, propertyValue.toString()); |
6086 |
preferences.flush(); |
6087 |
|
6088 |
IClasspathEntry[] entries = p.getRawClasspath(); |
6089 |
int length = entries.length; |
6090 |
System.arraycopy(entries, 0, entries = new IClasspathEntry[length+1], 0, length); |
6091 |
entries[length] = JavaCore.newContainerEntry(containerSuggestion.getPath()); |
6092 |
p.setRawClasspath(entries, null); |
6093 |
|
6094 |
assertClasspathEquals( |
6095 |
p.getResolvedClasspath(true), |
6096 |
"/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" + |
6097 |
""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" + |
6098 |
"/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/lib1src.zip][isExported:true]\n" + |
6099 |
"/P/lib2.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/lib2src.zip][isExported:true]\n" + |
6100 |
""+ getWorkspacePath() + "P\\lib1.jar[CPE_LIBRARY][K_BINARY][isExported:false]\n" + |
6101 |
""+ getWorkspacePath() + "P\\lib2.jar[CPE_LIBRARY][K_BINARY][isExported:false]" |
6102 |
); |
6103 |
|
6104 |
} finally { |
6105 |
deleteProject("P"); |
6106 |
} |
6107 |
} |
6108 |
|
5975 |
} |
6109 |
} |