]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] introduce a metadata resolver API that will allow just-in-time addition...
authorBrett Porter <brett@apache.org>
Wed, 25 Nov 2009 00:45:57 +0000 (00:45 +0000)
committerBrett Porter <brett@apache.org>
Wed, 25 Nov 2009 00:45:57 +0000 (00:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@883936 13f79535-47bb-0310-9956-ffa450edef68

18 files changed:
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/ShowArtifactActionTest.xml
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java [new file with mode: 0644]
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java [new file with mode: 0644]
archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/pom.xml
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DummyLifecycleBindingsInjector.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml [new file with mode: 0644]
archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java

index a2d8e89ea70ac99f4ae22cac32ebb3f82f44a007..e63468430e9561c7e9b19ab4c3e0b37ecd74046c 100644 (file)
@@ -25,7 +25,7 @@ import java.util.List;
 
 import com.opensymphony.xwork2.Validateable;
 import org.apache.archiva.metadata.model.ProjectBuildMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
@@ -71,7 +71,7 @@ public class ShowArtifactAction
     /**
      * @plexus.requirement
      */
-    private MetadataRepository metadataRepository;
+    private MetadataResolver metadataResolver;
 
     /* .\ Exposed Output Objects \.__________________________________ */
 
@@ -112,16 +112,16 @@ public class ShowArtifactAction
         {
             if ( build == null )
             {
-                // TODO: we don't really want the implementation being that intelligent - so another resolver to do
-                //  the "just-in-time" nature of picking up the metadata (if appropriate for the repository type) if not
-                //  found in the content repository is needed here
-                build = metadataRepository.getProjectBuild( repoId, groupId, artifactId, version );
+                // we don't really want the implementation being that intelligent - so another resolver to do the
+                // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
+                build = metadataResolver.getProjectBuild( repoId, groupId, artifactId, version );
                 if ( build != null )
                 {
                     repositoryId = repoId;      
                 }
             }
-            snapshotVersions.addAll( metadataRepository.getArtifactVersions( repoId, groupId, artifactId, version ) );
+
+            snapshotVersions.addAll( metadataResolver.getArtifactVersions( repoId, groupId, artifactId, version ) );
             snapshotVersions.remove( version );
         }
 
@@ -365,8 +365,8 @@ public class ShowArtifactAction
         this.snapshotVersions = snapshotVersions;
     }
 
-    public MetadataRepository getMetadataRepository()
+    public MetadataResolver getMetadataRepository()
     {
-        return metadataRepository;
+        return metadataResolver;
     }
 }
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/MemoryMetadataRepository.java
deleted file mode 100644 (file)
index 79e15ab..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.apache.archiva.metadata.repository.memory;
-
-/*
- * 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.
- */
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.model.ProjectBuildMetadata;
-import org.apache.archiva.metadata.model.ProjectMetadata;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-
-public class MemoryMetadataRepository
-    implements MetadataRepository
-{
-    private Map<String, ProjectBuildMetadata> projectBuilds = new HashMap<String, ProjectBuildMetadata>();
-
-    private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
-
-    public void updateProject( String repoId, ProjectMetadata project )
-    {
-        throw new UnsupportedOperationException( );
-    }
-
-    public void updateArtifact( String repoId, String namespace, String projectId, String buildId, ArtifactMetadata artifactMeta )
-    {
-        throw new UnsupportedOperationException( );
-    }
-
-    public void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
-    {
-        throw new UnsupportedOperationException( );
-    }
-
-    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
-    {
-        ProjectMetadata metadata = new ProjectMetadata();
-        metadata.setNamespace( namespace );
-        metadata.setId( projectId );
-        return metadata;
-    }
-
-    public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
-    {
-        return projectBuilds.get( createMapKey( repoId, namespace, projectId, buildId ) );
-    }
-
-    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
-    {
-        List<String> versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, buildId ) );
-        return ( versions != null ? versions : Collections.<String>emptyList() );
-    }
-
-    public void setProjectBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
-    {
-        projectBuilds.put( createMapKey( repoId, namespace, projectId, build.getId() ), build );
-    }
-
-    public void setArtifactVersions( String repoId, String namespace, String projectId, String version,
-                                     List<String> versions )
-    {
-        artifactVersions.put( createMapKey( repoId, namespace, projectId, version ), versions );
-    }
-
-    private String createMapKey( String repoId, String namespace, String projectId, String buildId )
-    {
-        return repoId + ":" + namespace + ":" + projectId + ":" + buildId;
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
new file mode 100644 (file)
index 0000000..40670f7
--- /dev/null
@@ -0,0 +1,73 @@
+package org.apache.archiva.metadata.repository.memory;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+
+public class TestMetadataResolver
+    implements MetadataResolver
+{
+    private Map<String, ProjectBuildMetadata> projectBuilds = new HashMap<String, ProjectBuildMetadata>();
+
+    private Map<String, List<String>> artifactVersions = new HashMap<String, List<String>>();
+
+    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+    {
+        ProjectMetadata metadata = new ProjectMetadata();
+        metadata.setNamespace( namespace );
+        metadata.setId( projectId );
+        return metadata;
+    }
+
+    public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
+    {
+        return projectBuilds.get( createMapKey( repoId, namespace, projectId, buildId ) );
+    }
+
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
+    {
+        List<String> versions = artifactVersions.get( createMapKey( repoId, namespace, projectId, buildId ) );
+        return ( versions != null ? versions : Collections.<String>emptyList() );
+    }
+
+    public void setProjectBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build )
+    {
+        projectBuilds.put( createMapKey( repoId, namespace, projectId, build.getId() ), build );
+    }
+
+    public void setArtifactVersions( String repoId, String namespace, String projectId, String version,
+                                     List<String> versions )
+    {
+        artifactVersions.put( createMapKey( repoId, namespace, projectId, version ), versions );
+    }
+
+    private String createMapKey( String repoId, String namespace, String projectId, String buildId )
+    {
+        return repoId + ":" + namespace + ":" + projectId + ":" + buildId;
+    }
+}
index e667eedfb9ca430cf7f058462b86ad890668ca7d..56e5d1d7383f012caa166dc55af135526579537b 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectBuildMetadata;
 import org.apache.archiva.metadata.model.Scm;
-import org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository;
+import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
 import org.apache.maven.archiva.model.ArchivaProjectModel;
@@ -102,7 +102,7 @@ public class ShowArtifactActionTest
 
     private ShowArtifactAction action;
 
-    private MemoryMetadataRepository metadataRepository;
+    private TestMetadataResolver metadataResolver;
 
     public void testInstantiation()
     {
@@ -111,7 +111,7 @@ public class ShowArtifactActionTest
 
     public void testGetArtifactUniqueRelease()
     {
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
 
         setActionParameters();
@@ -134,9 +134,9 @@ public class ShowArtifactActionTest
 
     public void testGetArtifactUniqueSnapshot()
     {
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_SNAPSHOT_VERSION ) );
-        metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
+        metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
                                                 ALL_TEST_SNAPSHOT_VERSIONS );
 
         action.setGroupId( TEST_GROUP_ID );
@@ -164,9 +164,9 @@ public class ShowArtifactActionTest
 
     public void testGetArtifactUniqueSnapshotTimestamped()
     {
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
-        metadataRepository.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
+        metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
                                                 ALL_TEST_SNAPSHOT_VERSIONS );
 
         action.setGroupId( TEST_GROUP_ID );
@@ -220,7 +220,7 @@ public class ShowArtifactActionTest
 
     public void testGetArtifactNotInObservableRepos()
     {
-        metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
 
         setActionParameters();
@@ -235,7 +235,7 @@ public class ShowArtifactActionTest
     public void testGetArtifactOnlySeenInSecondObservableRepo()
     {
         setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
 
         setActionParameters();
@@ -259,9 +259,9 @@ public class ShowArtifactActionTest
     public void testGetArtifactSeenInBothObservableRepo()
     {
         setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
-        metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
 
         setActionParameters();
@@ -285,9 +285,9 @@ public class ShowArtifactActionTest
     public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
     {
         setObservableRepos( Arrays.asList( TEST_REPO ) );
-        metadataRepository.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
-        metadataRepository.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
+        metadataResolver.setProjectBuild( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
                                             createProjectModel( TEST_VERSION ) );
 
         setActionParameters();
@@ -437,6 +437,6 @@ public class ShowArtifactActionTest
     {
         super.setUp();
         action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
-        metadataRepository = (MemoryMetadataRepository) action.getMetadataRepository();
+        metadataResolver = (TestMetadataResolver) action.getMetadataRepository();
     }
 }
index c829d6c15f2d1d4c7bcc9b339ebbe90f0945fda8..aab8338b67b15d4d08b2b08eb3f6dcf5f0068081 100644 (file)
@@ -36,9 +36,9 @@
       <implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation>
     </component>
     <component>
-      <role>org.apache.archiva.metadata.repository.MetadataRepository</role>
+      <role>org.apache.archiva.metadata.repository.MetadataResolver</role>
       <role-hint>default</role-hint>
-      <implementation>org.apache.archiva.metadata.repository.memory.MemoryMetadataRepository</implementation>
+      <implementation>org.apache.archiva.metadata.repository.memory.TestMetadataResolver</implementation>
       <instantiation-strategy>per-lookup</instantiation-strategy>
     </component>
   </components>
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/DefaultMetadataResolver.java
new file mode 100644 (file)
index 0000000..d7837a8
--- /dev/null
@@ -0,0 +1,69 @@
+package org.apache.archiva.metadata.repository;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver"
+ */
+public class DefaultMetadataResolver
+    implements MetadataResolver
+{
+    /**
+     * @plexus.requirement
+     */
+    private MetadataRepository metadataRepository;
+
+    /**
+     * TODO: this needs to be configurable based on storage type, and availability of proxy module
+     * TODO: could be a different type since we need methods to modify the storage metadata
+     * @plexus.requirement role-hint="maven2"
+     */
+    private MetadataResolver storageResolver;
+
+    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+    {
+        // TODO: intercept
+        return metadataRepository.getProject( repoId, namespace, projectId );
+    }
+
+    public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
+    {
+        ProjectBuildMetadata metadata = metadataRepository.getProjectBuild( repoId, namespace, projectId, buildId );
+        // TODO: do we want to detect changes as well by comparing timestamps? isProjectBuildNewerThan(updated)
+        //       in such cases we might also remove/update stale metadata, including adjusting plugin-based facets
+        if ( metadata == null )
+        {
+            metadata = storageResolver.getProjectBuild( repoId, namespace, projectId, buildId );
+            metadataRepository.updateBuild( repoId, namespace, projectId, metadata );
+        }
+        return metadata;
+    }
+
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
+    {
+        // TODO: intercept
+        return metadataRepository.getArtifactVersions( repoId, namespace, projectId, buildId );
+    }
+}
index 4440a9e07619736201348258da9f66ecabb7c8ed..6e20282c1ba1b336727b5c6358c1b12f1cd99eb5 100644 (file)
@@ -19,13 +19,12 @@ package org.apache.archiva.metadata.repository;
  * under the License.
  */
 
-import java.util.Collection;
-
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.model.ProjectBuildMetadata;
 import org.apache.archiva.metadata.model.ProjectMetadata;
 
 public interface MetadataRepository
+    extends MetadataResolver
 {
     /**
      * Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
@@ -37,9 +36,4 @@ public interface MetadataRepository
 
     void updateBuild( String repoId, String namespace, String projectId, ProjectBuildMetadata build );
 
-    ProjectMetadata getProject( String repoId, String namespace, String projectId );
-
-    ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
-
-    Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
 }
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataResolver.java
new file mode 100644 (file)
index 0000000..fd2cf83
--- /dev/null
@@ -0,0 +1,34 @@
+package org.apache.archiva.metadata.repository;
+
+/*
+ * 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.
+ */
+
+import java.util.Collection;
+
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+
+public interface MetadataResolver
+{
+    ProjectMetadata getProject( String repoId, String namespace, String projectId );
+
+    ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId );
+
+    Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId );
+}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/storage/RepositoryPathTranslator.java
new file mode 100644 (file)
index 0000000..3a581d6
--- /dev/null
@@ -0,0 +1,29 @@
+package org.apache.archiva.metadata.repository.storage;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+public interface RepositoryPathTranslator
+{
+    File toFile( File basedir, String namespace, String projectId, String buildId, String filename );
+
+    String toPath( String namespace, String projectId, String buildId, String filename );
+}
index 0cf46c7fb8b52eb7719c086866b99dea4f4fbc8d..1524507c7de857b817757faffd09cd1cca300919 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>metadata-model</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-repository-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-spring</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model-builder</artifactId>
+      <version>3.0-alpha-4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-configuration</artifactId>
+      <version>1.3-SNAPSHOT</version>
+    </dependency>
   </dependencies>
+  <dependencyManagement>
+    <dependencies>
+      <!-- TODO: this is to override the top level dependency management - we need to rationalise these -->
+      <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-model</artifactId>
+        <version>3.0-alpha-4</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
 </project>
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DummyLifecycleBindingsInjector.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/DummyLifecycleBindingsInjector.java
new file mode 100644 (file)
index 0000000..15b0d01
--- /dev/null
@@ -0,0 +1,39 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.building.ModelBuildingRequest;
+import org.apache.maven.model.building.ModelProblemCollector;
+import org.apache.maven.model.plugin.LifecycleBindingsInjector;
+
+/**
+ * Required as plexus-spring doesn't understand the optional = true argument added to Plexus and used here.
+ *
+ * @plexus.component role="org.apache.maven.model.plugin.LifecycleBindingsInjector"
+ */
+public class DummyLifecycleBindingsInjector
+    implements LifecycleBindingsInjector
+{
+    public void injectLifecycleBindings( Model model, ModelBuildingRequest modelBuildingRequest, ModelProblemCollector modelProblemCollector )
+    {
+        // left intentionally blank
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolver.java
new file mode 100644 (file)
index 0000000..ff414d8
--- /dev/null
@@ -0,0 +1,111 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.util.Collection;
+
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.building.DefaultModelBuildingRequest;
+import org.apache.maven.model.building.ModelBuilder;
+import org.apache.maven.model.building.ModelBuildingException;
+import org.apache.maven.model.building.ModelBuildingRequest;
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.MetadataResolver" role-hint="maven2"
+ */
+public class Maven2RepositoryMetadataResolver
+    implements MetadataResolver
+{
+    /**
+     * @plexus.requirement
+     */
+    private ModelBuilder builder;
+
+    /**
+     * @plexus.requirement
+     */
+    private ArchivaConfiguration archivaConfiguration;
+
+    /**
+     * @plexus.requirement role-hint="maven2"
+     */
+    private RepositoryPathTranslator pathTranslator;
+
+    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public ProjectBuildMetadata getProjectBuild( String repoId, String namespace, String projectId, String buildId )
+    {
+        ManagedRepositoryConfiguration repositoryConfiguration =
+            archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
+
+        File basedir = new File( repositoryConfiguration.getLocation() );
+        File file = pathTranslator.toFile( basedir, namespace, projectId, buildId, projectId + "-" + buildId + ".pom" );
+
+        ModelBuildingRequest req = new DefaultModelBuildingRequest();
+        req.setProcessPlugins( false );
+        req.setPomFile( file );
+        req.setModelResolver( new RepositoryModelResolver( basedir, pathTranslator ) );
+
+        Model model;
+        try
+        {
+            model = builder.build( req ).getEffectiveModel();
+        }
+        catch ( ModelBuildingException e )
+        {
+            // TODO: handle it
+            throw new RuntimeException( e );
+        }
+
+        MavenProjectFacet facet = new MavenProjectFacet();
+        facet.setGroupId( model.getGroupId() != null ? model.getGroupId() : model.getParent().getGroupId() );
+        facet.setArtifactId( model.getArtifactId() );
+        facet.setPackaging( model.getPackaging() );
+        if ( model.getParent() != null )
+        {
+            MavenProjectParent parent = new MavenProjectParent();
+            parent.setGroupId( model.getParent().getGroupId() );
+            parent.setArtifactId( model.getParent().getArtifactId() );
+            parent.setVersion( model.getParent().getVersion() );
+            facet.setParent( parent );
+        }
+        ProjectBuildMetadata metadata = new ProjectBuildMetadata();
+        metadata.setUrl( model.getUrl() );
+        metadata.addFacet( facet );
+        // TODO: convert project
+
+        return metadata;
+    }
+
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String buildId )
+    {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryPathTranslator.java
new file mode 100644 (file)
index 0000000..53cabac
--- /dev/null
@@ -0,0 +1,57 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+import java.io.File;
+
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+
+/*
+ * 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.
+ */
+
+/**
+ * @plexus.component role="org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator" role-hint="maven2"
+ */
+public class Maven2RepositoryPathTranslator
+    implements RepositoryPathTranslator
+{
+    private static final char PATH_SEPARATOR = '/';
+
+    private static final char GROUP_SEPARATOR = '.';
+
+    public File toFile( File basedir, String namespace, String projectId, String buildId, String filename )
+    {
+        return new File( basedir, toPath( namespace, projectId, buildId, filename ) );
+    }
+
+    public String toPath( String namespace, String projectId, String buildId, String filename )
+    {
+        StringBuilder path = new StringBuilder();
+
+        path.append( formatAsDirectory( namespace ) ).append( PATH_SEPARATOR );
+        path.append( projectId ).append( PATH_SEPARATOR );
+        path.append( buildId ).append( PATH_SEPARATOR );
+        path.append( filename );
+
+        return path.toString();
+    }
+
+    private String formatAsDirectory( String directory )
+    {
+        return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR );
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java b/archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/RepositoryModelResolver.java
new file mode 100644 (file)
index 0000000..b76d874
--- /dev/null
@@ -0,0 +1,66 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
+import org.apache.maven.model.Repository;
+import org.apache.maven.model.building.FileModelSource;
+import org.apache.maven.model.building.ModelSource;
+import org.apache.maven.model.resolution.InvalidRepositoryException;
+import org.apache.maven.model.resolution.ModelResolver;
+import org.apache.maven.model.resolution.UnresolvableModelException;
+
+public class RepositoryModelResolver
+    implements ModelResolver
+{
+    private File basedir;
+
+    private RepositoryPathTranslator pathTranslator;
+
+    public RepositoryModelResolver( File basedir, RepositoryPathTranslator pathTranslator )
+    {
+        this.basedir = basedir;
+
+        this.pathTranslator = pathTranslator;
+    }
+
+    public ModelSource resolveModel( String groupId, String artifactId, String version )
+        throws UnresolvableModelException
+    {
+        String filename = artifactId + "-" + version + ".pom";
+        // TODO: we need to convert 1.0-20091120.112233-1 type paths to baseVersion for the below call - add a test
+        return new FileModelSource( pathTranslator.toFile( basedir, groupId, artifactId, version, filename ) );
+    }
+
+    public void addRepository( Repository repository )
+        throws InvalidRepositoryException
+    {
+        // we just ignore repositories outside of the current one for now
+        // TODO: it'd be nice to look them up from Archiva's set, but we want to do that by URL / mapping, not just the
+        //       ID since they will rarely match
+    }
+
+    public ModelResolver newCopy()
+    {
+        return new RepositoryModelResolver( basedir, pathTranslator );
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java
new file mode 100644 (file)
index 0000000..ca6dfed
--- /dev/null
@@ -0,0 +1,64 @@
+package org.apache.archiva.configuration;
+
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ConfigurationListener;
+import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
+import org.codehaus.plexus.registry.RegistryException;
+import org.codehaus.plexus.registry.RegistryListener;
+
+/*
+ * 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.
+ */
+
+public class TestConfiguration
+    implements ArchivaConfiguration
+{
+    private Configuration configuration;
+
+    public Configuration getConfiguration()
+    {
+        return configuration;
+    }
+
+    public void save( Configuration configuration )
+        throws RegistryException, IndeterminateConfigurationException
+    {
+        this.configuration = configuration;
+    }
+
+    public boolean isDefaulted()
+    {
+        return false;
+    }
+
+    public void addListener( ConfigurationListener listener )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void removeListener( ConfigurationListener listener )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void addChangeListener( RegistryListener listener )
+    {
+        throw new UnsupportedOperationException();
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java
new file mode 100644 (file)
index 0000000..a1dde6b
--- /dev/null
@@ -0,0 +1,61 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.metadata.model.ProjectBuildMetadata;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.maven.archiva.configuration.ArchivaConfiguration;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+public class Maven2RepositoryMetadataResolverTest
+    extends PlexusInSpringTestCase
+{
+    private Maven2RepositoryMetadataResolver resolver;
+
+    private static final String TEST_REPO_ID = "test";
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        ArchivaConfiguration configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
+        Configuration c = new Configuration();
+        ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
+        testRepo.setId( TEST_REPO_ID );
+        testRepo.setLocation( getTestPath( "src/test/repositories/test" ) );
+        c.addManagedRepository( testRepo );
+        configuration.save( c );
+
+        resolver = (Maven2RepositoryMetadataResolver) lookup( MetadataResolver.class, "maven2" );
+    }
+
+    public void testGetProjectBuildMetadata()
+    {
+        ProjectBuildMetadata metadata =
+            resolver.getProjectBuild( TEST_REPO_ID, "org.apache.archiva", "archiva-common", "1.2.1" );
+        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+        assertEquals( "jar", facet.getPackaging() );
+        assertEquals( "http://archiva.apache.org/ref/1.2.1/archiva-base/archiva-common", metadata.getUrl() );
+        // TODO: more testing
+    }
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml b/archiva-modules/plugins/maven2-repository/src/test/resources/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.xml
new file mode 100644 (file)
index 0000000..d8ea35f
--- /dev/null
@@ -0,0 +1,27 @@
+<!--
+  ~ 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.
+  -->
+
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
+      <implementation>org.apache.archiva.configuration.TestConfiguration</implementation>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file
index a262ab24456df88c1c3389b2c11c52e619457f8b..54a755c87bffcf04076126b9c4f15330adb19578 100644 (file)
@@ -43,6 +43,7 @@ public class FileMetadataRepository
     implements MetadataRepository
 {
     /**
+     * TODO: this isn't suitable for production use
      * @plexus.configuration
      */
     private File directory = new File( System.getProperty( "user.home" ), ".archiva-metadata" );