View Javadoc
1   package org.apache.maven.plugin.coreit;
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.apache.maven.artifact.DependencyResolutionRequiredException;
23  import org.apache.maven.plugin.MojoExecutionException;
24  
25  /**
26   * Creates text files that list the dependencies with scope compile in the order returned from the Maven core. The path
27   * parameters of this mojo support the token <code>&#64;idx&#64;</code> to dynamically insert a running index in order
28   * to distinguish multiple executions of the same mojo.
29   *
30   * @goal compile
31   * @requiresDependencyResolution compile
32   *
33   * @author Benjamin Bentmann
34   *
35   */
36  public class CompileMojo
37      extends AbstractDependencyMojo
38  {
39  
40      /**
41       * The path to the output file for the project artifacts, relative to the project base directory. Each line of this
42       * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
43       * disk. Unlike the compile artifacts, the collection of project artifacts additionally contains those artifacts
44       * that do not contribute to the class path.
45       *
46       * @parameter property="depres.projectArtifacts"
47       */
48      private String projectArtifacts;
49  
50      /**
51       * The path to the output file for the compile artifacts, relative to the project base directory. Each line of this
52       * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
53       * disk.
54       *
55       * @parameter property="depres.compileArtifacts"
56       */
57      private String compileArtifacts;
58  
59      /**
60       * The path to the output file for the compile class path, relative to the project base directory. Each line of
61       * this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
62       * will not be written to disk.
63       *
64       * @parameter property="depres.compileClassPath"
65       */
66      private String compileClassPath;
67  
68      /**
69       * The path to the properties file for the checksums of the compile class path elements, relative to the project
70       * base directory. The (trimmed) path to a JAR is used as the property key, the property value is the SHA-1 hash of
71       * the JAR. If not specified, the class path checksums will not be calculated.
72       *
73       * @parameter property="depres.compileClassPathChecksums"
74       */
75      private String compileClassPathChecksums;
76  
77      /**
78       * Runs this mojo.
79       *
80       * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
81       */
82      public void execute()
83          throws MojoExecutionException
84      {
85          try
86          {
87              writeArtifacts( projectArtifacts, project.getArtifacts() );
88              writeArtifacts( compileArtifacts, project.getCompileArtifacts() );
89              writeClassPath( compileClassPath, project.getCompileClasspathElements() );
90              writeClassPathChecksums( compileClassPathChecksums, project.getCompileClasspathElements() );
91          }
92          catch ( DependencyResolutionRequiredException e )
93          {
94              throw new MojoExecutionException( "Failed to resolve dependencies", e );
95          }
96      }
97  
98  }