View Javadoc

1   package org.apache.maven.plugin.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 org.apache.maven.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.MojoFailureException;
24  import org.apache.maven.plugin.war.util.WebappStructureSerializer;
25  
26  import java.io.File;
27  import java.io.IOException;
28  
29  /**
30   * Saves the webapp structure cache.
31   *
32   * @author Stephane Nicoll
33   * 
34   * @version $Id: SaveWebappStructurePostPackagingTask.java 659222 2008-05-22 19:33:48Z olamy $
35   */
36  public class SaveWebappStructurePostPackagingTask
37      implements WarPostPackagingTask
38  {
39  
40      private final File targetFile;
41  
42      private final WebappStructureSerializer serialier;
43  
44  
45      public SaveWebappStructurePostPackagingTask( File targetFile )
46      {
47          this.targetFile = targetFile;
48          this.serialier = new WebappStructureSerializer();
49      }
50  
51      public void performPostPackaging( WarPackagingContext context )
52          throws MojoExecutionException, MojoFailureException
53      {
54          if ( targetFile == null )
55          {
56              context.getLog().debug( "Cache usage is disabled, not saving webapp structure." );
57          }
58          else
59          {
60              try
61              {
62                  serialier.toXml( context.getWebappStructure(), targetFile );
63                  context.getLog().debug( "Cache saved successfully." );
64              }
65              catch ( IOException e )
66              {
67                  throw new MojoExecutionException( "Could not save webapp structure", e );
68              }
69          }
70      }
71  }