Fix working with reactor builds and error detect bad GAVs

Each module when processed by the plugin needs to ensure
it has a clean set of tiles to work with. This fixes this problem.
The code has also been modified to ensure we test for correctly formed
GAVs and to error if they aren't there.

Change-Id: Ibd65a5e429de37eea1c8730b770404adb9ea28d0
This commit is contained in:
Richard Vowles
2014-07-27 08:03:24 +12:00
committed by Mark Derricutt
parent 94c1c79d1b
commit 7d924a378c
2 changed files with 64 additions and 24 deletions

View File

@@ -99,9 +99,18 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
* We store the groupId:artifactId -> Artifact of those tiles we have discovered in our meanderings through
* the
*/
Map<String, ArtifactModel> processedTiles = new HashMap<String, ArtifactModel>()
List<String> tileDiscoveryOrder = new ArrayList<String>()
Map<String, Artifact> unprocessedTiles = new HashMap<String, Artifact>()
Map<String, ArtifactModel> processedTiles = [:]
List<String> tileDiscoveryOrder = []
Map<String, Artifact> unprocessedTiles = [:]
/**
* reactor builds can/will have their own tile structures
*/
protected void resetTiles() {
processedTiles = [:]
tileDiscoveryOrder = []
unprocessedTiles = [:]
}
protected Artifact getArtifactFromCoordinates(String groupId, String artifactId, String version) {
return new DefaultArtifact(groupId, artifactId, VersionRange.createFromVersion(version), "compile",
@@ -121,13 +130,18 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
return tileArtifact
}
protected Artifact turnPropertyIntoUnprocessedTile(String propertyValue) {
protected Artifact turnPropertyIntoUnprocessedTile(String artifactGav, File pomFile)
throws MavenExecutionException {
StringTokenizer propertyTokens = new StringTokenizer(propertyValue, ":")
String[] gav = artifactGav.tokenize(":")
String groupId = propertyTokens.nextToken()
String artifactId = propertyTokens.nextToken()
String version = propertyTokens.nextToken()
if (gav.size() != 3) {
throw new MavenExecutionException("${artifactGav} does not have the form group:artifact:version-range", pomFile)
}
String groupId = gav[0]
String artifactId = gav[1]
String version = gav[2]
return getArtifactFromCoordinates(groupId, artifactId, version)
}
@@ -164,6 +178,7 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
//We're in a multi-module build, we need to trigger model merging on all sub-modules
for (MavenProject subModule : mavenSession.getProjects()) {
if (subModule != topLevelProject) {
resetTiles()
orchestrateMerge(subModule)
}
}
@@ -186,7 +201,7 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
Model propertyCollectionModel = project.getModel().clone()
// collect the first set of tiles
collectTiles(propertyCollectionModel)
collectTiles(propertyCollectionModel, project.getFile())
// collect any unprocessed tiles, and process them causing them to potentially load more unprocessed ones
resolveTiles()
@@ -303,7 +318,7 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
processedTiles.put(artifactName(resolvedTile), new ArtifactModel(resolvedTile, tileModel))
collectTiles(tileModel)
collectTiles(tileModel, resolvedTile.getFile())
}
}
@@ -319,7 +334,7 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
return String.format("%s:%s:%s", model.groupId, model.artifactId, model.version)
}
protected void collectTiles(Model model) {
protected void collectTiles(Model model, File pomFile) {
Xpp3Dom configuration = model?.build?.plugins?.
find({ Plugin plugin ->
return plugin.groupId == TILEPLUGIN_GROUP &&
@@ -327,15 +342,15 @@ public class TilesMavenLifecycleParticipant extends AbstractMavenLifecyclePartic
if (configuration) {
configuration.getChild("tiles")?.children?.each { Xpp3Dom tile ->
if (tile.getName() == "tile") {
collectConfigurationTile(model, tile.getValue())
if (tile.name == "tile") {
collectConfigurationTile(model, tile.value, pomFile)
}
}
}
}
protected void collectConfigurationTile(Model model, String tileDependencyName) {
Artifact unprocessedTile = turnPropertyIntoUnprocessedTile(tileDependencyName)
protected void collectConfigurationTile(Model model, String tileDependencyName, File pomFile) {
Artifact unprocessedTile = turnPropertyIntoUnprocessedTile(tileDependencyName, pomFile)
String depName = artifactName(unprocessedTile)

View File

@@ -34,6 +34,7 @@ import org.junit.runner.RunWith
import org.mockito.runners.MockitoJUnitRunner
import static org.mockito.Mockito.mock
import static groovy.test.GroovyAssert.shouldFail
/**
* If testMergeTile fails with java.io.FileNotFoundException: src/test/resources/licenses-tiles-pom.xml
@@ -99,25 +100,36 @@ public class TilesMavenLifecycleParticipantTest {
}
@Test
public void testMerge() throws MavenExecutionException {
Model model = new Model()
public void testBadGav() {
Model model = createBasicModel()
addTileAndPlugin(model, "groupid:artifactid")
participant = new TilesMavenLifecycleParticipant()
MavenProject project = new MavenProject(model)
model.setGroupId("com.bluetrainsoftware.maven")
model.setArtifactId("maven-tiles-example")
model.setVersion("1.1-SNAPSHOT")
Throwable failure = shouldFail {
participant.orchestrateMerge(project)
}
Properties model1Properties = new Properties()
model1Properties.setProperty("property1", "property1")
model.setProperties(model1Properties)
assert failure.message == "groupid:artifactid does not have the form group:artifact:version-range"
}
public void addTileAndPlugin(Model model, String gav) {
// add our plugin
model.build = new Build()
model.build.addPlugin(new Plugin())
model.build.plugins[0].with {
groupId = TilesMavenLifecycleParticipant.TILEPLUGIN_GROUP
artifactId = TilesMavenLifecycleParticipant.TILEPLUGIN_ARTIFACT
configuration = Xpp3DomBuilder.build(new StringReader("<configuration><tiles><tile>${TILE_TEST_COORDINATES}</tile></tiles></configuration>"))
// bad GAV
configuration = Xpp3DomBuilder.build(new StringReader("<configuration><tiles><tile>${gav}</tile></tiles></configuration>"))
}
}
@Test
public void testMerge() throws MavenExecutionException {
Model model = createBasicModel()
addTileAndPlugin(model, TILE_TEST_COORDINATES)
Model pureModel = model.clone()
@@ -166,4 +178,17 @@ public class TilesMavenLifecycleParticipantTest {
assert executions*.id.intersect(["print-antrun1", "print-antrun2"])
}
}
protected Model createBasicModel() {
Model model = new Model()
model.setGroupId("com.bluetrainsoftware.maven")
model.setArtifactId("maven-tiles-example")
model.setVersion("1.1-SNAPSHOT")
Properties model1Properties = new Properties()
model1Properties.setProperty("property1", "property1")
model.setProperties(model1Properties)
model
}
}