View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.jmod;
20  
21  import javax.inject.Inject;
22  
23  import java.io.File;
24  import java.io.IOException;
25  import java.util.List;
26  
27  import org.apache.maven.plugin.MojoExecutionException;
28  import org.apache.maven.plugin.MojoFailureException;
29  import org.apache.maven.plugins.annotations.LifecyclePhase;
30  import org.apache.maven.plugins.annotations.Mojo;
31  import org.apache.maven.plugins.annotations.Parameter;
32  import org.apache.maven.plugins.annotations.ResolutionScope;
33  import org.apache.maven.shared.utils.cli.Commandline;
34  import org.apache.maven.toolchain.ToolchainManager;
35  
36  /**
37   * <pre>
38   * jmod hash ...
39   * </pre>
40   *
41   * @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
42   */
43  // TODO: Reconsider resolution scope, phase ?
44  @Mojo(name = "hash", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PACKAGE)
45  public class JModHashMojo extends AbstractJModMojo {
46  
47      /**
48       * <code>--class-path &lt;path&gt;</code> Application jar files|dir containing classes.
49       */
50      @Parameter
51      private List<String> classPath;
52  
53      /**
54       * <code>--class-path &lt;path&gt;</code> Application jar files|dir containing classes.
55       */
56      @Parameter
57      private List<String> cmds;
58  
59      /**
60       * <code>--config &lt;path&gt;</code> Location of user-editable config files.
61       */
62      @Parameter
63      private File config;
64  
65      @Parameter
66      private boolean dryRun;
67  
68      @Parameter
69      private List<String> excludes;
70  
71      @Parameter
72      private String mainClass;
73  
74      @Parameter
75      private List<File> libs;
76  
77      @Parameter
78      private String moduleVersion;
79  
80      /**
81       * Define the modulepath for the <code>jmod</code> call. <code>--module-path &lt;path&gt;</code>
82       * Must be a directory.
83       */
84      @Parameter(required = true)
85      private File modulePath;
86  
87      @Inject
88      public JModHashMojo(ToolchainManager toolchainManager) {
89          super(toolchainManager);
90      }
91  
92      public void execute() throws MojoExecutionException, MojoFailureException {
93  
94          String jModExecutable;
95          try {
96              jModExecutable = getJModExecutable();
97          } catch (IOException e) {
98              throw new MojoFailureException("Unable to find jmod command: " + e.getMessage(), e);
99          }
100 
101         Commandline cmd = createJModHashCommandLine();
102         cmd.setExecutable(jModExecutable);
103 
104         // executeCommand( cmd, outputDirectory );
105 
106     }
107 
108     private Commandline createJModHashCommandLine() {
109         Commandline cmd = new Commandline();
110 
111         cmd.createArg().setValue("hash");
112 
113         if (dryRun) {
114             cmd.createArg().setValue("--dry-run");
115         }
116 
117         return cmd;
118     }
119 }