summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/pre-spec-changes/services/maven/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:11:56 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:11:56 +0000
commit9bed5ae38c581999db465b42b504026a7097af95 (patch)
treea32b086a857a4556b8aec1aa9ed3a586efd9461e /sca-java-1.x/branches/pre-spec-changes/services/maven/src
parentece4fd35da7b7fc76264776f81705e6b5b52d3e0 (diff)
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835141 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/pre-spec-changes/services/maven/src')
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java101
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java296
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java58
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java116
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java96
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java78
-rw-r--r--sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.warbin0 -> 443672 bytes
7 files changed, 745 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
new file mode 100644
index 0000000000..394ccae97c
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
@@ -0,0 +1,101 @@
+/*
+ * 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.services.maven;
+
+import java.util.Collection;
+
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.Property;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * Artifact repository used for resolving artifacts.
+ * <p/>
+ * This is used by the composite loader for resolving artifacts transitively. The repository uses the Maven API for
+ * resolving dependencies and hence expects the artifacts to be stored in a structure similar to the Maven repository
+ * layout. The repository first looks within the deployed unit (WAR for example), before resorting to a local and set of
+ * remote Maven repositories.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MavenArtifactRepository implements ArtifactRepository {
+
+ /**
+ * Maven helper
+ */
+ private MavenHelper mavenHelper;
+
+ /**
+ * WAR repository helper
+ */
+ private WarRepositoryHelper warRepositoryHelper;
+
+ /**
+ * Conctructs a new artifact repository.
+ */
+ public MavenArtifactRepository(@Property(name = "remoteRepoUrl")
+ String remoteRepoUrl, @Autowire
+ RuntimeInfo runtimeInfo) {
+ mavenHelper = new MavenHelper(remoteRepoUrl, runtimeInfo.isOnline());
+ warRepositoryHelper = new WarRepositoryHelper(runtimeInfo.getBaseURL());
+ mavenHelper.start();
+ }
+
+ /**
+ * Resolve an artifact. This ensures that the information associated with an artifact is fully populated;
+ * Specifically, after this operation the URL should contain a location where the artifact can be obtained.
+ *
+ * @param rootArtifact the artifact to be resolved
+ */
+ public void resolve(Artifact rootArtifact) {
+ if (warRepositoryHelper.resolveTransitively(rootArtifact)) {
+ return;
+ }
+ if (mavenHelper.resolveTransitively(rootArtifact)) {
+ return;
+ }
+ throw new TuscanyDependencyException("Unable to resolve artifact", rootArtifact.toString());
+ }
+
+ /**
+ * Resolve a collection of Artifacts.
+ *
+ * @param artifacts a collection of artifacts to be resolved
+ * @see #resolve(Artifact)
+ */
+ public void resolve(Collection<? extends Artifact> artifacts) {
+ for (Artifact artifact : artifacts) {
+ resolve(artifact);
+ }
+ }
+
+ /**
+ * Destroy method.
+ */
+ @Destroy
+ public void destroy() {
+ mavenHelper.stop();
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
new file mode 100644
index 0000000000..f82756afbd
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
@@ -0,0 +1,296 @@
+/*
+ * 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.services.maven;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+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.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+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.settings.MavenSettingsBuilder;
+import org.apache.maven.settings.Settings;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.codehaus.classworlds.ClassWorld;
+import org.codehaus.classworlds.DefaultClassRealm;
+import org.codehaus.classworlds.DuplicateRealmException;
+import org.codehaus.plexus.PlexusContainerException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.embed.Embedder;
+
+/**
+ * Utility class for embedding Maven.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MavenHelper {
+
+ /** Local repository */
+// private static final File LOCAL_REPO = new File(System.getProperty("user.home") + File.separator + ".m2" + File.separator + "repository");
+
+ /** Remote repository URLs */
+ private final String[] remoteRepositoryUrls;
+
+ /** Maven metadata source */
+ private ArtifactMetadataSource metadataSource;
+
+ /** Artifact factory */
+ private ArtifactFactory artifactFactory;
+
+ /** Local artifact repository */
+ private ArtifactRepository localRepository;
+
+ /** Remote artifact repositories */
+ private List<ArtifactRepository> remoteRepositories = new LinkedList<ArtifactRepository>();
+
+ /** Artifact resolver */
+ private ArtifactResolver artifactResolver;
+
+ /** Online */
+ private boolean online;
+
+ /**
+ * Initialize the remote repository URLs.
+ *
+ * @param remoteRepositoryUrls
+ * Remote repository URLS.
+ * @param runtimeInfo
+ * Runtime information.
+ */
+ public MavenHelper(String remoteRepositoryUrl, boolean online) {
+ this.remoteRepositoryUrls = remoteRepositoryUrl.split(",");
+ this.online = online;
+ }
+
+ /**
+ * Starts the embedder.
+ *
+ * @throws TuscanyDependencyException
+ * If unable to start the embedder.
+ */
+ public void start() throws TuscanyDependencyException {
+
+ try {
+
+ Embedder embedder = new Embedder();
+ ClassWorld classWorld = new ClassWorld();
+
+ classWorld.newRealm("plexus.core", getClass().getClassLoader());
+
+ // Evil hack for Tomcat classloader issue - starts
+ Field realmsField = ClassWorld.class.getDeclaredField("realms");
+ realmsField.setAccessible(true);
+ Map realms = (Map) realmsField.get(classWorld);
+ DefaultClassRealm realm = (DefaultClassRealm) realms.get("plexus.core");
+
+ Class clazz = Class.forName("org.codehaus.classworlds.RealmClassLoader");
+ Constructor ctr = clazz.getDeclaredConstructor(new Class[] { DefaultClassRealm.class, ClassLoader.class });
+ ctr.setAccessible(true);
+ Object realmClassLoader = ctr.newInstance(realm, getClass().getClassLoader());
+
+ Field realmClassLoaderField = DefaultClassRealm.class.getDeclaredField("classLoader");
+ realmClassLoaderField.setAccessible(true);
+ realmClassLoaderField.set(realm, realmClassLoader);
+ // Evil hack for Tomcat classloader issue - ends
+
+ embedder.start(classWorld);
+
+ metadataSource = (ArtifactMetadataSource) embedder.lookup(ArtifactMetadataSource.ROLE);
+ artifactFactory = (ArtifactFactory) embedder.lookup(ArtifactFactory.ROLE);
+ artifactResolver = (ArtifactResolver) embedder.lookup(ArtifactResolver.ROLE);
+
+ setUpRepositories(embedder);
+
+ embedder.stop();
+
+ } catch (DuplicateRealmException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (PlexusContainerException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ComponentLookupException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (NoSuchFieldException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (IllegalAccessException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ClassNotFoundException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (NoSuchMethodException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (InstantiationException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (InvocationTargetException ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /**
+ * Stops the embedder.
+ *
+ * @throws TuscanyDependencyException
+ * If unable to stop the embedder.
+ */
+ public void stop() throws TuscanyDependencyException {
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param artifact
+ * Artifact whose dependencies need to be resolved.
+ * @throws TuscanyDependencyException
+ * If unable to resolve the dependencies.
+ */
+ public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException {
+
+ 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 TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves the artifact.
+ */
+ private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+ artifactResolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
+ return true;
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ }
+
+ /*
+ * Sets up local and remote repositories.
+ */
+ private void setUpRepositories(Embedder embedder) {
+
+ try {
+
+ ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory) embedder.lookup(ArtifactRepositoryFactory.ROLE);
+
+ ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) embedder.lookup(ArtifactRepositoryLayout.ROLE, "default");
+
+ String updatePolicy = online ? ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS : ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER;
+ ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
+ ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, updatePolicy, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
+
+ MavenSettingsBuilder settingsBuilder = (MavenSettingsBuilder)embedder.lookup(MavenSettingsBuilder.ROLE);
+ Settings settings = settingsBuilder.buildSettings();
+ String localRepo = settings.getLocalRepository();
+
+ localRepository = artifactRepositoryFactory.createArtifactRepository("local", new File(localRepo).toURL().toString(), layout,
+ snapshotsPolicy, releasesPolicy);
+
+ if (!online) {
+ return;
+ }
+
+ for (String remoteRepositoryUrl : remoteRepositoryUrls) {
+ String repoid = remoteRepositoryUrl.replace(':', '_');
+ repoid = repoid.replace('/', '_');
+ repoid = repoid.replace('\\', '_');
+ remoteRepositories.add(artifactRepositoryFactory.createArtifactRepository(repoid, remoteRepositoryUrl, layout, snapshotsPolicy,
+ releasesPolicy));
+ }
+
+ } catch (Exception ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+
+ }
+
+ /*
+ * Resolves transitive dependencies.
+ */
+ private boolean resolveDependencies(Artifact rootArtifact, org.apache.maven.artifact.Artifact mavenRootArtifact) {
+
+ try {
+
+ ResolutionGroup resolutionGroup = null;
+ ArtifactResolutionResult result = null;
+
+ resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository, remoteRepositories);
+ result = artifactResolver.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;
+ Artifact artifact = new Artifact();
+ artifact.setName(depArtifact.getArtifactId());
+ artifact.setGroup(depArtifact.getGroupId());
+ artifact.setType(depArtifact.getType());
+ artifact.setVersion(depArtifact.getVersion());
+ artifact.setClassifier(depArtifact.getClassifier());
+ artifact.setUrl(depArtifact.getFile().toURL());
+ rootArtifact.addDependency(artifact);
+ }
+
+ } catch (ArtifactMetadataRetrievalException ex) {
+ return false;
+ } catch (MalformedURLException ex) {
+ throw new TuscanyDependencyException(ex);
+ } catch (ArtifactResolutionException ex) {
+ return false;
+ } catch (ArtifactNotFoundException ex) {
+ return false;
+ }
+
+ return true;
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
new file mode 100644
index 0000000000..a7817ff3be
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
@@ -0,0 +1,58 @@
+/*
+ * 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.services.maven;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * Exception thrown in case of an artifact error.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TuscanyDependencyException extends TuscanyRuntimeException {
+
+ /**
+ * Initializes the cause.
+ *
+ * @param cause Cause of the exception.
+ */
+ public TuscanyDependencyException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Initializes the message.
+ *
+ * @param message Message of the exception.
+ */
+ public TuscanyDependencyException(String message) {
+ super(message);
+ }
+
+
+ /**
+ * Initializes the message.
+ *
+ * @param message Message of the exception.
+ * @param identifier an identifier for the exeption.
+ */
+ public TuscanyDependencyException(String message, String identifier) {
+ super(message, identifier);
+ }
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java
new file mode 100644
index 0000000000..6b3ba3ed10
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/main/java/org/apache/tuscany/services/maven/WarRepositoryHelper.java
@@ -0,0 +1,116 @@
+/*
+ * 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.services.maven;
+
+import java.beans.XMLDecoder;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+import org.codehaus.plexus.util.IOUtil;
+
+/**
+ * Helper class for resolving dependencies from WAR files.
+ *
+ * @author Administrator
+ *
+ */
+public class WarRepositoryHelper {
+
+ /** WAR Repository URL */
+ private URL reporsitoryUrl;
+
+ /** Dependency metadata */
+ private Map<String, Set<String>> transDependencyMap = new HashMap<String, Set<String>>();
+
+ /**
+ * Initializes the repository URL.
+ * @param baseUrl Base URL.
+ */
+ @SuppressWarnings("unchecked")
+ public WarRepositoryHelper(URL baseUrl) {
+
+
+ InputStream transDepMapInputStream = null;
+ try {
+
+ reporsitoryUrl = new URL(baseUrl, "repository/");
+ URL transDependencyMapUrl = new URL(baseUrl, "repository/dependency.metadata");
+ transDepMapInputStream = transDependencyMapUrl.openStream();
+
+ XMLDecoder decoder = new XMLDecoder(transDepMapInputStream);
+ transDependencyMap = (Map<String, Set<String>>)decoder.readObject();
+ decoder.close();
+
+ } catch (MalformedURLException ex) {
+ // throw new TuscanyDependencyException(ex);
+ } catch (IOException ex) {
+ // throw new TuscanyDependencyException(ex);
+ } finally {
+ IOUtil.close(transDepMapInputStream);
+ }
+
+ }
+
+ /**
+ * Resolves the dependencies transitively.
+ *
+ * @param artifact
+ * Artifact whose dependencies need to be resolved.
+ * @throws TuscanyDependencyException
+ * If unable to resolve the dependencies.
+ */
+ public boolean resolveTransitively(Artifact rootArtifact) throws TuscanyDependencyException {
+
+ String artKey = rootArtifact.getGroup() + "/" + rootArtifact.getName() + "/" + rootArtifact.getVersion() + "/";
+ if(!transDependencyMap.containsKey(artKey)) {
+ return false;
+ }
+
+
+ for(String dep : transDependencyMap.get(artKey)) {
+
+ String[] tokens = dep.split("/");
+ String artName = tokens[1];
+
+ try {
+ if(artName.equals(rootArtifact.getName())) {
+ rootArtifact.setUrl(new URL(reporsitoryUrl, dep));
+ } else {
+ Artifact depArtifact = new Artifact();
+ depArtifact.setGroup(tokens[0]);
+ depArtifact.setName(tokens[1]);
+ depArtifact.setVersion(tokens[2]);
+ depArtifact.setUrl(new URL(reporsitoryUrl, dep));
+ rootArtifact.addDependency(depArtifact);
+
+ }
+ } catch (MalformedURLException ex) {
+ throw new TuscanyDependencyException(ex);
+ }
+ }
+ return rootArtifact.getUrl()!=null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java
new file mode 100644
index 0000000000..b4e9babd05
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/MavenArtifactRepositoryTestCase.java
@@ -0,0 +1,96 @@
+/*
+ * 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.services.maven;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MavenArtifactRepositoryTestCase extends TestCase {
+
+ public MavenArtifactRepositoryTestCase(String arg0) {
+ super(arg0);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ /*
+ * Test method for 'org.apache.tuscany.serviceBindings.maven.MavenArtifactRepository.resolve(Artifact)'
+ */
+ public void testResolveArtifact() throws Exception {
+
+ final URL BASE_URL = new File(System.getProperty("user.home") + File.separator + ".m2").toURL();
+ String remoteRepoUrl = "http://repo1.maven.org/maven2/";
+ MavenArtifactRepository repository = new MavenArtifactRepository(remoteRepoUrl, new RuntimeInfo() {
+ public File getApplicationRootDirectory() {
+ return null;
+ }
+
+ public URL getBaseURL() {
+ return BASE_URL;
+ }
+
+ public File getInstallDirectory() {
+ return null;
+ }
+
+ public boolean isOnline() {
+ return false;
+ }
+
+ public URI getDomain() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getRuntimeId() {
+ throw new UnsupportedOperationException();
+ }
+ });
+ Artifact artifact = new Artifact();
+ artifact.setGroup("junit");
+ artifact.setName("junit");
+ artifact.setVersion("3.8.1");
+ artifact.setType("jar");
+
+ repository.resolve(artifact);
+
+ Set<URL> urls = artifact.getUrls();
+
+ System.err.println(urls);
+
+ assertEquals(1, urls.size());
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java
new file mode 100644
index 0000000000..3a79599fa7
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/java/org/apache/tuscany/services/maven/WarRepositoryHelperTestCase.java
@@ -0,0 +1,78 @@
+/*
+ * 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.services.maven;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.apache.tuscany.spi.services.artifact.Artifact;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Administrator
+ *
+ */
+public class WarRepositoryHelperTestCase extends TestCase {
+
+ /**
+ * @param arg0
+ */
+ public WarRepositoryHelperTestCase(String arg0) {
+ super(arg0);
+ }
+
+ /**
+ * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}.
+ */
+ public void testWarRepositoryHelper() {
+
+ URL warUrl = getClass().getClassLoader().getResource("webapp.war");
+ URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl});
+
+ URL repoUrl = urlc.getResource("WEB-INF/tuscany/");
+ System.err.println(repoUrl);
+
+ WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl);
+ assertNotNull(warRepositoryHelper);
+
+ }
+
+ /**
+ * Test method for {@link org.apache.tuscany.services.maven.WarRepositoryHelper#WarRepositoryHelper(java.net.URL)}.
+ */
+ public void testResolveTransitively() {
+
+ URL warUrl = getClass().getClassLoader().getResource("webapp.war");
+ URLClassLoader urlc = new URLClassLoader(new URL[] {warUrl});
+
+ URL repoUrl = urlc.getResource("WEB-INF/tuscany/");
+ WarRepositoryHelper warRepositoryHelper = new WarRepositoryHelper(repoUrl);
+
+ Artifact artifact = new Artifact();
+ artifact.setGroup("commons-httpclient");
+ artifact.setName("commons-httpclient");
+ artifact.setVersion("3.0");
+
+ warRepositoryHelper.resolveTransitively(artifact);
+ assertEquals(4, artifact.getUrls().size());
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war
new file mode 100644
index 0000000000..4448aca8ff
--- /dev/null
+++ b/sca-java-1.x/branches/pre-spec-changes/services/maven/src/test/resources/webapp.war
Binary files differ