Browse Source

[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
tags/archiva-1.4-M1
Olivier Lamy 12 years ago
parent
commit
1bb10ee01e

+ 28
- 0
archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo View File

@@ -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;
}
]]></code>
</codeSegment>
</codeSegments>

+ 3
- 1
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/AbstractRepositoryAdmin.java View 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>();

+ 40
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/ArchivaAdministration.java View File

@@ -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;
}

+ 73
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java View File

@@ -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 );
}
}

+ 109
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/FileType.java View File

@@ -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;
}
}

+ 141
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/LegacyArtifactPath.java View File

@@ -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();
}
}

+ 102
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/admin/RepositoryScanning.java View File

@@ -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;
}
}

+ 63
- 0
archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java View File

@@ -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() );
}
}

Loading…
Cancel
Save