View Javadoc

1   package org.apache.maven.plugin.stubs;
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 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   * @author Edwin Punzalan
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 }