Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ItMojo |
|
| 3.0;3 |
1 | package org.apache.maven.plugin.coreit; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | import java.io.FileOutputStream; | |
24 | import java.io.IOException; | |
25 | import java.util.List; | |
26 | import java.util.Map; | |
27 | import java.util.Properties; | |
28 | ||
29 | import org.apache.maven.plugin.AbstractMojo; | |
30 | import org.apache.maven.plugin.MojoExecutionException; | |
31 | ||
32 | /** | |
33 | * Requires a singleton component in various ways and dumps the ids to a properties file. | |
34 | * | |
35 | * @goal it | |
36 | * @phase initialize | |
37 | * | |
38 | * @author Benjamin Bentmann | |
39 | * @version $Id: ItMojo.java 834849 2009-11-11 12:23:29Z bentmann $ | |
40 | */ | |
41 | 0 | public class ItMojo |
42 | extends AbstractMojo | |
43 | { | |
44 | ||
45 | /** | |
46 | * The path to the output file. | |
47 | * | |
48 | * @parameter expression="${touch.outputFile}" default-value="target/comp.properties" | |
49 | */ | |
50 | private File outputFile; | |
51 | ||
52 | /** | |
53 | * Component lookup without role hint. | |
54 | * | |
55 | * @component | |
56 | */ | |
57 | private Component componentWithoutRoleHint; | |
58 | ||
59 | /** | |
60 | * Component lookup with explicit role hint. | |
61 | * | |
62 | * @component roleHint="default" | |
63 | */ | |
64 | private Component componentWithRoleHint; | |
65 | ||
66 | /** | |
67 | * Component lookup via active map. | |
68 | * | |
69 | * @component role="org.apache.maven.plugin.coreit.Component" | |
70 | */ | |
71 | private Map componentMap; | |
72 | ||
73 | /** | |
74 | * Component lookup via active list. | |
75 | * | |
76 | * @component role="org.apache.maven.plugin.coreit.Component" | |
77 | */ | |
78 | private List componentList; | |
79 | ||
80 | /** | |
81 | * Runs this mojo. | |
82 | * | |
83 | * @throws MojoExecutionException If the output file could not be created. | |
84 | */ | |
85 | public void execute() | |
86 | throws MojoExecutionException | |
87 | { | |
88 | 0 | Component componentFromMap = (Component) componentMap.values().iterator().next(); |
89 | 0 | Component componentFromList = (Component) componentList.iterator().next(); |
90 | ||
91 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Using component: " + componentWithoutRoleHint ); |
92 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Using component: " + componentWithRoleHint ); |
93 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Using component: " + componentFromMap ); |
94 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Using component: " + componentFromList ); |
95 | ||
96 | 0 | Properties props = new Properties(); |
97 | 0 | props.setProperty( "id.0", componentWithoutRoleHint.getId() ); |
98 | 0 | props.setProperty( "id.1", componentWithRoleHint.getId() ); |
99 | 0 | props.setProperty( "id.2", componentFromMap.getId() ); |
100 | 0 | props.setProperty( "id.3", componentFromList.getId() ); |
101 | ||
102 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile ); |
103 | ||
104 | try | |
105 | { | |
106 | 0 | outputFile.getParentFile().mkdirs(); |
107 | 0 | FileOutputStream os = new FileOutputStream( outputFile ); |
108 | try | |
109 | { | |
110 | 0 | props.store( os, "MAVEN-CORE-IT-LOG" ); |
111 | } | |
112 | finally | |
113 | { | |
114 | 0 | os.close(); |
115 | 0 | } |
116 | } | |
117 | 0 | catch ( IOException e ) |
118 | { | |
119 | 0 | throw new MojoExecutionException( "Output file could not be created: " + outputFile, e ); |
120 | 0 | } |
121 | ||
122 | 0 | getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + outputFile ); |
123 | 0 | } |
124 | ||
125 | } |