Skip to content

Commit

Permalink
SHRINKRES-103 Removed scope from dependencyManagement check
Browse files Browse the repository at this point in the history
  • Loading branch information
kpiwko committed Jan 12, 2013
1 parent 319ccf8 commit 7481ccd
Show file tree
Hide file tree
Showing 36 changed files with 304 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ final class MavenDependencyImpl implements MavenDependency {
* {@link ScopeType#COMPILE}.
*
* @param coordinate
* Delegate, required
* Delegate, required
* @param scope
* @param optional
* @param exclusions
* {@link MavenDependencyExclusion}s, if <code>null</code> will be ignored
* {@link MavenDependencyExclusion}s, if <code>null</code> will be ignored
*/
MavenDependencyImpl(final MavenCoordinate coordinate, final ScopeType scope, final boolean optional,
final MavenDependencyExclusion... exclusions) {
final MavenDependencyExclusion... exclusions) {

// Precondition checks
assert coordinate != null : "coodinate is required";
Expand All @@ -58,7 +58,7 @@ final class MavenDependencyImpl implements MavenDependency {
this.scope = scope == null ? ScopeType.COMPILE : scope;
this.optional = optional;
final Set<MavenDependencyExclusion> exclusionsToSet = new HashSet<MavenDependencyExclusion>(
exclusions == null ? 0 : exclusions.length);
exclusions == null ? 0 : exclusions.length);
if (exclusions != null) {
for (final MavenDependencyExclusion exclusion : exclusions) {
if (exclusion != null) {
Expand Down Expand Up @@ -173,9 +173,6 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((delegate == null) ? 0 : delegate.hashCode());
result = prime * result + ((exclusions == null) ? 0 : exclusions.hashCode());
result = prime * result + (optional ? 1231 : 1237);
result = prime * result + ((scope == null) ? 0 : scope.hashCode());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.resolver.impl.maven.archive.util;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
* An utility to generate artifact jars
*
* @author <a href="mailto:kpiwko@redhat.com>Karel Piwko</a>
*
*/
@RunWith(Parameterized.class)
public class JarGenerator {
private String name;
private Class<?>[] content;

@Parameters
public static Collection<Object[]> jars() {
Object[][] data = new Object[][] { { "test-managed-dependency", new Class<?>[] { Object.class, List.class } },
{ "test-managed-dependency-2", new Class<?>[] { List.class } },
{ "test-dependency", new Class<?>[] { Arrays.class } },
{ "test-dependency-with-exclusion", new Class<?>[] { Collections.class } },
{ "test-exclusion", new Class<?>[] { ArrayList.class, LinkedList.class } },
{ "test-dependency-provided", new Class<?>[] { List.class, Map.class } },
{ "test-dependency-test", new Class<?>[] { ArrayList.class, HashMap.class } },
{ "test-parent", new Class<?>[] { File.class } }, { "test-child", new Class<?>[] { InputStream.class } },
{ "test-remote-parent", new Class<?>[] { OutputStream.class } },
{ "test-deps-a", new Class<?>[] { System.class } }, { "test-deps-b", new Class<?>[] { Field.class } },
{ "test-deps-c", new Class<?>[] { Integer.class } },
{ "test-deps-d", new Class<?>[] { Float.class, Double.class } },
{ "test-deps-e", new Class<?>[] { String.class, StringBuilder.class } },
{ "test-deps-f", new Class<?>[] { Thread.class } },
{ "test-deps-g", new Class<?>[] { Object.class, String.class } },
{ "test-deps-h", new Class<?>[] { Character.class, Byte.class } },
{ "test-deps-i", new Class<?>[] { System.class, PrintStream.class } },
{ "test-dependency-test-scope", new Class<?>[] { Method.class, Type.class, Field.class } }, };

return Arrays.asList(data);
}

public JarGenerator(String name, Class<?>[] content) {
this.name = name;
this.content = content;
}

@Test
public void createJars() {
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, name).addClasses(content);

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.resolver.impl.maven.archive.util;

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

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
* An utility to generate artifact wars
*
* @author <a href="kpiwko@redhat.com>Karel Piwko</a>
*
*/
@RunWith(Parameterized.class)
public class WarGenerator {
private String name;
private Class<?>[] classes;
private String[] directories;

@Parameters
public static Collection<Object[]> jars() {
Object[][] data = new Object[][] {
{ "test-war", new Class<?>[] { Object.class, List.class }, new String[] { "html", "jsp" } },
{ "test-war-classifier", new Class<?>[] { Arrays.class }, new String[] { "xhtml", "rf" } } };

return Arrays.asList(data);
}

public WarGenerator(String name, Class<?>[] classes, String[] directories) {
this.name = name;
this.classes = classes;
this.directories = directories;
}

@Test
public void createJars() {
WebArchive archive = ShrinkWrap.create(WebArchive.class, name).addClasses(classes).addAsDirectories(directories);

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public static void clearRemoteRepository() {
public void parentPomRepositories() {

File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child.tree"),
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
}

/**
Expand All @@ -68,10 +68,10 @@ public void parentPomRepositories() {
public void shortcutParentPomRepositories() {

File[] files = Maven.resolver().loadPomFromFile("target/poms/test-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withoutTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withoutTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child-shortcut.tree"),
ScopeType.COMPILE).validate(files);
ScopeType.COMPILE).validate(files);
}

/**
Expand All @@ -82,10 +82,10 @@ public void shortcutParentPomRepositories() {
public void parentPomRemoteRepositories() {

File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate(
files);
files);
}

/**
Expand All @@ -96,10 +96,10 @@ public void parentPomRemoteRepositories() {
public void shortcutParentPomRemoteRepositories() {

File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withoutTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withoutTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(files);
.validate(files);
}

/**
Expand All @@ -109,10 +109,10 @@ public void shortcutParentPomRemoteRepositories() {
@Test
public void artifactVersionRetrievalFromPom() {
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate(
files);
files);
}

/**
Expand All @@ -123,10 +123,10 @@ public void artifactVersionRetrievalFromPom() {
public void shortcutArtifactVersionRetrievalFromPom() {

File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().as(File.class);
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(files);
.validate(files);
}

/**
Expand All @@ -136,10 +136,10 @@ public void shortcutArtifactVersionRetrievalFromPom() {
@Test
public void shortcutArtifactVersionRetrievalFromPomAsFile() {
File file = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().asSingle(File.class);
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().asSingle(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(file);
.validate(file);
}

/**
Expand All @@ -151,12 +151,12 @@ public void shortcutArtifactVersionRetrievalFromPomAsFile() {
public void artifactVersionRetrievalFromPomOverride() {

final MavenDependency dependency = MavenDependencies.createDependency(
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.addDependency(dependency).resolve().withTransitivity().as(File.class);
.addDependency(dependency).resolve().withTransitivity().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-2.tree")).validate(
files);
files);
}

/**
Expand All @@ -168,12 +168,12 @@ public void artifactVersionRetrievalFromPomOverride() {
public void shortcutArtifactVersionRetrievalFromPomOverride() {

final MavenDependency dependency = MavenDependencies.createDependency(
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
File file = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml").addDependency(dependency)
.resolve().withoutTransitivity().asSingle(File.class);
.resolve().withoutTransitivity().asSingle(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-2-shortcut.tree"))
.validate(file);
.validate(file);
}

/**
Expand All @@ -184,10 +184,10 @@ public void shortcutArtifactVersionRetrievalFromPomOverride() {
public void pomBasedDependencies() {

File[] files = Maven.resolver().loadPomFromFile("target/poms/test-child.xml").importRuntimeDependencies()
.as(File.class);
.as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child.tree"), false,
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);

}

Expand All @@ -199,9 +199,24 @@ public void pomBasedDependencies() {
public void pomRemoteBasedDependencies() {

File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.importRuntimeDependencies().as(File.class);
.importRuntimeDependencies().as(File.class);

ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-remote-child.tree"),
false, ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
false, ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
}

/**
* Tests resolving a version from pom.xml which has non-default scope
* https://issues.jboss.org/browse/SHRINKRES-103
*
*/
@Test
public void scopedArtifactVersionRetrievalFromPom() {

File[] files = Maven.configureResolver().fromFile("target/settings/profiles/settings.xml")
.loadPomFromFile("target/poms/test-dependency-test-scope.xml")
.resolve("org.jboss.shrinkwrap.test:test-managed-dependency").withoutTransitivity().as(File.class);

new ValidationUtil("test-managed-dependency").validate(files);
}
}
Binary file not shown.
14 changes: 13 additions & 1 deletion impl-maven/src/test/resources/poms/install-all.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,19 @@
<phase>install</phase>
<configuration>
<file>${basedir}/test-system-scope.xml</file>
<pomFile>${basedir}/test-system-scope.xml</pomFile>
<pomFile>${basedir}/test-system-scope.xml</pomFile>
</configuration>
</execution>

<execution>
<id>install-dependency-test-scoped</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${basedir}/../artifacts/test-dependency-test-scope.jar</file>
<pomFile>${basedir}/test-dependency-test-scope.xml</pomFile>
</configuration>
</execution>
</executions>
Expand Down

0 comments on commit 7481ccd

Please sign in to comment.