Lines 19-24
Link Here
|
19 |
import org.eclipse.core.resources.IProject; |
19 |
import org.eclipse.core.resources.IProject; |
20 |
import org.eclipse.core.runtime.CoreException; |
20 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.IPath; |
21 |
import org.eclipse.core.runtime.IPath; |
|
|
22 |
import org.eclipse.core.runtime.IStatus; |
22 |
import org.eclipse.core.runtime.Path; |
23 |
import org.eclipse.core.runtime.Path; |
23 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
24 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
24 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
25 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
Lines 26-32
Link Here
|
26 |
import org.eclipse.jdt.core.IClasspathAttribute; |
27 |
import org.eclipse.jdt.core.IClasspathAttribute; |
27 |
import org.eclipse.jdt.core.IClasspathEntry; |
28 |
import org.eclipse.jdt.core.IClasspathEntry; |
28 |
import org.eclipse.jdt.core.IJavaElement; |
29 |
import org.eclipse.jdt.core.IJavaElement; |
|
|
30 |
import org.eclipse.jdt.core.IJavaModelStatus; |
31 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
29 |
import org.eclipse.jdt.core.IJavaProject; |
32 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
33 |
import org.eclipse.jdt.core.JavaConventions; |
30 |
import org.eclipse.jdt.core.JavaCore; |
34 |
import org.eclipse.jdt.core.JavaCore; |
31 |
import org.eclipse.jdt.core.index.*; |
35 |
import org.eclipse.jdt.core.index.*; |
32 |
import org.eclipse.jdt.core.search.SearchEngine; |
36 |
import org.eclipse.jdt.core.search.SearchEngine; |
Lines 863-866
Link Here
|
863 |
deleteProject("ForIndex"); |
867 |
deleteProject("ForIndex"); |
864 |
} |
868 |
} |
865 |
} |
869 |
} |
|
|
870 |
|
871 |
// test that the JavaConventions.validateIndexFile reports OK for a valid file |
872 |
public void testValidateIndex() throws IOException { |
873 |
String indexFilePath = getExternalResourcePath("Test.index"); |
874 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
875 |
try { |
876 |
createJar(new String[] { |
877 |
"pkg/Test.java", |
878 |
"package pkg;\n" + |
879 |
"public class Test {\n" + |
880 |
" protected Test(int i) {}\n" + |
881 |
"}"}, jarFilePath); |
882 |
|
883 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath); |
884 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new File(indexFilePath).toURL()); |
885 |
assertEquals(status.getCode(), IStatus.OK); |
886 |
} finally { |
887 |
new File(indexFilePath).delete(); |
888 |
new File(jarFilePath).delete(); |
889 |
} |
890 |
} |
891 |
|
892 |
// test that the JavaConventions.validateIndexFile reports error for a non-existent file |
893 |
public void testValidateNonExistentIndex() throws IOException { |
894 |
String indexFilePath = getExternalResourcePath("Test.index"); |
895 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
896 |
new File(indexFilePath).delete(); |
897 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new File(indexFilePath).toURL()); |
898 |
assertEquals("Should have been an error", status.getCode(), IJavaModelStatusConstants.INDEX_FILE_NOT_PRESENT); |
899 |
} |
900 |
|
901 |
// test that the JavaConventions.validateIndexFile reports error for an improper file |
902 |
public void testValidateImproperIndex() throws IOException { |
903 |
String indexFilePath = getExternalResourcePath("Test.index"); |
904 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
905 |
try { |
906 |
createJar(new String[] { |
907 |
"pkg/Test.java", |
908 |
"package pkg;\n" + |
909 |
"public class Test {\n" + |
910 |
" protected Test(int i) {}\n" + |
911 |
"}"}, jarFilePath); |
912 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new File(jarFilePath).toURL()); |
913 |
assertEquals("Should have been an error", status.getCode(), IJavaModelStatusConstants.INDEX_FILE_NOT_ABLE_TO_READ); |
914 |
System.out.println(status.getMessage()); |
915 |
} finally { |
916 |
new File(indexFilePath).delete(); |
917 |
new File(jarFilePath).delete(); |
918 |
} |
919 |
|
920 |
} |
921 |
|
922 |
// test that the JavaConventions.validateIndexFile works for a index in jar |
923 |
public void testValidateJarIndex() throws IOException { |
924 |
String indexFilePath = getExternalResourcePath("Test.index"); |
925 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
926 |
String indexZipPath = getExternalResourcePath("TestIndex.zip"); |
927 |
try { |
928 |
createJar(new String[] { |
929 |
"pkg/Test.java", |
930 |
"package pkg;\n" + |
931 |
"public class Test {\n" + |
932 |
" protected Test(int i) {}\n" + |
933 |
"}"}, jarFilePath); |
934 |
|
935 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath); |
936 |
Util.zipFiles(new File[]{new File(indexFilePath)}, indexZipPath); |
937 |
String url = "jar:file:"+indexZipPath+"!/Test.index"; |
938 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new URL(url)); |
939 |
assertEquals(status.getCode(), IStatus.OK); |
940 |
} finally { |
941 |
new File(indexFilePath).delete(); |
942 |
new File(jarFilePath).delete(); |
943 |
new File(indexZipPath).delete(); |
944 |
} |
945 |
} |
946 |
|
947 |
// test that the JavaConventions.validateIndexFile works for a jarurl as an index |
948 |
public void testValidateJarWOFileIndex() throws IOException { |
949 |
String indexFilePath = getExternalResourcePath("Test.index"); |
950 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
951 |
String indexZipPath = getExternalResourcePath("TestIndex.zip"); |
952 |
try { |
953 |
createJar(new String[] { |
954 |
"pkg/Test.java", |
955 |
"package pkg;\n" + |
956 |
"public class Test {\n" + |
957 |
" protected Test(int i) {}\n" + |
958 |
"}"}, jarFilePath); |
959 |
|
960 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath); |
961 |
Util.zipFiles(new File[]{new File(indexFilePath)}, indexZipPath); |
962 |
String url = "jar:file:"+indexZipPath+"!/"; |
963 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new URL(url)); |
964 |
assertEquals(status.getCode(), IJavaModelStatusConstants.INDEX_FILE_NOT_ABLE_TO_READ); |
965 |
} finally { |
966 |
new File(indexZipPath).delete(); |
967 |
new File(indexFilePath).delete(); |
968 |
new File(jarFilePath).delete(); |
969 |
} |
970 |
} |
971 |
|
972 |
// test that the JavaConventions.validateIndexFile works for non-existing index file in jar |
973 |
public void testValidateNonExistentJarIndex() throws IOException { |
974 |
String indexFilePath = getExternalResourcePath("Test.index"); |
975 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
976 |
String indexZipPath = getExternalResourcePath("TestIndexne.zip"); |
977 |
try { |
978 |
createJar(new String[] { |
979 |
"pkg/Test.java", |
980 |
"package pkg;\n" + |
981 |
"public class Test {\n" + |
982 |
" protected Test(int i) {}\n" + |
983 |
"}"}, jarFilePath); |
984 |
|
985 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath); |
986 |
Util.zipFiles(new File[]{new File(indexFilePath)}, indexZipPath); |
987 |
String url = "jar:file:"+indexZipPath+"!/Test1.index"; |
988 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new URL(url)); |
989 |
assertEquals(status.getCode(), IJavaModelStatusConstants.INDEX_FILE_NOT_PRESENT); |
990 |
} finally { |
991 |
new File(indexFilePath).delete(); |
992 |
new File(jarFilePath).delete(); |
993 |
new File(indexZipPath).delete(); |
994 |
} |
995 |
} |
996 |
|
997 |
// test that the JavaConventions.validateIndexFile works for non-existing index file in jar |
998 |
public void testValidateImproperJarIndex() throws IOException { |
999 |
String indexFilePath = getExternalResourcePath("Test.index"); |
1000 |
String jarFilePath = getExternalResourcePath("Test.jar"); |
1001 |
String indexZipPath = getExternalResourcePath("TestIndex.zip"); |
1002 |
try { |
1003 |
createJar(new String[] { |
1004 |
"pkg/Test.java", |
1005 |
"package pkg;\n" + |
1006 |
"public class Test {\n" + |
1007 |
" protected Test(int i) {}\n" + |
1008 |
"}"}, jarFilePath); |
1009 |
|
1010 |
JavaIndexer.generateIndexForJar(jarFilePath, indexFilePath); |
1011 |
Util.zipFiles(new File[]{new File(jarFilePath)}, indexZipPath); |
1012 |
String url = "jar:file:"+indexZipPath+"!/Test.jar"; |
1013 |
IJavaModelStatus status = JavaConventions.validateIndexFile(new Path(jarFilePath), new URL(url)); |
1014 |
assertEquals(status.getCode(), IJavaModelStatusConstants.INDEX_FILE_NOT_ABLE_TO_READ); |
1015 |
} finally { |
1016 |
new File(indexFilePath).delete(); |
1017 |
new File(jarFilePath).delete(); |
1018 |
new File(indexZipPath).delete(); |
1019 |
} |
1020 |
} |
866 |
} |
1021 |
} |