Author: mickael_istria
Date: 2012-10-09 09:20:18 -0400 (Tue, 09 Oct 2012)
New Revision: 44375
Modified:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/MergeTargetsMojo.java
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetToRepoMojo.java
Log:
Fix and factorization in TP-related Mojos
Modified:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java 2012-10-09
12:32:55 UTC (rev 44374)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/FlattenTargetMojo.java 2012-10-09
13:20:18 UTC (rev 44375)
@@ -92,23 +92,7 @@
}
if (this.sourceTargetArtifact != null) {
- if (!this.sourceTargetArtifact.isCorrectlySet()) {
- throw new MojoExecutionException("'sourceTargetArtifact' must
define groupId, artifactId and version");
- }
- getLog().debug("Downloading " + sourceTargetArtifact.toString());
- Artifact artifact =
this.repositorySystem.createArtifactWithClassifier(this.sourceTargetArtifact.getGroupId(),
this.sourceTargetArtifact.getArtifactId(), this.sourceTargetArtifact.getVersion(),
"target",
- this.sourceTargetArtifact.getArtifactId());
- ArtifactResolutionRequest request = new ArtifactResolutionRequest();
- request.setArtifact(artifact);
- request.setLocalRepository(this.session.getLocalRepository());
- request.setRemoteRepositories(this.project.getRemoteArtifactRepositories());
- this.repositorySystem.resolve(request);
-
- if (!artifact.isResolved()) {
- throw new RuntimeException("Could not resolve target platform
specification artifact " + artifact);
- }
-
- this.sourceTargetFile = artifact.getFile();
+ this.sourceTargetFile =
this.sourceTargetArtifact.getFile(this.repositorySystem, this.session, this.project);
}
try {
Modified:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/MergeTargetsMojo.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/MergeTargetsMojo.java 2012-10-09
12:32:55 UTC (rev 44374)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/MergeTargetsMojo.java 2012-10-09
13:20:18 UTC (rev 44375)
@@ -77,24 +77,8 @@
}
if (this.sourceTargetArtifacts != null) {
- for (TargetArtifact sourceTargetArtifact : sourceTargetArtifacts) {
- if (!sourceTargetArtifact.isCorrectlySet()) {
- throw new MojoExecutionException("'sourceTargetArtifact' must
define groupId, artifactId and version");
- }
- getLog().debug("Downloading " + sourceTargetArtifact.toString());
- Artifact artifact =
this.repositorySystem.createArtifactWithClassifier(sourceTargetArtifact.getGroupId(),
sourceTargetArtifact.getArtifactId(), sourceTargetArtifact.getVersion(),
"target",
- sourceTargetArtifact.getArtifactId());
- ArtifactResolutionRequest request = new ArtifactResolutionRequest();
- request.setArtifact(artifact);
- request.setLocalRepository(this.session.getLocalRepository());
-
request.setRemoteRepositories(this.project.getRemoteArtifactRepositories());
- this.repositorySystem.resolve(request);
-
- if (!artifact.isResolved()) {
- throw new RuntimeException("Could not resolve target platform
specification artifact " + artifact);
- }
-
- this.sourceTargetFiles.add(artifact.getFile());
+ for (TargetArtifact sourceTargetArtifact : this.sourceTargetArtifacts) {
+ this.sourceTargetFiles.add(sourceTargetArtifact.getFile(this.repositorySystem,
this.session, this.project));
}
}
Modified:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java 2012-10-09
12:32:55 UTC (rev 44374)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetArtifact.java 2012-10-09
13:20:18 UTC (rev 44375)
@@ -1,5 +1,14 @@
package org.jboss.tools.tycho.targets;
+import java.io.File;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
+
public class TargetArtifact {
private String groupId;
@@ -24,4 +33,22 @@
public String toString() {
return this.groupId + ":" + this.artifactId + ":" + this.version;
}
+
+ public File getFile(RepositorySystem repositorySystem, MavenSession session,
MavenProject project) throws MojoExecutionException {
+ if (!isCorrectlySet()) {
+ throw new MojoExecutionException("'sourceTargetArtifact' must define
groupId, artifactId and version");
+ }
+ Artifact artifact = repositorySystem.createArtifactWithClassifier(this.groupId,
this.artifactId, this.version, "target", this.artifactId);
+ ArtifactResolutionRequest request = new ArtifactResolutionRequest();
+ request.setArtifact(artifact);
+ request.setLocalRepository(session.getLocalRepository());
+ request.setRemoteRepositories(project.getRemoteArtifactRepositories());
+ repositorySystem.resolve(request);
+
+ if (!artifact.isResolved()) {
+ throw new MojoExecutionException("Could not resolve target platform
specification artifact " + artifact);
+ }
+
+ return artifact.getFile();
+ }
}
Modified:
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetToRepoMojo.java
===================================================================
---
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetToRepoMojo.java 2012-10-09
12:32:55 UTC (rev 44374)
+++
trunk/build/tycho-plugins/target-platform-utils/src/main/java/org/jboss/tools/tycho/targets/TargetToRepoMojo.java 2012-10-09
13:20:18 UTC (rev 44375)
@@ -20,6 +20,8 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
+import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.tycho.BuildOutputDirectory;
import org.eclipse.tycho.p2.resolver.TargetDefinitionFile;
@@ -51,30 +53,51 @@
* @readonly
*/
private MavenSession session;
+ /**
+ * @component
+ */
+ @Requirement
+ private RepositorySystem repositorySystem;
/**
- * @parameter expression="${project.artifactId}.target"
+ * @parameter
*/
- private File targetFile;
+ private File sourceTargetFile;
/**
+ * @parameter
+ */
+ private TargetArtifact sourceTargetArtifact;
+
+ /**
* @parameter
expression="${project.build.directory}/${project.artifactId}.target.repo"
*/
- private File targetRepository;
+ private File outputRepository;
/** @component */
private EquinoxServiceFactory p2;
public void execute() throws MojoExecutionException, MojoFailureException {
try {
- if (!this.targetFile.isFile()) {
- throw new MojoExecutionException("Specified 'targetFile' (value: "
+ targetFile + ") is not a valid file");
+ if (this.sourceTargetArtifact != null && this.sourceTargetFile != null) {
+ getLog().debug("sourceTargetArtifact: " +
this.sourceTargetArtifact.toString());
+ getLog().debug("sourceTargetFile; " + this.sourceTargetFile.toString());
+ throw new MojoExecutionException("Set either 'sourceTargetArtifact' XOR
'sourceTargetFile'");
}
- this.targetRepository.mkdirs();
+ if (this.sourceTargetFile == null && this.sourceTargetArtifact == null) {
+ this.sourceTargetFile = new File(this.project.getBasedir(),
this.project.getArtifactId() + ".target");
+ }
+ if (this.sourceTargetArtifact != null) {
+ this.sourceTargetFile = this.sourceTargetArtifact.getFile(this.repositorySystem,
this.session, this.project);
+ }
+ if (!this.sourceTargetFile.isFile()) {
+ throw new MojoExecutionException("Specified 'targetFile' (value: "
+ sourceTargetFile + ") is not a valid file");
+ }
+ this.outputRepository.mkdirs();
final MirrorApplicationService mirrorService =
p2.getService(MirrorApplicationService.class);
- TargetDefinitionFile target = TargetDefinitionFile.read(targetFile);
+ TargetDefinitionFile target = TargetDefinitionFile.read(sourceTargetFile);
final RepositoryReferences sourceDescriptor = new RepositoryReferences();
for (final Location loc : target.getLocations()) {
if (loc instanceof InstallableUnitLocation) {
@@ -85,7 +108,7 @@
}
}
- final DestinationRepositoryDescriptor destinationDescriptor = new
DestinationRepositoryDescriptor(this.targetRepository, this.targetFile.getName(), true,
false, true);
+ final DestinationRepositoryDescriptor destinationDescriptor = new
DestinationRepositoryDescriptor(this.outputRepository, this.sourceTargetFile.getName(),
true, false, true);
mirrorService.mirrorStandalone(sourceDescriptor, destinationDescriptor,
createIUDescriptions(target), createMirrorOptions(), new
BuildOutputDirectory(this.project.getBuild().getOutputDirectory()));
} catch (Exception ex) {