From 376f2338b4642855adff5fce0dbb678509cb0e9b Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Wed, 11 Apr 2007 20:04:51 +0000 Subject: [PATCH] missing classes and some test structure git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@527642 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultArchivaTaskScheduler.java | 3 +- .../ArchivaScheduledTaskExecutor.java | 129 +++++++++++++ .../scheduled/tasks/RepositoryTask.java | 60 ++++++ .../src/test/conf/repository-manager.xml | 182 ++++++++++++++++++ ... => ArchivaScheduledTaskExecutorTest.java} | 9 +- .../ArchivaScheduledTaskExecutorTest.xml | 69 +++++++ 6 files changed, 444 insertions(+), 8 deletions(-) create mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutor.java create mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/RepositoryTask.java create mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/conf/repository-manager.xml rename archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/{DataRefreshExecutorTest.java => ArchivaScheduledTaskExecutorTest.java} (88%) create mode 100644 archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.xml diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java index d5196b8b4..2ea5311c9 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java @@ -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 Brett Porter + * @author Jesse McConnell * @plexus.component role="org.apache.maven.archiva.scheduler.ArchivaTaskScheduler" */ public class DefaultArchivaTaskScheduler diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutor.java b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutor.java new file mode 100644 index 000000000..eca258966 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutor.java @@ -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 Jesse McConnell + * @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(); + + + + } +} diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/RepositoryTask.java b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/RepositoryTask.java new file mode 100644 index 000000000..fca9173d9 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/RepositoryTask.java @@ -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 Joakim Erdfelt + * @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; + } +} diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/conf/repository-manager.xml b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/conf/repository-manager.xml new file mode 100644 index 000000000..07e9f969b --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/conf/repository-manager.xml @@ -0,0 +1,182 @@ + + + + + + + internal + Archiva Managed Internal Repository + file://${appserver.home}/repositories/internal + default + true + false + true + 0 0 * * ? + + + snapshots + Archiva Managed Snapshot Repository + file://${appserver.home}/repositories/internal + default + false + true + true + 0 0,30 * * ? + + + central + Central Repository + http://repo1.maven.org/maven2 + default + true + false + false + + + maven2-repository.dev.java.net + Java.net Repository for Maven 2 + https://maven2-repository.dev.java.net/nonav/repository + default + true + false + false + + + + + + internal + central + + disabled + never + not-found + + + internal + maven2-repository.dev.java.net + + disabled + never + not-found + + javax/** + + + + + + + example + http + proxy.mycompany.com + 8080 + myself + mypass + + + + + + + artifacts + + **/*.pom + **/*.jar + **/*.ear + **/*.war + **/*.car + **/*.sar + **/*.mar + **/*.rar + **/*.dtd + **/*.tld + **/*.tar.gz + **/*.tar.bz2 + **/*.zip + + + + indexable-content + + **/*.txt + **/*.TXT + **/*.block + **/*.config + **/*.pom + **/*.xml + **/*.xsd + **/*.dtd + **/*.tld + + + + auto-remove + + **/*.bak + **/*~ + **/*- + + + + ignored + + **/.htaccess + **/KEYS + **/*.rb + **/*.sh + **/.svn/** + **/.DAV/** + + + + + update-db-artifact + create-missing-checksums + update-db-repository-metadata + validate-checksum + validate-signature + index-content + auto-remove + auto-rename + + + update-db-bad-content + + + + + 0 0 * * ? + + index-artifact + update-db-project + validate-repository-metadata + index-archive-toc + update-db-bytecode-stats + index-public-methods + + + not-present-remove-db-artifact + not-present-remove-db-project + not-present-remove-indexed + + + + diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/DataRefreshExecutorTest.java b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.java similarity index 88% rename from archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/DataRefreshExecutorTest.java rename to archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.java index e27847d71..7f8c2c727 100644 --- a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/DataRefreshExecutorTest.java +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.java @@ -33,9 +33,9 @@ import java.io.File; * IndexerTaskExecutorTest * * @author Joakim Erdfelt - * @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(); - } diff --git a/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.xml b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.xml new file mode 100644 index 000000000..7d1075a15 --- /dev/null +++ b/archiva-jpox-database-refactor/archiva-base/archiva-scheduled/src/test/resources/org/apache/maven/archiva/scheduled/executors/ArchivaScheduledTaskExecutorTest.xml @@ -0,0 +1,69 @@ + + + + + + + org.codehaus.plexus.taskqueue.execution.TaskExecutor + archiva-task-executor + org.apache.maven.archiva.scheduled.executors.ArchivaScheduledTaskExecutor + + + + org.apache.maven.archiva.configuration.ArchivaConfiguration + archivaConfiguration + test-configuration + + + org.apache.maven.archiva.database.updater.DatabaseUpdater + jdo + databaseUpdater + + + + + + org.apache.maven.archiva.configuration.ArchivaConfiguration + test-configuration + org.apache.maven.archiva.configuration.DefaultArchivaConfiguration + + + org.codehaus.plexus.registry.Registry + configured + + + + + + org.codehaus.plexus.registry.Registry + configured + org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry + + + + + + + + + + + -- 2.39.5