|
Lines 8-16
Link Here
|
| 8 |
|
8 |
|
| 9 |
import java.util.ArrayList; |
9 |
import java.util.ArrayList; |
| 10 |
import java.util.Collection; |
10 |
import java.util.Collection; |
| 11 |
import java.util.HashMap; |
|
|
| 12 |
import java.util.List; |
11 |
import java.util.List; |
| 13 |
import java.util.Map; |
12 |
import java.util.StringTokenizer; |
| 14 |
|
13 |
|
| 15 |
import junit.framework.Assert; |
14 |
import junit.framework.Assert; |
| 16 |
|
15 |
|
|
Lines 113-119
Link Here
|
| 113 |
AssertWarn.warnEquals("Archive type did not match imported project type", getExportType(), type); |
112 |
AssertWarn.warnEquals("Archive type did not match imported project type", getExportType(), type); |
| 114 |
} |
113 |
} |
| 115 |
|
114 |
|
| 116 |
String sProjVersion = J2EEProjectUtilities.getJ2EEProjectVersion(project); |
115 |
String sProjVersion = J2EEProjectUtilities.getJ2EEDDProjectVersion(project); |
| 117 |
int iProjVersion = J2EEVersionUtil.convertVersionStringToInt(sProjVersion); |
116 |
int iProjVersion = J2EEVersionUtil.convertVersionStringToInt(sProjVersion); |
| 118 |
int iVersionConstant = archiveQuickPeek.getVersion(); |
117 |
int iVersionConstant = archiveQuickPeek.getVersion(); |
| 119 |
if(iProjVersion != iVersionConstant){ |
118 |
if(iProjVersion != iVersionConstant){ |
|
Lines 127-132
Link Here
|
| 127 |
Assert.assertTrue("A project with name, " + project.getName() + ", should have been created by import", project.exists()); |
126 |
Assert.assertTrue("A project with name, " + project.getName() + ", should have been created by import", project.exists()); |
| 128 |
} |
127 |
} |
| 129 |
|
128 |
|
|
|
129 |
|
| 130 |
protected boolean isClassWithoutSource(IArchive archive, IArchiveResource aFile) { |
| 131 |
String javaUri = classUriToJavaUri(aFile.getPath().toString()); |
| 132 |
if (javaUri == null) |
| 133 |
return false; |
| 134 |
return !archive.containsArchiveResource(new Path(javaUri)); |
| 135 |
} |
| 136 |
|
| 137 |
protected final String DOT_CLASS = ".class"; //$NON-NLS-1$ |
| 138 |
|
| 139 |
protected final String DOT_JAVA = ".java"; //$NON-NLS-1$ |
| 140 |
|
| 141 |
public String classUriToJavaUri(String classUri) { |
| 142 |
if (classUri == null || !classUri.endsWith(DOT_CLASS)) |
| 143 |
return null; |
| 144 |
|
| 145 |
String truncated = truncateIgnoreCase(classUri, DOT_CLASS); |
| 146 |
StringTokenizer tok = new StringTokenizer(truncated, "$"); //$NON-NLS-1$ |
| 147 |
return tok.nextToken().concat(DOT_JAVA); |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Return a substring of the first parameter, up to the last index of the |
| 152 |
* second |
| 153 |
*/ |
| 154 |
public static String truncateIgnoreCase(String aString, String trailingSubString) { |
| 155 |
int index = aString.toLowerCase().lastIndexOf(trailingSubString.toLowerCase()); |
| 156 |
if (index != -1) |
| 157 |
return aString.substring(0, index); |
| 158 |
return aString; |
| 159 |
} |
| 130 |
private void verifyAllFilesImported(IArchive archive) throws Exception { |
160 |
private void verifyAllFilesImported(IArchive archive) throws Exception { |
| 131 |
List<IArchiveResource> resources = archive.getArchiveResources(); |
161 |
List<IArchiveResource> resources = archive.getArchiveResources(); |
| 132 |
IPath resourcePath = null; |
162 |
IPath resourcePath = null; |
|
Lines 137-151
Link Here
|
| 137 |
IFolder rootFolder = (IFolder)rootVirtFolder.getUnderlyingFolder(); |
167 |
IFolder rootFolder = (IFolder)rootVirtFolder.getUnderlyingFolder(); |
| 138 |
Assert.assertTrue("The root folder " + rootFolder.getName() + " should exist in the project" , rootFolder.exists()); |
168 |
Assert.assertTrue("The root folder " + rootFolder.getName() + " should exist in the project" , rootFolder.exists()); |
| 139 |
|
169 |
|
| 140 |
//when the foreach loops is done the classesMap will contain only thouse classes that were imported, |
170 |
// when the for loops is done the classes will contain only those classes that were imported, |
| 141 |
// the sourceResources list will contain a list of all of the java source resources, |
171 |
// the sourceResources list will contain a list of all of the java source resources, |
| 142 |
// the otherResources list will contain all other resources that arnt nested archives, |
172 |
// the otherResources list will contain all other resources that are not nested archives, |
| 143 |
// and any nested archive in this archive will have been set as a nested archive in 'archive' |
173 |
// and any nested archive in this archive will have been set as a nested archive in 'archive' |
| 144 |
Map<String,IArchiveResource> classesMap = new HashMap<String,IArchiveResource>(); |
174 |
List<IArchiveResource> classes = new ArrayList<IArchiveResource>(); |
| 145 |
List<IArchiveResource> sourceResources = new ArrayList<IArchiveResource>(); |
175 |
List<IArchiveResource> sourceResources = new ArrayList<IArchiveResource>(); |
| 146 |
List<IArchiveResource> otherResources = new ArrayList<IArchiveResource>(); |
176 |
List<IArchiveResource> otherResources = new ArrayList<IArchiveResource>(); |
| 147 |
|
177 |
|
| 148 |
String fileName = null; |
|
|
| 149 |
String extension = null; |
178 |
String extension = null; |
| 150 |
for(IArchiveResource resource : resources) { |
179 |
for(IArchiveResource resource : resources) { |
| 151 |
resourcePath = resource.getPath(); |
180 |
resourcePath = resource.getPath(); |
|
Lines 154-171
Link Here
|
| 154 |
case IArchiveResource.FILE_TYPE : |
183 |
case IArchiveResource.FILE_TYPE : |
| 155 |
extension = resourcePath.getFileExtension(); |
184 |
extension = resourcePath.getFileExtension(); |
| 156 |
|
185 |
|
| 157 |
if(extension.equals(CLASS_EXTENSION) || extension.equals(JAVA_EXTENSION)) { |
186 |
if(extension.equals(CLASS_EXTENSION)){ |
| 158 |
fileName = resourcePath.removeFileExtension().lastSegment(); |
187 |
if(isClassWithoutSource(archive, resource)){ |
| 159 |
if(classesMap.containsKey(fileName)) { |
188 |
classes.add(resource); |
| 160 |
if(extension.equals(CLASS_EXTENSION)) { |
|
|
| 161 |
sourceResources.add(classesMap.remove(fileName)); |
| 162 |
} else if(extension.equals(JAVA_EXTENSION)) { |
| 163 |
sourceResources.add(resource); |
| 164 |
classesMap.remove(fileName); |
| 165 |
} |
| 166 |
} else { |
| 167 |
classesMap.put(fileName, resource); |
| 168 |
} |
189 |
} |
|
|
190 |
} else if(extension.equals(JAVA_EXTENSION)){ |
| 191 |
sourceResources.add(resource); |
| 169 |
} else if(extension.equals(JAR_EXTENSION) || extension.equals(RAR_EXTENSION) || extension.equals(WAR_EXTENSION)) { |
192 |
} else if(extension.equals(JAR_EXTENSION) || extension.equals(RAR_EXTENSION) || extension.equals(WAR_EXTENSION)) { |
| 170 |
archive.getNestedArchive(resource); |
193 |
archive.getNestedArchive(resource); |
| 171 |
} else { |
194 |
} else { |
|
Lines 182-191
Link Here
|
| 182 |
} |
205 |
} |
| 183 |
} |
206 |
} |
| 184 |
|
207 |
|
| 185 |
Collection<IArchiveResource> importedClassesResources = classesMap.values(); |
|
|
| 186 |
List<IArchive> nestedArchives = archive.getNestedArchives(); |
208 |
List<IArchive> nestedArchives = archive.getNestedArchives(); |
| 187 |
|
209 |
|
| 188 |
verifyImportedResources(sourceResources, importedClassesResources, otherResources, nestedArchives, rootFolder, importedClassesFolder); |
210 |
verifyImportedResources(sourceResources, classes, otherResources, nestedArchives, rootFolder, importedClassesFolder); |
| 189 |
} |
211 |
} |
| 190 |
|
212 |
|
| 191 |
protected abstract void verifyImportedResources(Collection<IArchiveResource> sourceResources, Collection<IArchiveResource> importedClassesResources, Collection<IArchiveResource> otherResources, Collection<IArchive> nestedArchives, IFolder rootFolder, IFolder importedClassesFolder) throws Exception; |
213 |
protected abstract void verifyImportedResources(Collection<IArchiveResource> sourceResources, Collection<IArchiveResource> importedClassesResources, Collection<IArchiveResource> otherResources, Collection<IArchive> nestedArchives, IFolder rootFolder, IFolder importedClassesFolder) throws Exception; |