Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
407100 : use CLASSPATH_ARCHIVENAME_ATTRIBUTE when available
Signed-off-by: Fred Bricon <fbricon@gmail.com>
  • Loading branch information
fbricon committed May 5, 2013
1 parent e5c1944 commit 4e76da3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Expand Up @@ -12,6 +12,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -65,6 +66,19 @@ public abstract class AbstractWTPTestCase extends AbstractMavenProjectTestCase {
protected static final String MAVEN_CLASSPATH_CONTAINER = "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER";
protected static final String JRE_CONTAINER_J2SE_1_5 = "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5";

protected static final String CLASSPATH_ARCHIVENAME_ATTRIBUTE;

static {
String archiveNameAttribute = null;
try {
Field classpathArchiveNameField = IClasspathDependencyConstants.class.getField("CLASSPATH_ARCHIVENAME_ATTRIBUTE");
archiveNameAttribute = (String)classpathArchiveNameField.get(null);
} catch (Exception e) {
System.err.println("IClasspathDependencyConstants.CLASSPATH_ARCHIVENAME_ATTRIBUTE not available");
}
CLASSPATH_ARCHIVENAME_ATTRIBUTE = archiveNameAttribute;
}

protected static final boolean canRunJavaEe7Tests = checkJavaEe7Compatibility();

protected static IClasspathContainer getWebLibClasspathContainer(IJavaProject project) throws JavaModelException {
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
Expand All @@ -51,6 +52,7 @@
import org.eclipse.m2e.core.project.ProjectImportConfiguration;
import org.eclipse.m2e.core.project.ResolverConfiguration;
import org.eclipse.m2e.jdt.internal.BuildPathManager;
import org.eclipse.m2e.tests.common.ClasspathHelpers;
import org.eclipse.m2e.wtp.MavenWtpConstants;
import org.eclipse.m2e.wtp.Messages;
import org.eclipse.m2e.wtp.WTPProjectsUtil;
Expand Down Expand Up @@ -253,8 +255,21 @@ public void testSameArtifactId() throws Exception {
IClasspathEntry[] cp = container.getClasspathEntries();

assertEquals(2, cp.length);
assertEquals("junit-junit-3.8.1.jar", cp[0].getPath().lastSegment());
assertEquals("test-junit-3.8.1.jar", cp[1].getPath().lastSegment());
if (CLASSPATH_ARCHIVENAME_ATTRIBUTE == null) {
assertEquals("junit-junit-3.8.1.jar", cp[0].getPath().lastSegment());
assertEquals("test-junit-3.8.1.jar", cp[1].getPath().lastSegment());
} else {
assertEquals("junit-3.8.1.jar", cp[0].getPath().lastSegment());
IClasspathAttribute archiveNameAttribute = ClasspathHelpers.getClasspathAttribute(cp[0], CLASSPATH_ARCHIVENAME_ATTRIBUTE);
assertNotNull(CLASSPATH_ARCHIVENAME_ATTRIBUTE+" is missing", archiveNameAttribute);
assertEquals("junit-junit-3.8.1.jar", archiveNameAttribute.getValue());

assertEquals("junit-3.8.1.jar", cp[1].getPath().lastSegment());
archiveNameAttribute = ClasspathHelpers.getClasspathAttribute(cp[1], CLASSPATH_ARCHIVENAME_ATTRIBUTE);
assertNotNull(CLASSPATH_ARCHIVENAME_ATTRIBUTE+" is missing", archiveNameAttribute);
assertEquals("test-junit-3.8.1.jar", archiveNameAttribute.getValue());

}
}

@Test
Expand Down

0 comments on commit 4e76da3

Please sign in to comment.