1 package org.apache.maven.plugin.assembly.archive.phase;
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.assembly.AssemblerConfigurationSource;
23 import org.apache.maven.plugin.assembly.InvalidAssemblerConfigurationException;
24 import org.apache.maven.plugin.assembly.archive.ArchiveCreationException;
25 import org.apache.maven.plugin.assembly.archive.phase.wrappers.RepoBuilderConfigSourceWrapper;
26 import org.apache.maven.plugin.assembly.archive.phase.wrappers.RepoInfoWrapper;
27 import org.apache.maven.plugin.assembly.archive.task.AddDirectoryTask;
28 import org.apache.maven.plugin.assembly.format.AssemblyFormattingException;
29 import org.apache.maven.plugin.assembly.model.Assembly;
30 import org.apache.maven.plugin.assembly.model.Repository;
31 import org.apache.maven.plugin.assembly.utils.AssemblyFormatUtils;
32 import org.apache.maven.plugin.assembly.utils.TypeConversionUtils;
33 import org.apache.maven.shared.repository.RepositoryAssembler;
34 import org.apache.maven.shared.repository.RepositoryAssemblyException;
35 import org.apache.maven.shared.repository.RepositoryBuilderConfigSource;
36 import org.apache.maven.shared.repository.model.RepositoryInfo;
37 import org.codehaus.plexus.archiver.Archiver;
38 import org.codehaus.plexus.component.annotations.Component;
39 import org.codehaus.plexus.component.annotations.Requirement;
40 import org.codehaus.plexus.logging.AbstractLogEnabled;
41
42 import java.io.File;
43 import java.util.List;
44
45
46
47
48 @Component( role = AssemblyArchiverPhase.class, hint = "repositories" )
49 public class RepositoryAssemblyPhase
50 extends AbstractLogEnabled
51 implements AssemblyArchiverPhase, PhaseOrder
52 {
53
54 @Requirement
55 private RepositoryAssembler repositoryAssembler;
56
57 public RepositoryAssemblyPhase()
58 {
59
60 }
61
62
63 public RepositoryAssemblyPhase( final RepositoryAssembler repositoryAssembler )
64 {
65 this.repositoryAssembler = repositoryAssembler;
66 }
67
68
69
70
71 @SuppressWarnings( "ResultOfMethodCallIgnored" )
72 public void execute( final Assembly assembly, final Archiver archiver,
73 final AssemblerConfigurationSource configSource )
74 throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException
75 {
76 final List<Repository> repositoriesList = assembly.getRepositories();
77
78 final File tempRoot = configSource.getTemporaryRootDirectory();
79
80 for ( final Repository repository : repositoriesList )
81 {
82 final String outputDirectory =
83 AssemblyFormatUtils.getOutputDirectory( repository.getOutputDirectory(), configSource.getFinalName(),
84 configSource, AssemblyFormatUtils.moduleProjectInterpolator(
85 configSource.getProject() ), AssemblyFormatUtils.artifactProjectInterpolator( null ) );
86
87 final File repositoryDirectory = new File( tempRoot, outputDirectory );
88
89 if ( !repositoryDirectory.exists() )
90 {
91 repositoryDirectory.mkdirs();
92 }
93
94 try
95 {
96 getLogger().debug( "Assembling repository to: " + repositoryDirectory );
97 repositoryAssembler.buildRemoteRepository( repositoryDirectory, wrap( repository ),
98 wrap( configSource ) );
99 getLogger().debug( "Finished assembling repository to: " + repositoryDirectory );
100 }
101 catch ( final RepositoryAssemblyException e )
102 {
103 throw new ArchiveCreationException( "Failed to assemble repository: " + e.getMessage(), e );
104 }
105
106 final AddDirectoryTask task = new AddDirectoryTask( repositoryDirectory );
107
108 final int dirMode = TypeConversionUtils.modeToInt( repository.getDirectoryMode(), getLogger() );
109 if ( dirMode != -1 )
110 {
111 task.setDirectoryMode( dirMode );
112 }
113
114 final int fileMode = TypeConversionUtils.modeToInt( repository.getFileMode(), getLogger() );
115 if ( fileMode != -1 )
116 {
117 task.setFileMode( fileMode );
118 }
119
120 task.setOutputDirectory( outputDirectory );
121
122 task.execute( archiver );
123 }
124 }
125
126 private RepositoryBuilderConfigSource wrap( final AssemblerConfigurationSource configSource )
127 {
128 return new RepoBuilderConfigSourceWrapper( configSource );
129 }
130
131 private RepositoryInfo wrap( final Repository repository )
132 {
133 return new RepoInfoWrapper( repository );
134 }
135
136 public int order()
137 {
138
139 return 50;
140
141 }
142 }
143