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