Skip to content

Commit

Permalink
[SHRINKWRAP-350] Remove cyclic dependency with test/release
Browse files Browse the repository at this point in the history
  • Loading branch information
ALRubinger committed Oct 31, 2011
1 parent 2ce7d93 commit f7ddceb
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ static interface EffectivePomMavenImporter extends Assignable {
*/
EffectivePomMavenImporter importTestDependencies();

/**
* Adds all dependencies defined by a pom file in scope test. User have to use filtering for the dependencies.
* This is supported only for WAR and EAR packagings.
*
* @param filter The filter to use
* @return The modified archive
* @throws IllegalArgumentException If the filter is not specified
*/
EffectivePomMavenImporter importTestDependencies(MavenResolutionFilter filter) throws IllegalArgumentException;

/**
* Adds any dependencies defined by a pom file. User have to use a filter to filter the dependencies. This is supported
* only for WAR and EAR packagings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter;
import org.jboss.shrinkwrap.resolver.api.maven.filter.DependenciesFilter;
import org.junit.Test;

public class EarTestCase {
Expand Down Expand Up @@ -66,8 +67,9 @@ public void testEnterpriseArchiveAsMavenImporter() {
@Test
public void testEarWithTestArtifacts() {
EnterpriseArchive archive = ShrinkWrap.create(MavenImporter.class, "testWithTestArtifacts.ear")
.loadEffectivePom("../ear-sample/pom.xml").importBuildOutput().importTestDependencies()
.loadEffectivePom("../ear-sample/pom.xml").importBuildOutput().importTestDependencies(new DependenciesFilter("junit:junit"))
.as(EnterpriseArchive.class);
System.out.println(archive.toString(true));

Assert.assertNotNull("Archive is not null", archive);
Assert.assertTrue("Archive contains test.xml", archive.contains("test.xml"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,29 @@ public void testWebArchiveAsMavenImporter() {
@Test
public void testWarWithTestArtifacts() {
WebArchive archive = ShrinkWrap.create(MavenImporter.class, "testWithTestArtifacts.war").loadEffectivePom("pom.xml")
.importBuildOutput().importTestBuildOutput().importTestDependencies().as(WebArchive.class);
.importBuildOutput().importTestBuildOutput().importTestDependencies(new DependenciesFilter("junit:junit")).as(WebArchive.class);
System.out.println(archive.toString(true));

Assert.assertNotNull("Archive is not null", archive);
Assert.assertTrue("Archive contains war class", archive.contains("WEB-INF/classes/test/WarClass.class"));
Assert.assertTrue("Archive contains main.properties", archive.contains("WEB-INF/classes/main.properties"));
Assert.assertTrue("Archive contains war test class", archive.contains("WEB-INF/classes/test/WarTestCase.class"));
Assert.assertTrue("Archive contains test.properties", archive.contains("WEB-INF/classes/test.properties"));

boolean foundJunit = false;
Set<ArchivePath> libs = archive.getContent(new Filter<ArchivePath>() {

public boolean include(ArchivePath arg0) {
return arg0.get().startsWith("/WEB-INF/lib");
}
}).keySet();
for(final ArchivePath lib: libs){
if(lib.get().startsWith("/WEB-INF/lib/junit")){
foundJunit = true;
}
}

Assert.assertTrue("There are more then two libs", libs.size() > 2);
Assert.assertTrue("Should have been able to import test dependency upon junit", foundJunit);
}

@Test
Expand All @@ -102,7 +109,7 @@ public void testWarWithFilteredTestArtifacts() {
.importBuildOutput()
.importTestBuildOutput()
.importAnyDependencies(
new DependenciesFilter("org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven", "junit:junit"))
new DependenciesFilter("junit:junit"))
.as(WebArchive.class);

Assert.assertNotNull("Archive is not null", archive);
Expand All @@ -119,7 +126,7 @@ public boolean include(ArchivePath arg0) {
}
}).keySet();

Assert.assertEquals("There are two filtered libs", 2, libs.size());
Assert.assertEquals("There should be one filtered lib", 1, libs.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.jboss.shrinkwrap.resolver.impl.maven;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.Stack;
Expand All @@ -28,6 +30,7 @@
import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter;
import org.jboss.shrinkwrap.resolver.api.maven.MavenImporter.EffectivePomMavenImporter;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolutionFilter;
import org.jboss.shrinkwrap.resolver.api.maven.filter.CombinedFilter;
import org.jboss.shrinkwrap.resolver.api.maven.filter.ScopeFilter;
import org.sonatype.aether.RepositorySystemSession;

Expand Down Expand Up @@ -106,7 +109,21 @@ public EffectivePomMavenImporter importAnyDependencies(MavenResolutionFilter fil
return this;
}

private MavenDependencyResolver getMavenDependencyResolver(Stack<MavenDependency> dependencies,
/**
* {@inheritDoc}
* @see org.jboss.shrinkwrap.resolver.api.maven.MavenImporter.EffectivePomMavenImporter#importTestDependencies(org.jboss.shrinkwrap.resolver.api.maven.MavenResolutionFilter)
*/
@Override
public EffectivePomMavenImporter importTestDependencies(final MavenResolutionFilter filter) throws IllegalArgumentException {
// Precondition checks
if (filter == null) {
throw new IllegalArgumentException("At least one filter must be defined");
}

return this.importAnyDependencies(new CombinedFilter(new ScopeFilter("test"), filter));
}

private MavenDependencyResolver getMavenDependencyResolver(Stack<MavenDependency> dependencies,
Set<MavenDependency> versionManagement) {

return new MavenBuilderImpl(system, session, settings, dependencies, versionManagement);
Expand Down

0 comments on commit f7ddceb

Please sign in to comment.