Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Added test to verify classpath attributes retained
Browse files Browse the repository at this point in the history
This test checks that we do not drop the attributes after project
configuration.
  • Loading branch information
WonderCsabo committed Jan 16, 2015
1 parent 09f56d6 commit fd1b7c8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
Expand Up @@ -75,6 +75,9 @@
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
Expand Down
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
Expand Down
Expand Up @@ -9,11 +9,13 @@
package me.gladwell.eclipse.m2e.android.test;

import static java.io.File.separator;
import static me.gladwell.eclipse.m2e.android.configuration.Classpaths.findSourceEntry;
import static me.gladwell.eclipse.m2e.android.test.ClasspathMatchers.containsEntry;
import static me.gladwell.eclipse.m2e.android.test.ClasspathMatchers.containsIncludePattern;
import static me.gladwell.eclipse.m2e.android.test.ClasspathMatchers.hasAttribute;
import static org.eclipse.jdt.core.IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS;
import static org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER;
import static org.junit.Assert.assertThat;
import static me.gladwell.eclipse.m2e.android.configuration.Classpaths.findSourceEntry;
import static me.gladwell.eclipse.m2e.android.test.ClasspathMatchers.containsEntry;

import java.io.File;

Expand All @@ -29,9 +31,11 @@
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.junit.JUnitCore;
import org.eclipse.jdt.junit.TestRunListener;
import org.eclipse.jdt.junit.model.ITestElement;
Expand Down Expand Up @@ -281,4 +285,24 @@ public void testConfigureDoesNotSetIgnoreWarnings() throws Exception {
IClasspathEntry gen = findSourceEntry(javaProject.getRawClasspath(), "gen");
assertFalse("external assets folder isn't linked", booleanAttribute(IGNORE_OPTIONAL_PROBLEMS, gen));
}

public void testConfigureDoesNotRemoveIncludesFromEntry() throws Exception {
IClasspathEntry mainJava = findSourceEntry(javaProject.getRawClasspath(), "src" + separator + "main" + separator + "java");
assertThat(mainJava, containsIncludePattern("**" + separator + "*.java"));
}

public void testConfigureDoesNotRemovePomDerivedAttributeFromEntry() throws JavaModelException {
IClasspathEntry mainJava = findSourceEntry(javaProject.getRawClasspath(), "src" + separator + "main" + separator + "java");
assertThat(mainJava, hasAttribute(IClasspathManager.POMDERIVED_ATTRIBUTE, "true"));
}

public void testConfigureDoesNotRemoveOptionalAttributeFromEntry() throws Exception {
IClasspathEntry mainJava = findSourceEntry(javaProject.getRawClasspath(), "src" + separator + "main" + separator + "java");
assertThat(mainJava, hasAttribute(IClasspathAttribute.OPTIONAL, "true"));
}

public void testConfigureDoesNotRemovePomDerivedAttributeFromMavenContainer() throws Exception {
IClasspathEntry mavenContainer = getClasspathContainer(javaProject, IClasspathManager.CONTAINER_ID);
assertThat(mavenContainer, hasAttribute(IClasspathManager.POMDERIVED_ATTRIBUTE, "true"));
}
}
Expand Up @@ -8,6 +8,9 @@

package me.gladwell.eclipse.m2e.android.test;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
Expand Down Expand Up @@ -42,4 +45,58 @@ private static boolean containsEntry(String path, IRuntimeClasspathEntry[] class
}
return false;
}

public static Matcher<IClasspathEntry> containsIncludePattern(final String pattern) {
return new BaseMatcher<IClasspathEntry>() {

@Override
public boolean matches(Object target) {
IClasspathEntry entry = (IClasspathEntry) target;
return containsIncludePattern(pattern, entry);
}

@Override
public void describeTo(Description description) {
description.appendText("classpath entry containing include pattern") //
.appendText(pattern);
}
};
}

private static boolean containsIncludePattern(String pattern, IClasspathEntry entry) {
for (IPath inclusionPattern : entry.getInclusionPatterns()) {
if (inclusionPattern.toOSString().equals(pattern)) {
return true;
}
}
return false;
}

public static Matcher<IClasspathEntry> hasAttribute(final String attributeName, final String attributeValue) {
return new BaseMatcher<IClasspathEntry>() {

@Override
public boolean matches(Object target) {
IClasspathEntry entry = (IClasspathEntry) target;
return hasAttribute(entry, attributeName, attributeValue);
}

@Override
public void describeTo(Description description) {
description.appendText("classpath entry having attribute ") //
.appendText(attributeName) //
.appendText(" with value ") //
.appendText(attributeValue);
}
};
}

public static boolean hasAttribute(IClasspathEntry entry, String attributeName, String attributeValue) {
for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
if (attribute.getName().equals(attributeName) && attribute.getValue().equals(attributeValue)) {
return true;
}
}
return false;
}
}

0 comments on commit fd1b7c8

Please sign in to comment.