summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorOlivier Lamy <olamy@apache.org>2011-11-02 22:30:08 +0000
committerOlivier Lamy <olamy@apache.org>2011-11-02 22:30:08 +0000
commit43eae0e795122cfd4db1aacad9fba6fbad88cbac (patch)
treeddc3e9f79ca7c017c8d7a0dca7d93c5df4a13330 /archiva-modules/archiva-base
parent546014d1946edb769bd6dceb7db53a6cd23a974e (diff)
downloadarchiva-43eae0e795122cfd4db1aacad9fba6fbad88cbac.tar.gz
archiva-43eae0e795122cfd4db1aacad9fba6fbad88cbac.zip
add a convenient method to create index in repository admin service
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196836 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java11
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java82
2 files changed, 89 insertions, 4 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
index ff3c1ed03..156f7b6d3 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-api/src/main/java/org/apache/archiva/admin/model/managed/ManagedRepositoryAdmin.java
@@ -22,6 +22,7 @@ package org.apache.archiva.admin.model.managed;
import org.apache.archiva.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.maven.index.context.IndexingContext;
import java.util.List;
import java.util.Map;
@@ -53,5 +54,15 @@ public interface ManagedRepositoryAdmin
AuditInformation auditInformation, boolean resetStats )
throws RepositoryAdminException;
+ /**
+ *
+ * @param repository
+ * @return
+ * @throws RepositoryAdminException
+ * @since 1.4-M2
+ */
+ IndexingContext createIndexContext( ManagedRepository repository )
+ throws RepositoryAdminException;
+
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
index 15d2bc823..5348630a2 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
@@ -24,8 +24,13 @@ import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent;
+import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.RepositorySession;
@@ -37,12 +42,10 @@ import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.GenericValidator;
-import org.apache.archiva.configuration.Configuration;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.configuration.ProxyConnectorConfiguration;
-import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.maven.index.NexusIndexer;
+import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
+import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.redback.role.RoleManager;
import org.codehaus.plexus.redback.role.RoleManagerException;
import org.codehaus.plexus.taskqueue.TaskQueueException;
@@ -51,10 +54,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -93,10 +98,23 @@ public class DefaultManagedRepositoryAdmin
@Inject
private PlexusSisuBridge plexusSisuBridge;
+ @Inject
+ private MavenIndexerUtils mavenIndexerUtils;
@Inject
protected RoleManager roleManager;
+ @PostConstruct
+ private void initialize()
+ throws RepositoryAdminException
+ {
+ // initialize index context on start
+ for ( ManagedRepository managedRepository : getManagedRepositories() )
+ {
+ createIndexContext( managedRepository );
+ }
+ }
+
public List<ManagedRepository> getManagedRepositories()
throws RepositoryAdminException
{
@@ -494,6 +512,62 @@ public class DefaultManagedRepositoryAdmin
}
configuration.addManagedRepository( repository );
+
+ }
+
+ public IndexingContext createIndexContext( ManagedRepository repository )
+ throws RepositoryAdminException
+ {
+ try
+ {
+ List<? extends IndexCreator> indexCreators = mavenIndexerUtils.getAllIndexCreators();
+ NexusIndexer indexer = plexusSisuBridge.lookup( NexusIndexer.class );
+
+ IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
+
+ if ( context != null )
+ {
+ log.debug( "skip adding repository with id {} as already exists", repository.getId() );
+ return context;
+ }
+
+ String indexDir = repository.getIndexDirectory();
+ File managedRepository = new File( repository.getLocation() );
+
+ File indexDirectory = null;
+ if ( indexDir != null && !"".equals( indexDir ) )
+ {
+ indexDirectory = new File( repository.getIndexDirectory() );
+ }
+ else
+ {
+ indexDirectory = new File( managedRepository, ".indexer" );
+ }
+
+ context =
+ indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
+ managedRepository.toURI().toURL().toExternalForm(),
+ indexDirectory.toURI().toURL().toString(), indexCreators );
+
+ context.setSearchable( repository.isScanned() );
+ return context;
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new RepositoryAdminException( e.getMessage(), e );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryAdminException( e.getMessage(), e );
+ }
+ catch ( PlexusSisuBridgeException e )
+ {
+ throw new RepositoryAdminException( e.getMessage(), e );
+ }
+ catch ( UnsupportedExistingLuceneIndexException e )
+ {
+ throw new RepositoryAdminException( e.getMessage(), e );
+ }
}
private ManagedRepositoryConfiguration getStageRepoConfig( ManagedRepositoryConfiguration repository )