1 package org.apache.maven.plugin.coreit;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.project.MavenProject;
26
27 import java.io.File;
28 import java.io.FileWriter;
29 import java.io.IOException;
30 import java.util.Map;
31
32
33
34
35
36
37
38
39 public class CoreItTouchMojo
40 extends AbstractMojo
41 {
42
43
44
45 private MavenProject project;
46
47
48
49
50
51
52
53 private String outputDirectory;
54
55
56
57
58
59
60
61 private Map<String, Artifact> pluginArtifacts;
62
63
64
65
66
67
68
69
70 private File basedirAlignmentDirectory;
71
72
73
74
75 private String pluginItem = "foo";
76
77
78
79
80 private String goalItem = "bar";
81
82
83
84
85
86
87 private String artifactToFile;
88
89
90
91
92
93
94 private boolean fail = false;
95
96 public void execute()
97 throws MojoExecutionException
98 {
99 if ( fail )
100 {
101 throw new MojoExecutionException( "Failing per \'fail\' parameter"
102 + " (specified in pom or system properties)" );
103 }
104
105 File outDir = new File( outputDirectory );
106
107 touch( outDir, "touch.txt" );
108
109
110
111 if ( !basedirAlignmentDirectory.isAbsolute() )
112 {
113 throw new MojoExecutionException( "basedirAlignmentDirectory not aligned" );
114 }
115 touch( basedirAlignmentDirectory, "touch.txt" );
116
117
118 if ( pluginItem != null )
119 {
120 touch( outDir, pluginItem );
121 }
122
123 if ( goalItem != null )
124 {
125 touch( outDir, goalItem );
126 }
127
128 if ( artifactToFile != null )
129 {
130 Artifact artifact = pluginArtifacts.get( artifactToFile );
131
132 File artifactFile = artifact.getFile();
133
134 String filename = artifactFile.getAbsolutePath().replace( '/', '_' ).replace( ':', '_' ) + ".txt";
135
136 touch( outDir, filename );
137 }
138
139 project.getBuild().setFinalName( "coreitified" );
140 }
141
142 private void touch( File dir, String file )
143 throws MojoExecutionException
144 {
145 try
146 {
147 if ( !dir.exists() )
148 {
149 dir.mkdirs();
150 }
151
152 File touch = new File( dir, file );
153
154 getLog().info( "Touching file: " + touch.getAbsolutePath() );
155
156 FileWriter w = new FileWriter( touch );
157
158 w.write( file );
159
160 w.close();
161 }
162
163 catch ( IOException e )
164 {
165 throw new MojoExecutionException( "Error touching file", e );
166 }
167 }
168 }