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 CoreItMojo
40 extends AbstractMojo
41 {
42
43
44
45 private MavenProject project;
46
47
48
49
50
51 private String outputDirectory;
52
53
54
55
56
57 private Map pluginArtifacts;
58
59
60
61
62 private File basedirAlignmentDirectory;
63
64
65
66
67 private String pluginItem = "foo";
68
69
70
71
72 private String goalItem = "bar";
73
74
75
76
77 private String artifactToFile;
78
79
80
81
82 private boolean fail = false;
83
84 public void execute()
85 throws MojoExecutionException
86 {
87 if ( fail )
88 {
89 throw new MojoExecutionException( "Failing per \'fail\' parameter (specified in pom or system properties)" );
90 }
91
92 touch( new File( outputDirectory ), "touch.txt" );
93
94
95
96
97 if ( !basedirAlignmentDirectory.isAbsolute() )
98 {
99 throw new MojoExecutionException( "basedirAlignmentDirectory not aligned" );
100 }
101
102 touch( basedirAlignmentDirectory, "touch.txt" );
103
104 File outDir = new File( outputDirectory );
105
106
107 if ( pluginItem != null )
108 {
109 touch( outDir, pluginItem );
110 }
111
112 if ( goalItem != null )
113 {
114 touch( outDir, goalItem );
115 }
116
117 if ( artifactToFile != null )
118 {
119 Artifact artifact = (Artifact) pluginArtifacts.get( artifactToFile );
120
121 File artifactFile = artifact.getFile();
122
123 String filename = artifactFile.getAbsolutePath().replace('/', '_').replace(':', '_') + ".txt";
124
125 touch( outDir, filename );
126 }
127
128 project.getBuild().setFinalName( "coreitified" );
129 }
130
131 private void touch( File dir, String file )
132 throws MojoExecutionException
133 {
134 try
135 {
136 if ( !dir.exists() )
137 {
138 dir.mkdirs();
139 }
140
141 File touch = new File( dir, file );
142
143 getLog().info( "Touching file: " + touch.getAbsolutePath() );
144
145 FileWriter w = new FileWriter( touch );
146
147 w.write( file );
148
149 w.close();
150 }
151 catch ( IOException e )
152 {
153 throw new MojoExecutionException( "Error touching file", e );
154 }
155 }
156 }