[206086] improved archive support for ee5
diff --git a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEExportDataModelVerifier.java b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEExportDataModelVerifier.java index d00f758..8b2b0f4 100644 --- a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEExportDataModelVerifier.java +++ b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEExportDataModelVerifier.java
@@ -121,7 +121,7 @@ int type = archiveQuickPeek.getType(); AssertWarn.warnEquals("Archive type did not match exported type", getExportType(), type); int iVersionConstant = archiveQuickPeek.getVersion(); - String sProjVersion = J2EEProjectUtilities.getJ2EEProjectVersion(exportedProj); + String sProjVersion = J2EEProjectUtilities.getJ2EEDDProjectVersion(exportedProj); int iProjVersion = J2EEVersionUtil.convertVersionStringToInt(sProjVersion); AssertWarn.warnEquals("Archive version did not match exported project version", iProjVersion, iVersionConstant); } finally {
diff --git a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEImportDataModelVerifier.java b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEImportDataModelVerifier.java index aaf7743..0037acc 100644 --- a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEImportDataModelVerifier.java +++ b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/j2ee/verifiers/JEEImportDataModelVerifier.java
@@ -8,9 +8,8 @@ import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.StringTokenizer; import junit.framework.Assert; @@ -113,7 +112,7 @@ AssertWarn.warnEquals("Archive type did not match imported project type", getExportType(), type); } - String sProjVersion = J2EEProjectUtilities.getJ2EEProjectVersion(project); + String sProjVersion = J2EEProjectUtilities.getJ2EEDDProjectVersion(project); int iProjVersion = J2EEVersionUtil.convertVersionStringToInt(sProjVersion); int iVersionConstant = archiveQuickPeek.getVersion(); if(iProjVersion != iVersionConstant){ @@ -127,6 +126,37 @@ Assert.assertTrue("A project with name, " + project.getName() + ", should have been created by import", project.exists()); } + + protected boolean isClassWithoutSource(IArchive archive, IArchiveResource aFile) { + String javaUri = classUriToJavaUri(aFile.getPath().toString()); + if (javaUri == null) + return false; + return !archive.containsArchiveResource(new Path(javaUri)); + } + + protected final String DOT_CLASS = ".class"; //$NON-NLS-1$ + + protected final String DOT_JAVA = ".java"; //$NON-NLS-1$ + + public String classUriToJavaUri(String classUri) { + if (classUri == null || !classUri.endsWith(DOT_CLASS)) + return null; + + String truncated = truncateIgnoreCase(classUri, DOT_CLASS); + StringTokenizer tok = new StringTokenizer(truncated, "$"); //$NON-NLS-1$ + return tok.nextToken().concat(DOT_JAVA); + } + + /** + * Return a substring of the first parameter, up to the last index of the + * second + */ + public static String truncateIgnoreCase(String aString, String trailingSubString) { + int index = aString.toLowerCase().lastIndexOf(trailingSubString.toLowerCase()); + if (index != -1) + return aString.substring(0, index); + return aString; + } private void verifyAllFilesImported(IArchive archive) throws Exception { List<IArchiveResource> resources = archive.getArchiveResources(); IPath resourcePath = null; @@ -137,15 +167,14 @@ IFolder rootFolder = (IFolder)rootVirtFolder.getUnderlyingFolder(); Assert.assertTrue("The root folder " + rootFolder.getName() + " should exist in the project" , rootFolder.exists()); - //when the foreach loops is done the classesMap will contain only thouse classes that were imported, + // when the for loops is done the classes will contain only those classes that were imported, // the sourceResources list will contain a list of all of the java source resources, - // the otherResources list will contain all other resources that arnt nested archives, + // the otherResources list will contain all other resources that are not nested archives, // and any nested archive in this archive will have been set as a nested archive in 'archive' - Map<String,IArchiveResource> classesMap = new HashMap<String,IArchiveResource>(); + List<IArchiveResource> classes = new ArrayList<IArchiveResource>(); List<IArchiveResource> sourceResources = new ArrayList<IArchiveResource>(); List<IArchiveResource> otherResources = new ArrayList<IArchiveResource>(); - String fileName = null; String extension = null; for(IArchiveResource resource : resources) { resourcePath = resource.getPath(); @@ -154,18 +183,12 @@ case IArchiveResource.FILE_TYPE : extension = resourcePath.getFileExtension(); - if(extension.equals(CLASS_EXTENSION) || extension.equals(JAVA_EXTENSION)) { - fileName = resourcePath.removeFileExtension().lastSegment(); - if(classesMap.containsKey(fileName)) { - if(extension.equals(CLASS_EXTENSION)) { - sourceResources.add(classesMap.remove(fileName)); - } else if(extension.equals(JAVA_EXTENSION)) { - sourceResources.add(resource); - classesMap.remove(fileName); - } - } else { - classesMap.put(fileName, resource); + if(extension.equals(CLASS_EXTENSION)){ + if(isClassWithoutSource(archive, resource)){ + classes.add(resource); } + } else if(extension.equals(JAVA_EXTENSION)){ + sourceResources.add(resource); } else if(extension.equals(JAR_EXTENSION) || extension.equals(RAR_EXTENSION) || extension.equals(WAR_EXTENSION)) { archive.getNestedArchive(resource); } else { @@ -182,10 +205,9 @@ } } - Collection<IArchiveResource> importedClassesResources = classesMap.values(); List<IArchive> nestedArchives = archive.getNestedArchives(); - verifyImportedResources(sourceResources, importedClassesResources, otherResources, nestedArchives, rootFolder, importedClassesFolder); + verifyImportedResources(sourceResources, classes, otherResources, nestedArchives, rootFolder, importedClassesFolder); } protected abstract void verifyImportedResources(Collection<IArchiveResource> sourceResources, Collection<IArchiveResource> importedClassesResources, Collection<IArchiveResource> otherResources, Collection<IArchive> nestedArchives, IFolder rootFolder, IFolder importedClassesFolder) throws Exception;
diff --git a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/web/verifiers/WebImportDataModelVerifier.java b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/web/verifiers/WebImportDataModelVerifier.java index 529d315..ad512b6 100644 --- a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/web/verifiers/WebImportDataModelVerifier.java +++ b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tests/web/verifiers/WebImportDataModelVerifier.java
@@ -6,6 +6,7 @@ */ package org.eclipse.wtp.j2ee.headless.tests.web.verifiers; +import java.io.FileNotFoundException; import java.util.Collection; import junit.framework.Assert; @@ -13,6 +14,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveConstants; +import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil; import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; import org.eclipse.jst.jee.archive.IArchive; import org.eclipse.jst.jee.archive.IArchiveResource; @@ -60,7 +64,9 @@ for(IArchiveResource importedClassResource : importedClassesResources) { resourcePath = importedClassResource.getPath().removeFirstSegments(2); resourceFile = importedClassesFolder.getFile(resourcePath); - Assert.assertTrue("The imported class " + resourcePath + " should exist in the project", resourceFile.exists()); + if(!resourceFile.exists()){ + Assert.fail("The imported class " + resourcePath + " should exist in the project"); + } } for(IArchiveResource otherResource : otherResources) { @@ -73,4 +79,48 @@ } } + + protected boolean isClassWithoutSource(IArchive archive, IArchiveResource aFile) { + String javaUri = ArchiveUtil.classUriToJavaUri(aFile.getPath().toString()); + if (javaUri == null) + return true; + IPath javaPath = new Path(javaUri); + if (archive.containsArchiveResource(javaPath)) { + return false; + } + // see if it is a JSP + String jspUri = javaUri.substring(0, javaUri.indexOf(ArchiveUtil.DOT_JAVA)); + int lastSlash = jspUri.lastIndexOf('/'); + int _index = lastSlash == -1 ? ArchiveConstants.WEBAPP_CLASSES_URI.length() : lastSlash + 1; + if (jspUri.charAt(_index) == '_') { + jspUri = jspUri.substring(ArchiveConstants.WEBAPP_CLASSES_URI.length(), _index) + jspUri.substring(_index + 1) + ArchiveUtil.DOT_JSP; + IPath jspPath = new Path(jspUri); + if (archive.containsArchiveResource(jspPath)) { + return false; + } + } + + //This is to handle archives created by an earlier version + //The format was to include the source files in a directory called source in WEB-INF + //Example: class is in WEB-INF/classes/test/Foo.class + // source is in WEB-INF/source/test/Foo.java + if(javaPath.segmentCount() > 2 && javaPath.segment(0).equals("WEB-INF") && javaPath.segment(1).equals("classes")){ + String alternateJavaUri = javaUri.replaceFirst("classes", "source"); + IPath alternateJavaPath = new Path(alternateJavaUri); + if (archive.containsArchiveResource(alternateJavaPath)){ + IArchiveResource sourceFile; + try { + sourceFile = archive.getArchiveResource(alternateJavaPath); + if(sourceFile != null){ + return false; + } + } catch (FileNotFoundException e) { + } + + } + + } + + return true; + } }
diff --git a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tets/appclient/verifiers/AppClientImportDataModelVerifier.java b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tets/appclient/verifiers/AppClientImportDataModelVerifier.java index 32f3a90..bb57c5a 100644 --- a/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tets/appclient/verifiers/AppClientImportDataModelVerifier.java +++ b/tests/org.eclipse.jst.j2ee.tests/j2ee-verifiers/org/eclipse/wtp/j2ee/headless/tets/appclient/verifiers/AppClientImportDataModelVerifier.java
@@ -52,7 +52,9 @@ for(IArchiveResource sourceResource : sourceResources) { resourcePath = sourceResource.getPath(); resourceFile = rootFolder.getFile(resourcePath); - Assert.assertTrue("The file " + resourcePath + " should exist in the project", resourceFile.exists()); + if(!resourceFile.exists()){ + Assert.fail("The file " + resourcePath + " should exist in the project"); + } } for(IArchiveResource importedClassResource : importedClassesResources) {