Skip to content

Commit

Permalink
Use Maven properties to store artifact versions
Browse files Browse the repository at this point in the history
* version.arquillian_core used by arquillian:bom
* version.junit used by junit:junit
* version.testng used by testng:testng
  • Loading branch information
aslakknutsen committed Mar 17, 2012
1 parent 27034d6 commit 317070e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
54 changes: 35 additions & 19 deletions src/main/java/org/jboss/forge/arquillian/ArquillianPlugin.java
Expand Up @@ -51,6 +51,15 @@ public class ArquillianPlugin implements Plugin {
Velocity.init(properties);
}

public static final String ARQ_CORE_VERSION_PROP_NAME = "version.arquillian_core";
public static final String ARQ_CORE_VERSION_PROP = "${" + ARQ_CORE_VERSION_PROP_NAME + "}";

public static final String JUNIT_VERSION_PROP_NAME = "version.junit";
public static final String JUNIT_VERSION_PROP = "${" + JUNIT_VERSION_PROP_NAME + "}";

public static final String TESTNG_VERSION_PROP_NAME = "version.testng";
public static final String TESTNG_VERSION_PROP = "${" + TESTNG_VERSION_PROP_NAME + "}";

@Inject
private Project project;

Expand Down Expand Up @@ -89,14 +98,14 @@ public void installContainer(

dependencyFacet = project.getFacet(DependencyFacet.class);

installArquillianBom();

if (testframework.equals("junit")) {
installJunitDependencies();
} else {
installTestNgDependencies();
}

installArquillianBom();

List<Container> containers = containerDirectoryParser.getContainers();

boolean foundContainer = false;
Expand Down Expand Up @@ -252,17 +261,15 @@ private void installJunitDependencies() {
if (!dependencyFacet.hasEffectiveDependency(junitDependency)) {
List<Dependency> dependencies = dependencyFacet.resolveAvailableVersions(junitDependency);
Dependency dependency = shell.promptChoiceTyped("Which version of JUnit do you want to install?", dependencies, DependencyUtil.getLatestNonSnapshotVersion(dependencies));
dependencyFacet.addDirectDependency(dependency);

dependencyFacet.setProperty(JUNIT_VERSION_PROP_NAME, dependency.getVersion());
dependencyFacet.addDirectDependency(
DependencyBuilder.create(dependency).setVersion(JUNIT_VERSION_PROP));
}

DependencyBuilder junitArquillianDependency = createJunitArquillianDependency();
if (!dependencyFacet.hasEffectiveDependency(junitArquillianDependency)) {
List<Dependency> dependencies = dependencyFacet.resolveAvailableVersions(junitArquillianDependency);
Dependency dependency = shell.promptChoiceTyped("Which version of Arquillian do you want to install?", dependencies, DependencyUtil.getLatestNonSnapshotVersion(dependencies));
arquillianVersion = dependency.getVersion();
dependencyFacet.addDirectDependency(dependency);
} else {
arquillianVersion = dependencyFacet.getDirectDependency(junitArquillianDependency).getVersion();
dependencyFacet.addDirectDependency(junitArquillianDependency);
}
}

Expand All @@ -271,17 +278,15 @@ private void installTestNgDependencies() {
if (!dependencyFacet.hasEffectiveDependency(testngDependency)) {
List<Dependency> dependencies = dependencyFacet.resolveAvailableVersions(testngDependency);
Dependency dependency = shell.promptChoiceTyped("Which version of TestNG do you want to install?", dependencies, DependencyUtil.getLatestNonSnapshotVersion(dependencies));
dependencyFacet.addDirectDependency(dependency);

dependencyFacet.setProperty(TESTNG_VERSION_PROP_NAME, dependency.getVersion());
dependencyFacet.addDirectDependency(
DependencyBuilder.create(dependency).setVersion(TESTNG_VERSION_PROP));
}

DependencyBuilder testNgArquillianDependency = createTestNgArquillianDependency();
if (!dependencyFacet.hasEffectiveDependency(testNgArquillianDependency)) {
List<Dependency> dependencies = dependencyFacet.resolveAvailableVersions(testNgArquillianDependency);
Dependency dependency = shell.promptChoiceTyped("Which version of Arquillian do you want to install?", dependencies, DependencyUtil.getLatestNonSnapshotVersion(dependencies));
arquillianVersion = dependency.getVersion();
dependencyFacet.addDirectDependency(dependency);
} else {
arquillianVersion = dependencyFacet.getManagedDependency(testNgArquillianDependency).getVersion();
dependencyFacet.addDirectDependency(testNgArquillianDependency);
}
}

Expand All @@ -290,10 +295,21 @@ private void installArquillianBom() {
.setGroupId("org.jboss.arquillian")
.setArtifactId("arquillian-bom")
.setPackagingType("pom")
.setVersion(arquillianVersion)
.setScopeType(ScopeType.IMPORT);

dependencyFacet.addDirectManagedDependency(arquillianBom);
arquillianVersion = dependencyFacet.getProperty(ARQ_CORE_VERSION_PROP_NAME);
if(arquillianVersion == null) {
List<Dependency> dependencies = dependencyFacet.resolveAvailableVersions(arquillianBom);
Dependency dependency = shell.promptChoiceTyped("Which version of Arquillian do you want to install?", dependencies, DependencyUtil.getLatestNonSnapshotVersion(dependencies));
arquillianVersion = dependency.getVersion();
dependencyFacet.setProperty(ARQ_CORE_VERSION_PROP_NAME, arquillianVersion);
}

// need to set version after resolve is done, else nothing will resolve.
if(!dependencyFacet.hasDirectManagedDependency(arquillianBom)) {
arquillianBom.setVersion(ARQ_CORE_VERSION_PROP);
dependencyFacet.addDirectManagedDependency(arquillianBom);
}
}

private DependencyBuilder createJunitDependency() {
Expand Down Expand Up @@ -321,6 +337,6 @@ private DependencyBuilder createTestNgArquillianDependency() {
return DependencyBuilder.create()
.setGroupId("org.jboss.arquillian.testng")
.setArtifactId("arquillian-testng-container")
.setVersion(arquillianVersion);
.setScopeType(ScopeType.TEST);
}
}
20 changes: 18 additions & 2 deletions src/test/java/test/integration/PluginTest.java
Expand Up @@ -2,6 +2,7 @@

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.hasItem;
import static org.junit.matchers.JUnitMatchers.hasItems;
Expand All @@ -10,6 +11,7 @@
import java.util.List;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
Expand Down Expand Up @@ -51,7 +53,7 @@ public static JavaArchive getDeployment()
// ArchivePaths.create("beans.xml"));
}

private void installContainer(final String container, final List<DependencyMatcher> dependencies) throws Exception
private Project installContainer(final String container, final List<DependencyMatcher> dependencies) throws Exception
{
Project project = initializeJavaProject();

Expand All @@ -63,7 +65,7 @@ private void installContainer(final String container, final List<DependencyMatch
}
assertThat(profiles.size(), is(0));

queueInputLines(container, "19", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
queueInputLines(container, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
getShell().execute("arquillian setup");

assertThat(coreFacet.getPOM().getProfiles().size(), is(1));
Expand All @@ -72,6 +74,20 @@ private void installContainer(final String container, final List<DependencyMatch
for (DependencyMatcher dependency : dependencies) {
assertThat(profile.getDependencies(), hasItem(dependency));
}

Model pom = coreFacet.getPOM();
DependencyMatcher arqBom = new DependencyMatcher("arquillian-bom");

assertThat("Verify arquillian:bom was added to DependencyManagement ",
pom.getDependencyManagement().getDependencies(), hasItem(arqBom));

assertNotNull("Verify that the plugin use a version property for arquillian core",
pom.getProperties().get(ArquillianPlugin.ARQ_CORE_VERSION_PROP_NAME));

assertNotNull("Verify that the plugin use a version property for junit",
pom.getProperties().get(ArquillianPlugin.JUNIT_VERSION_PROP_NAME));

return project;
}

@Test
Expand Down

0 comments on commit 317070e

Please sign in to comment.