From 1bb10ee01e2f32135eeaf12a6639cacd75563e04 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 8 Sep 2011 20:15:23 +0000 Subject: [PATCH] [MRM-1511] api to configure LegacyArtifactPath create services 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 --- .../src/main/mdo/configuration.mdo | 28 ++++ .../repository/AbstractRepositoryAdmin.java | 4 +- .../admin/ArchivaAdministration.java | 40 +++++ .../admin/DefaultArchivaAdministration.java | 73 +++++++++ .../admin/repository/admin/FileType.java | 109 ++++++++++++++ .../repository/admin/LegacyArtifactPath.java | 141 ++++++++++++++++++ .../repository/admin/RepositoryScanning.java | 102 +++++++++++++ .../admin/ArchivaAdministrationTest.java | 63 ++++++++ 8 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java create mode 100644 archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index c31a7e531..58ac3a087 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -646,6 +646,34 @@ { 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; + } ]]> diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java index c5bcc3bdc..d917a6a48 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java @@ -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 auditListeners = new ArrayList(); 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 index 000000000..589e9a78c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java @@ -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 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 index 000000000..ac2b89e56 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -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 getLegacyArtifactPaths() + throws RepositoryAdminException + { + List legacyArtifactPaths = new ArrayList(); + 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 index 000000000..eba5b262c --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java @@ -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 patterns; + + public FileType() + { + // no op + } + + public FileType( String id, List patterns ) + { + this.id = id; + this.patterns = patterns; + } + + public String getId() + { + return id; + } + + public void setId( String id ) + { + this.id = id; + } + + public List getPatterns() + { + if ( patterns == null ) + { + this.patterns = new ArrayList(); + } + return patterns; + } + + public void setPatterns( List 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 index 000000000..e9489489e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java @@ -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 index 000000000..2bb9db987 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java @@ -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 fileTypes; + + /** + * Field knownContentConsumers. + */ + private List knownContentConsumers; + + /** + * Field invalidContentConsumers. + */ + private List invalidContentConsumers; + + public RepositoryScanning() + { + // no op + } + + public RepositoryScanning( List fileTypes, List knownContentConsumers, + List invalidContentConsumers ) + { + this.fileTypes = fileTypes; + this.knownContentConsumers = knownContentConsumers; + this.invalidContentConsumers = invalidContentConsumers; + } + + public List getFileTypes() + { + if ( this.fileTypes == null ) + { + this.fileTypes = new ArrayList(); + } + return fileTypes; + } + + public void setFileTypes( List fileTypes ) + { + this.fileTypes = fileTypes; + } + + public List getKnownContentConsumers() + { + if ( this.knownContentConsumers == null ) + { + this.knownContentConsumers = new ArrayList(); + } + return knownContentConsumers; + } + + public void setKnownContentConsumers( List knownContentConsumers ) + { + this.knownContentConsumers = knownContentConsumers; + } + + public List getInvalidContentConsumers() + { + if ( this.invalidContentConsumers == null ) + { + this.invalidContentConsumers = new ArrayList(); + } + return invalidContentConsumers; + } + + public void setInvalidContentConsumers( List 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 index 000000000..76f283c3f --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java @@ -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() ); + } +} -- 2.39.5