1 package org.apache.maven.plugin.stubs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.compiler.CompilerConfiguration;
23 import org.codehaus.plexus.compiler.CompilerError;
24 import org.codehaus.plexus.compiler.CompilerException;
25 import org.codehaus.plexus.compiler.CompilerOutputStyle;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.Collections;
30 import java.util.List;
31
32
33
34
35 public class CompilerStub
36 implements org.codehaus.plexus.compiler.Compiler
37 {
38 private boolean shouldFail;
39
40 public CompilerStub()
41 {
42 this( false );
43 }
44
45 public CompilerStub( boolean shouldFail )
46 {
47 this.shouldFail = shouldFail;
48 }
49
50 public CompilerOutputStyle getCompilerOutputStyle()
51 {
52 return CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES;
53 }
54
55 public String getInputFileEnding( CompilerConfiguration compilerConfiguration )
56 throws CompilerException
57 {
58 return "java";
59 }
60
61 public String getOutputFileEnding( CompilerConfiguration compilerConfiguration )
62 throws CompilerException
63 {
64 return "class";
65 }
66
67 public String getOutputFile( CompilerConfiguration compilerConfiguration )
68 throws CompilerException
69 {
70 return "output-file";
71 }
72
73 public boolean canUpdateTarget( CompilerConfiguration compilerConfiguration )
74 throws CompilerException
75 {
76 return false;
77 }
78
79 public List compile( CompilerConfiguration compilerConfiguration )
80 throws CompilerException
81 {
82 File outputDir = new File( compilerConfiguration.getOutputLocation() );
83
84 try
85 {
86 outputDir.mkdirs();
87
88 File outputFile = new File( outputDir, "compiled.class" );
89 if ( !outputFile.exists() && !outputFile.createNewFile() )
90 {
91 throw new CompilerException( "could not create output file: " + outputFile.getAbsolutePath() );
92 }
93 }
94 catch ( IOException e )
95 {
96 throw new CompilerException( "An exception occurred while creating output file", e );
97 }
98
99 return Collections.singletonList( new CompilerError( "message 1", shouldFail ) );
100 }
101
102 public String[] createCommandLine( CompilerConfiguration compilerConfiguration )
103 throws CompilerException
104 {
105 return new String[0];
106 }
107 }