This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #7 from amolenaar/master

Make the plugin work with the latest FitNesse code + new feature
  • Loading branch information...
lvonk committed Oct 16, 2011
2 parents 9e1529c + 00c17c4 commit b5e6d1ae9944a20fa0c862eadca73de89c38c05b
View
6 README
@@ -4,7 +4,11 @@
2. How to use.
- Releases after v20101101 are NOT supported, since the way the classpath is completely refactored in FitNesse. Working on it...
+ - Download the distribution.
+ - Get yourself an up-to-date copy of fitnesse (> 20110601)
+ - Add the following line to plugins.properties: SymbolTypes = fitnesse.wikitext.widgets.MavenClasspathSymbolType.
+ - Refer to the pom file as follows: !pomFile /path/to/pom.xml.
+ - you can define the file as pom.xml@compile to include a specific scope.
For v20101101 and earlier:
- Download the 1.2 distribution.
View
@@ -5,6 +5,7 @@
<artifactId>maven-classpath-plugin</artifactId>
<name>Maven Classpath Plugin</name>
<version>1.3-SNAPSHOT</version>
+
<dependencies>
<dependency>
<groupId>org.jvnet.hudson</groupId>
@@ -14,7 +15,7 @@
<dependency>
<groupId>org.fitnesse</groupId>
<artifactId>fitnesse</artifactId>
- <version>20110104</version>
+ <version>20111003</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -32,6 +33,12 @@
</dependencies>
<repositories>
+ <repository>
+ <id>os-xebia</id>
+ <name>Xebia Open Source Repository</name>
+ <url>http://os.xebia.com/repository/</url>
+ </repository>
+
<repository>
<id>fitnesse-local</id>
<url>file://${basedir}/src/fitnesse</url>
@@ -3,6 +3,7 @@
import hudson.maven.MavenEmbedderException;
import hudson.maven.MavenRequest;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingResult;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@@ -16,10 +17,16 @@
*/
public class MavenClasspathExtractor {
+ public final static String DEFAULT_SCOPE = "test";
+
private File userSettingsFile;
private File globalSettingsFile;
- public List<String> extractClasspathEntries(File pomFile) throws MavenClasspathExtractionException {
+ public List<String> extractClasspathEntries(File pomFile) {
+ return extractClasspathEntries(pomFile, DEFAULT_SCOPE);
+ }
+
+ public List<String> extractClasspathEntries(File pomFile, String scope) throws MavenClasspathExtractionException {
try {
MavenRequest mavenRequest = mavenConfiguration();
@@ -31,7 +38,7 @@
new DependencyResolvingMavenEmbedder(getClass().getClassLoader(), mavenRequest);
ProjectBuildingResult projectBuildingResult = dependencyResolvingMavenEmbedder.buildProject(pomFile);
- return projectBuildingResult.getProject().getTestClasspathElements();
+ return getClasspathForScope(projectBuildingResult, scope);
} catch (MavenEmbedderException mee) {
throw new MavenClasspathExtractionException(mee);
@@ -42,10 +49,23 @@
} catch (ProjectBuildingException e) {
throw new MavenClasspathExtractionException(e);
}
-
}
-
+ private List<String> getClasspathForScope(
+ ProjectBuildingResult projectBuildingResult, String scope)
+ throws DependencyResolutionRequiredException {
+ MavenProject project = projectBuildingResult.getProject();
+
+ if ("compile".equalsIgnoreCase(scope)) {
+ return project.getCompileClasspathElements();
+ } else if ("runtime".equalsIgnoreCase(scope)) {
+ return project.getRuntimeClasspathElements();
+ }
+ return project.getTestClasspathElements();
+
+ }
+
+
// protected for test purposes
protected MavenRequest mavenConfiguration() throws MavenEmbedderException, ComponentLookupException {
MavenRequest mavenRequest = new MavenRequest();
@@ -81,5 +101,4 @@ protected void setMavenGlobalSettingsFile(File globalSettingsFile) {
this.globalSettingsFile = globalSettingsFile;
}
-
}
@@ -5,17 +5,16 @@
import util.Maybe;
import java.io.File;
+import java.util.Collection;
import java.util.List;
/**
* FitNesse SymbolType implementation which enables Maven classpath integration for FitNesse.
*/
-public class MavenClasspathSymbolType extends SymbolType implements Rule, Translation {
+public class MavenClasspathSymbolType extends SymbolType implements Rule, Translation, PathsProvider {
private MavenClasspathExtractor mavenClasspathExtractor;
- private String pomFile;
-
public MavenClasspathSymbolType() {
super("MavenClasspathSymbolType");
this.mavenClasspathExtractor = new MavenClasspathExtractor();
@@ -28,9 +27,7 @@ public MavenClasspathSymbolType() {
@Override
public String toTarget(Translator translator, Symbol symbol) {
- pomFile = symbol.childAt(0).getContent();
-
- List<String> classpathElements = mavenClasspathExtractor.extractClasspathEntries(new File(pomFile));
+ List<String> classpathElements = getClasspathElements(symbol);
String classpathForRender = "";
for (String element : classpathElements) {
@@ -41,6 +38,19 @@ public String toTarget(Translator translator, Symbol symbol) {
}
+ private List<String> getClasspathElements(Symbol symbol) {
+ String pomFile = symbol.childAt(0).getContent();
+ String scope = MavenClasspathExtractor.DEFAULT_SCOPE;
+
+ if (pomFile.contains("@")) {
+ String[] s = pomFile.split("@");
+ pomFile = s[0];
+ scope = s[1];
+ }
+
+ return mavenClasspathExtractor.extractClasspathEntries(new File(pomFile), scope);
+ }
+
@Override
public Maybe<Symbol> parse(Symbol symbol, Parser parser) {
Symbol next = parser.moveNext(1);
@@ -65,6 +75,11 @@ public boolean matchesFor(SymbolType symbolType) {
protected void setMavenClasspathExtractor(MavenClasspathExtractor mavenClasspathExtractor) {
this.mavenClasspathExtractor = mavenClasspathExtractor;
}
+
+ @Override
+ public Collection<String> providePaths(Translator translator, Symbol symbol) {
+ return getClasspathElements(symbol);
+ }
}
@@ -32,7 +32,7 @@ public void extractedClasspathIncludesTestScopeDependencies() {
String path = sb.toString();
- assertEquals(4, classpathEntries.size());
+ assertEquals(3, classpathEntries.size());
assertTrue(path.contains("commons-lang"));
}
@@ -3,16 +3,15 @@
import fitnesse.wikitext.parser.Parser;
import fitnesse.wikitext.parser.Symbol;
import fitnesse.wikitext.parser.SymbolType;
+
import org.junit.Before;
import org.junit.Test;
import util.Maybe;
import java.io.File;
import java.util.Arrays;
-import static junit.framework.Assert.assertNotNull;
-import static junit.framework.Assert.assertNotSame;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class MavenClasspathSymbolTypeTest {
@@ -52,11 +51,25 @@ public void translatesToClasspathEntries() {
when(symbol.childAt(0)).thenReturn(child);
when(child.getContent()).thenReturn("thePomFile");
- when(mavenClasspathExtractor.extractClasspathEntries(any(File.class)))
+ when(mavenClasspathExtractor.extractClasspathEntries(any(File.class), isA(String.class)))
.thenReturn(Arrays.asList("test1", "test2"));
assertEquals("<span class=\"meta\">classpath: test1</span><br/><span class=\"meta\">classpath: test2</span><br/>"
, mavenClasspathSymbolType.toTarget(null, symbol));
}
+ @Test
+ public void translatesToJavaClasspath() {
+ Symbol child = mock(Symbol.class);
+
+ when(symbol.childAt(0)).thenReturn(child);
+ when(child.getContent()).thenReturn("thePomFile");
+
+ when(mavenClasspathExtractor.extractClasspathEntries(any(File.class), isA(String.class)))
+ .thenReturn(Arrays.asList("test1", "test2"));
+
+ assertArrayEquals(new Object[] { "test1", "test2" }, mavenClasspathSymbolType.providePaths(null, symbol).toArray());
+ }
+
+
}

0 comments on commit b5e6d1a

Please sign in to comment.