]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1512] api to configure RepositoryScanningConfiguration
authorOlivier Lamy <olamy@apache.org>
Fri, 9 Sep 2011 08:32:59 +0000 (08:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 9 Sep 2011 08:32:59 +0000 (08:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167034 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/scanning/RepositoryScanningAction.java

index 58ac3a0877f661a968fa23daf4aed1e955e64eb3..ed461dbb96bc6ac3cbed904643cb51b1def27f6a 100644 (file)
           </association>
         </field>
       </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+          <code><![CDATA[
+
+            @Override
+            public boolean equals( Object o )
+            {
+                if ( this == o )
+                {
+                    return true;
+                }
+                if ( o == null || getClass() != o.getClass() )
+                {
+                    return false;
+                }
+
+                FileType fileType = (FileType) o;
+
+                if ( id != null ? !id.equals( fileType.id ) : fileType.id != null )
+                {
+                    return false;
+                }
+
+                return true;
+            }
+
+            @Override
+            public int hashCode()
+            {
+                return id != null ? 37 + id.hashCode() : 0;
+            }
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
     </class>
 
     <!--
index 61fc21ba88a5584650c4f7e85982babe05fd17b9..57289303b817ed9dd4479eac4d66f5124140cafd 100644 (file)
@@ -38,4 +38,38 @@ public interface ArchivaAdministration
 
     void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
         throws RepositoryAdminException;
+
+    RepositoryScanning getRepositoryScanning()
+        throws RepositoryAdminException;
+
+    void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    FileType getFileType( String fileTypeId )
+        throws RepositoryAdminException;
+
+    void addFileType( FileType fileType, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void removeFileType( String fileTypeId, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void addInvalidContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
+    void removeInvalidContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException;
+
 }
index ec07874c3a67d967004081d06e78cbfbb3202552..2d50de92f94933a1761f46ac560557a81de8c2a0 100644 (file)
@@ -22,7 +22,10 @@ import net.sf.beanlib.provider.replicator.BeanReplicator;
 import org.apache.archiva.admin.AuditInformation;
 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
 import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.archiva.audit.AuditEvent;
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.configuration.Configuration;
+import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
@@ -46,6 +49,7 @@ public class DefaultArchivaAdministration
                 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
         }
         return legacyArtifactPaths;
+
     }
 
     public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
@@ -57,6 +61,7 @@ public class DefaultArchivaAdministration
                                                                                  org.apache.maven.archiva.configuration.LegacyArtifactPath.class ) );
 
         saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
     }
 
     public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
@@ -70,5 +75,144 @@ public class DefaultArchivaAdministration
         configuration.removeLegacyArtifactPath( legacyArtifactPath );
 
         saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
+    }
+
+    public void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+        configuration.setRepositoryScanning(
+            new BeanReplicator().replicateBean( repositoryScanning, RepositoryScanningConfiguration.class ) );
+
+        saveConfiguration( configuration );
+    }
+
+    public RepositoryScanning getRepositoryScanning()
+        throws RepositoryAdminException
+    {
+        return new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
+                                                   RepositoryScanning.class );
+    }
+
+    public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+        org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
+        if ( fileType == null )
+        {
+            return;
+        }
+        fileType.addPattern( pattern );
+
+        saveConfiguration( configuration );
+    }
+
+    public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+        org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
+        if ( fileType == null )
+        {
+            return;
+        }
+        fileType.removePattern( pattern );
+
+        saveConfiguration( configuration );
+    }
+
+    public FileType getFileType( String fileTypeId )
+        throws RepositoryAdminException
+    {
+        org.apache.maven.archiva.configuration.FileType fileType =
+            getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
+        if ( fileType == null )
+        {
+            return null;
+        }
+        return new BeanReplicator().replicateBean( fileType, FileType.class );
+    }
+
+    public void addFileType( FileType fileType, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        if ( getFileTypeById( fileType.getId(), configuration ) != null )
+        {
+            throw new RepositoryAdminException(
+                "impossible to FileType with id " + fileType.getId() + " already exists" );
+        }
+
+        configuration.getRepositoryScanning().addFileType(
+            new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
+        saveConfiguration( configuration );
+    }
+
+    public void removeFileType( String fileTypeId, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        org.apache.maven.archiva.configuration.FileType fileType =
+            new org.apache.maven.archiva.configuration.FileType();
+        fileType.setId( fileTypeId );
+        configuration.getRepositoryScanning().removeFileType( fileType );
+        saveConfiguration( configuration );
+    }
+
+    public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
+        saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
+    }
+
+    public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
+        saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
+    }
+
+    public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
+        saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
+    }
+
+    public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
+        saveConfiguration( configuration );
+        triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
+    }
+
+//-------------------------
+    //
+    //-------------------------
+
+    private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
+    {
+        for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
+        {
+            if ( StringUtils.equals( id, fileType.getId() ) )
+            {
+                return fileType;
+            }
+        }
+        return null;
     }
 }
index eba5b262ce91e64702aae982eec734b82cde80f1..8f3a3f24d0e3bcaf34ab0751042bd167320f1924 100644 (file)
@@ -79,6 +79,11 @@ public class FileType
         getPatterns().add( pattern );
     }
 
+    public void removePattern( String pattern )
+    {
+        getPatterns().remove( pattern );
+    }
+
     @Override
     public boolean equals( Object o )
     {
@@ -106,4 +111,15 @@ public class FileType
     {
         return id != null ? 37 + id.hashCode() : 0;
     }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( "FileType" );
+        sb.append( "{id='" ).append( id ).append( '\'' );
+        sb.append( ", patterns=" ).append( patterns );
+        sb.append( '}' );
+        return sb.toString();
+    }
 }
index 2bb9db987c356e8e0f06d3ac1f1122a97d0d26ff..7a91b89e9d0f7319a45702ed1e0f3010b6727552 100644 (file)
@@ -18,8 +18,6 @@ package org.apache.archiva.admin.repository.admin;
  * under the License.
  */
 
-import org.apache.maven.archiva.configuration.FileType;
-
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
index 8e1afed25d48bf239d637d08c1bb8c8562a48f22..9a9629fe448e391516381b723c4649937dc7d0a7 100644 (file)
@@ -19,9 +19,11 @@ package org.apache.archiva.admin.repository.admin;
  */
 
 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
 import org.junit.Test;
 
 import javax.inject.Inject;
+import java.util.Arrays;
 
 /**
  * @author Olivier Lamy
@@ -34,7 +36,7 @@ public class ArchivaAdministrationTest
 
 
     @Test
-    public void getAll()
+    public void getAllLegacyPaths()
         throws Exception
     {
         assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
@@ -43,7 +45,7 @@ public class ArchivaAdministrationTest
         log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
     }
 
-    public void addAndDelete()
+    public void addAndDeleteLegacyPath()
         throws Exception
     {
         int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
@@ -60,4 +62,44 @@ public class ArchivaAdministrationTest
             archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
         assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
     }
+
+    @Test
+    public void addAndUpdateAndDeleteFileType()
+        throws RepositoryAdminException
+    {
+        int initialSize = archivaAdministration.getRepositoryScanning().getFileTypes().size();
+
+        FileType fileType = new FileType();
+        fileType.setId( "foo" );
+        fileType.setPatterns( Arrays.asList( "bar", "toto" ) );
+
+        archivaAdministration.addFileType( fileType, getFakeAuditInformation() );
+
+        assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+        archivaAdministration.addFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
+
+        assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+        assertEquals( 3, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
+
+        assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
+        assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
+        assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
+
+        archivaAdministration.removeFileTypePattern( "foo", "zorro", getFakeAuditInformation() );
+
+        assertEquals( initialSize + 1, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+
+        assertEquals( 2, archivaAdministration.getFileType( "foo" ).getPatterns().size() );
+
+        assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "bar" ) );
+        assertTrue( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "toto" ) );
+        assertFalse( archivaAdministration.getFileType( "foo" ).getPatterns().contains( "zorro" ) );
+
+        archivaAdministration.removeFileType( "foo", getFakeAuditInformation() );
+
+        assertEquals( initialSize, archivaAdministration.getRepositoryScanning().getFileTypes().size() );
+        assertNull( archivaAdministration.getFileType( "foo" ) );
+    }
 }
index 9079034d38fc664120f7e0d747b932018e8ce43a..a260234f770154b61a16934129e9eb288fcc585f 100644 (file)
@@ -140,6 +140,29 @@ public class RepositoryScanningAction
         return saveConfiguration();
     }
 
+    public String removeFiletypePattern()
+    {
+        log.info( "Remove File Type Pattern [" + getFileTypeId() + ":" + getPattern() + "]" );
+
+        if ( !isValidFiletypeCommand() )
+        {
+            return INPUT;
+        }
+
+        FileType filetype = findFileType( getFileTypeId() );
+        if ( filetype == null )
+        {
+            addActionError( "Pattern not removed, unable to find filetype " + getFileTypeId() );
+            return INPUT;
+        }
+
+        filetype.removePattern( getPattern() );
+
+        triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
+
+        return saveConfiguration();
+    }
+
     public String getFileTypeId()
     {
         return fileTypeId;
@@ -192,9 +215,8 @@ public class RepositoryScanningAction
         CollectionUtils.forAllDo( reposcanning.getFileTypes(), filetypeToMapClosure );
         fileTypeMap = filetypeToMapClosure.getMap();
 
-        AddAdminRepoConsumerClosure addAdminRepoConsumer;
-
-        addAdminRepoConsumer = new AddAdminRepoConsumerClosure( reposcanning.getKnownContentConsumers() );
+        AddAdminRepoConsumerClosure addAdminRepoConsumer =
+            new AddAdminRepoConsumerClosure( reposcanning.getKnownContentConsumers() );
         CollectionUtils.forAllDo( repoconsumerUtil.getAvailableKnownConsumers(), addAdminRepoConsumer );
         this.knownContentConsumers = addAdminRepoConsumer.getList();
         Collections.sort( knownContentConsumers, AdminRepositoryConsumerComparator.getInstance() );
@@ -209,29 +231,6 @@ public class RepositoryScanningAction
         Collections.sort( fileTypeIds );
     }
 
-    public String removeFiletypePattern()
-    {
-        log.info( "Remove File Type Pattern [" + getFileTypeId() + ":" + getPattern() + "]" );
-
-        if ( !isValidFiletypeCommand() )
-        {
-            return INPUT;
-        }
-
-        FileType filetype = findFileType( getFileTypeId() );
-        if ( filetype == null )
-        {
-            addActionError( "Pattern not removed, unable to find filetype " + getFileTypeId() );
-            return INPUT;
-        }
-
-        filetype.removePattern( getPattern() );
-
-        triggerAuditEvent( AuditEvent.REMOVE_PATTERN + " " + pattern );
-
-        return saveConfiguration();
-    }
-
     public void setFileTypeId( String fileTypeId )
     {
         this.fileTypeId = fileTypeId;