[MRM-1512] api to configure RepositoryScanningConfiguration

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1167034 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-09 08:32:59 +00:00
parent 5b7476e8d6
commit 9a7ab73755
7 changed files with 298 additions and 30 deletions

View File

@ -1092,6 +1092,41 @@
</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>
<!--

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

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

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

View 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;

View 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" ) );
}
}

View 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;