geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r378370 - in /geronimo/branches/configid/modules: kernel/src/java/org/apache/geronimo/kernel/config/ kernel/src/java/org/apache/geronimo/kernel/repository/ system/src/java/org/apache/geronimo/system/repository/
Date Thu, 16 Feb 2006 21:12:00 GMT
Author: dain
Date: Thu Feb 16 13:11:57 2006
New Revision: 378370

URL: http://svn.apache.org/viewcvs?rev=378370&view=rev
Log:
Added artifact resolver

Added:
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactManager.java
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
Modified:
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
    geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ListableRepository.java
    geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
    geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven1Repository.java
    geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven2Repository.java

Modified: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java?rev=378370&r1=378369&r2=378370&view=diff
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
(original)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
Thu Feb 16 13:11:57 2006
@@ -37,6 +37,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.ArrayList;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -143,6 +144,11 @@
      */
     private final Artifact[] parentId;
 
+    /**
+     * List of the parent configurations
+     */
+    private final List parents;
+
     private final List dependencies;
     private final List classPath;
     private final boolean inverseClassLoading;
@@ -187,6 +193,7 @@
         id = null;
         moduleType = null;
         parentId = null;
+        parents = null;
         nameKeys = null;
         objectNames = null;
         configurationClassLoader = null;
@@ -258,6 +265,16 @@
         }
 
         this.nameKeys = nameKeys;
+
+        parents = new ArrayList();
+        if (parentId != null && parentId.length > 0) {
+            for (int i = 0; i < parentId.length; i++) {
+                Artifact artifact = parentId[i];
+                ObjectName parentName = getConfigurationObjectName(artifact);
+                parents.add(kernel.getProxyManager().createProxy(parentName, Configuration.class));
+            }
+        }
+
         addParentDependencies(kernel, id, parentId);
     }
 
@@ -269,6 +286,10 @@
         return nameKeys;
     }
 
+    public List getDependencies() {
+        return dependencies;
+    }
+
     public void doStart() throws Exception {
         // build configurationClassLoader
         URL[] urls = resolveClassPath(classPath, baseURL, dependencies, repositories);
@@ -452,6 +473,21 @@
      */
     public Artifact[] getParentId() {
         return parentId;
+    }
+
+    /**
+     * Gets the parent configurations of this configuration.
+     * @return the parents of this configuration
+     */
+    public List getParents() {
+        return parents;
+    }
+
+    /**
+     * If true the configuration will search local dependencies for classes before searching
parents.
+     */
+    public boolean isInverseClassLoading() {
+        return inverseClassLoading;
     }
 
     /**

Added: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactManager.java?rev=378370&view=auto
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactManager.java
(added)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactManager.java
Thu Feb 16 13:11:57 2006
@@ -0,0 +1,28 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.kernel.repository;
+
+import java.util.List;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactManager {
+    void loadArtifacts(List artifacts);
+    void unloadArtifacts(List artifacts);
+    List getLoadedArtifacts(String groupId, String artifactId, String type);
+}

Added: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java?rev=378370&view=auto
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
(added)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ArtifactResolver.java
Thu Feb 16 13:11:57 2006
@@ -0,0 +1,26 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.kernel.repository;
+
+import java.util.Collection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactResolver {
+    void resolve(Collection parentConfigurations, Collection artifacts) throws MissingDependencyException;
+}

Added: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java?rev=378370&view=auto
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
(added)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/DefaultArtifactResolver.java
Thu Feb 16 13:11:57 2006
@@ -0,0 +1,146 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.kernel.repository;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Collections;
+
+import org.apache.geronimo.kernel.config.Configuration;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultArtifactResolver implements ArtifactResolver {
+    private final ArtifactManager artifactManager;
+    private final ListableRepository repository;
+
+    public DefaultArtifactResolver(ArtifactManager artifactManager, ListableRepository repository)
{
+        this.artifactManager = artifactManager;
+        this.repository = repository;
+    }
+
+    public void resolve(Collection parentConfigurations, Collection artifacts) throws MissingDependencyException
{
+        for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
+            Artifact artifact = (Artifact) iterator.next();
+            if (!artifact.isResolved()) {
+                resolveArtifact(parentConfigurations, artifact);
+            }
+        }
+    }
+
+    private void resolveArtifact(Collection parentConfigurations, Artifact artifact) throws
MissingDependencyException {
+        if (artifact.getArtifactId() == null) {
+            throw new IllegalArgumentException("ArtifactId not set " + artifact);
+        }
+
+        if (artifact.getGroupId() == null) {
+            artifact.setGroupId(Artifact.DEFAULT_GROUP_ID);
+        }
+
+        if (artifact.getVersion() == null) {
+            // check if we have any existing artifacts loaded
+            Version version = resolveVersion(parentConfigurations, artifact.getGroupId(),
artifact.getArtifactId(), artifact.getType());
+            if (version == null) {
+                throw new MissingDependencyException("Unable to resolve dependency " + artifact);
+            }
+            artifact.setVersion(version);
+        }
+    }
+
+    private Version resolveVersion(Collection parentConfigurations, String groupId, String
artifactId, String type) {
+        List existingArtifacts = artifactManager.getLoadedArtifacts(groupId, artifactId,
type);
+
+        // if we have exactally one artifact loaded use it's version
+        if (existingArtifacts.size() == 1) {
+            Artifact existingArtifact = ((Artifact) existingArtifacts.get(0));
+            return existingArtifact.getVersion();
+        }
+
+        // if we have no existing loaded artifacts grab the highest version from the repository
+        if (existingArtifacts.size() == 0) {
+            List list = repository.list(groupId, artifactId, type);
+            Collections.sort(list);
+
+            Artifact repositoryArtifact = (Artifact) list.get(list.size() -1);
+            return repositoryArtifact.getVersion();
+        }
+
+        // more than one version of the artifact was loaded...
+
+        // if one of parents already loaded the artifact, use that version
+        Version version = searchParents(parentConfigurations, groupId, artifactId, type);
+        if (version != null) {
+            return version;
+        }
+
+        // it wasn't declared by the parent so just use the highest verstion already loaded
+        Collections.sort(existingArtifacts);
+        Artifact repositoryArtifact = (Artifact) existingArtifacts.get(existingArtifacts.size()
-1);
+        return repositoryArtifact.getVersion();
+    }
+
+    private Version searchParents(Collection parentConfigurations, String groupId, String
artifactId, String type) {
+        for (Iterator iterator = parentConfigurations.iterator(); iterator.hasNext();) {
+            Configuration configuration = (Configuration) iterator.next();
+
+            if (configuration.isInverseClassLoading()) {
+                // Search dependencies of the configuration before searching the parents
+                List dependencies = configuration.getDependencies();
+                Version version = getArtifactVersion(dependencies, groupId, artifactId, type);
+                if (version != null) {
+                    return version;
+                }
+
+                // wasn't declared in the dependencies, so searcht the parents of the configuration
+                version = searchParents(configuration.getParents(), groupId, artifactId,
type);
+                if (version != null) {
+                    return version;
+                }
+
+            } else {
+                // Search the parents before the dependencies of the configuration
+                Version version = searchParents(configuration.getParents(), groupId, artifactId,
type);
+                if (version != null) {
+                    return version;
+                }
+
+                // wasn't declared in a parent check the dependencies of the configuration
+                List dependencies = configuration.getDependencies();
+                version = getArtifactVersion(dependencies, groupId, artifactId, type);
+                if (version != null) {
+                    return version;
+                }
+            }
+        }
+        return null;
+    }
+
+    private Version getArtifactVersion(List artifacts, String groupId, String artifactId,
String type) {
+        for (Iterator iterator = artifacts.iterator(); iterator.hasNext();) {
+            Artifact artifact = (Artifact) iterator.next();
+            if (groupId.equals(artifact.getGroupId()) &&
+                    artifactId.equals(artifact.getArtifactId()) &&
+                    type.equals(artifact.getType())) {
+                return artifact.getVersion();
+            }
+        }
+        return null;
+    }
+
+}

Modified: geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ListableRepository.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ListableRepository.java?rev=378370&r1=378369&r2=378370&view=diff
==============================================================================
--- geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ListableRepository.java
(original)
+++ geronimo/branches/configid/modules/kernel/src/java/org/apache/geronimo/kernel/repository/ListableRepository.java
Thu Feb 16 13:11:57 2006
@@ -30,4 +30,6 @@
      * Gets a list of all the items available in the repository.
      */
     public List list();
+
+    public List list(String groupId, String artifactId, String type);
 }

Modified: geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java?rev=378370&r1=378369&r2=378370&view=diff
==============================================================================
--- geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
(original)
+++ geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
Thu Feb 16 13:11:57 2006
@@ -32,6 +32,7 @@
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
 import org.apache.geronimo.kernel.repository.WriteableRepository;
+import org.apache.geronimo.kernel.repository.ListableRepository;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 
 /**

Modified: geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven1Repository.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven1Repository.java?rev=378370&r1=378369&r2=378370&view=diff
==============================================================================
--- geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven1Repository.java
(original)
+++ geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven1Repository.java
Thu Feb 16 13:11:57 2006
@@ -27,12 +27,13 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ListableRepository;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 
 /**
  * @version $Rev$ $Date$
  */
-public class Maven1Repository extends AbstractRepository {
+public class Maven1Repository extends AbstractRepository implements ListableRepository {
     public Maven1Repository(URI root, ServerInfo serverInfo) {
         super(root, serverInfo);
     }
@@ -47,6 +48,25 @@
         path = new File(path, artifact.getArtifactId() + "-" + artifact.getVersion() + "."
+ artifact.getType());
 
         return path;
+    }
+
+    public List list(String groupId, String artifactId, String type) {
+        List artifacts = new ArrayList();
+
+        File path = new File(rootFile, groupId);
+        path = new File(path, type + "s");
+
+        File[] files = path.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            File file = files[i];
+            String fileName = file.getName();
+            if (fileName.startsWith(artifactId + "-") && fileName.endsWith("." +
type)) {
+                String version = fileName.substring(artifactId.length() + 1);
+                version = version.substring(0, version.length() - 1 - type.length());
+                artifacts.add(new Artifact(groupId, artifactId, version, type, true));
+            }
+        }
+        return artifacts;
     }
 
     //thanks to Brett Porter for this regex lifted from a maven1-2 porting tool

Modified: geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven2Repository.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven2Repository.java?rev=378370&r1=378369&r2=378370&view=diff
==============================================================================
--- geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven2Repository.java
(original)
+++ geronimo/branches/configid/modules/system/src/java/org/apache/geronimo/system/repository/Maven2Repository.java
Thu Feb 16 13:11:57 2006
@@ -24,12 +24,13 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ListableRepository;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 
 /**
  * @version $Rev$ $Date$
  */
-public class Maven2Repository extends AbstractRepository {
+public class Maven2Repository extends AbstractRepository implements ListableRepository {
     public Maven2Repository(URI root, ServerInfo serverInfo) {
         super(root, serverInfo);
     }
@@ -59,6 +60,31 @@
                     if (versionDir.canRead() && versionDir.isDirectory()) {
                         artifacts.addAll(getArtifacts(null, versionDir));
                     }
+                }
+            }
+        }
+        return artifacts;
+    }
+
+    public List list(String groupId, String artifactId, String type) {
+        File path = new File(rootFile, groupId.replace('.', File.separatorChar));
+        path = new File(path, artifactId);
+
+        List artifacts = new ArrayList();
+
+        File[] versionDirs = path.listFiles();
+        for (int i = 0; i < versionDirs.length; i++) {
+            File versionDir = versionDirs[i];
+            if (versionDir.canRead() && versionDir.isDirectory()) {
+                String version = versionDir.getName();
+                String fileName = artifactId + "-" + version + "." + type;
+                File file = new File(versionDir, fileName);
+                if (file.canRead() && file.isFile()) {
+                    artifacts.add(new Artifact(groupId,
+                            artifactId,
+                            version,
+                            type,
+                            true));
                 }
             }
         }



Mime
View raw message