tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meer...@apache.org
Subject svn commit: r453908 - in /incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven: MavenArtifactRepository.java MavenHelper.java TuscanyDependencyException.java TuscanyMavenException.java
Date Sat, 07 Oct 2006 14:01:52 GMT
Author: meerajk
Date: Sat Oct  7 07:01:51 2006
New Revision: 453908

URL: http://svn.apache.org/viewvc?view=rev&rev=453908
Log:
Added functionality to resolve dependency from WAR.

Added:
    incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
      - copied, changed from r453871, incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyMavenException.java
Removed:
    incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyMavenException.java
Modified:
    incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
    incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java

Modified: incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java?view=diff&rev=453908&r1=453907&r2=453908
==============================================================================
--- incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
(original)
+++ incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenArtifactRepository.java
Sat Oct  7 07:01:51 2006
@@ -40,6 +40,9 @@
 
     /** Maven helper */
     private MavenHelper mavenHelper;
+    
+    /** WAR repository helper */
+    private WarRepositoryHelper warRepositoryHelper;
 
     /**
      * Conctructs a new artifact repository.
@@ -47,7 +50,8 @@
     public MavenArtifactRepository(@Property(name = "remoteRepoUrls")
     String[] remoteRepoUrls, @Autowire
     RuntimeInfo runtimeInfo) {
-        mavenHelper = new MavenHelper(remoteRepoUrls, runtimeInfo.getBaseURL());
+        mavenHelper = new MavenHelper(remoteRepoUrls);
+        warRepositoryHelper = new WarRepositoryHelper(runtimeInfo.getBaseURL());
         mavenHelper.start();
     }
 
@@ -59,7 +63,13 @@
      *            the artifact to be resolved
      */
     public void resolve(Artifact rootArtifact) {
-        mavenHelper.resolveTransitively(rootArtifact);
+        if(warRepositoryHelper.resolveTransitively(rootArtifact)) {
+            return;
+        } 
+        if(mavenHelper.resolveTransitively(rootArtifact)) {
+            return;
+        }
+        throw new TuscanyDependencyException("Unable to resolve artifact: " + rootArtifact.getName());
     }
 
     /**

Modified: incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java?view=diff&rev=453908&r1=453907&r2=453908
==============================================================================
--- incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
(original)
+++ incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/MavenHelper.java
Sat Oct  7 07:01:51 2006
@@ -21,7 +21,6 @@
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -57,9 +56,6 @@
     /** Remote repository URLs */
     private final String[] remoteRepositoryUrls;
 
-    /** Deployed repository URL */
-    private final URL deployedRepositoryUrl;
-
     /** Maven metadata source */
     private ArtifactMetadataSource metadataSource;
 
@@ -69,9 +65,6 @@
     /** Local artifact repository */
     private ArtifactRepository localRepository;
 
-    /** Repository from the deployed unit like a WAR or standalobe distribution */
-    private ArtifactRepository deployedRepository;
-
     /** Remote artifact repositories */
     private List<ArtifactRepository> remoteRepositories = new LinkedList<ArtifactRepository>();
 
@@ -86,22 +79,17 @@
      * @param runtimeInfo
      *            Runtime information.
      */
-    public MavenHelper(String[] remoteRepositoryUrls, URL baseUrl) {
-        try {
-            this.remoteRepositoryUrls = remoteRepositoryUrls;
-            this.deployedRepositoryUrl = new URL(baseUrl, "repository");
-        } catch (MalformedURLException ex) {
-            throw new TuscanyMavenException(ex);
-        }
+    public MavenHelper(String[] remoteRepositoryUrls) {
+        this.remoteRepositoryUrls = remoteRepositoryUrls;
     }
 
     /**
      * Starts the embedder.
      * 
-     * @throws TuscanyMavenException
+     * @throws TuscanyDependencyException
      *             If unable to start the embedder.
      */
-    public void start() throws TuscanyMavenException {
+    public void start() throws TuscanyDependencyException {
 
         try {
 
@@ -120,11 +108,11 @@
             embedder.stop();
 
         } catch (DuplicateRealmException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         } catch (PlexusContainerException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         } catch (ComponentLookupException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         }
 
     }
@@ -132,10 +120,10 @@
     /**
      * Stops the embedder.
      * 
-     * @throws TuscanyMavenException
+     * @throws TuscanyDependencyException
      *             If unable to stop the embedder.
      */
-    public void stop() throws TuscanyMavenException {
+    public void stop() throws TuscanyDependencyException {
     }
 
     /**
@@ -143,27 +131,28 @@
      * 
      * @param artifact
      *            Artifact whose dependencies need to be resolved.
-     * @throws TuscanyMavenException
+     * @throws TuscanyDependencyException
      *             If unable to resolve the dependencies.
      */
-    public void resolveTransitively(Artifact rootArtifact) throws TuscanyMavenException {
+    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, Collections.EMPTY_LIST, deployedRepository)) {
-                rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
-                resolveDependencies(rootArtifact, mavenRootArtifact, true);
-            } else if (resolve(mavenRootArtifact, remoteRepositories, localRepository)) {
+            if (resolve(mavenRootArtifact)) {
                 rootArtifact.setUrl(mavenRootArtifact.getFile().toURL());
-                resolveDependencies(rootArtifact, mavenRootArtifact, false);
+                if(resolveDependencies(rootArtifact, mavenRootArtifact)) {
+                    return true;
+                } else {
+                    return false;
+                }
             } else {
-                throw new TuscanyMavenException("Unable to resolve artifact " + mavenRootArtifact.toString());
+                return false;
             }
         } catch (MalformedURLException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         }
 
     }
@@ -171,7 +160,7 @@
     /*
      * Resolves the artifact.
      */
-    private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact, List remoteRepositories,
ArtifactRepository localRepository) {
+    private boolean resolve(org.apache.maven.artifact.Artifact mavenRootArtifact) {
         try {
             artifactResolver.resolve(mavenRootArtifact, remoteRepositories, localRepository);
             return true;
@@ -206,18 +195,10 @@
                         snapshotsPolicy, releasesPolicy));
             }
 
-            ArtifactRepositoryPolicy deployedRepositorySnapshotsPolicy = new ArtifactRepositoryPolicy(false,
-                    ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
-            ArtifactRepositoryPolicy deployedRepositoryReleasesPolicy = new ArtifactRepositoryPolicy(false,
-                    ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
-
-            deployedRepository = artifactRepositoryFactory.createArtifactRepository("local",
deployedRepositoryUrl.toExternalForm(), layout,
-                    deployedRepositorySnapshotsPolicy, deployedRepositoryReleasesPolicy);
-
         } catch (MalformedURLException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         } catch (ComponentLookupException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         }
 
     }
@@ -225,22 +206,16 @@
     /*
      * Resolves transitive dependencies.
      */
-    private void resolveDependencies(Artifact rootArtifact, org.apache.maven.artifact.Artifact
mavenRootArtifact, boolean resolvedFromDeployment) {
+    private boolean resolveDependencies(Artifact rootArtifact, org.apache.maven.artifact.Artifact
mavenRootArtifact) {
 
         try {
 
             ResolutionGroup resolutionGroup = null;
             ArtifactResolutionResult result = null;
 
-            if (resolvedFromDeployment) {
-                resolutionGroup = metadataSource.retrieve(mavenRootArtifact, deployedRepository,
Collections.EMPTY_LIST);
-                result = artifactResolver.resolveTransitively(resolutionGroup.getArtifacts(),
mavenRootArtifact, Collections.EMPTY_LIST, deployedRepository,
-                        metadataSource);
-            } else {
-                resolutionGroup = metadataSource.retrieve(mavenRootArtifact, localRepository,
remoteRepositories);
-                result = artifactResolver.resolveTransitively(resolutionGroup.getArtifacts(),
mavenRootArtifact, remoteRepositories, localRepository,
+            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()) {
@@ -255,14 +230,16 @@
             }
 
         } catch (ArtifactMetadataRetrievalException ex) {
-            throw new TuscanyMavenException(ex);
+            return false;
         } catch (MalformedURLException ex) {
-            throw new TuscanyMavenException(ex);
+            throw new TuscanyDependencyException(ex);
         } catch (ArtifactResolutionException ex) {
-            throw new TuscanyMavenException(ex);
+            return false;
         } catch (ArtifactNotFoundException ex) {
-            throw new TuscanyMavenException(ex);
+            return false;
         }
+        
+        return true;
 
     }
 

Copied: incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
(from r453871, incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyMavenException.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java?view=diff&rev=453908&p1=incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyMavenException.java&r1=453871&p2=incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java&r2=453908
==============================================================================
--- incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyMavenException.java
(original)
+++ incubator/tuscany/java/sca/services/maven/src/main/java/org/apache/tuscany/services/maven/TuscanyDependencyException.java
Sat Oct  7 07:01:51 2006
@@ -25,13 +25,13 @@
  * 
  * @version $Rev$ $Date$
  */
-public class TuscanyMavenException extends TuscanyRuntimeException {
+public class TuscanyDependencyException extends TuscanyRuntimeException {
 
     /**
      * Initializes the cause.
      * @param cause Cause of the exception.
      */
-    public TuscanyMavenException(Throwable cause) {
+    public TuscanyDependencyException(Throwable cause) {
         super(cause);
     }
 
@@ -39,7 +39,7 @@
      * Initializes the message.
      * @param message Message of the exception.
      */
-    public TuscanyMavenException(String message) {
+    public TuscanyDependencyException(String message) {
         super(message);
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message