]> source.dussan.org Git - archiva.git/commitdiff
starting to move the discoverer (indexer) over to the core
authorBrett Porter <brett@apache.org>
Thu, 20 Jul 2006 03:10:39 +0000 (03:10 +0000)
committerBrett Porter <brett@apache.org>
Thu, 20 Jul 2006 03:10:39 +0000 (03:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@423734 13f79535-47bb-0310-9956-ffa450edef68

32 files changed:
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java [new file with mode: 0644]
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeListener.java
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationStore.java
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/DefaultConfigurationStore.java
maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java [new file with mode: 0644]
maven-repository-configuration/src/main/mdo/configuration.mdo
maven-repository-core/pom.xml
maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java [new file with mode: 0644]
maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java [new file with mode: 0644]
maven-repository-webapp/pom.xml
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/GeneralSearchAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/PackageSearchAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/QuickSearchAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/ConfigureAction.java
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java [new file with mode: 0644]
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java [deleted file]
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java [deleted file]
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java [deleted file]
maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java
maven-repository-webapp/src/main/plexus/plexus.xml
maven-repository-webapp/src/main/resources/xwork.xml
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/admin/configure.jsp
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf [new file with mode: 0644]
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/quickSearch.jsp
maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp

diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/ConfigurationChangeException.java
new file mode 100644 (file)
index 0000000..547bff7
--- /dev/null
@@ -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 );
+    }
+}
index b02717df22a29f6a0db62e439eddc400aaafb457..ca01a493f9361b91cf8f255ca1dcf001fbc93f24 100644 (file)
@@ -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;
 }
index 432062c53fe9d6b0349526c80230084edb75e5e3..2fa116d0f3546c08e46bc2a6a57787ad0fa551c1 100644 (file)
@@ -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 );
 }
index 2eb858d2af5085982ff3b5748f4b96e836d6f0d8..5ac90a8efaf6e49fe800730e488453a73feaadec 100644 (file)
@@ -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 );
+    }
 }
diff --git a/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java b/maven-repository-configuration/src/main/java/org/apache/maven/repository/configuration/InvalidConfigurationException.java
new file mode 100644 (file)
index 0000000..b88d4f3
--- /dev/null
@@ -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;
+    }
+}
index 189a3f6af59df8e22df720e5e9db723ba762163e..80583cab4e4957b8e2da0d16e486d605ba962d82 100644 (file)
           </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>
index be593d8ccc1ac4f09a756c7a90aacd54dd8a4894..ea3da3de35525c4a668f3e6566db0ec69042f0ff 100644 (file)
   <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>
     <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>
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java b/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/ConfiguredRepositoryFactory.java
new file mode 100644 (file)
index 0000000..c71b219
--- /dev/null
@@ -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 );
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java b/maven-repository-core/src/main/java/org/apache/maven/repository/configuration/DefaultConfiguredRepositoryFactory.java
new file mode 100644 (file)
index 0000000..5e41e30
--- /dev/null
@@ -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 );
+    }
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/DefaultRepositoryTaskScheduler.java
new file mode 100644 (file)
index 0000000..2e31e56
--- /dev/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();
+
+    }
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/IndexerTask.java
new file mode 100644 (file)
index 0000000..724f93e
--- /dev/null
@@ -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();
+    }
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTask.java
new file mode 100644 (file)
index 0000000..92b6f93
--- /dev/null
@@ -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;
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskJob.java
new file mode 100644 (file)
index 0000000..874f6bc
--- /dev/null
@@ -0,0 +1,56 @@
+package org.apache.maven.repository.scheduler;\r
+\r
+/*\r
+ * Copyright 2005-2006 The Apache Software Foundation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+import org.codehaus.plexus.scheduler.AbstractJob;\r
+import org.quartz.JobDataMap;\r
+import org.quartz.JobExecutionContext;\r
+import org.quartz.JobExecutionException;\r
+\r
+/**\r
+ * This class is the discoverer job that is executed by the scheduler.\r
+ */\r
+public class RepositoryTaskJob\r
+    extends AbstractJob\r
+{\r
+    static final String TASK_KEY = "EXECUTION";\r
+\r
+    /**\r
+     * Execute the discoverer and the indexer.\r
+     *\r
+     * @param context\r
+     * @throws org.quartz.JobExecutionException\r
+     *\r
+     */\r
+    public void execute( JobExecutionContext context )\r
+        throws JobExecutionException\r
+    {\r
+        JobDataMap dataMap = context.getJobDetail().getJobDataMap();\r
+        setJobDataMap( dataMap );\r
+\r
+        RepositoryTask executor = (RepositoryTask) dataMap.get( TASK_KEY );\r
+        try\r
+        {\r
+            executor.execute();\r
+        }\r
+        catch ( TaskExecutionException e )\r
+        {\r
+            throw new JobExecutionException( e );\r
+        }\r
+    }\r
+\r
+}\r
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/RepositoryTaskScheduler.java
new file mode 100644 (file)
index 0000000..46db976
--- /dev/null
@@ -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;
+}
diff --git a/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java b/maven-repository-core/src/main/java/org/apache/maven/repository/scheduler/TaskExecutionException.java
new file mode 100644 (file)
index 0000000..7ab2290
--- /dev/null
@@ -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 );
+    }
+}
index 39f89081f1e4956cb7e301ff798ba8149870cf57..7d6d2433a8eb812771337d3bec20fa9794f7b9e5 100644 (file)
       <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>
index f9e5f223d0ef0a6f7a39624ea07d28a6a76bc432..26b0bf863ea9f4e76c0ac3441dff7bde8df491bc 100644 (file)
@@ -19,8 +19,7 @@ package org.apache.maven.repository.manager.web.action;
 import com.opensymphony.webwork.interceptor.ParameterAware;\r
 import com.opensymphony.xwork.ActionSupport;\r
 import org.apache.maven.repository.configuration.Configuration;\r
-import org.apache.maven.repository.manager.web.execution.DiscovererExecution;\r
-import org.apache.maven.repository.manager.web.job.DiscovererScheduler;\r
+import org.apache.maven.repository.configuration.ConfigurationStore;\r
 import org.apache.maven.repository.manager.web.utils.ConfigurationManager;\r
 \r
 import java.util.HashMap;\r
@@ -31,25 +30,17 @@ import java.util.Map;
  * It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler.\r
  *\r
  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="baseAction"\r
+ * @todo don't like this as a base and as a forwarding action!\r
  */\r
 public class BaseAction\r
     extends ActionSupport\r
     implements ParameterAware\r
 {\r
-    /**\r
-     * @plexus.requirement\r
-     */\r
-    private DiscovererExecution execution;\r
-\r
-    /**\r
-     * @plexus.requirement\r
-     */\r
-    private DiscovererScheduler discovererScheduler;\r
 \r
     /**\r
      * @plexus.requirement\r
      */\r
-    private ConfigurationManager configManager;\r
+    private ConfigurationStore configurationStore;\r
 \r
     private Map parameters;\r
 \r
@@ -72,18 +63,17 @@ public class BaseAction
     {\r
         try\r
         {\r
-            Configuration config = configManager.getConfiguration();\r
+            Configuration config = configurationStore.getConfigurationFromStore();\r
             Map parameters = new HashMap();\r
             parameters.put( ConfigurationManager.INDEXPATH, config.getIndexPath() );\r
             parameters.put( ConfigurationManager.MIN_INDEXPATH, config.getMinimalIndexPath() );\r
             parameters.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, config.getDiscoveryBlackListPatterns() );\r
             parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, Boolean.valueOf( config.isDiscoverSnapshots() ) );\r
-            parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getDiscoveryCronExpression() );\r
+            parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getIndexerCronExpression() );\r
             this.parameters = parameters;\r
 \r
             //Configuration configuration = new Configuration(); // TODO!\r
 //            execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) );\r
-            discovererScheduler.setSchedule( config.getDiscoveryCronExpression() );\r
         }\r
         catch ( Exception e )\r
         {\r
index a0927b660d4c57d639271951f5ad8a45e5b2d584..900da9b8ee5692ed1f9ba38b7be8fd7df9cded94 100644 (file)
@@ -18,9 +18,8 @@ package org.apache.maven.repository.manager.web.action;
 \r
 import com.opensymphony.xwork.Action;\r
 import org.apache.maven.artifact.repository.ArtifactRepository;\r
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;\r
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;\r
 import org.apache.maven.repository.configuration.Configuration;\r
+import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory;\r
 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;\r
 import org.apache.maven.repository.indexing.RepositoryIndexException;\r
 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;\r
@@ -30,7 +29,6 @@ import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
 import java.io.File;\r
 import java.net.MalformedURLException;\r
 import java.util.List;\r
-import java.util.Map;\r
 \r
 /**\r
  * Searches for searchString in all indexed fields.\r
@@ -57,12 +55,7 @@ public class GeneralSearchAction
     /**\r
      * @plexus.requirement\r
      */\r
-    private ArtifactRepositoryFactory repositoryFactory;\r
-\r
-    /**\r
-     * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"\r
-     */\r
-    private Map repositoryLayouts;\r
+    private ConfiguredRepositoryFactory repositoryFactory;\r
 \r
     public String execute()\r
         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException\r
@@ -72,14 +65,7 @@ public class GeneralSearchAction
             Configuration configuration = new Configuration(); // TODO!\r
             File indexPath = new File( configuration.getIndexPath() );\r
 \r
-            // TODO: [!] repository should only have been instantiated once\r
-            File repositoryDirectory = new File( configuration.getRepositoryDirectory() );\r
-            String repoDir = repositoryDirectory.toURL().toString();\r
-\r
-            ArtifactRepositoryLayout layout =\r
-                (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() );\r
-            ArtifactRepository repository =\r
-                repositoryFactory.createArtifactRepository( "test", repoDir, layout, null, null );\r
+            ArtifactRepository repository = repositoryFactory.createRepository( configuration );\r
 \r
             ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );\r
 \r
index cbd28f1e030bddcc55b8812704aed5b75038b664..6f64bd904f5e83795b58d429659edd84730a7e80 100644 (file)
@@ -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 );
 
index c480af4b6f94ffcf19cd432305650c5a00102858..8db744554c934de35f07a6858800b4b29e9160a0 100644 (file)
@@ -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;
     }
 
 }
index 6ccb922a3ff631084549c121f278ee5a70d2a685..2e8955957f61c587960aa06fd8e15ba7508a12df 100644 (file)
@@ -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();
     }
diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/admin/RunIndexerAction.java
new file mode 100644 (file)
index 0000000..2443460
--- /dev/null
@@ -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;
+    }
+}
diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/execution/DiscovererExecution.java
deleted file mode 100644 (file)
index f2d6b02..0000000
+++ /dev/null
@@ -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 );
-    }
-}
diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererJob.java
deleted file mode 100644 (file)
index af350dc..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-package org.apache.maven.repository.manager.web.job;\r
-\r
-/*\r
- * Copyright 2005-2006 The Apache Software Foundation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-import org.apache.maven.repository.indexing.RepositoryIndexException;\r
-import org.apache.maven.repository.manager.web.execution.DiscovererExecution;\r
-import org.codehaus.plexus.scheduler.AbstractJob;\r
-import org.quartz.JobDataMap;\r
-import org.quartz.JobExecutionContext;\r
-import org.quartz.JobExecutionException;\r
-\r
-import java.net.MalformedURLException;\r
-\r
-/**\r
- * This class is the discoverer job that is executed by the scheduler.\r
- *\r
- * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererJob"\r
- */\r
-public class DiscovererJob\r
-    extends AbstractJob\r
-{\r
-    public static final String ROLE = DiscovererJob.class.getName();\r
-\r
-    public static final String MAP_DISCOVERER_EXECUTION = "EXECUTION";\r
-\r
-    /**\r
-     * Execute the discoverer and the indexer.\r
-     *\r
-     * @param context\r
-     * @throws org.quartz.JobExecutionException\r
-     *\r
-     */\r
-    public void execute( JobExecutionContext context )\r
-        throws JobExecutionException\r
-    {\r
-        JobDataMap dataMap = context.getJobDetail().getJobDataMap();\r
-        setJobDataMap( dataMap );\r
-        getLogger().info( "[DiscovererJob] Start execution of DiscovererJob.." );\r
-\r
-        try\r
-        {\r
-            DiscovererExecution execution = (DiscovererExecution) dataMap.get( MAP_DISCOVERER_EXECUTION );\r
-            execution.executeDiscoverer();\r
-        }\r
-        catch ( RepositoryIndexException e )\r
-        {\r
-            getLogger().error( "Error indexing: " + e.getMessage(), e );\r
-        }\r
-        catch ( MalformedURLException me )\r
-        {\r
-            getLogger().error( "Error indexing: " + me.getMessage(), me );\r
-        }\r
-\r
-        getLogger().info( "[DiscovererJob] DiscovererJob has finished executing." );\r
-    }\r
-\r
-}\r
diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/job/DiscovererScheduler.java
deleted file mode 100644 (file)
index bad9471..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-package org.apache.maven.repository.manager.web.job;\r
-\r
-/*\r
- * Copyright 2005-2006 The Apache Software Foundation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-import org.apache.maven.repository.manager.web.execution.DiscovererExecution;\r
-import org.codehaus.plexus.logging.AbstractLogEnabled;\r
-import org.codehaus.plexus.scheduler.AbstractJob;\r
-import org.codehaus.plexus.scheduler.Scheduler;\r
-import org.quartz.CronTrigger;\r
-import org.quartz.JobDataMap;\r
-import org.quartz.JobDetail;\r
-import org.quartz.SchedulerException;\r
-\r
-import java.text.ParseException;\r
-\r
-/**\r
- * This class sets the job to be executed in the plexus-quartz scheduler\r
- *\r
- * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererScheduler"\r
- */\r
-public class DiscovererScheduler\r
-    extends AbstractLogEnabled\r
-{\r
-    /**\r
-     * @plexus.requirement\r
-     */\r
-    private Scheduler scheduler;\r
-\r
-    /**\r
-     * @plexus.requirement\r
-     */\r
-    private DiscovererExecution execution;\r
-\r
-    /**\r
-     * Method that sets the schedule in the plexus-quartz scheduler\r
-     *\r
-     * @param cronExpression\r
-     * @throws ParseException\r
-     * @throws SchedulerException\r
-     */\r
-    public void setSchedule( String cronExpression )\r
-        throws ParseException, SchedulerException\r
-    {\r
-        JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class );\r
-        JobDataMap dataMap = new JobDataMap();\r
-        dataMap.put( AbstractJob.LOGGER, getLogger() );\r
-        dataMap.put( DiscovererJob.MAP_DISCOVERER_EXECUTION, execution );\r
-        jobDetail.setJobDataMap( dataMap );\r
-\r
-        CronTrigger trigger = new CronTrigger( "DiscovererTrigger", "DISCOVERER", cronExpression );\r
-        scheduler.scheduleJob( jobDetail, trigger );\r
-    }\r
-}\r
index 793967ddc018521ffc2683d233f63634e7e9fdf2..f055590a2c10c4d383cbb09be46f101d6234a52f 100644 (file)
@@ -90,7 +90,7 @@ public class ConfigurationManager
 
             if ( name.equals( DISCOVERY_CRON_EXPRESSION ) )
             {
-                config.setDiscoveryCronExpression( value );
+                config.setIndexerCronExpression( value );
             }
             if ( name.equals( REPOSITORY_LAYOUT ) )
             {
index d8d3b78c1389221a1cd16c81878d445b5f149bbf..d16efcc31e7a19d31515eab7ae5981f6f8b09350 100644 (file)
       </lifecycle-handler>
     </lifecycle-handlers>
   </lifecycle-handler-manager>
+
+  <load-on-start>
+    <component>
+      <role>org.apache.maven.repository.scheduler.RepositoryTaskScheduler</role>
+    </component>
+  </load-on-start>
 </plexus>
index 9a71a8c4c56a9e06e70df9f0a4f3660ea7b1b988..a29c0da59da9153dd010e212ce0213e108d1e8f5 100644 (file)
       <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>
 
index 2e6ffec66085bbe34863edeece668894bc211a32..8f70c11945f42afad4f80fd3882f74fc50751d35 100644 (file)
@@ -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>
diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/include/quickSearchForm.jspf
new file mode 100644 (file)
index 0000000..b40dcd7
--- /dev/null
@@ -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>
\ No newline at end of file
index aacb872a87d119ba73373adc7277676ef2309648..8cc2e22fb2b28629f5394a89a63e5881fae82836 100644 (file)
 <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>
index 4be180a5eae011ecc6494d223bf4967825a73538..9ebbdd0707102ad48ce6eca5b38b67871838967f 100644 (file)
@@ -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.
   ~
   ~ 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>