You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2006/12/15 22:16:13 UTC
svn commit: r487664 - in /incubator/tuscany/java/sca/plugins/plugin.itest:
./ src/main/java/org/apache/tuscany/sca/plugin/itest/
src/main/resources/META-INF/tuscany/
Author: rfeng
Date: Fri Dec 15 13:16:12 2006
New Revision: 487664
URL: http://svn.apache.org/viewvc?view=rev&rev=487664
Log:
Fix for TUSCANY-995: Add extension support for itest plugin
Added:
incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java (with props)
Removed:
incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedArtifactRepository.java
Modified:
incubator/tuscany/java/sca/plugins/plugin.itest/pom.xml
incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java
incubator/tuscany/java/sca/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl
Modified: incubator/tuscany/java/sca/plugins/plugin.itest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/pom.xml?view=diff&rev=487664&r1=487663&r2=487664
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/pom.xml (original)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/pom.xml Fri Dec 15 13:16:12 2006
@@ -35,6 +35,11 @@
<version>2.0.4</version>
</dependency>
<dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0.4</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-api</artifactId>
<version>2.0</version>
@@ -51,5 +56,12 @@
<artifactId>core</artifactId>
<version>1.0-incubator-SNAPSHOT</version>
</dependency>
+ <!-- [rfeng] A big hack to resolve servlet-api -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>runtime</scope>
+ </dependency>
</dependencies>
</project>
Added: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java?view=auto&rev=487664
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java (added)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java Fri Dec 15 13:16:12 2006
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.plugin.itest;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+
+/**
+ * Represents a configured tuscany dependency for boot and extension libraries.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Dependency {
+
+ /**
+ * JAR type artifact.
+ */
+ private static final String TYPE_JAR = "jar";
+
+ /**
+ * Group Id that is injected in from configuration.
+ */
+ private String groupId;
+
+ /**
+ * Artifact Id that is injected in from configuration.
+ */
+ private String artifactId;
+
+ /**
+ * Version that is injected in from configuration.
+ */
+ private String version;
+
+ /**
+ * Default constructor.
+ */
+ public Dependency() {
+ }
+
+ /**
+ * Initializes the field.
+ *
+ * @param groupId Group id.
+ * @param artifactId Artifact id.
+ * @param version Artifact version.
+ */
+ public Dependency(String groupId, String artifactId, String version) {
+ super();
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ /**
+ * Gets the artifact using the specified artifact factory.
+ *
+ * @param artifactFactory Artifact factory to use.
+ * @return Artifact identified by the dependency.
+ */
+ public Artifact getArtifact(ArtifactFactory artifactFactory) {
+ return artifactFactory.createArtifact(groupId, artifactId, version, Artifact.SCOPE_RUNTIME, TYPE_JAR);
+ }
+
+}
Propchange: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/Dependency.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java?view=diff&rev=487664&r1=487663&r2=487664
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java (original)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java Fri Dec 15 13:16:12 2006
@@ -18,21 +18,32 @@
*/
package org.apache.tuscany.sca.plugin.itest;
-import javax.xml.stream.XMLInputFactory;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashMap;
+import java.util.Map;
-import org.osoa.sca.SCA;
+import javax.xml.stream.XMLInputFactory;
-import org.apache.tuscany.core.runtime.AbstractRuntime;
-import org.apache.tuscany.core.launcher.CompositeContextImpl;
import org.apache.tuscany.core.bootstrap.Bootstrapper;
import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
-import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.sca.plugin.itest.TuscanyStartMojo.MavenEmbeddedArtifactRepository;
import org.apache.tuscany.spi.bootstrap.ComponentNames;
+import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.spi.component.Component;
import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.CompositeClassLoader;
import org.apache.tuscany.spi.deployer.Deployer;
import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.host.MonitorFactory;
-import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+import org.osoa.sca.SCA;
/**
* @version $Rev$ $Date$
@@ -43,6 +54,13 @@
private CompositeComponent systemComponent;
private CompositeComponent tuscanySystem;
private CompositeComponent application;
+
+ private ArtifactRepository artifactRepository;
+ private Map extensions = new HashMap();
+
+ public void addExtension(String extensionName, URL extentionSCDL) {
+ extensions.put(extensionName, extentionSCDL);
+ }
public void initialize() {
ClassLoader bootClassLoader = getClass().getClassLoader();
@@ -66,6 +84,9 @@
// register the monitor factory provided by the host
systemComponent.registerJavaObject("MonitorFactory", MonitorFactory.class, mf);
+ systemComponent.registerJavaObject(MavenEmbeddedArtifactRepository.COMPONENT_NAME,
+ ArtifactRepository.class,
+ artifactRepository);
systemComponent.start();
@@ -82,6 +103,10 @@
// switch to the system deployer
deployer = (Deployer) tuscanySystem.getSystemChild("deployer").getServiceInstance();
+ for (Object extensionName : extensions.keySet()) {
+ deployExtension(tuscanySystem, deployer, (String) extensionName, (URL) extensions.get(extensionName));
+ }
+
application = deployApplicationScdl(deployer,
runtime.getRootComponent(),
getApplicationName(),
@@ -95,6 +120,27 @@
e.printStackTrace();
}
}
+
+ protected void deployExtension(CompositeComponent composite, Deployer deployer, String extensionName, URL url)
+ throws LoaderException {
+ SystemCompositeImplementation implementation = new SystemCompositeImplementation();
+ URL scdlLocation;
+ try {
+ scdlLocation = new URL("jar:" + url.toExternalForm() + "!/META-INF/sca/default.scdl");
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ implementation.setScdlLocation(scdlLocation);
+ implementation.setClassLoader(new CompositeClassLoader(new URL[] {url}, getClass().getClassLoader()));
+
+ ComponentDefinition<SystemCompositeImplementation> definition =
+ new ComponentDefinition<SystemCompositeImplementation>(extensionName, implementation);
+
+ Component component = deployer.deploy(composite, definition);
+
+ component.start();
+ }
public void destroy() {
context = null;
@@ -118,6 +164,10 @@
public SCA getContext() {
return context;
+ }
+
+ public void setArtifactRepository(ArtifactRepository artifactRepository) {
+ this.artifactRepository = artifactRepository;
}
}
Modified: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java?view=diff&rev=487664&r1=487663&r2=487664
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java (original)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/TuscanyStartMojo.java Fri Dec 15 13:16:12 2006
@@ -18,28 +18,147 @@
*/
package org.apache.tuscany.sca.plugin.itest;
-import java.net.URL;
+import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URL;
import java.net.URLClassLoader;
-import java.util.List;
-import java.util.Iterator;
+import java.util.Collection;
import java.util.Enumeration;
-import java.io.File;
-import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.osoa.sca.SCA;
-import org.apache.tuscany.host.runtime.TuscanyRuntime;
-
/**
* @version $Rev$ $Date$
* @goal start
* @phase pre-integration-test
*/
public class TuscanyStartMojo extends AbstractMojo {
+
+ public class MavenEmbeddedArtifactRepository implements org.apache.tuscany.spi.services.artifact.ArtifactRepository {
+ public static final String COMPONENT_NAME = "MavenEmbeddedArtifactRepository";
+
+ public void resolve(org.apache.tuscany.spi.services.artifact.Artifact artifact) {
+ resolveTransitively(artifact);
+ }
+
+ public void resolve(Collection artifacts) {
+ for (Object a : artifacts) {
+ resolve((Artifact)a);
+ }
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param artifact Artifact whose dependencies need to be resolved.
+ * @throws TuscanyDependencyException If unable to resolve the
+ * dependencies.
+ */
+ public boolean resolveTransitively(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact) {
+
+ org.apache.maven.artifact.Artifact mavenRootArtifact =
+ artifactFactory.createArtifact(rootArtifact.getGroup(), rootArtifact.getName(), rootArtifact
+ .getVersion(), org.apache.maven.artifact.Artifact.SCOPE_RUNTIME, rootArtifact.getType());
+
+ try {
+
+ if (resolve(mavenRootArtifact)) {
+ rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
+ if (resolveDependencies(rootArtifact, mavenRootArtifact)) {
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves the artifact.
+ */
+ private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+ resolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
+ return true;
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ }
+
+ /*
+ * Resolves transitive dependencies.
+ */
+ private boolean resolveDependencies(org.apache.tuscany.spi.services.artifact.Artifact rootArtifact,
+ org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+
+ ResolutionGroup resolutionGroup = null;
+ ArtifactResolutionResult result = null;
+
+ resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository, remoteRepositories);
+ result =
+ resolver.resolveTransitively(resolutionGroup.getArtifacts(),
+ mavenRootArtifact,
+ remoteRepositories,
+ localRepository,
+ metadataSource);
+
+ // Add the artifacts to the deployment unit
+ for (Object obj : result.getArtifacts()) {
+ org.apache.maven.artifact.Artifact depArtifact = (org.apache.maven.artifact.Artifact)obj;
+ org.apache.tuscany.spi.services.artifact.Artifact artifact =
+ new org.apache.tuscany.spi.services.artifact.Artifact();
+ artifact.setName(depArtifact.getArtifactId());
+ artifact.setGroup(depArtifact.getGroupId());
+ artifact.setType(depArtifact.getType());
+ artifact.setClassifier(depArtifact.getClassifier());
+ artifact.setUrl(depArtifact.getFile().toURL());
+ artifact.setVersion(depArtifact.getVersion());
+ rootArtifact.addDependency(artifact);
+ }
+
+ } catch (ArtifactMetadataRetrievalException ex) {
+ return false;
+ } catch (MalformedURLException ex) {
+ throw new IllegalArgumentException(ex);
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+ }
+
/**
* @parameter
*/
@@ -57,6 +176,58 @@
*/
private List testClassPath;
+ /**
+ * Extensions
+ *
+ * @parameter
+ */
+ private Dependency[] extensions = new Dependency[0];
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+ * @required
+ * @readonly
+ */
+ private ArtifactResolver resolver;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.metadata.ArtifactMetadataSource}"
+ * @required
+ * @readonly
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ */
+ private List remoteRepositories;
+
+ /**
+ * Used to look up Artifacts in the remote repository.
+ *
+ * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+ * @required
+ * @readonly
+ */
+ private ArtifactFactory artifactFactory;
+
static ThreadLocal<ClassLoader> foo = new ThreadLocal<ClassLoader>();
public void execute() throws MojoExecutionException, MojoFailureException {
@@ -68,7 +239,21 @@
}
MavenRuntimeInfo runtimeInfo = new MavenRuntimeInfo();
- TuscanyRuntime runtime = new MavenEmbeddedRuntime();
+ MavenEmbeddedRuntime runtime = new MavenEmbeddedRuntime();
+ runtime.setArtifactRepository(new MavenEmbeddedArtifactRepository());
+
+ for (Dependency d : extensions) {
+ try {
+ Artifact artifact = d.getArtifact(artifactFactory);
+ resolver.resolve(artifact, remoteRepositories, localRepository);
+ URL url = artifact.getFile().toURL();
+ getLog().info(url.toString());
+ runtime.addExtension(artifact.getGroupId() + ":" + artifact.getArtifactId(), url);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Fail to resolve an extension", e);
+ }
+ }
+
runtime.setMonitorFactory(runtime.createDefaultMonitorFactory());
runtime.setSystemScdl(systemScdl);
runtime.setHostClassLoader(hostClassLoader);
@@ -84,7 +269,7 @@
if (!resources.hasMoreElements()) {
throw new MojoExecutionException("No SCDL found on test classpath");
}
- applicationScdl = (URL) resources.nextElement();
+ applicationScdl = (URL)resources.nextElement();
if (resources.hasMoreElements()) {
StringBuffer msg = new StringBuffer();
msg.append("Multiple SCDL files found on test classpath:\n");
@@ -94,6 +279,14 @@
} while (resources.hasMoreElements());
throw new MojoExecutionException(msg.toString());
}
+ } else {
+ if (applicationScdl.getProtocol() == null) {
+ String resource = applicationScdl.getPath();
+ applicationScdl = applicationClassLoader.getResource(resource);
+ if (applicationScdl == null) {
+ throw new MojoExecutionException("Application SCDL cannot be resolved: " + resource);
+ }
+ }
}
runtime.setApplicationName("application");
runtime.setApplicationScdl(applicationScdl);
@@ -110,7 +303,7 @@
URL[] urls = new URL[testClassPath.size()];
int idx = 0;
for (Iterator i = testClassPath.iterator(); i.hasNext();) {
- File pathElement = new File((String) i.next());
+ File pathElement = new File((String)i.next());
try {
URL url = pathElement.toURI().toURL();
getLog().debug("Adding application URL: " + url);
Modified: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl?view=diff&rev=487664&r1=487663&r2=487664
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl (original)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/src/main/resources/META-INF/tuscany/embeddedMaven.scdl Fri Dec 15 13:16:12 2006
@@ -111,11 +111,6 @@
<!-- Java implementation type -->
<include name="org.apache.tuscany.core.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl"/>
- <!-- service for resolving artifacts using Maven repositories -->
- <component name="artifactRepository">
- <system:implementation.system class="org.apache.tuscany.sca.plugin.itest.MavenEmbeddedArtifactRepository"/>
- </component>
-
<!-- WorkScheduler service -->
<component name="workManager">
<system:implementation.system
@@ -133,6 +128,11 @@
<component name="propertyFactory">
<system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl"/>
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore"/>
</component>
</composite>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org