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.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.apache.maven.project.MavenProject;
25
26 import java.io.File;
27 import java.io.FileOutputStream;
28 import java.io.OutputStreamWriter;
29 import java.io.IOException;
30
31
32
33
34
35
36 public class TouchMojo
37 extends AbstractMojo
38 {
39
40 static final String FINAL_NAME = "coreitified";
41
42
43
44
45 private MavenProject project;
46
47
48
49
50
51 private File outputDirectory;
52
53 public void execute()
54 throws MojoExecutionException
55 {
56 getLog().info( "[MAVEN-CORE-IT-LOG] Project build directory " + project.getBuild().getDirectory() );
57
58 touch( new File( project.getBuild().getDirectory() ), "touch.log" );
59
60 getLog().info( "[MAVEN-CORE-IT-LOG] Using output directory " + outputDirectory );
61
62 touch( outputDirectory, "touch.txt" );
63
64 project.getBuild().setFinalName( FINAL_NAME );
65 }
66
67 static void touch( File dir, String file )
68 throws MojoExecutionException
69 {
70 try
71 {
72 if ( !dir.exists() )
73 {
74 dir.mkdirs();
75 }
76
77 File touch = new File( dir, file );
78
79
80 OutputStreamWriter w = new OutputStreamWriter( new FileOutputStream( touch, true ), "UTF-8" );
81
82 w.write( file );
83 w.write( "\n" );
84
85 w.close();
86 }
87 catch ( IOException e )
88 {
89 throw new MojoExecutionException( "Error touching file", e );
90 }
91 }
92
93 }