View Javadoc
1   package org.codehaus.mojo.truezip;
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.AbstractMojo;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.project.MavenProject;
26  import org.apache.maven.shared.model.fileset.FileSet;
27  import org.codehaus.mojo.truezip.internal.DefaultTrueZip;
28  import org.codehaus.mojo.truezip.internal.DefaultTrueZipArchiveDetector;
29  
30  import de.schlichtherle.truezip.file.TFile;
31  import de.schlichtherle.truezip.fs.FsSyncException;
32  
33  public abstract class AbstractArchiveMojo
34      extends AbstractMojo
35  {
36  
37      /**
38       * Internal Maven's project
39       * 
40       * @parameter default-value="${project}"
41       * @readonly
42       * @since 1.0 beta-1
43       */
44      protected MavenProject project;
45  
46      /**
47       * @since 1.0 beta-1
48       */
49      protected TrueZip truezip = new DefaultTrueZip();
50  
51      /**
52       * Enable automatic file update after each MOJO execution. If set to <code>false</code>, immediate update is not
53       * performed. Then, the updated files are flushed at undefined time (when the VM finalizes objects). Otherwise, a
54       * forced file update can be triggered by using <code>update</code> goal in an separate execution.
55       * 
56       * @parameter default-value="true"
57       * @since 1.0 beta-2
58       */
59      protected boolean immediateUpdate;
60  
61      /**
62       * Skip
63       * 
64       * @parameter property="truezip.skip" default-value="false"
65       * @since 1.2
66       */
67      protected boolean skip;
68  
69      protected String resolveRelativePath( String path )
70      {
71          if ( path != null && !new TFile( path ).isAbsolute() )
72          {
73              path = new TFile( this.project.getBasedir(), path ).getAbsolutePath();
74          }
75  
76          return path;
77      }
78  
79      protected void resolveRelativePath( FileSet fileSet )
80      {
81          fileSet.setDirectory( resolveRelativePath( fileSet.getDirectory() ) );
82          fileSet.setOutputDirectory( resolveRelativePath( fileSet.getOutputDirectory() ) );
83      }
84  
85      protected void resolveRelativePath( FileItem fileItem )
86      {
87          fileItem.setOutputDirectory( resolveRelativePath( fileItem.getOutputDirectory() ) );
88          fileItem.setSource( resolveRelativePath( fileItem.getSource() ) );
89      }
90  
91      protected void tryImmediateUpdate()
92          throws MojoExecutionException
93      {
94  
95          if ( immediateUpdate )
96          {
97              try
98              {
99                  truezip.sync();
100             }
101             catch ( FsSyncException e )
102             {
103                 throw new MojoExecutionException( "Immediate file update failed!", e );
104             }
105         }
106     }
107 
108     protected void intitializeArchiveDectector()
109     {
110         DefaultTrueZipArchiveDetector archiveDetector = new DefaultTrueZipArchiveDetector();
111         archiveDetector.init();
112     }
113 
114     public void execute()
115         throws MojoExecutionException, MojoFailureException
116     {
117         // StaticLoggerBinder.getSingleton().setMavenLog( this.getLog() );
118 
119     }
120 }