git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@423734 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-0.9-alpha-1
@@ -0,0 +1,31 @@ | |||
package org.apache.maven.repository.configuration; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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. | |||
*/ | |||
/** | |||
* An error changing the configuration | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public class ConfigurationChangeException | |||
extends Exception | |||
{ | |||
public ConfigurationChangeException( String message, Throwable cause ) | |||
{ | |||
super( message, cause ); | |||
} | |||
} |
@@ -28,6 +28,9 @@ public interface ConfigurationChangeListener | |||
* Notify the object that there has been a configuration change. | |||
* | |||
* @param configuration the new configuration | |||
* @throws InvalidConfigurationException if there is a problem with the new configuration | |||
* @throws ConfigurationChangeException if there is a problem changing the configuration, but the configuration is valid | |||
*/ | |||
void notifyOfConfigurationChange( Configuration configuration ); | |||
void notifyOfConfigurationChange( Configuration configuration ) | |||
throws InvalidConfigurationException, ConfigurationChangeException; | |||
} |
@@ -43,5 +43,12 @@ public interface ConfigurationStore | |||
* @param configuration the configuration to store | |||
*/ | |||
void storeConfiguration( Configuration configuration ) | |||
throws ConfigurationStoreException; | |||
throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException; | |||
/** | |||
* Add a configuration change listener. | |||
* | |||
* @param listener the listener | |||
*/ | |||
void addChangeListener( ConfigurationChangeListener listener ); | |||
} |
@@ -106,7 +106,7 @@ public class DefaultConfigurationStore | |||
} | |||
public void storeConfiguration( Configuration configuration ) | |||
throws ConfigurationStoreException | |||
throws ConfigurationStoreException, InvalidConfigurationException, ConfigurationChangeException | |||
{ | |||
for ( Iterator i = listeners.iterator(); i.hasNext(); ) | |||
{ | |||
@@ -133,4 +133,9 @@ public class DefaultConfigurationStore | |||
IOUtil.close( fileWriter ); | |||
} | |||
} | |||
public void addChangeListener( ConfigurationChangeListener listener ) | |||
{ | |||
listeners.add( listener ); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
package org.apache.maven.repository.configuration; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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. | |||
*/ | |||
/** | |||
* An error in the configuration. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public class InvalidConfigurationException | |||
extends Exception | |||
{ | |||
private final String name; | |||
public InvalidConfigurationException( String name, String message, Throwable cause ) | |||
{ | |||
super( message, cause ); | |||
this.name = name; | |||
} | |||
public String getName() | |||
{ | |||
return name; | |||
} | |||
} |
@@ -55,11 +55,18 @@ | |||
</description> | |||
</field> | |||
<field> | |||
<name>discoveryCronExpression</name> | |||
<name>indexerCronExpression</name> | |||
<version>1.0.0</version> | |||
<type>String</type> | |||
<description>When to run the discovery mechanism.</description> | |||
<defaultValue>0 0 8 * * ?</defaultValue> | |||
<description>When to run the indexing mechanism. Default is every hour on the hour.</description> | |||
<defaultValue>0 0 * * * ?</defaultValue> | |||
</field> | |||
<field> | |||
<name>converterCronExpression</name> | |||
<version>1.0.0</version> | |||
<type>String</type> | |||
<description>When to run the converter mechanism. Default is every 4 hours, on the half hour.</description> | |||
<defaultValue>0 30 0/4 * * ?</defaultValue> | |||
</field> | |||
<field> | |||
<name>discoverSnapshots</name> |
@@ -10,6 +10,10 @@ | |||
<artifactId>maven-repository-core</artifactId> | |||
<name>Maven Repository Manager Core</name> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.apache.maven.repository</groupId> | |||
<artifactId>maven-repository-configuration</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.maven.repository</groupId> | |||
<artifactId>maven-repository-converter</artifactId> | |||
@@ -21,7 +25,12 @@ | |||
<dependency> | |||
<groupId>org.apache.maven.repository</groupId> | |||
<artifactId>maven-repository-reports-standard</artifactId> | |||
</dependency> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-quartz</artifactId> | |||
<version>1.0-alpha-2</version> | |||
</dependency> | |||
<!-- Testing --> | |||
<dependency> | |||
<groupId>junit</groupId> |
@@ -0,0 +1,36 @@ | |||
package org.apache.maven.repository.configuration; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.artifact.repository.ArtifactRepository; | |||
/** | |||
* Create an artifact repository from the given configuration. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public interface ConfiguredRepositoryFactory | |||
{ | |||
String ROLE = ConfiguredRepositoryFactory.class.getName(); | |||
/** | |||
* Create an artifact repository from the given configuration. | |||
* | |||
* @param configuration the configuration | |||
*/ | |||
ArtifactRepository createRepository( Configuration configuration ); | |||
} |
@@ -0,0 +1,55 @@ | |||
package org.apache.maven.repository.configuration; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import java.io.File; | |||
import java.util.Map; | |||
/** | |||
* Create artifact repositories from a configuration. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
* @plexus.component role="org.apache.maven.repository.configuration.ConfiguredRepositoryFactory" | |||
*/ | |||
public class DefaultConfiguredRepositoryFactory | |||
implements ConfiguredRepositoryFactory | |||
{ | |||
/** | |||
* @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" | |||
*/ | |||
private Map repositoryLayouts; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ArtifactRepositoryFactory repoFactory; | |||
public ArtifactRepository createRepository( Configuration configuration ) | |||
{ | |||
File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); | |||
String repoDir = repositoryDirectory.toURI().toString(); | |||
ArtifactRepositoryLayout layout = | |||
(ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); | |||
// TODO: real ID | |||
return repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | |||
} | |||
} |
@@ -0,0 +1,164 @@ | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfigurationChangeException; | |||
import org.apache.maven.repository.configuration.ConfigurationChangeListener; | |||
import org.apache.maven.repository.configuration.ConfigurationStore; | |||
import org.apache.maven.repository.configuration.ConfigurationStoreException; | |||
import org.apache.maven.repository.configuration.InvalidConfigurationException; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; | |||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; | |||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; | |||
import org.codehaus.plexus.scheduler.AbstractJob; | |||
import org.codehaus.plexus.scheduler.Scheduler; | |||
import org.quartz.CronTrigger; | |||
import org.quartz.JobDataMap; | |||
import org.quartz.JobDetail; | |||
import org.quartz.SchedulerException; | |||
import java.text.ParseException; | |||
/** | |||
* Default implementation of a scheduling component for the application. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
* @todo should we use plexus-taskqueue instead of or in addition to this? | |||
* @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTaskScheduler" | |||
*/ | |||
public class DefaultRepositoryTaskScheduler | |||
extends AbstractLogEnabled | |||
implements RepositoryTaskScheduler, Startable, ConfigurationChangeListener | |||
{ | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private Scheduler scheduler; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ConfigurationStore configurationStore; | |||
private static final String DISCOVERER_GROUP = "DISCOVERER"; | |||
private static final String INDEXER_JOB = "indexerTask"; | |||
/** | |||
* @plexus.requirement role-hint="indexer" | |||
*/ | |||
private RepositoryTask indexerTask; | |||
public void start() | |||
throws StartingException | |||
{ | |||
Configuration configuration; | |||
try | |||
{ | |||
configuration = configurationStore.getConfigurationFromStore(); | |||
configurationStore.addChangeListener( this ); | |||
} | |||
catch ( ConfigurationStoreException e ) | |||
{ | |||
throw new StartingException( "Unable to read configuration from the store", e ); | |||
} | |||
try | |||
{ | |||
scheduleJobs( configuration ); | |||
} | |||
catch ( ParseException e ) | |||
{ | |||
throw new StartingException( "Invalid configuration: " + configuration.getIndexerCronExpression(), e ); | |||
} | |||
catch ( SchedulerException e ) | |||
{ | |||
throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); | |||
} | |||
} | |||
private void scheduleJobs( Configuration configuration ) | |||
throws ParseException, SchedulerException | |||
{ | |||
JobDetail jobDetail = new JobDetail( INDEXER_JOB, DISCOVERER_GROUP, RepositoryTaskJob.class ); | |||
JobDataMap dataMap = new JobDataMap(); | |||
dataMap.put( AbstractJob.LOGGER, getLogger() ); | |||
dataMap.put( RepositoryTaskJob.TASK_KEY, indexerTask ); | |||
jobDetail.setJobDataMap( dataMap ); | |||
getLogger().info( "Scheduling indexer: " + configuration.getIndexerCronExpression() ); | |||
CronTrigger trigger = | |||
new CronTrigger( INDEXER_JOB + "Trigger", DISCOVERER_GROUP, configuration.getIndexerCronExpression() ); | |||
scheduler.scheduleJob( jobDetail, trigger ); | |||
try | |||
{ | |||
indexerTask.executeNowIfNeeded(); | |||
} | |||
catch ( TaskExecutionException e ) | |||
{ | |||
getLogger().error( "Error executing task first time, continuing anyway: " + e.getMessage(), e ); | |||
} | |||
// TODO: wire in the converter | |||
} | |||
public void stop() | |||
throws StoppingException | |||
{ | |||
try | |||
{ | |||
scheduler.unscheduleJob( INDEXER_JOB, DISCOVERER_GROUP ); | |||
} | |||
catch ( SchedulerException e ) | |||
{ | |||
throw new StoppingException( "Unable to unschedule tasks", e ); | |||
} | |||
} | |||
public void notifyOfConfigurationChange( Configuration configuration ) | |||
throws InvalidConfigurationException, ConfigurationChangeException | |||
{ | |||
try | |||
{ | |||
stop(); | |||
scheduleJobs( configuration ); | |||
} | |||
catch ( StoppingException e ) | |||
{ | |||
throw new ConfigurationChangeException( "Unable to unschedule previous tasks", e ); | |||
} | |||
catch ( ParseException e ) | |||
{ | |||
throw new InvalidConfigurationException( "discoveryCronExpression", "Invalid cron expression", e ); | |||
} | |||
catch ( SchedulerException e ) | |||
{ | |||
throw new ConfigurationChangeException( "Unable to schedule new tasks", e ); | |||
} | |||
} | |||
public void runIndexer() | |||
throws TaskExecutionException | |||
{ | |||
indexerTask.execute(); | |||
} | |||
} |
@@ -0,0 +1,210 @@ | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfigurationStore; | |||
import org.apache.maven.repository.configuration.ConfigurationStoreException; | |||
import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; | |||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||
import org.apache.maven.repository.indexing.MetadataRepositoryIndex; | |||
import org.apache.maven.repository.indexing.PomRepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import java.io.File; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* Task for discovering changes in the repository. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
* @plexus.component role="org.apache.maven.repository.scheduler.RepositoryTask" role-hint="indexer" | |||
*/ | |||
public class IndexerTask | |||
extends AbstractLogEnabled | |||
implements RepositoryTask | |||
{ | |||
/** | |||
* Configuration store. | |||
* | |||
* @plexus.requirement | |||
*/ | |||
private ConfigurationStore configurationStore; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private RepositoryIndexingFactory indexFactory; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ConfiguredRepositoryFactory repoFactory; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" | |||
*/ | |||
private Map artifactDiscoverers; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer" | |||
*/ | |||
private Map metadataDiscoverers; | |||
public void execute() | |||
throws TaskExecutionException | |||
{ | |||
Configuration configuration; | |||
try | |||
{ | |||
configuration = configurationStore.getConfigurationFromStore(); | |||
} | |||
catch ( ConfigurationStoreException e ) | |||
{ | |||
throw new TaskExecutionException( e.getMessage(), e ); | |||
} | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
execute( configuration, indexPath ); | |||
} | |||
private void execute( Configuration configuration, File indexPath ) | |||
throws TaskExecutionException | |||
{ | |||
getLogger().info( "Starting repository discovery process" ); | |||
try | |||
{ | |||
String blacklistedPatterns = configuration.getDiscoveryBlackListPatterns(); | |||
boolean includeSnapshots = configuration.isDiscoverSnapshots(); | |||
ArtifactRepository defaultRepository = repoFactory.createRepository( configuration ); | |||
String layoutProperty = configuration.getRepositoryLayout(); | |||
ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty ); | |||
List artifacts = discoverer.discoverArtifacts( defaultRepository, blacklistedPatterns, includeSnapshots ); | |||
if ( !artifacts.isEmpty() ) | |||
{ | |||
getLogger().info( "Indexing " + artifacts.size() + " new artifacts" ); | |||
indexArtifact( artifacts, indexPath, defaultRepository ); | |||
} | |||
List models = discoverer.discoverStandalonePoms( defaultRepository, blacklistedPatterns, includeSnapshots ); | |||
if ( !models.isEmpty() ) | |||
{ | |||
getLogger().info( "Indexing " + models.size() + " new POMs" ); | |||
indexPom( models, indexPath, defaultRepository ); | |||
} | |||
MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty ); | |||
List metadataList = | |||
metadataDiscoverer.discoverMetadata( new File( defaultRepository.getBasedir() ), blacklistedPatterns ); | |||
if ( !metadataList.isEmpty() ) | |||
{ | |||
getLogger().info( "Indexing " + metadataList.size() + " new metadata files" ); | |||
indexMetadata( metadataList, indexPath, defaultRepository ); | |||
} | |||
} | |||
catch ( RepositoryIndexException e ) | |||
{ | |||
throw new TaskExecutionException( e.getMessage(), e ); | |||
} | |||
getLogger().info( "Finished repository indexing process" ); | |||
} | |||
public void executeNowIfNeeded() | |||
throws TaskExecutionException | |||
{ | |||
Configuration configuration; | |||
try | |||
{ | |||
configuration = configurationStore.getConfigurationFromStore(); | |||
} | |||
catch ( ConfigurationStoreException e ) | |||
{ | |||
throw new TaskExecutionException( e.getMessage(), e ); | |||
} | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
try | |||
{ | |||
ArtifactRepository repository = repoFactory.createRepository( configuration ); | |||
ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath, repository ); | |||
if ( !artifactIndex.indexExists() ) | |||
{ | |||
execute( configuration, indexPath ); | |||
} | |||
} | |||
catch ( RepositoryIndexException e ) | |||
{ | |||
throw new TaskExecutionException( e.getMessage(), e ); | |||
} | |||
} | |||
/** | |||
* Index the artifacts in the list | |||
* | |||
* @param artifacts the artifacts to be indexed | |||
* @param indexPath the path to the index file | |||
* @param repository the repository where the artifacts are located | |||
*/ | |||
protected void indexArtifact( List artifacts, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath, repository ); | |||
artifactIndex.indexArtifacts( artifacts ); | |||
artifactIndex.optimize(); | |||
} | |||
/** | |||
* Index the metadata in the list | |||
* | |||
* @param metadataList the metadata to be indexed | |||
* @param indexPath the path to the index file | |||
*/ | |||
protected void indexMetadata( List metadataList, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex( indexPath, repository ); | |||
metadataIndex.indexMetadata( metadataList ); | |||
metadataIndex.optimize(); | |||
} | |||
/** | |||
* Index the poms in the list | |||
* | |||
* @param models list of poms that will be indexed | |||
* @param indexPath the path to the index | |||
* @param repository the artifact repository where the poms were discovered | |||
*/ | |||
protected void indexPom( List models, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
PomRepositoryIndex pomIndex = indexFactory.createPomRepositoryIndex( indexPath, repository ); | |||
pomIndex.indexPoms( models ); | |||
pomIndex.optimize(); | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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. | |||
*/ | |||
/** | |||
* A repository task. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public interface RepositoryTask | |||
{ | |||
/** | |||
* Execute the task. | |||
*/ | |||
void execute() | |||
throws TaskExecutionException; | |||
/** | |||
* Execute the task now if needed because the target doesn't exist. | |||
*/ | |||
void executeNowIfNeeded() | |||
throws TaskExecutionException; | |||
} |
@@ -1,4 +1,4 @@ | |||
package org.apache.maven.repository.manager.web.job; | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
@@ -16,26 +16,18 @@ package org.apache.maven.repository.manager.web.job; | |||
* limitations under the License. | |||
*/ | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | |||
import org.codehaus.plexus.scheduler.AbstractJob; | |||
import org.quartz.JobDataMap; | |||
import org.quartz.JobExecutionContext; | |||
import org.quartz.JobExecutionException; | |||
import java.net.MalformedURLException; | |||
/** | |||
* This class is the discoverer job that is executed by the scheduler. | |||
* | |||
* @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererJob" | |||
*/ | |||
public class DiscovererJob | |||
public class RepositoryTaskJob | |||
extends AbstractJob | |||
{ | |||
public static final String ROLE = DiscovererJob.class.getName(); | |||
public static final String MAP_DISCOVERER_EXECUTION = "EXECUTION"; | |||
static final String TASK_KEY = "EXECUTION"; | |||
/** | |||
* Execute the discoverer and the indexer. | |||
@@ -49,23 +41,16 @@ public class DiscovererJob | |||
{ | |||
JobDataMap dataMap = context.getJobDetail().getJobDataMap(); | |||
setJobDataMap( dataMap ); | |||
getLogger().info( "[DiscovererJob] Start execution of DiscovererJob.." ); | |||
RepositoryTask executor = (RepositoryTask) dataMap.get( TASK_KEY ); | |||
try | |||
{ | |||
DiscovererExecution execution = (DiscovererExecution) dataMap.get( MAP_DISCOVERER_EXECUTION ); | |||
execution.executeDiscoverer(); | |||
executor.execute(); | |||
} | |||
catch ( RepositoryIndexException e ) | |||
catch ( TaskExecutionException e ) | |||
{ | |||
getLogger().error( "Error indexing: " + e.getMessage(), e ); | |||
throw new JobExecutionException( e ); | |||
} | |||
catch ( MalformedURLException me ) | |||
{ | |||
getLogger().error( "Error indexing: " + me.getMessage(), me ); | |||
} | |||
getLogger().info( "[DiscovererJob] DiscovererJob has finished executing." ); | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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. | |||
*/ | |||
/** | |||
* The component that takes care of scheduling in the application. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public interface RepositoryTaskScheduler | |||
{ | |||
/** | |||
* The Plexus component role. | |||
*/ | |||
String ROLE = RepositoryTaskScheduler.class.getName(); | |||
void runIndexer() | |||
throws TaskExecutionException; | |||
} |
@@ -0,0 +1,31 @@ | |||
package org.apache.maven.repository.scheduler; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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. | |||
*/ | |||
/** | |||
* Exception occurring during task execution. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
*/ | |||
public class TaskExecutionException | |||
extends Exception | |||
{ | |||
public TaskExecutionException( String message, Throwable t ) | |||
{ | |||
super( message, t ); | |||
} | |||
} |
@@ -37,6 +37,16 @@ | |||
<artifactId>sitemesh</artifactId> | |||
<version>2.2.1</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>taglibs</groupId> | |||
<artifactId>standard</artifactId> | |||
<version>1.1.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>jstl</groupId> | |||
<artifactId>jstl</artifactId> | |||
<version>1.1.2</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.plexus</groupId> | |||
<artifactId>plexus-xwork-integration-single</artifactId> |
@@ -19,8 +19,7 @@ package org.apache.maven.repository.manager.web.action; | |||
import com.opensymphony.webwork.interceptor.ParameterAware; | |||
import com.opensymphony.xwork.ActionSupport; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.manager.web.execution.DiscovererExecution; | |||
import org.apache.maven.repository.manager.web.job.DiscovererScheduler; | |||
import org.apache.maven.repository.configuration.ConfigurationStore; | |||
import org.apache.maven.repository.manager.web.utils.ConfigurationManager; | |||
import java.util.HashMap; | |||
@@ -31,25 +30,17 @@ import java.util.Map; | |||
* It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler. | |||
* | |||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="baseAction" | |||
* @todo don't like this as a base and as a forwarding action! | |||
*/ | |||
public class BaseAction | |||
extends ActionSupport | |||
implements ParameterAware | |||
{ | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private DiscovererExecution execution; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private DiscovererScheduler discovererScheduler; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ConfigurationManager configManager; | |||
private ConfigurationStore configurationStore; | |||
private Map parameters; | |||
@@ -72,18 +63,17 @@ public class BaseAction | |||
{ | |||
try | |||
{ | |||
Configuration config = configManager.getConfiguration(); | |||
Configuration config = configurationStore.getConfigurationFromStore(); | |||
Map parameters = new HashMap(); | |||
parameters.put( ConfigurationManager.INDEXPATH, config.getIndexPath() ); | |||
parameters.put( ConfigurationManager.MIN_INDEXPATH, config.getMinimalIndexPath() ); | |||
parameters.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, config.getDiscoveryBlackListPatterns() ); | |||
parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, Boolean.valueOf( config.isDiscoverSnapshots() ) ); | |||
parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getDiscoveryCronExpression() ); | |||
parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getIndexerCronExpression() ); | |||
this.parameters = parameters; | |||
//Configuration configuration = new Configuration(); // TODO! | |||
// execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) ); | |||
discovererScheduler.setSchedule( config.getDiscoveryCronExpression() ); | |||
} | |||
catch ( Exception e ) | |||
{ |
@@ -18,9 +18,8 @@ package org.apache.maven.repository.manager.web.action; | |||
import com.opensymphony.xwork.Action; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; | |||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | |||
@@ -30,7 +29,6 @@ import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||
import java.io.File; | |||
import java.net.MalformedURLException; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* Searches for searchString in all indexed fields. | |||
@@ -57,12 +55,7 @@ public class GeneralSearchAction | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ArtifactRepositoryFactory repositoryFactory; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" | |||
*/ | |||
private Map repositoryLayouts; | |||
private ConfiguredRepositoryFactory repositoryFactory; | |||
public String execute() | |||
throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException | |||
@@ -72,14 +65,7 @@ public class GeneralSearchAction | |||
Configuration configuration = new Configuration(); // TODO! | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
// TODO: [!] repository should only have been instantiated once | |||
File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); | |||
String repoDir = repositoryDirectory.toURL().toString(); | |||
ArtifactRepositoryLayout layout = | |||
(ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); | |||
ArtifactRepository repository = | |||
repositoryFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | |||
ArtifactRepository repository = repositoryFactory.createRepository( configuration ); | |||
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); | |||
@@ -18,9 +18,8 @@ package org.apache.maven.repository.manager.web.action; | |||
import com.opensymphony.xwork.Action; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; | |||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
@@ -32,7 +31,6 @@ import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | |||
import java.io.File; | |||
import java.net.MalformedURLException; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* Search by package name. | |||
@@ -54,15 +52,10 @@ public class PackageSearchAction | |||
*/ | |||
private RepositoryIndexingFactory factory; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" | |||
*/ | |||
private Map repositoryLayouts; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ArtifactRepositoryFactory repositoryFactory; | |||
private ConfiguredRepositoryFactory repositoryFactory; | |||
/** | |||
* @plexus.requirement | |||
@@ -93,13 +86,7 @@ public class PackageSearchAction | |||
Configuration configuration = new Configuration(); | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); | |||
String repoDir = repositoryDirectory.toURL().toString(); | |||
ArtifactRepositoryLayout layout = | |||
(ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); | |||
ArtifactRepository repository = | |||
repositoryFactory.createArtifactRepository( "repository", repoDir, layout, null, null ); | |||
ArtifactRepository repository = repositoryFactory.createRepository( configuration ); | |||
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); | |||
@@ -18,11 +18,10 @@ package org.apache.maven.repository.manager.web.action; | |||
import com.opensymphony.xwork.ActionSupport; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfigurationStore; | |||
import org.apache.maven.repository.configuration.ConfigurationStoreException; | |||
import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; | |||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | |||
@@ -50,7 +49,7 @@ public class QuickSearchAction | |||
/** | |||
* Search results. | |||
*/ | |||
private List searchResult; | |||
private List searchResults; | |||
/** | |||
* @plexus.requirement | |||
@@ -65,7 +64,7 @@ public class QuickSearchAction | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ArtifactRepositoryFactory repositoryFactory; | |||
private ConfiguredRepositoryFactory repositoryFactory; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" | |||
@@ -88,7 +87,7 @@ public class QuickSearchAction | |||
Configuration configuration = configurationStore.getConfigurationFromStore(); | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
ArtifactRepository repository = getDefaultRepository( configuration ); | |||
ArtifactRepository repository = repositoryFactory.createRepository( configuration ); | |||
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository ); | |||
@@ -98,23 +97,11 @@ public class QuickSearchAction | |||
return ERROR; | |||
} | |||
searchResult = searchLayer.searchGeneral( q, index ); | |||
searchResults = searchLayer.searchGeneral( q, index ); | |||
return SUCCESS; | |||
} | |||
private ArtifactRepository getDefaultRepository( Configuration configuration ) | |||
throws MalformedURLException | |||
{ | |||
// TODO: [!] repository should only have been instantiated once | |||
File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); | |||
String repoDir = repositoryDirectory.toURI().toURL().toString(); | |||
ArtifactRepositoryLayout layout = | |||
(ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); | |||
return repositoryFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | |||
} | |||
public String doInput() | |||
{ | |||
return INPUT; | |||
@@ -130,9 +117,9 @@ public class QuickSearchAction | |||
this.q = q; | |||
} | |||
public List getSearchResult() | |||
public List getSearchResults() | |||
{ | |||
return searchResult; | |||
return searchResults; | |||
} | |||
} |
@@ -20,8 +20,10 @@ import com.opensymphony.xwork.ActionSupport; | |||
import com.opensymphony.xwork.ModelDriven; | |||
import com.opensymphony.xwork.Preparable; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.configuration.ConfigurationChangeException; | |||
import org.apache.maven.repository.configuration.ConfigurationStore; | |||
import org.apache.maven.repository.configuration.ConfigurationStoreException; | |||
import org.apache.maven.repository.configuration.InvalidConfigurationException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexSearchException; | |||
import org.codehaus.plexus.util.StringUtils; | |||
@@ -49,7 +51,8 @@ public class ConfigureAction | |||
private Configuration configuration; | |||
public String execute() | |||
throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException | |||
throws IOException, RepositoryIndexException, RepositoryIndexSearchException, ConfigurationStoreException, | |||
InvalidConfigurationException, ConfigurationChangeException | |||
{ | |||
// TODO: if this didn't come from the form, go to configure.action instead of going through with re-saving what was just loaded | |||
@@ -98,7 +101,7 @@ public class ConfigureAction | |||
} | |||
public void prepare() | |||
throws Exception | |||
throws ConfigurationStoreException | |||
{ | |||
configuration = configurationStore.getConfigurationFromStore(); | |||
} |
@@ -0,0 +1,43 @@ | |||
package org.apache.maven.repository.manager.web.action.admin; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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 com.opensymphony.xwork.ActionSupport; | |||
import org.apache.maven.repository.scheduler.RepositoryTaskScheduler; | |||
import org.apache.maven.repository.scheduler.TaskExecutionException; | |||
/** | |||
* Configures the application. | |||
* | |||
* @plexus.component role="com.opensymphony.xwork.Action" role-hint="runIndexerAction" | |||
*/ | |||
public class RunIndexerAction | |||
extends ActionSupport | |||
{ | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private RepositoryTaskScheduler taskScheduler; | |||
public String execute() | |||
throws TaskExecutionException | |||
{ | |||
taskScheduler.runIndexer(); | |||
return SUCCESS; | |||
} | |||
} |
@@ -1,188 +0,0 @@ | |||
package org.apache.maven.repository.manager.web.execution; | |||
/* | |||
* Copyright 2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.lucene.index.IndexReader; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import org.apache.maven.repository.configuration.Configuration; | |||
import org.apache.maven.repository.discovery.ArtifactDiscoverer; | |||
import org.apache.maven.repository.discovery.MetadataDiscoverer; | |||
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; | |||
import org.apache.maven.repository.indexing.MetadataRepositoryIndex; | |||
import org.apache.maven.repository.indexing.PomRepositoryIndex; | |||
import org.apache.maven.repository.indexing.RepositoryIndexException; | |||
import org.apache.maven.repository.indexing.RepositoryIndexingFactory; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import java.io.File; | |||
import java.net.MalformedURLException; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* This is the class that executes the discoverer and indexer. | |||
* | |||
* @plexus.component role="org.apache.maven.repository.manager.web.execution.DiscovererExecution" | |||
* @todo note that a legacy repository will fail due to lack of metadata discoverer | |||
*/ | |||
public class DiscovererExecution | |||
extends AbstractLogEnabled | |||
{ | |||
/** | |||
* @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" | |||
*/ | |||
private Map artifactDiscoverers; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer" | |||
*/ | |||
private Map metadataDiscoverers; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private RepositoryIndexingFactory indexFactory; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private ArtifactRepositoryFactory repoFactory; | |||
/** | |||
* @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" | |||
*/ | |||
private Map repositoryLayouts; | |||
/** | |||
* Executes discoverer and indexer if an index does not exist yet | |||
* | |||
* @param indexDir | |||
* @throws MalformedURLException | |||
* @throws RepositoryIndexException | |||
*/ | |||
public void executeDiscovererIfIndexDoesNotExist( File indexDir ) | |||
throws MalformedURLException, RepositoryIndexException | |||
{ | |||
boolean isExisting = false; | |||
if ( IndexReader.indexExists( indexDir ) ) | |||
{ | |||
isExisting = true; | |||
} | |||
if ( !isExisting ) | |||
{ | |||
executeDiscoverer(); | |||
} | |||
} | |||
/** | |||
* Method that executes the discoverer and indexer | |||
*/ | |||
public void executeDiscoverer() | |||
throws MalformedURLException, RepositoryIndexException | |||
{ | |||
Configuration configuration = new Configuration(); // TODO! | |||
File indexPath = new File( configuration.getIndexPath() ); | |||
String blacklistedPatterns = configuration.getDiscoveryBlackListPatterns(); | |||
boolean includeSnapshots = configuration.isDiscoverSnapshots(); | |||
ArtifactRepository defaultRepository = getDefaultRepository( configuration ); | |||
getLogger().info( "[DiscovererExecution] Started discovery and indexing.." ); | |||
String layoutProperty = configuration.getRepositoryLayout(); | |||
ArtifactDiscoverer discoverer = (ArtifactDiscoverer) artifactDiscoverers.get( layoutProperty ); | |||
List artifacts = discoverer.discoverArtifacts( defaultRepository, blacklistedPatterns, includeSnapshots ); | |||
indexArtifact( artifacts, indexPath, defaultRepository ); | |||
List models = discoverer.discoverStandalonePoms( defaultRepository, blacklistedPatterns, includeSnapshots ); | |||
indexPom( models, indexPath, defaultRepository ); | |||
MetadataDiscoverer metadataDiscoverer = (MetadataDiscoverer) metadataDiscoverers.get( layoutProperty ); | |||
List metadataList = | |||
metadataDiscoverer.discoverMetadata( new File( defaultRepository.getBasedir() ), blacklistedPatterns ); | |||
indexMetadata( metadataList, indexPath, defaultRepository ); | |||
getLogger().info( "[DiscovererExecution] Finished discovery and indexing." ); | |||
} | |||
/** | |||
* Index the artifacts in the list | |||
* | |||
* @param artifacts the artifacts to be indexed | |||
* @param indexPath the path to the index file | |||
* @param repository the repository where the artifacts are located | |||
*/ | |||
protected void indexArtifact( List artifacts, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
ArtifactRepositoryIndex artifactIndex = indexFactory.createArtifactRepositoryIndex( indexPath, repository ); | |||
artifactIndex.indexArtifacts( artifacts ); | |||
artifactIndex.optimize(); | |||
} | |||
/** | |||
* Index the metadata in the list | |||
* | |||
* @param metadataList the metadata to be indexed | |||
* @param indexPath the path to the index file | |||
*/ | |||
protected void indexMetadata( List metadataList, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
MetadataRepositoryIndex metadataIndex = indexFactory.createMetadataRepositoryIndex( indexPath, repository ); | |||
metadataIndex.indexMetadata( metadataList ); | |||
metadataIndex.optimize(); | |||
} | |||
/** | |||
* Index the poms in the list | |||
* | |||
* @param models list of poms that will be indexed | |||
* @param indexPath the path to the index | |||
* @param repository the artifact repository where the poms were discovered | |||
*/ | |||
protected void indexPom( List models, File indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
PomRepositoryIndex pomIndex = indexFactory.createPomRepositoryIndex( indexPath, repository ); | |||
pomIndex.indexPoms( models ); | |||
pomIndex.optimize(); | |||
} | |||
/** | |||
* Method that creates the artifact repository | |||
* | |||
* @return an ArtifactRepository instance | |||
* @throws java.net.MalformedURLException | |||
*/ | |||
protected ArtifactRepository getDefaultRepository( Configuration configuration ) | |||
throws MalformedURLException | |||
{ | |||
// TODO! share with general search action, should only instantiate once | |||
File repositoryDirectory = new File( configuration.getRepositoryDirectory() ); | |||
String repoDir = repositoryDirectory.toURL().toString(); | |||
ArtifactRepositoryFactory repoFactory = new DefaultArtifactRepositoryFactory(); | |||
ArtifactRepositoryLayout layout = | |||
(ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() ); | |||
return repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | |||
} | |||
} |
@@ -1,67 +0,0 @@ | |||
package org.apache.maven.repository.manager.web.job; | |||
/* | |||
* Copyright 2005-2006 The Apache Software Foundation. | |||
* | |||
* Licensed 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.repository.manager.web.execution.DiscovererExecution; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import org.codehaus.plexus.scheduler.AbstractJob; | |||
import org.codehaus.plexus.scheduler.Scheduler; | |||
import org.quartz.CronTrigger; | |||
import org.quartz.JobDataMap; | |||
import org.quartz.JobDetail; | |||
import org.quartz.SchedulerException; | |||
import java.text.ParseException; | |||
/** | |||
* This class sets the job to be executed in the plexus-quartz scheduler | |||
* | |||
* @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererScheduler" | |||
*/ | |||
public class DiscovererScheduler | |||
extends AbstractLogEnabled | |||
{ | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private Scheduler scheduler; | |||
/** | |||
* @plexus.requirement | |||
*/ | |||
private DiscovererExecution execution; | |||
/** | |||
* Method that sets the schedule in the plexus-quartz scheduler | |||
* | |||
* @param cronExpression | |||
* @throws ParseException | |||
* @throws SchedulerException | |||
*/ | |||
public void setSchedule( String cronExpression ) | |||
throws ParseException, SchedulerException | |||
{ | |||
JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class ); | |||
JobDataMap dataMap = new JobDataMap(); | |||
dataMap.put( AbstractJob.LOGGER, getLogger() ); | |||
dataMap.put( DiscovererJob.MAP_DISCOVERER_EXECUTION, execution ); | |||
jobDetail.setJobDataMap( dataMap ); | |||
CronTrigger trigger = new CronTrigger( "DiscovererTrigger", "DISCOVERER", cronExpression ); | |||
scheduler.scheduleJob( jobDetail, trigger ); | |||
} | |||
} |
@@ -90,7 +90,7 @@ public class ConfigurationManager | |||
if ( name.equals( DISCOVERY_CRON_EXPRESSION ) ) | |||
{ | |||
config.setDiscoveryCronExpression( value ); | |||
config.setIndexerCronExpression( value ); | |||
} | |||
if ( name.equals( REPOSITORY_LAYOUT ) ) | |||
{ |
@@ -91,4 +91,10 @@ | |||
</lifecycle-handler> | |||
</lifecycle-handlers> | |||
</lifecycle-handler-manager> | |||
<load-on-start> | |||
<component> | |||
<role>org.apache.maven.repository.scheduler.RepositoryTaskScheduler</role> | |||
</component> | |||
</load-on-start> | |||
</plexus> |
@@ -101,6 +101,10 @@ | |||
<result name="input">/WEB-INF/jsp/admin/configure.jsp</result> | |||
<result>/WEB-INF/jsp/admin/configure.jsp</result> | |||
</action> | |||
<action name="runIndexer" class="runIndexerAction"> | |||
<!-- TODO: back to page where this comes from! --> | |||
</action> | |||
</package> | |||
</xwork> | |||
@@ -30,7 +30,7 @@ | |||
<ww:actionmessage /> | |||
<ww:form method="post" action="saveConfiguration" namespace="/admin" validate="true"> | |||
<ww:textfield name="repositoryDirectory" label="Repository Directory" size="100" /> | |||
<ww:textfield name="discoveryCronExpression" label="Discovery Cron Expression" /> | |||
<ww:textfield name="indexerCronExpression" label="Indexing Cron Expression" /> | |||
<ww:submit value="Save Configuration" /> | |||
</ww:form> | |||
</div> |
@@ -0,0 +1,28 @@ | |||
<%@ taglib prefix="ww" uri="/webwork" %> | |||
<%-- | |||
~ Copyright 2005-2006 The Apache Software Foundation. | |||
~ | |||
~ Licensed 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. | |||
--%> | |||
<div id="searchBox"> | |||
<ww:form method="post" action="quickSearch" validate="true"> | |||
<ww:textfield label="Search for" size="50" name="q" /> | |||
<ww:submit label="Go!" /> | |||
</ww:form> | |||
<p> | |||
Enter your search terms. A variety of data will be searched for your keywords. | |||
<ww:actionerror /> | |||
</p> | |||
</div> |
@@ -26,16 +26,7 @@ | |||
<h1>Search</h1> | |||
<div id="contentArea"> | |||
<div id="searchBox"> | |||
<ww:form method="post" action="quickSearch" validate="true"> | |||
<ww:textfield label="Search for" size="50" name="q" /> | |||
<ww:submit label="Go!" /> | |||
</ww:form> | |||
<p> | |||
Enter your search terms. A variety of data will be searched for your keywords. | |||
<ww:actionerror /> | |||
</p> | |||
</div> | |||
<%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %> | |||
</div> | |||
</body> |
@@ -1,3 +1,5 @@ | |||
<%@ taglib uri="/webwork" prefix="ww" %> | |||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |||
<%-- | |||
~ Copyright 2005-2006 The Apache Software Foundation. | |||
~ | |||
@@ -14,38 +16,55 @@ | |||
~ limitations under the License. | |||
--%> | |||
<%@ taglib uri="webwork" prefix="ww" %> | |||
<html> | |||
<head> | |||
<title>Maven Repository Manager</title> | |||
<title>Search Results</title> | |||
<ww:head /> | |||
</head> | |||
<body> | |||
<h1>Maven Repository Manager</h1> | |||
<h1>Search Results</h1> | |||
<%@ include file="form.jspf" %> | |||
<div id="contentArea"> | |||
<div id="searchBox"> | |||
<%@ include file="/WEB-INF/jsp/include/quickSearchForm.jspf" %> | |||
<table border="1px" cellspacing="0"> | |||
<tr> | |||
<th>Group ID</th> | |||
<th>Artifact ID</th> | |||
<th>Version</th> | |||
</tr> | |||
<ww:iterator value="searchResult"> | |||
<tr> | |||
<td valign="top"> | |||
<ww:property value="Artifact.getGroupId()"/> | |||
</td> | |||
<td valign="top"> | |||
<ww:property value="Artifact.getArtifactId()"/> | |||
</td> | |||
<td valign="top"> | |||
<ww:property value="Artifact.getVersion()"/> | |||
</td> | |||
</tr> | |||
</ww:iterator> | |||
</table> | |||
<div id="resultsBox"> | |||
<table class="bodyTable"> | |||
<tr class="a"> | |||
<th>Group</th> | |||
<th>Artifact</th> | |||
<th>Version</th> | |||
<%-- TODO | |||
<th>Hits</th> | |||
<th></th> | |||
--%> | |||
</tr> | |||
<ww:set name="searchResults" scope="request" value="searchResults" /> | |||
<c:forEach items="${searchResults}" var="result" varStatus="i"> | |||
<tr class="${i.index % 2 == 0 ? "b" : "a"}"> | |||
<td><c:out value="${result.artifact.groupId}" /></td> | |||
<td><c:out value="${result.artifact.artifactId}" /></td> | |||
<td><c:out value="${result.artifact.version}" /></td> | |||
<%-- TODO: hits | |||
<td> | |||
<code>org.apache.maven</code> | |||
(package) | |||
<br/> | |||
<code>org.apache.maven.model</code> | |||
(package) | |||
</td> | |||
<td> | |||
<a href="artifact.html">Details</a> | |||
</td> | |||
--%> | |||
</tr> | |||
</c:forEach> | |||
</table> | |||
</div> | |||
</div> | |||
</div> | |||
</body> | |||
</html> |