1 package org.apache.maven.plugin.assembly.mojos;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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.Iterator;
33 import java.util.List;
34
35
36
37
38 @Deprecated
39 public abstract class AbstractDirectoryMojo
40 extends AbstractAssemblyMojo
41 {
42 @Override
43 public void execute()
44 throws MojoExecutionException, MojoFailureException
45 {
46 final AssemblyReader reader = getAssemblyReader();
47
48 List<Assembly> assemblies;
49 try
50 {
51 assemblies = reader.readAssemblies( this );
52 }
53 catch ( final AssemblyReadException e )
54 {
55 throw new MojoExecutionException( "Error reading assembly descriptors: " + e.getMessage(), e );
56 }
57 catch ( final InvalidAssemblerConfigurationException e )
58 {
59 throw new MojoFailureException( reader, e.getMessage(), "Mojo configuration is invalid: " + e.getMessage() );
60 }
61
62 for ( final Iterator<Assembly> i = assemblies.iterator(); i.hasNext(); )
63 {
64 final Assembly assembly = i.next();
65 createDirectory( assembly );
66 }
67 }
68
69 private void createDirectory( final Assembly assembly )
70 throws MojoExecutionException, MojoFailureException
71 {
72 final AssemblyArchiver archiver = getAssemblyArchiver();
73
74 String fullName = getFinalName();
75
76 if ( appendAssemblyId )
77 {
78 fullName = fullName + "-" + assembly.getId();
79 }
80 else if ( getClassifier() != null )
81 {
82 fullName = fullName + "-" + getClassifier();
83 }
84
85 try
86 {
87 archiver.createArchive( assembly, fullName, "dir", this );
88 }
89 catch ( final ArchiveCreationException e )
90 {
91 throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
92 }
93 catch ( final AssemblyFormattingException e )
94 {
95 throw new MojoExecutionException( "Error creating assembly: " + e.getMessage(), e );
96 }
97 catch ( final InvalidAssemblerConfigurationException e )
98 {
99 throw new MojoFailureException( assembly, "Assembly is incorrectly configured: " + assembly.getId(),
100 "Assembly: " + assembly.getId() + " is not configured correctly: "
101 + e.getMessage() );
102 }
103 }
104
105 }