Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CrawlRepositoryMojo |
|
| 4.0;4 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one | |
3 | * or more contributor license agreements. See the NOTICE file | |
4 | * distributed with this work for additional information | |
5 | * regarding copyright ownership. The ASF licenses this file | |
6 | * to you under the Apache License, Version 2.0 (the | |
7 | * "License"); you may not use this file except in compliance | |
8 | * with the License. You may obtain a copy of the License at | |
9 | * | |
10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
11 | * | |
12 | * Unless required by applicable law or agreed to in writing, | |
13 | * software distributed under the License is distributed on an | |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | * KIND, either express or implied. See the License for the | |
16 | * specific language governing permissions and limitations | |
17 | * under the License. | |
18 | */ | |
19 | ||
20 | package org.apache.maven.archetype.mojos; | |
21 | ||
22 | import org.apache.maven.archetype.catalog.ArchetypeCatalog; | |
23 | import org.apache.maven.archetype.repositorycrawler.RepositoryCrawler; | |
24 | import org.apache.maven.plugin.AbstractMojo; | |
25 | import org.apache.maven.plugin.MojoExecutionException; | |
26 | import org.apache.maven.plugin.MojoFailureException; | |
27 | ||
28 | import java.io.File; | |
29 | ||
30 | /** | |
31 | * Crawl a Maven 2 repository (Filesystem, not HTTP) | |
32 | * and creates a catalog file. | |
33 | * | |
34 | * @author rafale | |
35 | * @requiresProject false | |
36 | * @goal crawl | |
37 | */ | |
38 | 0 | public class CrawlRepositoryMojo |
39 | extends AbstractMojo | |
40 | { | |
41 | /** | |
42 | * The archetype's catalog to update. | |
43 | * | |
44 | * @parameter expression="${catalog}" | |
45 | */ | |
46 | private File catalogFile; | |
47 | ||
48 | /** | |
49 | * @component | |
50 | */ | |
51 | private RepositoryCrawler crawler; | |
52 | ||
53 | /** | |
54 | * The repository to crawl. | |
55 | * | |
56 | * @parameter expression="${repository}" default-value="${settings.localRepository}" | |
57 | */ | |
58 | private File repository; | |
59 | ||
60 | public void execute () | |
61 | throws MojoExecutionException, MojoFailureException | |
62 | { | |
63 | 0 | System.err.println ( "repository " + repository ); |
64 | 0 | System.err.println ( "catalogFile " + catalogFile ); |
65 | 0 | if ( repository == null ) |
66 | { | |
67 | 0 | throw new MojoFailureException ( |
68 | "The repository is not defined. Use -Drepository=/path/to/repository" | |
69 | ); | |
70 | } | |
71 | ||
72 | 0 | ArchetypeCatalog catalog = crawler.crawl ( repository ); |
73 | 0 | if ( catalogFile == null ) |
74 | { | |
75 | 0 | catalogFile = new File ( repository, "archetype-catalog.xml" ); |
76 | } | |
77 | 0 | crawler.writeCatalog ( catalog, catalogFile ); |
78 | 0 | } |
79 | } |