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 and runtime in the order returned from the Maven
27 * core. The path parameters of this mojo support the token <code>@idx@</code> to dynamically insert a running
28 * index in order to distinguish multiple executions of the same mojo.
29 *
30 * @goal compile-runtime
31 * @requiresDependencyResolution compile+runtime
32 *
33 * @author Benjamin Bentmann
34 *
35 */
36 public class CompileRuntimeMojo
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 * The path to the output file for the runtime artifacts, relative to the project base directory. Each line of this
79 * UTF-8 encoded file specifies an artifact identifier. If not specified, the artifact list will not be written to
80 * disk.
81 *
82 * @parameter property="depres.runtimeArtifacts"
83 */
84 private String runtimeArtifacts;
85
86 /**
87 * The path to the output file for the runtime class path, relative to the project base directory. Each line of
88 * this UTF-8 encoded file specifies the absolute path to a class path element. If not specified, the class path
89 * will not be written to disk.
90 *
91 * @parameter property="depres.runtimeClassPath"
92 */
93 private String runtimeClassPath;
94
95 /**
96 * The path to the properties file for the checksums of the runtime class path elements, relative to the project
97 * base directory. The (trimmed) path to a JAR is used as the property key, the property value is the SHA-1 hash of
98 * the JAR. If not specified, the class path checksums will not be calculated.
99 *
100 * @parameter property="depres.runtimeClassPathChecksums"
101 */
102 private String runtimeClassPathChecksums;
103
104 /**
105 * Runs this mojo.
106 *
107 * @throws MojoExecutionException If the output file could not be created or any dependency could not be resolved.
108 */
109 public void execute()
110 throws MojoExecutionException
111 {
112 try
113 {
114 writeArtifacts( projectArtifacts, project.getArtifacts() );
115 writeArtifacts( compileArtifacts, project.getCompileArtifacts() );
116 writeClassPath( compileClassPath, project.getCompileClasspathElements() );
117 writeClassPathChecksums( compileClassPathChecksums, project.getCompileClasspathElements() );
118 writeArtifacts( runtimeArtifacts, project.getRuntimeArtifacts() );
119 writeClassPath( runtimeClassPath, project.getRuntimeClasspathElements() );
120 writeClassPathChecksums( runtimeClassPathChecksums, project.getRuntimeClasspathElements() );
121 }
122 catch ( DependencyResolutionRequiredException e )
123 {
124 throw new MojoExecutionException( "Failed to resolve dependencies", e );
125 }
126 }
127
128 }