Skip to content
Browse files

Use Maven properties to store artifact versions

* version.arquillian_core used by arquillian:bom
* version.junit used by junit:junit
* version.testng used by testng:testng
  • Loading branch information...
1 parent 27034d6 commit 317070e7dbe2d2925b9cf9f65efe88bc0e886380 @aslakknutsen aslakknutsen committed Mar 17, 2012
View
54 src/main/java/org/jboss/forge/arquillian/ArquillianPlugin.java
@@ -51,6 +51,15 @@
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;
@@ -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;
@@ -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);
}
}
@@ -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);
}
}
@@ -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() {
@@ -321,6 +337,6 @@ private DependencyBuilder createTestNgArquillianDependency() {
return DependencyBuilder.create()
.setGroupId("org.jboss.arquillian.testng")
.setArtifactId("arquillian-testng-container")
- .setVersion(arquillianVersion);
+ .setScopeType(ScopeType.TEST);
}
}
View
20 src/test/java/test/integration/PluginTest.java
@@ -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;
@@ -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;
@@ -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();
@@ -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));
@@ -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

0 comments on commit 317070e

Please sign in to comment.
Something went wrong with that request. Please try again.