Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.jboss.shrinkwrap.resolver.api.maven;

import java.io.File;
import java.util.Collection;

import org.jboss.shrinkwrap.api.GenericArchive;
Expand Down Expand Up @@ -59,4 +60,23 @@ public interface EffectivePomMavenDependencyShortcut {
* @throws {@link IllegalArgumentException} If target archive view is not supplied
*/
Collection<GenericArchive> dependencies(String... coordinates) throws ResolutionException;

/**
* Resolves dependency for dependency builder.
*
* @param coordinates Coordinates specified to a created artifact, specified in an implementation-specific format.
* @return A File which contain resolved artifact.
* @throws ResolutionException If artifact could not be resolved
*/
File resolveAsFile(String coordinates) throws ResolutionException;

/**
* Resolves dependencies for dependency builder.
*
* @param coordinates A list of coordinates specified to the created artifacts, specified in an implementation-specific
* format.
* @return An array of Files which contains resolved artifacts
* @throws ResolutionException If artifact could not be resolved
*/
File[] resolveAsFiles(String... coordinates) throws ResolutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package org.jboss.shrinkwrap.resolver.api.maven;

import java.io.File;
import java.util.Collection;

import org.jboss.shrinkwrap.api.GenericArchive;
Expand Down Expand Up @@ -62,6 +63,29 @@ public static Collection<GenericArchive> dependencies(String... coordinates) thr
return DependencyResolvers.use(MavenDependencyShortcut.class).dependencies(coordinates);
}

/**
* Resolves dependency for dependency builder.
*
* @param coordinates Coordinates specified to a created artifact, specified in an implementation-specific format.
* @return A File which contain resolved artifact.
* @throws ResolutionException If artifact could not be resolved
*/
public static File resolveAsFile(String coordinates) throws ResolutionException {
return DependencyResolvers.use(MavenDependencyShortcut.class).resolveAsFile(coordinates);
}

/**
* Resolves dependencies for dependency builder.
*
* @param coordinates A list of coordinates specified to the created artifacts, specified in an implementation-specific
* format.
* @return An array of Files which contains resolved artifacts
* @throws ResolutionException If artifact could not be resolved
*/
public static File[] resolveAsFiles(String... coordinates) throws ResolutionException {
return DependencyResolvers.use(MavenDependencyShortcut.class).resolveAsFiles(coordinates);
}

/**
* Loads remote repositories for a POM file. If repositories are defined in the parent of the POM file and there are
* accessible via local file system, they are set as well.
Expand All @@ -77,5 +101,4 @@ public static Collection<GenericArchive> dependencies(String... coordinates) thr
public static EffectivePomMavenDependencyShortcut withPom(String path) {
return DependencyResolvers.use(MavenDependencyShortcut.class).withPom(path);
}

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

import java.io.File;
import java.util.Collection;

import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.resolver.api.ResolutionException;
import org.jboss.shrinkwrap.resolver.api.maven.EffectivePomMavenDependencyShortcut;
Expand Down Expand Up @@ -53,7 +55,6 @@ public MavenDependencyShortcutImpl() {
*/
@Override
public GenericArchive dependency(String coordinates) throws ResolutionException {

Collection<GenericArchive> result = delegate.artifact(coordinates).resolveAs(GenericArchive.class, new StrictFilter());

if (result != null && result.size() != 1) {
Expand All @@ -77,6 +78,36 @@ public Collection<GenericArchive> dependencies(String... coordinates) throws Res
return delegate.artifacts(coordinates).resolveAs(GenericArchive.class, new StrictFilter());
}

/**
* Resolves dependency for dependency builder.
*
* @param coordinates Coordinates specified to a created artifact, specified in an implementation-specific format.
* @return A File which contain resolved artifact.
* @throws ResolutionException If artifact could not be resolved
*/
@Override
public File resolveAsFile(String coordinates) throws ResolutionException {
File[] result = delegate.artifact(coordinates).resolveAsFiles(new StrictFilter());

if (result != null && result.length != 1) {
throw new ResolutionException("Only one file should have been resolved. Resolved " + result.length + " files.");
}
return result[0];
}

/**
* Resolves dependencies for dependency builder.
*
* @param coordinates A list of coordinates specified to the created artifacts, specified in an implementation-specific
* format.
* @return An array of Files which contains resolved artifacts
* @throws ResolutionException If artifact could not be resolved
*/
@Override
public File[] resolveAsFiles(String... coordinates) throws ResolutionException {
return delegate.artifacts(coordinates).resolveAsFiles(new StrictFilter());
}

/**
* Loads remote repositories for a POM file. If repositories are defined in the parent of the POM file and there are
* accessible via local file system, they are set as well.
Expand All @@ -90,9 +121,9 @@ public Collection<GenericArchive> dependencies(String... coordinates) throws Res
* @return A dependency builder with remote repositories set according to the content of POM file.
* @throws ResolutionException If artifact coordinates are wrong or if version cannot be determined.
*/
@Override
public EffectivePomMavenDependencyShortcut withPom(final String path, String... profiles) throws ResolutionException {
this.delegate = delegate.loadEffectivePom(path, profiles).up();
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ public static void setRemoteRepository() {
public static void clearRemoteRepository() {
System.clearProperty(MavenSettingsBuilder.ALT_USER_SETTINGS_XML_LOCATION);
System.clearProperty(MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION);

}

// -------------------------------------------------------------------------------------||
// Tests
// ------------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
Expand Down Expand Up @@ -112,6 +111,20 @@ public void testShortcutSimpleResolution() throws ResolutionException {
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests a resolution of an artifact from central
*
* @throws ResolutionException
*/
@Test
public void testShortcutSimpleResolutionAsFile() throws ResolutionException {
File file = Maven.resolveAsFile("org.jboss.shrinkwrap.test:test-deps-c:1.0.0");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c-shortcut.tree"));
desc.validateFiles(file).results();
}

/**
* Tests a resolution of an artifact from central with custom settings
*
Expand All @@ -130,7 +143,6 @@ public void testSimpleResolutionWithCustomSettings() throws ResolutionException
desc.validateArchive(war).results();

war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);

}

/**
Expand All @@ -145,7 +157,6 @@ public void testInvalidSettingsPath() throws ResolutionException {
ShrinkWrap.create(WebArchive.class, "testSimpleResolutionWithCustomSettings.war").addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class).configureFrom("src/test/invalid/custom-settings.xml")
.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").resolveAs(GenericArchive.class));

}

/**
Expand All @@ -166,7 +177,6 @@ public void testMultipleResolution() throws ResolutionException {
desc.validateArchive(war).results();

war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);

}

/**
Expand All @@ -190,7 +200,6 @@ public void testMultipleResolutionSingleCall() throws ResolutionException {
desc.validateArchive(war).results();

war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);

}

/**
Expand All @@ -213,4 +222,19 @@ public void testShortcutMultipleResolutionSingleCall() throws ResolutionExceptio

war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests a resolution of two artifacts from central using single call
*
* @throws ResolutionException
*/
@Test
public void testShortcutMultipleResolutionSingleCallAsFiles() throws ResolutionException {
File[] files = Maven.resolveAsFiles("org.jboss.shrinkwrap.test:test-deps-c:1.0.0",
"org.jboss.shrinkwrap.test:test-deps-g:1.0.0");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c+g-shortcut.tree"));
desc.validateFiles(files).results();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ public void testShortcutParentPomRepositories() throws ResolutionException {
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests loading of a POM file with parent not available on local file system
*
* @throws ResolutionException
*/
@Test
public void testShortcutParentPomRepositoriesAsFile() throws ResolutionException {
File file = Maven.withPom("target/poms/test-child.xml").resolveAsFile("org.jboss.shrinkwrap.test:test-child:1.0.0");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-child-shortcut.tree"), "compile");
desc.validateFiles(file).results();
}

/**
* Tests loading of a POM file with parent available on local file system
*
Expand All @@ -95,9 +109,8 @@ public void testParentPomRemoteRepositories() throws ResolutionException {
String name = "parentPomRemoteRepositories";

WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war").addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class)
.loadEffectivePom("target/poms/test-remote-child.xml").up()
.artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").resolveAs(GenericArchive.class));
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("target/poms/test-remote-child.xml")
.up().artifact("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").resolveAs(GenericArchive.class));

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c.tree"));
Expand Down Expand Up @@ -125,6 +138,21 @@ public void testShortcutParentPomRemoteRepositories() throws ResolutionException
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests loading of a POM file with parent available on local file system
*
* @throws ResolutionException
*/
@Test
public void testShortcutParentPomRemoteRepositoriesAsFile() throws ResolutionException {
File file = Maven.withPom("target/poms/test-remote-child.xml").resolveAsFile(
"org.jboss.shrinkwrap.test:test-deps-c:1.0.0");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c-shortcut.tree"));
desc.validateFiles(file).results();
}

/**
* Tests loading of a POM file with parent available on local file system Uses POM to get artifact version
*
Expand All @@ -135,9 +163,8 @@ public void testArtifactVersionRetrievalFromPom() throws ResolutionException {
String name = "artifactVersionRetrievalFromPom";

WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war").addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class)
.loadEffectivePom("target/poms/test-remote-child.xml").up()
.artifact("org.jboss.shrinkwrap.test:test-deps-c").resolveAs(GenericArchive.class));
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("target/poms/test-remote-child.xml")
.up().artifact("org.jboss.shrinkwrap.test:test-deps-c").resolveAs(GenericArchive.class));

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c.tree"));
Expand Down Expand Up @@ -165,6 +192,20 @@ public void testShortcutArtifactVersionRetrievalFromPom() throws ResolutionExcep
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests loading of a POM file with parent available on local file system Uses POM to get artifact version
*
* @throws ResolutionException
*/
@Test
public void testShortcutArtifactVersionRetrievalFromPomAsFile() throws ResolutionException {
File file = Maven.withPom("target/poms/test-remote-child.xml").resolveAsFile("org.jboss.shrinkwrap.test:test-deps-c");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c-shortcut.tree"));
desc.validateFiles(file).results();
}

/**
* Tests loading of a POM file with parent available on local file system. However, the artifact version is not used from
* there, but specified manually
Expand All @@ -176,9 +217,8 @@ public void testArtifactVersionRetrievalFromPomOverride() throws ResolutionExcep
String name = "artifactVersionRetrievalFromPomOverride";

WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war").addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class)
.loadEffectivePom("target/poms/test-remote-child.xml").up()
.artifact("org.jboss.shrinkwrap.test:test-deps-c:2.0.0").resolveAs(GenericArchive.class));
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("target/poms/test-remote-child.xml")
.up().artifact("org.jboss.shrinkwrap.test:test-deps-c:2.0.0").resolveAs(GenericArchive.class));

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c-2.tree"));
Expand Down Expand Up @@ -207,6 +247,22 @@ public void testShortcutArtifactVersionRetrievalFromPomOverride() throws Resolut
war.as(ZipExporter.class).exportTo(new File("target/" + name + ".war"), true);
}

/**
* Tests loading of a POM file with parent available on local file system. However, the artifact version is not used from
* there, but specified manually
*
* @throws ResolutionException
*/
@Test
public void testShortcutArtifactVersionRetrievalFromPomOverrideAsFile() throws ResolutionException {
File file = Maven.withPom("target/poms/test-remote-child.xml").resolveAsFile(
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0");

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-deps-c-2-shortcut.tree"));
desc.validateFiles(file).results();
}

/**
* Tests resolution of dependencies for a POM file with parent on local file system
*
Expand Down Expand Up @@ -237,9 +293,8 @@ public void testPomRemoteBasedDependencies() throws ResolutionException {
String name = "pomRemoteBasedDependencies";

WebArchive war = ShrinkWrap.create(WebArchive.class, name + ".war").addAsLibraries(
DependencyResolvers.use(MavenDependencyResolver.class)
.loadEffectivePom("target/poms/test-remote-child.xml").importAllDependencies()
.resolveAs(JavaArchive.class));
DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("target/poms/test-remote-child.xml")
.importAllDependencies().resolveAs(JavaArchive.class));

DependencyTreeDescription desc = new DependencyTreeDescription(new File(
"src/test/resources/dependency-trees/test-remote-child.tree"));
Expand Down