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