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.creadur.whisker.plugin.maven;
20  
21  import java.io.File;
22  
23  import org.apache.maven.plugin.AbstractMojo;
24  import org.apache.maven.plugin.MojoExecutionException;
25  import org.apache.creadur.whisker.app.Act;
26  import org.apache.creadur.whisker.app.Whisker;
27  import org.apache.creadur.whisker.app.load.StreamableResourceFactory;
28  import org.apache.creadur.whisker.app.out.WriteResultsIntoDirectoryFactory;
29  import org.apache.creadur.whisker.out.velocity.VelocityEngine;
30  
31  
32  /**
33   * Generates licensing related materials such as LICENSE and NOTICE documents
34   * for assembled applications.
35   * @goal generate
36   */
37  public class GenerateMojo extends AbstractMojo {
38  
39      /**
40       * Destination for generated materials
41       *
42       * @parameter default-value="${project.build.directory}"
43       */
44      private File outputDirectory;
45  
46      /**
47       * The licensing materials will be encoding thus.
48       * @parameter property="outputEncoding" default-value="${project.build.sourceEncoding}"
49       */
50      private String outputEncoding;
51  
52      /**
53       * This file contains a description of the licensing qualities of
54       * the expected contents of the assembled application.
55       *
56       * @required
57       * @parameter property="apacheWhiskerDescriptor"
58       */
59      private File descriptor;
60  
61      /**
62       * Generate licensing related materials such as LICENSE and NOTICE documents.
63       * @throws MojoExecutionException when Whisker fails,
64       * or when configured cannot be executed
65       * @see org.apache.maven.plugin.Mojo#execute()
66       */
67      public void execute() throws MojoExecutionException {
68          if (descriptor.exists()) {
69              if (descriptor.canRead()) {
70                   try {
71                      new Whisker().setLicenseDescriptor(new StreamableResourceFactory().streamFromFileResource(descriptor))
72                          .setEngine(new VelocityEngine(new MojoToJCLLog(getLog())))
73                          .setWriterFactory(new WriteResultsIntoDirectoryFactory(outputDirectory, outputEncoding))
74                          .setAct(Act.GENERATE).act();
75                  } catch (Exception e) {
76                      throw new MojoExecutionException("Whisker failed to generate materials: " + e.getMessage(), e);
77                  }
78              } else {
79                  throw new MojoExecutionException("Read permission requires on Whisker descriptor file: " + descriptor);
80              }
81          } else {
82              throw new MojoExecutionException("Whisker descriptor file is missing: " + descriptor);
83          }
84      }
85  
86  }