]> source.dussan.org Git - archiva.git/blob
acf062e95d878756211be4585427eec772b3c213
[archiva.git] /
1 package org.apache.maven.repository.manager.web.job;\r
2 \r
3 /*\r
4  * Copyright 2005-2006 The Apache Software Foundation.\r
5  *\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
9  *\r
10  *      http://www.apache.org/licenses/LICENSE-2.0\r
11  *\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
17  */\r
18 \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
24 \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
37 \r
38 /**\r
39  * This class sets the job to be executed in the plexus-quartz scheduler\r
40  *\r
41  * @plexus.component role="org.apache.maven.repository.manager.web.job.DiscovererScheduler"\r
42  */\r
43 public class DiscovererScheduler\r
44     extends AbstractLogEnabled\r
45 {\r
46     /**\r
47      * @plexus.requirement\r
48      */\r
49     private Configuration config;\r
50 \r
51     /**\r
52      * @plexus.requirement\r
53      */\r
54     private Scheduler scheduler;\r
55 \r
56     /**\r
57      * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultArtifactDiscoverer"\r
58      */\r
59     private ArtifactDiscoverer defaultArtifactDiscoverer;\r
60 \r
61     /**\r
62      * @plexus.requirement role="org.apache.maven.repository.discovery.ArtifactDiscoverer" role-hint="org.apache.maven.repository.discovery.LegacyArtifactDiscoverer"\r
63      */\r
64     private ArtifactDiscoverer legacyArtifactDiscoverer;\r
65 \r
66     /**\r
67      * @plexus.requirement role="org.apache.maven.repository.discovery.MetadataDiscoverer" role-hint="org.apache.maven.repository.discovery.DefaultMetadataDiscoverer"\r
68      */\r
69     private MetadataDiscoverer defaultMetadataDiscoverer;\r
70 \r
71     /**\r
72      * @plexus.requirement\r
73      */\r
74     private RepositoryIndexingFactory indexFactory;\r
75 \r
76     /**\r
77      * @plexus.requirement\r
78      */\r
79     private ArtifactRepositoryFactory repoFactory;\r
80 \r
81     private Properties props;\r
82 \r
83     /**\r
84      * Method that sets the schedule in the plexus-quartz scheduler\r
85      *\r
86      * @throws IOException\r
87      * @throws ParseException\r
88      * @throws SchedulerException\r
89      */\r
90     public void setSchedule()\r
91         throws IOException, ParseException, SchedulerException\r
92     {\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
110 \r
111         CronTrigger trigger = new CronTrigger( "DiscovererTrigger", "DISCOVERER", props.getProperty( "cron.expression" ) );\r
112         scheduler.scheduleJob( jobDetail, trigger );\r
113     }\r
114 \r
115     /**\r
116      * Method that creates the artifact repository\r
117      *\r
118      * @return an ArtifactRepository instance\r
119      * @throws java.net.MalformedURLException\r
120      */\r
121     private ArtifactRepository getDefaultRepository()\r
122         throws MalformedURLException\r
123     {\r
124         File repositoryDirectory = new File( config.getRepositoryDirectory() );\r
125         String repoDir = repositoryDirectory.toURL().toString();\r
126         ArtifactRepositoryFactory repoFactory = new DefaultArtifactRepositoryFactory();\r
127 \r
128         return repoFactory.createArtifactRepository( "test", repoDir, config.getLayout(), null, null );\r
129     }\r
130 \r
131     /**\r
132      * Method that sets the configuration object\r
133      *\r
134      * @param config\r
135      */\r
136     public void setConfiguration( Configuration config )\r
137     {\r
138         this.config = config;\r
139     }\r
140 \r
141     /**\r
142      * Returns the cofiguration\r
143      *\r
144      * @return a Configuration object that contains the configuration values\r
145      */\r
146     public Configuration getConfiguration()\r
147     {\r
148         return config;\r
149     }\r
150 \r
151 }\r