]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1511] api to configure LegacyArtifactPath create services
authorOlivier Lamy <olamy@apache.org>
Thu, 8 Sep 2011 20:15:23 +0000 (20:15 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 8 Sep 2011 20:15:23 +0000 (20:15 +0000)
and add some beans for other archiva admin service

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166882 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/AbstractRepositoryAdmin.java
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java [new file with mode: 0644]

index c31a7e5314472ff1f3f5d0d83aae96eaaba2baff..58ac3a0877f661a968fa23daf4aed1e955e64eb3 100644 (file)
     {
         return artifact.split( ":" )[4];
     }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+
+        LegacyArtifactPath that = (LegacyArtifactPath) o;
+
+        if ( path != null ? !path.equals( that.path ) : that.path != null )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return path != null ? 37 + path.hashCode() : 0;
+    }
        ]]></code>
         </codeSegment>
       </codeSegments>
index c5bcc3bdce554e1e559d4df464df722b582ef96b..d917a6a48a5f0633dc9229873bb08d84999503ee 100644 (file)
@@ -24,10 +24,11 @@ import org.apache.archiva.audit.AuditListener;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
-import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
 import org.codehaus.plexus.redback.users.User;
 import org.codehaus.plexus.registry.Registry;
 import org.codehaus.plexus.registry.RegistryException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
 import javax.inject.Named;
@@ -40,6 +41,7 @@ import java.util.List;
  */
 public abstract class AbstractRepositoryAdmin
 {
+    protected Logger log = LoggerFactory.getLogger( getClass() );
 
     @Inject
     private List<AuditListener> auditListeners = new ArrayList<AuditListener>();
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java
new file mode 100644 (file)
index 0000000..589e9a7
--- /dev/null
@@ -0,0 +1,40 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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.admin.repository.RepositoryAdminException;
+
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public interface ArchivaAdministration
+{
+
+    List<LegacyArtifactPath> getLegacyArtifactPaths()
+        throws RepositoryAdminException;
+
+    void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
+        throws RepositoryAdminException;
+
+    void deleteLegacyArtifactPath( String path )
+        throws RepositoryAdminException;
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java
new file mode 100644 (file)
index 0000000..ac2b89e
--- /dev/null
@@ -0,0 +1,73 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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 net.sf.beanlib.provider.replicator.BeanReplicator;
+import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
+import org.apache.archiva.admin.repository.RepositoryAdminException;
+import org.apache.maven.archiva.configuration.Configuration;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service("archivaAdministration#default")
+public class DefaultArchivaAdministration
+    extends AbstractRepositoryAdmin
+    implements ArchivaAdministration
+{
+    public List<LegacyArtifactPath> getLegacyArtifactPaths()
+        throws RepositoryAdminException
+    {
+        List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
+        for ( org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath : getArchivaConfiguration().getConfiguration().getLegacyArtifactPaths() )
+        {
+            legacyArtifactPaths.add(
+                new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
+        }
+        return legacyArtifactPaths;
+    }
+
+    public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+
+        configuration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
+                                                                                 org.apache.maven.archiva.configuration.LegacyArtifactPath.class ) );
+
+        saveConfiguration( configuration );
+    }
+
+    public void deleteLegacyArtifactPath( String path )
+        throws RepositoryAdminException
+    {
+        Configuration configuration = getArchivaConfiguration().getConfiguration();
+        org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath =
+            new org.apache.maven.archiva.configuration.LegacyArtifactPath();
+
+        legacyArtifactPath.setPath( path );
+        configuration.removeLegacyArtifactPath( legacyArtifactPath );
+
+        saveConfiguration( configuration );
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java
new file mode 100644 (file)
index 0000000..eba5b26
--- /dev/null
@@ -0,0 +1,109 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public class FileType
+    implements Serializable
+{
+    /**
+     * Field id.
+     */
+    private String id;
+
+    /**
+     * Field patterns.
+     */
+    private List<String> patterns;
+
+    public FileType()
+    {
+        // no op
+    }
+
+    public FileType( String id, List<String> patterns )
+    {
+        this.id = id;
+        this.patterns = patterns;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setId( String id )
+    {
+        this.id = id;
+    }
+
+    public List<String> getPatterns()
+    {
+        if ( patterns == null )
+        {
+            this.patterns = new ArrayList<String>();
+        }
+        return patterns;
+    }
+
+    public void setPatterns( List<String> patterns )
+    {
+        this.patterns = patterns;
+    }
+
+    public void addPattern( String pattern )
+    {
+        getPatterns().add( pattern );
+    }
+
+    @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;
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java
new file mode 100644 (file)
index 0000000..e948948
--- /dev/null
@@ -0,0 +1,141 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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.Serializable;
+
+/**
+ * @author Olivier Lamy
+ * @since 1.4
+ */
+public class LegacyArtifactPath
+    implements Serializable
+{
+    /**
+     * The legacy path.
+     */
+    private String path;
+
+    /**
+     * The artifact reference, as " [groupId] :
+     * [artifactId] : [version] : [classifier] : [type] ".
+     */
+    private String artifact;
+
+    public LegacyArtifactPath()
+    {
+        // no op
+    }
+
+    public LegacyArtifactPath( String path, String artifact )
+    {
+        this.path = path;
+        this.artifact = artifact;
+    }
+
+    public String getPath()
+    {
+        return path;
+    }
+
+    public void setPath( String path )
+    {
+        this.path = path;
+    }
+
+    public String getArtifact()
+    {
+        return artifact;
+    }
+
+    public void setArtifact( String artifact )
+    {
+        this.artifact = artifact;
+    }
+
+    public boolean match( String path )
+    {
+        return path.equals( this.path );
+    }
+
+    public String getGroupId()
+    {
+        return artifact.split( ":" )[0];
+    }
+
+    public String getArtifactId()
+    {
+        return artifact.split( ":" )[1];
+    }
+
+    public String getVersion()
+    {
+        return artifact.split( ":" )[2];
+    }
+
+    public String getClassifier()
+    {
+        String classifier = artifact.split( ":" )[3];
+        return classifier.length() > 0 ? classifier : null;
+    }
+
+    public String getType()
+    {
+        return artifact.split( ":" )[4];
+    }
+
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( this == o )
+        {
+            return true;
+        }
+        if ( o == null || getClass() != o.getClass() )
+        {
+            return false;
+        }
+
+        LegacyArtifactPath that = (LegacyArtifactPath) o;
+
+        if ( path != null ? !path.equals( that.path ) : that.path != null )
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return path != null ? 37 + path.hashCode() : 0;
+    }
+
+    @Override
+    public String toString()
+    {
+        final StringBuilder sb = new StringBuilder();
+        sb.append( "LegacyArtifactPath" );
+        sb.append( "{path='" ).append( path ).append( '\'' );
+        sb.append( ", artifact='" ).append( artifact ).append( '\'' );
+        sb.append( '}' );
+        return sb.toString();
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java
new file mode 100644 (file)
index 0000000..2bb9db9
--- /dev/null
@@ -0,0 +1,102 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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.archiva.configuration.FileType;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+public class RepositoryScanning
+    implements Serializable
+{
+    /**
+     * Field fileTypes.
+     */
+    private List<FileType> fileTypes;
+
+    /**
+     * Field knownContentConsumers.
+     */
+    private List<String> knownContentConsumers;
+
+    /**
+     * Field invalidContentConsumers.
+     */
+    private List<String> invalidContentConsumers;
+
+    public RepositoryScanning()
+    {
+        // no op
+    }
+
+    public RepositoryScanning( List<FileType> fileTypes, List<String> knownContentConsumers,
+                               List<String> invalidContentConsumers )
+    {
+        this.fileTypes = fileTypes;
+        this.knownContentConsumers = knownContentConsumers;
+        this.invalidContentConsumers = invalidContentConsumers;
+    }
+
+    public List<FileType> getFileTypes()
+    {
+        if ( this.fileTypes == null )
+        {
+            this.fileTypes = new ArrayList<FileType>();
+        }
+        return fileTypes;
+    }
+
+    public void setFileTypes( List<FileType> fileTypes )
+    {
+        this.fileTypes = fileTypes;
+    }
+
+    public List<String> getKnownContentConsumers()
+    {
+        if ( this.knownContentConsumers == null )
+        {
+            this.knownContentConsumers = new ArrayList<String>();
+        }
+        return knownContentConsumers;
+    }
+
+    public void setKnownContentConsumers( List<String> knownContentConsumers )
+    {
+        this.knownContentConsumers = knownContentConsumers;
+    }
+
+    public List<String> getInvalidContentConsumers()
+    {
+        if ( this.invalidContentConsumers == null )
+        {
+            this.invalidContentConsumers = new ArrayList<String>();
+        }
+        return invalidContentConsumers;
+    }
+
+    public void setInvalidContentConsumers( List<String> invalidContentConsumers )
+    {
+        this.invalidContentConsumers = invalidContentConsumers;
+    }
+}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java
new file mode 100644 (file)
index 0000000..76f283c
--- /dev/null
@@ -0,0 +1,63 @@
+package org.apache.archiva.admin.repository.admin;
+/*
+ * 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.admin.repository.AbstractRepositoryAdminTest;
+import org.junit.Test;
+
+import javax.inject.Inject;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ArchivaAdministrationTest
+    extends AbstractRepositoryAdminTest
+{
+    @Inject
+    ArchivaAdministration archivaAdministration;
+
+
+    @Test
+    public void getAll()
+        throws Exception
+    {
+        assertNotNull( archivaAdministration.getLegacyArtifactPaths() );
+        assertFalse( archivaAdministration.getLegacyArtifactPaths().isEmpty() );
+        assertEquals( 1, archivaAdministration.getLegacyArtifactPaths().size() );
+        log.info( "all legacy paths {}", archivaAdministration.getLegacyArtifactPaths() );
+    }
+
+    public void addAndDelete()
+        throws Exception
+    {
+        int initialSize = archivaAdministration.getLegacyArtifactPaths().size();
+
+        LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath( "foo", "bar" );
+        archivaAdministration.addLegacyArtifactPath( legacyArtifactPath );
+
+        assertTrue( archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
+        assertEquals( initialSize + 1, archivaAdministration.getLegacyArtifactPaths().size() );
+
+        archivaAdministration.deleteLegacyArtifactPath( legacyArtifactPath.getPath() );
+
+        assertFalse(
+            archivaAdministration.getLegacyArtifactPaths().contains( new LegacyArtifactPath( "foo", "bar" ) ) );
+        assertEquals( initialSize, archivaAdministration.getLegacyArtifactPaths().size() );
+    }
+}