1 package org.apache.maven.repository.manager.web.job;
\r
4 * Copyright 2005-2006 The Apache Software Foundation.
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
19 import java.io.File;
\r
20 import java.io.IOException;
\r
21 import java.net.MalformedURLException;
\r
22 import java.text.ParseException;
\r
23 import java.util.Properties;
\r
25 import org.apache.maven.artifact.repository.ArtifactRepository;
\r
26 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
\r
27 import org.apache.maven.artifact.repository.DefaultArtifactRepositoryFactory;
\r
28 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
\r
29 import org.apache.maven.repository.discovery.MetadataDiscoverer;
\r
30 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
\r
31 import org.codehaus.plexus.logging.AbstractLogEnabled;
\r
32 import org.codehaus.plexus.scheduler.Scheduler;
\r
33 import org.quartz.CronTrigger;
\r
34 import org.quartz.JobDataMap;
\r
35 import org.quartz.JobDetail;
\r
36 import org.quartz.SchedulerException;
\r
39 * This class sets the job to be executed in the plexus-quartz scheduler
\r
41 * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererScheduler"
\r
43 public class DiscovererScheduler
\r
44 extends AbstractLogEnabled
\r
47 * @plexus.requirement
\r
49 private Configuration config;
\r
52 * @plexus.requirement
\r
54 private Scheduler scheduler;
\r
57 * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"
\r
59 private ArtifactDiscoverer defaultArtifactDiscoverer;
\r
62 * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"
\r
64 private ArtifactDiscoverer legacyArtifactDiscoverer;
\r
67 * @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer"
\r
69 private MetadataDiscoverer defaultMetadataDiscoverer;
\r
72 * @plexus.requirement
\r
74 private RepositoryIndexingFactory indexFactory;
\r
77 * @plexus.requirement
\r
79 private ArtifactRepositoryFactory repoFactory;
\r
81 private Properties props;
\r
84 * Method that sets the schedule in the plexus-quartz scheduler
\r
86 * @throws IOException
\r
87 * @throws ParseException
\r
88 * @throws SchedulerException
\r
90 public void setSchedule()
\r
91 throws IOException, ParseException, SchedulerException
\r
93 props = config.getProperties();
\r
94 JobDetail jobDetail = new JobDetail( "discovererJob", "DISCOVERER", DiscovererJob.class );
\r
95 JobDataMap dataMap = new JobDataMap();
\r
96 dataMap.put( DiscovererJob.LOGGER, getLogger() );
\r
97 dataMap.put( DiscovererJob.MAP_INDEXPATH, props.getProperty( "index.path" ) );
\r
98 dataMap.put( DiscovererJob.MAP_BLACKLIST, props.getProperty( "blacklist.patterns" ) );
\r
99 dataMap.put( DiscovererJob.MAP_DEFAULT_REPOSITORY, getDefaultRepository() );
\r
100 dataMap.put( DiscovererJob.MAP_LAYOUT, props.getProperty( "layout" ) );
\r
101 dataMap.put( DiscovererJob.MAP_SNAPSHOTS, new Boolean( props.getProperty( "include.snapshots" ) ) );
\r
102 dataMap.put( DiscovererJob.MAP_CONVERT, new Boolean( props.getProperty( "convert.snapshots" ) ) );
\r
103 dataMap.put( DiscovererJob.MAP_DEF_ARTIFACT_DISCOVERER, defaultArtifactDiscoverer );
\r
104 dataMap.put( DiscovererJob.MAP_LEG_ARTIFACT_DISCOVERER, legacyArtifactDiscoverer );
\r
105 dataMap.put( DiscovererJob.MAP_DEF_METADATA_DISCOVERER, defaultMetadataDiscoverer );
\r
106 dataMap.put( DiscovererJob.MAP_IDX_FACTORY, indexFactory );
\r
107 dataMap.put( DiscovererJob.MAP_REPO_LAYOUT, config.getLayout() );
\r
108 dataMap.put( DiscovererJob.MAP_REPO_FACTORY, repoFactory );
\r
109 jobDetail.setJobDataMap( dataMap );
\r
111 CronTrigger trigger = new CronTrigger( "DiscovererTrigger", "DISCOVERER", props.getProperty( "cron.expression" ) );
\r
112 scheduler.scheduleJob( jobDetail, trigger );
\r
116 * Method that creates the artifact repository
\r
118 * @return an ArtifactRepository instance
\r
119 * @throws java.net.MalformedURLException
\r
121 private ArtifactRepository getDefaultRepository()
\r
122 throws MalformedURLException
\r
124 File repositoryDirectory = new File( config.getRepositoryDirectory() );
\r
125 String repoDir = repositoryDirectory.toURL().toString();
\r
126 ArtifactRepositoryFactory repoFactory = new DefaultArtifactRepositoryFactory();
\r
128 return repoFactory.createArtifactRepository( "test", repoDir, config.getLayout(), null, null );
\r
132 * Method that sets the configuration object
\r
136 public void setConfiguration( Configuration config )
\r
138 this.config = config;
\r
142 * Returns the cofiguration
\r
144 * @return a Configuration object that contains the configuration values
\r
146 public Configuration getConfiguration()
\r