git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@527642 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-1.0-alpha-1
@@ -46,9 +46,10 @@ import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* Default implementation of a scheduling component for the application. | |||
* Default implementation of a scheduling component for archiva.. | |||
* | |||
* @author <a href="mailto:brett@apache.org">Brett Porter</a> | |||
* @author <a href="mailto:jmcconnell@apache.org">Jesse McConnell</a> | |||
* @plexus.component role="org.apache.maven.archiva.scheduler.ArchivaTaskScheduler" | |||
*/ | |||
public class DefaultArchivaTaskScheduler |
@@ -0,0 +1,129 @@ | |||
package org.apache.maven.archiva.scheduled.executors; | |||
/* | |||
* 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.ArchivaConfiguration; | |||
import org.apache.maven.archiva.configuration.Configuration; | |||
import org.apache.maven.archiva.database.ArchivaDatabaseException; | |||
import org.apache.maven.archiva.database.updater.DatabaseUpdater; | |||
import org.apache.maven.archiva.scheduled.tasks.DatabaseTask; | |||
import org.apache.maven.archiva.scheduled.tasks.RepositoryTask; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import org.codehaus.plexus.taskqueue.Task; | |||
import org.codehaus.plexus.taskqueue.execution.TaskExecutionException; | |||
import org.codehaus.plexus.taskqueue.execution.TaskExecutor; | |||
import java.io.IOException; | |||
import java.util.ArrayList; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* | |||
* @author <a href="mailto:jmcconnell@apache.org">Jesse McConnell</a> | |||
* @version $Id:$ | |||
* | |||
* @plexus.component role="org.codehaus.plexus.taskqueue.execution.TaskExecutor" | |||
* role-hint="archiva-task-executor" | |||
*/ | |||
public class ArchivaScheduledTaskExecutor extends AbstractLogEnabled implements TaskExecutor | |||
{ | |||
/** | |||
* Configuration store. | |||
* | |||
* @plexus.requirement | |||
*/ | |||
private ArchivaConfiguration archivaConfiguration; | |||
/** | |||
* @plexus.requirement role-hint="jdo" | |||
*/ | |||
private DatabaseUpdater databaseUpdater; | |||
public void executeTask( Task task ) throws TaskExecutionException | |||
{ | |||
if ( task instanceof DatabaseTask ) | |||
{ | |||
executeDatabaseTask( (DatabaseTask) task ); | |||
} | |||
else if ( task instanceof RepositoryTask ) | |||
{ | |||
executeRepositoryTask( (RepositoryTask) task ); | |||
} | |||
else | |||
{ | |||
throw new TaskExecutionException( "Unknown Task: " + task.toString() ); | |||
} | |||
} | |||
private void executeDatabaseTask( DatabaseTask task ) throws TaskExecutionException | |||
{ | |||
getLogger().info( "Executing task from queue with job name: " + task.getName() ); | |||
long time = System.currentTimeMillis(); | |||
try | |||
{ | |||
databaseUpdater.updateAllUnprocessed(); | |||
} | |||
catch ( ArchivaDatabaseException e ) | |||
{ | |||
throw new TaskExecutionException( "Error running unprocessed updater", e ); | |||
} | |||
try | |||
{ | |||
databaseUpdater.updateAllProcessed(); | |||
} | |||
catch ( ArchivaDatabaseException e ) | |||
{ | |||
throw new TaskExecutionException( "Error running processed updater", e ); | |||
} | |||
time = System.currentTimeMillis() - time; | |||
getLogger().info( "Finished database task in " + time + "ms." ); | |||
} | |||
private void executeRepositoryTask ( RepositoryTask task ) throws TaskExecutionException | |||
{ | |||
getLogger().info( "Executing task from queue with job name: " + task.getName() ); | |||
long time = System.currentTimeMillis(); | |||
time = System.currentTimeMillis() - time; | |||
getLogger().info( "Finished repository task for " + time + "ms." ); | |||
} | |||
public void execute() throws TaskExecutionException | |||
{ | |||
Configuration configuration = archivaConfiguration.getConfiguration(); | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
package org.apache.maven.archiva.scheduled.tasks; | |||
/** | |||
* DataRefreshTask - task for discovering changes in the repository | |||
* and updating all associated data. | |||
* | |||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> | |||
* @version $Id: DataRefreshTask.java 525176 2007-04-03 15:21:33Z joakime $ | |||
*/ | |||
public class RepositoryTask | |||
implements ArchivaTask | |||
{ | |||
String repositoryId; | |||
String name; | |||
String queuePolicy; | |||
long maxExecutionTime; | |||
public String getRepositoryId() | |||
{ | |||
return repositoryId; | |||
} | |||
public void setRepositoryId( String repositoryId ) | |||
{ | |||
this.repositoryId = repositoryId; | |||
} | |||
public long getMaxExecutionTime() | |||
{ | |||
return maxExecutionTime; | |||
} | |||
public void setMaxExecutionTime( long maxExecutionTime ) | |||
{ | |||
this.maxExecutionTime = maxExecutionTime; | |||
} | |||
public String getName() | |||
{ | |||
return name; | |||
} | |||
public void setName( String name ) | |||
{ | |||
this.name = name; | |||
} | |||
public String getQueuePolicy() | |||
{ | |||
return queuePolicy; | |||
} | |||
public void setQueuePolicy( String queuePolicy ) | |||
{ | |||
this.queuePolicy = queuePolicy; | |||
} | |||
} |
@@ -0,0 +1,182 @@ | |||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||
<!-- | |||
~ 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. | |||
--> | |||
<configuration> | |||
<repositories> | |||
<repository> | |||
<id>internal</id> | |||
<name>Archiva Managed Internal Repository</name> | |||
<url>file://${appserver.home}/repositories/internal</url> | |||
<layout>default</layout> | |||
<releases>true</releases> | |||
<snapshots>false</snapshots> | |||
<indexed>true</indexed> | |||
<refreshCronExpression>0 0 * * ?</refreshCronExpression> | |||
</repository> | |||
<repository> | |||
<id>snapshots</id> | |||
<name>Archiva Managed Snapshot Repository</name> | |||
<url>file://${appserver.home}/repositories/internal</url> | |||
<layout>default</layout> | |||
<releases>false</releases> | |||
<snapshots>true</snapshots> | |||
<indexed>true</indexed> | |||
<refreshCronExpression>0 0,30 * * ?</refreshCronExpression> | |||
</repository> | |||
<repository> | |||
<id>central</id> | |||
<name>Central Repository</name> | |||
<url>http://repo1.maven.org/maven2</url> | |||
<layout>default</layout> | |||
<releases>true</releases> | |||
<snapshots>false</snapshots> | |||
<indexed>false</indexed> | |||
</repository> | |||
<repository> | |||
<id>maven2-repository.dev.java.net</id> | |||
<name>Java.net Repository for Maven 2</name> | |||
<url>https://maven2-repository.dev.java.net/nonav/repository</url> | |||
<layout>default</layout> | |||
<releases>true</releases> | |||
<snapshots>false</snapshots> | |||
<indexed>false</indexed> | |||
</repository> | |||
</repositories> | |||
<proxyConnectors> | |||
<proxyConnector> | |||
<sourceRepoId>internal</sourceRepoId> | |||
<targetRepoId>central</targetRepoId> | |||
<proxyId /> | |||
<snapshotsPolicy>disabled</snapshotsPolicy> | |||
<releasePolicy>never</releasePolicy> | |||
<failurePolicy>not-found</failurePolicy> | |||
</proxyConnector> | |||
<proxyConnector> | |||
<sourceRepoId>internal</sourceRepoId> | |||
<targetRepoId>maven2-repository.dev.java.net</targetRepoId> | |||
<proxyId /> | |||
<snapshotsPolicy>disabled</snapshotsPolicy> | |||
<releasePolicy>never</releasePolicy> | |||
<failurePolicy>not-found</failurePolicy> | |||
<whiteListPatterns> | |||
<whiteListPattern>javax/**</whiteListPattern> | |||
</whiteListPatterns> | |||
</proxyConnector> | |||
</proxyConnectors> | |||
<networkProxies> | |||
<networkProxy> | |||
<id>example</id> | |||
<protocol>http</protocol> | |||
<host>proxy.mycompany.com</host> | |||
<port>8080</port> | |||
<username>myself</username> | |||
<password>mypass</password> | |||
</networkProxy> | |||
</networkProxies> | |||
<repositoryScanning> | |||
<fileTypes> | |||
<fileType> | |||
<id>artifacts</id> | |||
<patterns> | |||
<pattern>**/*.pom</pattern> | |||
<pattern>**/*.jar</pattern> | |||
<pattern>**/*.ear</pattern> | |||
<pattern>**/*.war</pattern> | |||
<pattern>**/*.car</pattern> | |||
<pattern>**/*.sar</pattern> | |||
<pattern>**/*.mar</pattern> | |||
<pattern>**/*.rar</pattern> | |||
<pattern>**/*.dtd</pattern> | |||
<pattern>**/*.tld</pattern> | |||
<pattern>**/*.tar.gz</pattern> | |||
<pattern>**/*.tar.bz2</pattern> | |||
<pattern>**/*.zip</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>indexable-content</id> | |||
<patterns> | |||
<pattern>**/*.txt</pattern> | |||
<pattern>**/*.TXT</pattern> | |||
<pattern>**/*.block</pattern> | |||
<pattern>**/*.config</pattern> | |||
<pattern>**/*.pom</pattern> | |||
<pattern>**/*.xml</pattern> | |||
<pattern>**/*.xsd</pattern> | |||
<pattern>**/*.dtd</pattern> | |||
<pattern>**/*.tld</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>auto-remove</id> | |||
<patterns> | |||
<pattern>**/*.bak</pattern> | |||
<pattern>**/*~</pattern> | |||
<pattern>**/*-</pattern> | |||
</patterns> | |||
</fileType> | |||
<fileType> | |||
<id>ignored</id> | |||
<patterns> | |||
<pattern>**/.htaccess</pattern> | |||
<pattern>**/KEYS</pattern> | |||
<pattern>**/*.rb</pattern> | |||
<pattern>**/*.sh</pattern> | |||
<pattern>**/.svn/**</pattern> | |||
<pattern>**/.DAV/**</pattern> | |||
</patterns> | |||
</fileType> | |||
</fileTypes> | |||
<goodConsumers> | |||
<goodConsumer>update-db-artifact</goodConsumer> | |||
<goodConsumer>create-missing-checksums</goodConsumer> | |||
<goodConsumer>update-db-repository-metadata</goodConsumer> | |||
<goodConsumer>validate-checksum</goodConsumer> | |||
<goodConsumer>validate-signature</goodConsumer> | |||
<goodConsumer>index-content</goodConsumer> | |||
<goodConsumer>auto-remove</goodConsumer> | |||
<goodConsumer>auto-rename</goodConsumer> | |||
</goodConsumers> | |||
<badConsumers> | |||
<badConsumer>update-db-bad-content</badConsumer> | |||
</badConsumers> | |||
</repositoryScanning> | |||
<databaseScanning> | |||
<cronExpression>0 0 * * ?</cronExpression> | |||
<unprocessedConsumers> | |||
<unprocessedConsumer>index-artifact</unprocessedConsumer> | |||
<unprocessedConsumer>update-db-project</unprocessedConsumer> | |||
<unprocessedConsumer>validate-repository-metadata</unprocessedConsumer> | |||
<unprocessedConsumer>index-archive-toc</unprocessedConsumer> | |||
<unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer> | |||
<unprocessedConsumer>index-public-methods</unprocessedConsumer> | |||
</unprocessedConsumers> | |||
<processedConsumers> | |||
<processedConsumer>not-present-remove-db-artifact</processedConsumer> | |||
<processedConsumer>not-present-remove-db-project</processedConsumer> | |||
<processedConsumer>not-present-remove-indexed</processedConsumer> | |||
</processedConsumers> | |||
</databaseScanning> | |||
</configuration> |
@@ -33,9 +33,9 @@ import java.io.File; | |||
* IndexerTaskExecutorTest | |||
* | |||
* @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a> | |||
* @version $Id$ | |||
* @version $Id:$ | |||
*/ | |||
public class DataRefreshExecutorTest | |||
public class ArchivaScheduledTaskExecutorTest | |||
extends PlexusTestCase | |||
{ | |||
private TaskExecutor taskExecutor; | |||
@@ -46,11 +46,6 @@ public class DataRefreshExecutorTest | |||
super.setUp(); | |||
taskExecutor = (TaskExecutor) lookup( "org.codehaus.plexus.taskqueue.execution.TaskExecutor", "archiva-task-executor" ); | |||
ArchivaConfiguration archivaConfiguration = | |||
(ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() ); | |||
Configuration configuration = archivaConfiguration.getConfiguration(); | |||
} | |||
@@ -0,0 +1,69 @@ | |||
<?xml version="1.0" encoding="ISO-8859-1"?> | |||
<!-- | |||
~ 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. | |||
--> | |||
<component-set> | |||
<component> | |||
<role>org.codehaus.plexus.taskqueue.execution.TaskExecutor</role> | |||
<role-hint>archiva-task-executor</role-hint> | |||
<implementation>org.apache.maven.archiva.scheduled.executors.ArchivaScheduledTaskExecutor</implementation> | |||
<description></description> | |||
<requirements> | |||
<requirement> | |||
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> | |||
<field-name>archivaConfiguration</field-name> | |||
<role-hint>test-configuration</role-hint> | |||
</requirement> | |||
<requirement> | |||
<role>org.apache.maven.archiva.database.updater.DatabaseUpdater</role> | |||
<role-hint>jdo</role-hint> | |||
<field-name>databaseUpdater</field-name> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
<component> | |||
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> | |||
<role-hint>test-configuration</role-hint> | |||
<implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation> | |||
<requirements> | |||
<requirement> | |||
<role>org.codehaus.plexus.registry.Registry</role> | |||
<role-hint>configured</role-hint> | |||
</requirement> | |||
</requirements> | |||
</component> | |||
<component> | |||
<role>org.codehaus.plexus.registry.Registry</role> | |||
<role-hint>configured</role-hint> | |||
<implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation> | |||
<configuration> | |||
<properties> | |||
<system/> | |||
<xml fileName="${basedir}/src/test/conf/repository-manager.xml" | |||
config-name="org.apache.maven.archiva" config-at="org.apache.maven.archiva"/> | |||
</properties> | |||
</configuration> | |||
</component> | |||
</component-set> |