]> source.dussan.org Git - archiva.git/commitdiff
[MNG-734] fix plugin-level metadata handling
authorBrett Porter <brett@apache.org>
Thu, 20 Mar 2008 12:21:49 +0000 (12:21 +0000)
committerBrett Porter <brett@apache.org>
Thu, 20 Mar 2008 12:21:49 +0000 (12:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@639260 13f79535-47bb-0310-9956-ffa450edef68

21 files changed:
archiva-1.0.x/archiva-base/archiva-model/src/main/mdo/archiva-base.xml
archiva-1.0.x/archiva-base/archiva-proxy/src/test/java/org/apache/maven/archiva/proxy/MetadataTransferTest.java
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml [new file with mode: 0644]
archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/MetadataTools.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataReader.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/metadata/RepositoryMetadataWriter.java
archiva-1.0.x/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java
archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/AbstractRepositoryServletProxiedMetadataTestCase.java
archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyMetadataTest.java
archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletNoProxyTest.java
archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataLocalOnlyTest.java
archiva-1.0.x/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/repository/RepositoryServletProxiedMetadataRemoteOnlyTest.java

index 663cc4f715148c22eba38a6a75a0158e9c7b9615..e4286f737c2354d62a9f9bf2a59be28933ba1e28 100644 (file)
             <multiplicity>1</multiplicity>
           </association>
         </field>
+        <field>
+          <name>plugins</name>
+          <identifier>false</identifier>
+          <version>1.0.0+</version>
+          <required>false</required>
+          <description>
+            The available plugins.
+          </description>
+          <association stash.part="true"
+                       jpox.join="false">
+            <type>Plugin</type>
+            <multiplicity>*</multiplicity>
+          </association>
+        </field>
         <field>
           <name>availableVersions</name>
           <identifier>false</identifier>
       </codeSegments>
     </class>
 
+    <class stash.storable="true"
+           jpox.not-persisted-fields="modelEncoding"
+           jpox.table="REPOSITORY_METADATA_PLUGINS">
+      <name>Plugin</name>
+      <description>The Plugin</description>
+      <version>1.0.0+</version>
+      <fields>
+        <field stash.maxSize="20"
+               jpox.column="PLUGIN_PREFIX">
+          <name>prefix</name>
+          <type>String</type>
+          <identifier>false</identifier>
+          <required>true</required>
+          <description>
+            The prefix for a plugin
+          </description>
+        </field>
+        <field
+               jpox.column="PLUGIN_ARTIFACT_ID">
+          <name>artifactId</name>
+          <type>String</type>
+          <identifier>true</identifier>
+          <required>true</required>
+          <description>
+            The artifactId for a plugin
+          </description>
+        </field>
+        <field jpox.column="PLUGIN_NAME">
+          <name>name</name>
+          <type>String</type>
+          <identifier>false</identifier>
+          <required>true</required>
+          <description>
+            The name for a plugin
+          </description>
+        </field>
+      </fields>
+    </class>
+
 
     <!-- _______________________________________________________________
         ____       __
index d46d4e9fdd2a741fc47ef3b56c48e8e751326575..2496e3b68f14e81e0b66ea664cd6d57fea0b7c95 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.maven.archiva.proxy;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.common.utils.VersionUtil;
 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
+import org.apache.maven.archiva.model.Plugin;
 import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.model.SnapshotVersion;
 import org.apache.maven.archiva.model.VersionedReference;
@@ -123,7 +124,7 @@ public class MetadataTransferTest
 
         wagonMockControl.replay();
 
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         wagonMockControl.verify();
 
@@ -148,7 +149,7 @@ public class MetadataTransferTest
         assertResourceNotFound( requestedResource );
 
         // No proxy setup, nothing fetched, failure expected.
-        assertFetchProjectFailed( requestedResource );
+        assertFetchProjectOrGroupFailed( requestedResource );
 
         // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
         assertResourceNotFound( requestedResource );
@@ -164,7 +165,7 @@ public class MetadataTransferTest
         assertResourceExists( requestedResource );
 
         // No proxy setup, nothing fetched from remote, but local exists.
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // Nothing fetched.  Should only contain contents of what is in the repository.
         // A metadata update is not performed in this use case.  Local metadata content is only
@@ -190,7 +191,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED2, requestedResource );
 
         // Two proxies setup, metadata fetched from both remotes.
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // Nothing fetched.  Should only contain contents of what is in the repository.
         assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1" }, "1.0.1", "1.0.1" );
@@ -216,7 +217,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED2, requestedResource );
 
         // Two proxies setup, nothing fetched from remotes, local does not exist.
-        assertFetchProjectFailed( requestedResource );
+        assertFetchProjectOrGroupFailed( requestedResource );
 
         // Nothing fetched.  Nothing should exist.
         assertResourceNotFound( requestedResource );
@@ -239,7 +240,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED1, requestedResource );
 
         // One proxy setup, metadata fetched from remote, local does not exist.
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // Remote fetched.  Local created/updated.
         assertProjectMetadataContents( requestedResource, new String[] { "1.0.5" }, "1.0.5", "1.0.5" );
@@ -264,7 +265,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED2, requestedResource );
 
         // Two proxies setup, metadata fetched from both remotes.
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // metadata fetched from both repos, and merged with local version.
         assertProjectMetadataContents( requestedResource, new String[] { "1.0", "1.0.1", "2.0" }, "2.0", "2.0" );
@@ -290,7 +291,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED2, requestedResource );
 
         // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // metadata not fetched from both repos, and local version exists.
         // Since there was no updated metadata content from a remote/proxy, a metadata update on
@@ -315,7 +316,7 @@ public class MetadataTransferTest
         assertNoRepoMetadata( ID_PROXIED1, requestedResource );
 
         // One proxy setup, metadata fetched from remote, local exists.
-        assertFetchProject( requestedResource );
+        assertFetchProjectOrGroup( requestedResource );
 
         // Remote fetched.  Local updated.
         assertProjectMetadataContents( requestedResource, new String[] { "1.0.8", "1.0.22", "2.0" }, "2.0", "2.0" );
@@ -416,7 +417,7 @@ public class MetadataTransferTest
 
         assertResourceNotFound( requestedResource );
 
-        assertFetchProjectFailed( requestedResource );
+        assertFetchProjectOrGroupFailed( requestedResource );
 
         assertResourceNotFound( requestedResource );
         assertNoRepoMetadata( ID_PROXIED1, requestedResource );
@@ -704,13 +705,197 @@ public class MetadataTransferTest
         assertRepoSnapshotMetadataContents( ID_PROXIED1, requestedResource, "20050831", "101112", 1 );
     }
 
+    public void testGetGroupMetadataNotProxiedNotLocal()
+        throws Exception
+    {
+        // The artifactId "get-default-metadata-nonexistant" does not exist (intentionally).
+        String requestedResource = "org/apache/maven/test/groups/get-default-metadata-nonexistant/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        assertResourceNotFound( requestedResource );
+
+        // No proxy setup, nothing fetched, failure expected.
+        assertFetchProjectOrGroupFailed( requestedResource );
+
+        // No local artifactId, and no fetch, should equal no metadata file downloaded / created / updated.
+        assertResourceNotFound( requestedResource );
+    }
+
+    public void testGetGroupMetadataNotProxiedOnLocal()
+        throws Exception
+    {
+        // Project metadata that exists and has multiple versions
+        String requestedResource = "org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        assertResourceExists( requestedResource );
+
+        // No proxy setup, nothing fetched from remote, but local exists.
+        assertFetchProjectOrGroup( requestedResource );
+
+        // Nothing fetched.  Should only contain contents of what is in the repository.
+        // A metadata update is not performed in this use case.  Local metadata content is only
+        // updated via the metadata updater consumer.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
+    }
+
+    public void testGetGroupMetadataProxiedNotLocalMultipleRemotes()
+        throws Exception
+    {
+        // Project metadata that does not exist locally, but has multiple versions in remote repos
+        String requestedResource = "org/apache/maven/test/groups/get-default-layout/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertResourceNotFound( requestedResource );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+        // Two proxies setup, metadata fetched from both remotes.
+        assertFetchProjectOrGroup( requestedResource );
+
+        // Nothing fetched.  Should only contain contents of what is in the repository.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin2", "plugin1" } );
+        assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1" } );
+        assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin2" } );
+    }
+
+    public void testGetGroupsMetadataProxiedNotLocalNotRemote()
+        throws Exception
+    {
+        // Non-existant project metadata that does not exist locally and doesn't exist on remotes.
+        String requestedResource = "org/apache/maven/test/groups/get-bogus-artifact/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertResourceNotFound( requestedResource );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+        // Two proxies setup, nothing fetched from remotes, local does not exist.
+        assertFetchProjectOrGroupFailed( requestedResource );
+
+        // Nothing fetched.  Nothing should exist.
+        assertResourceNotFound( requestedResource );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+    }
+
+    public void testGetGroupMetadataProxiedNotLocalOnRemote()
+        throws Exception
+    {
+        // New project metadata that does not exist locally but exists on remote.
+        String requestedResource = "org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertResourceNotFound( requestedResource );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+
+        // One proxy setup, metadata fetched from remote, local does not exist.
+        assertFetchProjectOrGroup( requestedResource );
+
+        // Remote fetched.  Local created/updated.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin3" } );
+        assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin3" } );
+    }
+
+    public void testGetGroupMetadataProxiedOnLocalMultipleRemote()
+        throws Exception
+    {
+        // Project metadata that exist locally, and has multiple versions in remote repos
+        String requestedResource = "org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin1" } );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+        // Two proxies setup, metadata fetched from both remotes.
+        assertFetchProjectOrGroup( requestedResource );
+
+        // metadata fetched from both repos, and merged with local version.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin1", "plugin2", "plugin4" } );
+        assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin1", "plugin4" } );
+        assertRepoGroupMetadataContents( ID_PROXIED2, requestedResource, new String[] { "plugin1", "plugin2" } );
+    }
+
+    public void testGetGroupMetadataProxiedOnLocalNotRemote()
+        throws Exception
+    {
+        // Project metadata that exist locally, and does not exist in remote repos.
+        String requestedResource = "org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED2, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+
+        // Two proxies setup, metadata fetch from remotes fail (because they dont exist).
+        assertFetchProjectOrGroup( requestedResource );
+
+        // metadata not fetched from both repos, and local version exists.
+        // Since there was no updated metadata content from a remote/proxy, a metadata update on
+        // the local file never ran.  Local only updates are performed via the metadata updater consumer.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin5" } );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+        assertNoRepoMetadata( ID_PROXIED2, requestedResource );
+    }
+
+    public void testGetGroupMetadataProxiedOnLocalOnRemote()
+        throws Exception
+    {
+        // Project metadata that exist locally and exists on remote.
+        String requestedResource = "org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml";
+        setupTestableManagedRepository( requestedResource );
+
+        // Configure Connector (usually done within archiva.xml configuration)
+        saveConnector( ID_DEFAULT_MANAGED, ID_PROXIED1, ChecksumPolicy.FIX, ReleasesPolicy.ALWAYS,
+                       SnapshotsPolicy.ALWAYS, CachedFailuresPolicy.NO );
+
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7" } );
+        assertNoRepoMetadata( ID_PROXIED1, requestedResource );
+
+        // One proxy setup, metadata fetched from remote, local exists.
+        assertFetchProjectOrGroup( requestedResource );
+
+        // Remote fetched.  Local updated.
+        assertGroupMetadataContents( requestedResource, new String[] { "plugin6", "plugin7", "plugin4" } );
+        assertRepoGroupMetadataContents( ID_PROXIED1, requestedResource, new String[] { "plugin7", "plugin4" } );
+    }
+
     /**
      * Transfer the metadata file.
      *
      * @param requestedResource the requested resource
      * @throws Exception
      */
-    private void assertFetchProject( String requestedResource )
+    private void assertFetchProjectOrGroup( String requestedResource )
         throws Exception
     {
         File expectedFile = new File( managedDefaultDir, requestedResource );
@@ -735,7 +920,7 @@ public class MetadataTransferTest
      * @param requestedResource the requested resource
      * @throws Exception
      */
-    private void assertFetchProjectFailed( String requestedResource )
+    private void assertFetchProjectOrGroupFailed( String requestedResource )
         throws Exception
     {
         File expectedFile = new File( managedDefaultDir, requestedResource );
@@ -850,6 +1035,64 @@ public class MetadataTransferTest
         assertFalse( "Repo specific metadata should not exist: " + actualFile, actualFile.exists() );
     }
 
+    private void assertGroupMetadataContents( String requestedResource, String expectedPlugins[] )
+        throws Exception
+    {
+        File actualFile = new File( managedDefaultDir, requestedResource );
+        assertTrue( "Snapshot Metadata should exist: " + requestedResource, actualFile.exists() );
+
+        ProjectReference actualMetadata = createGroupReference( requestedResource );
+
+        assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
+    }
+
+    private ProjectReference createGroupReference( String requestedResource )
+        throws RepositoryMetadataException
+    {
+        ProjectReference projectReference = createProjectReference( requestedResource );
+        projectReference.setGroupId( projectReference.getGroupId() + "." + projectReference.getArtifactId() );
+        projectReference.setArtifactId( null );
+        return projectReference;
+    }
+
+    private void assertRepoGroupMetadataContents( String proxiedRepoId, String requestedResource,
+                                                  String expectedPlugins[] )
+        throws Exception
+    {
+        String proxiedFile = metadataTools.getRepositorySpecificName( proxiedRepoId, requestedResource );
+
+        File actualFile = new File( managedDefaultDir, proxiedFile );
+        assertTrue( "Repo Specific Group Metadata should exist: " + requestedResource, actualFile.exists() );
+
+        ProjectReference actualMetadata = createGroupReference( requestedResource );
+
+        assertGroupMetadata( actualFile, actualMetadata, expectedPlugins );
+    }
+
+    private void assertGroupMetadata( File actualFile, ProjectReference actualMetadata, String expectedPlugins[] )
+        throws Exception
+    {
+        // Build expected metadata XML
+        StringWriter expectedMetadataXml = new StringWriter();
+        ArchivaRepositoryMetadata m = new ArchivaRepositoryMetadata();
+        m.setGroupId( actualMetadata.getGroupId() );
+
+        for ( String pluginId : expectedPlugins )
+        {
+            Plugin p = new Plugin();
+            p.setPrefix( pluginId );
+            p.setArtifactId( pluginId + "-maven-plugin" );
+            p.setName( "The " + pluginId + " Plugin" );
+            m.getPlugins().add( p );
+        }
+
+        m.setModelEncoding( null );
+        RepositoryMetadataWriter.write( m, expectedMetadataXml );
+
+        // Compare the file to the actual contents.
+        assertMetadataEquals( expectedMetadataXml.toString(), actualFile );
+    }
+
     /**
      * Test for the existance of the requestedResource in the default managed repository, and if it exists,
      * does it contain the specified list of expected versions?
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-not-on-remotes/maven-metadata.xml
new file mode 100644 (file)
index 0000000..6053adc
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-not-on-remotes</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin5</prefix>
+      <artifactId>plugin5-maven-plugin</artifactId>
+      <name>The plugin5 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml
new file mode 100644 (file)
index 0000000..14196bd
--- /dev/null
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-on-local-on-remote</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin6</prefix>
+      <artifactId>plugin6-maven-plugin</artifactId>
+      <name>The plugin6 Plugin</name>
+    </plugin>
+    <plugin>
+      <prefix>plugin7</prefix>
+      <artifactId>plugin7-maven-plugin</artifactId>
+      <name>The plugin7 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml
new file mode 100644 (file)
index 0000000..a044289
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin1</prefix>
+      <artifactId>plugin1-maven-plugin</artifactId>
+      <name>The plugin1 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/managed/org/apache/maven/test/groups/get-project-metadata/maven-metadata.xml
new file mode 100644 (file)
index 0000000..e0829c1
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-project-metadata</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin1</prefix>
+      <artifactId>plugin1-maven-plugin</artifactId>
+      <name>The plugin1 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml
new file mode 100644 (file)
index 0000000..9f6bf92
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-default-layout</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin1</prefix>
+      <artifactId>plugin1-maven-plugin</artifactId>
+      <name>The plugin1 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-found-in-proxy/maven-metadata.xml
new file mode 100644 (file)
index 0000000..9010286
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-found-in-proxy</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin3</prefix>
+      <artifactId>plugin3-maven-plugin</artifactId>
+      <name>The plugin3 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-local-on-remote/maven-metadata.xml
new file mode 100644 (file)
index 0000000..23f12bb
--- /dev/null
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-on-local-on-remote</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin7</prefix>
+      <artifactId>plugin7-maven-plugin</artifactId>
+      <name>The plugin7 Plugin</name>
+    </plugin>
+    <plugin>
+      <prefix>plugin4</prefix>
+      <artifactId>plugin4-maven-plugin</artifactId>
+      <name>The plugin4 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied1/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml
new file mode 100644 (file)
index 0000000..3abe069
--- /dev/null
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin1</prefix>
+      <artifactId>plugin1-maven-plugin</artifactId>
+      <name>The plugin1 Plugin</name>
+    </plugin>
+    <plugin>
+      <prefix>plugin4</prefix>
+      <artifactId>plugin4-maven-plugin</artifactId>
+      <name>The plugin4 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-default-layout/maven-metadata.xml
new file mode 100644 (file)
index 0000000..4110985
--- /dev/null
@@ -0,0 +1,29 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-default-layout</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin2</prefix>
+      <artifactId>plugin2-maven-plugin</artifactId>
+      <name>The plugin2 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
diff --git a/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml b/archiva-1.0.x/archiva-base/archiva-proxy/src/test/repositories/proxied2/org/apache/maven/test/groups/get-on-multiple-repos/maven-metadata.xml
new file mode 100644 (file)
index 0000000..b7db006
--- /dev/null
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<metadata>
+  <groupId>org.apache.maven.test.groups.get-on-multiple-repos</groupId>
+  <plugins>
+    <plugin>
+      <prefix>plugin1</prefix>
+      <artifactId>plugin1-maven-plugin</artifactId>
+      <name>The plugin1 Plugin</name>
+    </plugin>
+    <plugin>
+      <prefix>plugin2</prefix>
+      <artifactId>plugin2-maven-plugin</artifactId>
+      <name>The plugin2 Plugin</name>
+    </plugin>
+  </plugins>
+</metadata>
index 960f3d7983fb1b3bd4cfffa682e19ce20992e1ef..35af14277503ff535f782f0369248d86b4e02ca1 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
 import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.model.Plugin;
 import org.apache.maven.archiva.model.ProjectReference;
 import org.apache.maven.archiva.model.SnapshotVersion;
 import org.apache.maven.archiva.model.VersionedReference;
@@ -56,6 +57,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -394,14 +396,16 @@ public class MetadataTools
     }
 
     /**
-     * Update the metadata to represent the all versions of
-     * the provided groupId:artifactId project reference,
+     * Update the metadata to represent the all versions/plugins of
+     * the provided groupId:artifactId project or group reference,
      * based off of information present in the repository,
      * the maven-metadata.xml files, and the proxy/repository specific
      * metadata file contents.
      *
+     * We must treat this as a group or a project metadata file as there is no way to know in advance
+     *
      * @param managedRepository the managed repository where the metadata is kept.
-     * @param reference         the versioned referencfe to update.
+     * @param reference         the reference to update.
      * @throws LayoutException
      * @throws RepositoryMetadataException
      * @throws IOException
@@ -421,6 +425,19 @@ public class MetadataTools
         // Gather up all versions found in the managed repository.
         Set<String> allVersions = managedRepository.getVersions( reference );
 
+        // Gather up all plugins found in the managed repository.
+        // TODO: do we know this information instead?
+//        Set<Plugin> allPlugins = managedRepository.getPlugins( reference );
+        Set<Plugin> allPlugins;
+        if ( metadataFile.exists() )
+        {
+            allPlugins = new LinkedHashSet<Plugin>( RepositoryMetadataReader.read( metadataFile ).getPlugins() );
+        }
+        else
+        {
+            allPlugins = new LinkedHashSet<Plugin>();
+        }
+
         // Does this repository have a set of remote proxied repositories?
         Set<String> proxiedRepoIds = this.proxies.get( managedRepository.getId() );
 
@@ -436,6 +453,7 @@ public class MetadataTools
                 if ( proxyMetadata != null )
                 {
                     allVersions.addAll( proxyMetadata.getAvailableVersions() );
+                    allPlugins.addAll( proxyMetadata.getPlugins() );
                     long proxyLastUpdated = getLastUpdated( proxyMetadata );
 
                     lastUpdated = Math.max( lastUpdated, proxyLastUpdated );
@@ -443,47 +461,55 @@ public class MetadataTools
             }
         }
 
-        if ( allVersions.size() == 0 )
+        if ( !allVersions.isEmpty() )
         {
-            throw new IOException( "No versions found for reference." );
-        }
-
-        // Sort the versions
-        List<String> sortedVersions = new ArrayList<String>( allVersions );
-        Collections.sort( sortedVersions, VersionComparator.getInstance() );
+            // Sort the versions
+            List<String> sortedVersions = new ArrayList<String>( allVersions );
+            Collections.sort( sortedVersions, VersionComparator.getInstance() );
 
-        // Split the versions into released and snapshots.
-        List<String> releasedVersions = new ArrayList<String>();
-        List<String> snapshotVersions = new ArrayList<String>();
+            // Split the versions into released and snapshots.
+            List<String> releasedVersions = new ArrayList<String>();
+            List<String> snapshotVersions = new ArrayList<String>();
 
-        for ( String version : sortedVersions )
-        {
-            if ( VersionUtil.isSnapshot( version ) )
+            for ( String version : sortedVersions )
             {
-                snapshotVersions.add( version );
+                if ( VersionUtil.isSnapshot( version ) )
+                {
+                    snapshotVersions.add( version );
+                }
+                else
+                {
+                    releasedVersions.add( version );
+                }
             }
-            else
+
+            Collections.sort( releasedVersions, VersionComparator.getInstance() );
+            Collections.sort( snapshotVersions, VersionComparator.getInstance() );
+
+            String latestVersion = sortedVersions.get( sortedVersions.size() - 1 );
+            String releaseVersion = null;
+
+            if ( CollectionUtils.isNotEmpty( releasedVersions ) )
             {
-                releasedVersions.add( version );
+                releaseVersion = releasedVersions.get( releasedVersions.size() - 1 );
             }
-        }
-
-        Collections.sort( releasedVersions, VersionComparator.getInstance() );
-        Collections.sort( snapshotVersions, VersionComparator.getInstance() );
 
-        String latestVersion = sortedVersions.get( sortedVersions.size() - 1 );
-        String releaseVersion = null;
+            // Add the versions to the metadata model.
+            metadata.setAvailableVersions( sortedVersions );
 
-        if ( CollectionUtils.isNotEmpty( releasedVersions ) )
-        {
-            releaseVersion = releasedVersions.get( releasedVersions.size() - 1 );
+            metadata.setLatestVersion( latestVersion );
+            metadata.setReleasedVersion( releaseVersion );
         }
+        else
+        {
+            // Add the plugins to the metadata model.
+            metadata.setPlugins( new ArrayList<Plugin>( allPlugins ) );
 
-        // Add the versions to the metadata model.
-        metadata.setAvailableVersions( sortedVersions );
+            // artifact ID was actually the last part of the group
+            metadata.setGroupId( metadata.getGroupId() + "." + metadata.getArtifactId() );
+            metadata.setArtifactId( null );
+        }
 
-        metadata.setLatestVersion( latestVersion );
-        metadata.setReleasedVersion( releaseVersion );
         if ( lastUpdated > 0 )
         {
             metadata.setLastUpdatedTimestamp( toLastUpdatedDate( lastUpdated ) );
index 5d24df83518e75e5a0b2ce32bcf53878c27294d9..1e18caf86720b67945017b37251074f6e4cd6bcc 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.maven.archiva.repository.metadata;
 
 import org.apache.commons.lang.math.NumberUtils;
 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
+import org.apache.maven.archiva.model.Plugin;
 import org.apache.maven.archiva.model.SnapshotVersion;
 import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.archiva.xml.XMLReader;
@@ -78,6 +79,15 @@ public class RepositoryMetadataReader
                 metadata.setSnapshotVersion( snapshot );
             }
 
+            for ( Element plugin : xml.getElementList( "//metadata/plugins/plugin" ) )
+            {
+                Plugin p = new Plugin();
+                p.setPrefix( plugin.elementTextTrim( "prefix" ) );
+                p.setArtifactId( plugin.elementTextTrim( "artifactId" ) );
+                p.setName( plugin.elementTextTrim( "name" ) );
+                metadata.addPlugin( p );
+            }
+
             return metadata;
         }
         catch ( XMLException e )
index fb99fb235e7b2ddcfa4d049658249ef12ba190fb..9b0d1b283b9e94cae8218daed950a769ba2de6f3 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.model.ArchivaRepositoryMetadata;
+import org.apache.maven.archiva.model.Plugin;
 import org.apache.maven.archiva.xml.XMLException;
 import org.apache.maven.archiva.xml.XMLWriter;
 import org.dom4j.Document;
@@ -34,6 +35,7 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * RepositoryMetadataWriter 
@@ -73,9 +75,21 @@ public class RepositoryMetadataWriter
         doc.setRootElement( root );
 
         root.addElement( "groupId" ).setText( metadata.getGroupId() );
-        root.addElement( "artifactId" ).setText( metadata.getArtifactId() );
+        addOptionalElementText( root, "artifactId", metadata.getArtifactId() );
         addOptionalElementText( root, "version", metadata.getVersion() );
 
+        if ( CollectionUtils.isNotEmpty( metadata.getPlugins() ) )
+        {
+            Element plugins = root.addElement( "plugins" );
+            for ( Plugin plugin : (List<Plugin>)metadata.getPlugins() )
+            {
+                Element p = plugins.addElement( "plugin" );
+                p.addElement( "prefix" ).setText( plugin.getPrefix() );
+                p.addElement( "artifactId" ).setText( plugin.getArtifactId() );
+                addOptionalElementText( p, "name", plugin.getName() );
+            }
+        }
+
         if ( CollectionUtils.isNotEmpty( metadata.getAvailableVersions() )
             || StringUtils.isNotBlank( metadata.getReleasedVersion() )
             || StringUtils.isNotBlank( metadata.getLatestVersion() )
index 223238da2d9564b6feb91422e70785bfddd5ad80..892cbe7480a73408349371e040ebd28b634ccbf0 100644 (file)
@@ -37,6 +37,7 @@ import org.custommonkey.xmlunit.DetailedDiff;
 import org.custommonkey.xmlunit.Diff;
 import org.xml.sax.SAXException;
 
+import javax.xml.parsers.ParserConfigurationException;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -44,8 +45,6 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Set;
 
-import javax.xml.parsers.ParserConfigurationException;
-
 /**
  * MetadataToolsTest
  *
@@ -114,19 +113,20 @@ public class MetadataToolsTest
         assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName );
     }
 
-    public void testUpdateProjectBadArtifact()
-        throws Exception
-    {
-        try
-        {
-            assertUpdatedProjectMetadata( "bad_artifact", null );
-            fail( "Should have thrown an IOException on a bad artifact." );
-        }
-        catch ( IOException e )
-        {
-            // Expected path
-        }
-    }
+    // TODO: replace with group tests
+//    public void testUpdateProjectBadArtifact()
+//        throws Exception
+//    {
+//        try
+//        {
+//            assertUpdatedProjectMetadata( "bad_artifact", null );
+//            fail( "Should have thrown an IOException on a bad artifact." );
+//        }
+//        catch ( IOException e )
+//        {
+//            // Expected path
+//        }
+//    }
 
     public void testUpdateProjectMissingMultipleVersions()
         throws Exception
index 1ad6e20fca41b8eba7f26c030d84155a1ece595e..b35de9fdc4b8124a917a8ab438b9a58d4f1a95dd 100644 (file)
@@ -23,7 +23,6 @@ import com.meterware.httpunit.GetMethodWebRequest;
 import com.meterware.httpunit.HttpUnitOptions;
 import com.meterware.httpunit.WebRequest;
 import com.meterware.httpunit.WebResponse;
-
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.commons.lang.StringUtils;
 import org.custommonkey.xmlunit.DetailedDiff;
@@ -145,6 +144,34 @@ public abstract class AbstractRepositoryServletProxiedMetadataTestCase
         return buf.toString();
     }
 
+    protected String createGroupMetadata( String groupId, String[] plugins )
+    {
+        StringBuffer buf = new StringBuffer();
+
+        buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
+        buf.append( "<metadata>\n" );
+        buf.append( "  <groupId>" ).append( groupId ).append( "</groupId>\n" );
+
+        boolean hasPlugins = !ArrayUtils.isEmpty( plugins );
+
+        if ( hasPlugins )
+        {
+            buf.append( "  <plugins>\n" );
+            for ( String plugin : plugins )
+            {
+                buf.append( "    <plugin>\n" );
+                buf.append( "      <prefix>" ).append( plugin ).append( "</prefix>\n" );
+                buf.append( "      <artifactId>" ).append( plugin + "-maven-plugin" ).append( "</artifactId>\n" );
+                buf.append( "      <name>" ).append( "The " + plugin + " Plugin" ).append( "</name>\n" );
+                buf.append( "    </plugin>\n" );
+            }
+            buf.append( "  </plugins>\n" );
+        }
+        buf.append( "</metadata>" );
+
+        return buf.toString();
+    }
+
     protected void setupPrivateSnapshotsRemoteRepo()
         throws Exception
     {
index 2db6fa32e039016e889478df55b3595dc562c0f7..15df75479813581d7f077607a8e4460de0abb67d 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.repository;
 import com.meterware.httpunit.GetMethodWebRequest;
 import com.meterware.httpunit.WebRequest;
 import com.meterware.httpunit.WebResponse;
-
 import org.apache.commons.io.FileUtils;
 
 import java.io.File;
@@ -72,6 +71,24 @@ public class RepositoryServletNoProxyMetadataTest
         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
     }
 
+    public void testGetGroupMetadataDefaultLayout()
+        throws Exception
+    {
+        String commonsLangMetadata = "commons-lang/maven-metadata.xml";
+        String expectedMetadataContents = "metadata-for-commons-lang-group";
+
+        File checksumFile = new File( repoRootInternal, commonsLangMetadata );
+        checksumFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( checksumFile, expectedMetadataContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
+    }
+
     public void testGetSnapshotVersionMetadataDefaultLayout()
         throws Exception
     {
index 4e01fe48778f276ae28afefaac3bbad31cc8e052..3222c01b3ed0d5c66789b6fff2f783d70af423f4 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.maven.archiva.web.repository;
 import com.meterware.httpunit.GetMethodWebRequest;
 import com.meterware.httpunit.WebRequest;
 import com.meterware.httpunit.WebResponse;
-
 import org.apache.commons.io.FileUtils;
 
 import java.io.File;
@@ -107,6 +106,24 @@ public class RepositoryServletNoProxyTest
         assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
     }
 
+    public void testGetNoProxyGroupMetadataDefaultLayout()
+        throws Exception
+    {
+        String commonsLangMetadata = "commons-lang/maven-metadata.xml";
+        String expectedMetadataContents = "dummy-group-metadata";
+
+        File metadataFile = new File( repoRootInternal, commonsLangMetadata );
+        metadataFile.getParentFile().mkdirs();
+
+        FileUtils.writeStringToFile( metadataFile, expectedMetadataContents, null );
+
+        WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangMetadata );
+        WebResponse response = sc.getResponse( request );
+        assertResponseOK( response );
+
+        assertEquals( "Expected file contents", expectedMetadataContents, response.getText() );
+    }
+
     public void testGetNoProxyArtifactDefaultLayout()
         throws Exception
     {
index c04fbf0f8848d217683a62ca9d2d026ee013c992..883f382524b668fa1e2d97a70a212f675cdbc37f 100644 (file)
@@ -95,4 +95,24 @@ public class RepositoryServletProxiedMetadataLocalOnlyTest
         // --- Verification
         assertExpectedMetadata( expectedMetadata, actualMetadata );
     }
+
+    public void testGetProxiedGroupMetadataLocalOnly()
+        throws Exception
+    {
+        // --- Setup
+        setupSnapshotsRemoteRepo();
+        setupPrivateSnapshotsRemoteRepo();
+        setupCleanInternalRepo();
+
+        String path = "org/apache/archiva/maven-metadata.xml";
+        String expectedMetadata = createGroupMetadata( "org.apache.archiva", new String[] { "archivatest-maven-plugin" } );
+
+        populateRepo( repoRootInternal, path, expectedMetadata );
+
+        // --- Execution
+        String actualMetadata = requestMetadataOK( path );
+
+        // --- Verification
+        assertExpectedMetadata( expectedMetadata, actualMetadata );
+    }
 }
index 63eaf241672e8a31064d25b8fb3e3419ced9215c..f7db72da9e00c934307177e8014712bb5876a41a 100644 (file)
@@ -139,4 +139,28 @@ public class RepositoryServletProxiedMetadataRemoteOnlyTest
         // --- Verification
         assertExpectedMetadata( expectedMetadata, actualMetadata );
     }
+
+    public void testGetProxiedGroupMetadataRemoteOnly()
+        throws Exception
+    {
+        // --- Setup
+        setupSnapshotsRemoteRepo();
+        setupPrivateSnapshotsRemoteRepo();
+        setupCleanInternalRepo();
+
+        String path = "org/apache/archiva/maven-metadata.xml";
+        String expectedMetadata = createGroupMetadata( "org.apache.archiva", new String[] { "archivatest-maven-plugin" } );
+
+        File managedFile = populateRepo( remoteSnapshots, path, expectedMetadata );
+
+        setupConnector( REPOID_INTERNAL, remoteSnapshots );
+        setupConnector( REPOID_INTERNAL, remotePrivateSnapshots );
+        saveConfiguration();
+
+        // --- Execution
+        String actualMetadata = requestMetadataOK( path );
+
+        // --- Verification
+        assertExpectedMetadata( expectedMetadata, actualMetadata );
+    }
 }