View Javadoc
1   package org.apache.maven.plugins.war.packaging;
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 java.io.File;
23  import java.io.IOException;
24  
25  import org.apache.maven.plugin.MojoExecutionException;
26  import org.apache.maven.plugin.MojoFailureException;
27  import org.apache.maven.plugin.logging.Log;
28  import org.apache.maven.plugin.logging.SystemStreamLog;
29  
30  /**
31   * @author Haikal Saadh
32   *
33   */
34  public class CopyUserManifestTask
35      extends AbstractWarPackagingTask
36  {
37  
38      /** Instance logger */
39      private Log log;
40  
41      public Log getLog()
42      {
43          if ( log == null )
44          {
45              log = new SystemStreamLog();
46          }
47          return log;
48      }
49  
50      public void setLog( Log log )
51      {
52          this.log = log;
53      }
54  
55      public void performPackaging( WarPackagingContext context )
56          throws MojoExecutionException, MojoFailureException
57      {
58          File userManifest = context.getArchive().getManifestFile();
59          if ( userManifest != null )
60          {
61  
62              try
63              {
64                  getLog().info( "Copying manifest..." );
65                  File metainfDir = new File( context.getWebappDirectory(), META_INF_PATH );
66                  copyFile( context, userManifest, new File( metainfDir, "MANIFEST.MF" ), "META-INF/MANIFEST.MF", true );
67  
68              }
69              catch ( IOException e )
70              {
71                  throw new MojoExecutionException( "Error copying user manifest", e );
72              }
73          }
74  
75      }
76  
77  }