View Javadoc
1   package org.apache.maven.plugin.assembly.mojos;
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.assembly.InvalidAssemblerConfigurationException;
25  import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
26  import org.apache.maven.plugin.assembly.archive.AssemblyArchiver;
27  import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
28  import org.apache.maven.plugin.assembly.io.AssemblyReadException;
29  import org.apache.maven.plugin.assembly.io.AssemblyReader;
30  import org.apache.maven.plugin.assembly.model.Assembly;
31  
32  import java.util.List;
33  
34  /**
35   * @version $Id: AbstractDirectoryMojo.java 1639422 2014-11-13 18:08:07Z krosenvold $
36   */
37  @Deprecated
38  public abstract class AbstractDirectoryMojo
39      extends AbstractAssemblyMojo
40  {
41      @Override
42      public void execute()
43          throws MojoExecutionException, MojoFailureException
44      {
45          final AssemblyReader reader = getAssemblyReader();
46  
47          List<Assembly> assemblies;
48          try
49          {
50              assemblies = reader.readAssemblies( this );
51          }
52          catch ( final AssemblyReadException e )
53          {
54              throw new MojoExecutionException( "Error reading assembly descriptors: " + e.getMessage(), e );
55          }
56          catch ( final InvalidAssemblerConfigurationException e )
57          {
58              throw new MojoFailureException( reader, e.getMessage(),
59                                              "Mojo configuration is invalid: " + e.getMessage() );
60          }
61  
62          for ( Assembly assembly : assemblies )
63          {
64              createDirectory( assembly );
65          }
66      }
67  
68      private void createDirectory( final Assembly assembly )
69          throws MojoExecutionException, MojoFailureException
70      {
71          final AssemblyArchiver archiver = getAssemblyArchiver();
72  
73          String fullName = getFinalName();
74  
75          if ( appendAssemblyId )
76          {
77              fullName = fullName + "-" + assembly.getId();
78          }
79          else if ( getClassifier() != null )
80          {
81              fullName = fullName + "-" + getClassifier();
82          }
83  
84          try
85          {
86              archiver.createArchive( assembly, fullName, "dir", this, isRecompressZippedFiles() );
87          }
88          catch ( final ArchiveCreationException e )
89          {
90              throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
91          }
92          catch ( final AssemblyFormattingException e )
93          {
94              throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
95          }
96          catch ( final InvalidAssemblerConfigurationException e )
97          {
98              throw new MojoFailureException( assembly, "Assembly is incorrectly configured: " + assembly.getId(),
99                                              "Assembly: " + assembly.getId() + " is not configured correctly: "
100                                                 + e.getMessage() );
101         }
102     }
103 
104 }