Update tuscany run plugin to support specifying additional contributions in the plugin config xml, and to support NodeFactory config properties

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@935611 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
antelder 2010-04-19 15:05:53 +00:00
parent cb340e0c96
commit c685f5cc5d

View file

@ -22,13 +22,15 @@ import java.io.File;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugin.logging.Log;
import org.apache.tuscany.sca.domain.node.DomainNode; import org.apache.maven.project.MavenProject;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
/** /**
* Maven Mojo to run the SCA contribution project in Tuscany. * Maven Mojo to run the SCA contribution project in Tuscany.
@ -41,6 +43,15 @@ import org.apache.tuscany.sca.domain.node.DomainNode;
*/ */
public class TuscanyRunMojo extends AbstractMojo { public class TuscanyRunMojo extends AbstractMojo {
/**
* The maven project.
*
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
/** /**
* The project artifactId. * The project artifactId.
* *
@ -74,14 +85,18 @@ public class TuscanyRunMojo extends AbstractMojo {
protected File finalName; protected File finalName;
/** /**
* @parameter expression="${domain}" default-value="tuscany:default" * @parameter expression="${domain}" default-value="default"
*/ */
private String domain; private String domain;
/**
* @parameter expression="${config}" default-value="uri:defaultDomain"
*/
private String config;
/** /**
* @parameter expression="${contributions}" * @parameter expression="${contributions}"
*/ */
private String contributions; private String[] contributions;
public void execute() throws MojoExecutionException, MojoFailureException { public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Starting Tuscany Runtime..."); getLog().info("Starting Tuscany Runtime...");
@ -89,17 +104,39 @@ public class TuscanyRunMojo extends AbstractMojo {
List<String> contributionList = new ArrayList<String>(); List<String> contributionList = new ArrayList<String>();
addProjectContribution(contributionList); addProjectContribution(contributionList);
addAdditionalContributions(contributionList);
Node node = NodeFactory.newInstance(config).createNode((String)null, contributionList.toArray(new String[contributionList.size()])).start();
waitForShutdown(node, getLog());
}
private void addAdditionalContributions(List<String> contributionList) throws MojoExecutionException {
if (contributions != null) { if (contributions != null) {
StringTokenizer st = new StringTokenizer(contributions, ","); for (String s : contributions) {
while (st.hasMoreTokens()) { if (new File(s).exists()) {
contributionList.add(st.nextToken()); contributionList.add(s);
} else {
boolean found = false;
for (Object o : project.getDependencyArtifacts()) {
Artifact a = (Artifact) o;
if (a.getId().startsWith(s)) {
try {
contributionList.add(a.getFile().toURI().toURL().toString());
} catch (MalformedURLException e) {
throw new MojoExecutionException("", e);
}
found = true;
break;
}
}
if (!found) {
throw new IllegalArgumentException("Contribution not found as file or dependency: " + s);
}
}
} }
} }
DomainNode domainNode = new DomainNode(domain, contributionList.toArray(new String[contributionList.size()]));
waitForShutdown(domainNode, getLog());
} }
protected void addProjectContribution(List<String> cs) throws MojoExecutionException { protected void addProjectContribution(List<String> cs) throws MojoExecutionException {
@ -118,7 +155,7 @@ public class TuscanyRunMojo extends AbstractMojo {
} }
} }
protected void waitForShutdown(DomainNode node, Log log) { protected void waitForShutdown(Node node, Log log) {
Runtime.getRuntime().addShutdownHook(new ShutdownThread(node, log)); Runtime.getRuntime().addShutdownHook(new ShutdownThread(node, log));
synchronized (this) { synchronized (this) {
try { try {
@ -132,10 +169,10 @@ public class TuscanyRunMojo extends AbstractMojo {
protected static class ShutdownThread extends Thread { protected static class ShutdownThread extends Thread {
private DomainNode node; private Node node;
private Log log; private Log log;
public ShutdownThread(DomainNode node, Log log) { public ShutdownThread(Node node, Log log) {
super(); super();
this.node = node; this.node = node;
this.log = log; this.log = log;