|
35 | 35 | import java.io.IOException; |
36 | 36 | import java.util.Properties; |
37 | 37 |
|
| 38 | +import org.apache.maven.artifact.Artifact; |
38 | 39 | import org.apache.maven.plugin.MojoExecutionException; |
39 | 40 | import org.apache.maven.plugins.annotations.Component; |
40 | 41 | import org.apache.maven.plugins.annotations.Mojo; |
@@ -128,35 +129,43 @@ public void execute() throws MojoExecutionException { |
128 | 129 | Iterable<ArtifactResult> resolveDependencies = dependencyResolver |
129 | 130 | .resolveDependencies(buildingRequest, coordinate, scopeFilter); |
130 | 131 | for (ArtifactResult result : resolveDependencies) { |
| 132 | + Artifact artifact = result.getArtifact(); |
131 | 133 | try { |
132 | | - if (project.getArtifact().equals(result.getArtifact())) { |
133 | | - installArtifact(result.getArtifact(), appDir, appSubdirectory, false, |
| 134 | + if (project.getArtifact().equals(artifact)) { |
| 135 | + installArtifact(artifact, appDir, appSubdirectory, false, |
134 | 136 | deleteOtherVersionsPolicy); |
135 | 137 | continue; |
136 | 138 | } |
137 | 139 | // Resolution of the subdirectory for dependencies is handled in installArtifact |
138 | 140 | if (!ignoreDependencies) { |
139 | | - ProjectBuildingResult build = mavenProjectBuilder.build(result.getArtifact(), session.getProjectBuildingRequest()); |
140 | | - Properties properties = build.getProject().getProperties(); |
141 | | - String subdir = (String) properties.get( APP_SUBDIRECTORY_PROPERTY ); |
| 141 | + String subdir = getAppSubDirectoryProperty(artifact); |
142 | 142 |
|
143 | | - installArtifact(result.getArtifact(), appDir, subdir, false, deleteOtherVersionsPolicy); |
| 143 | + installArtifact(artifact, appDir, subdir, false, deleteOtherVersionsPolicy); |
144 | 144 | } |
145 | 145 | } |
146 | 146 | catch (IOException e) { |
147 | 147 | throw new MojoExecutionException("Couldn't download artifact " + |
148 | 148 | result.getArtifact() + ": " + e.getMessage(), e); |
149 | 149 | } |
150 | | - catch ( ProjectBuildingException e ) |
151 | | - { |
152 | | - throw new MojoExecutionException( "Couldn't determine " + |
153 | | - APP_SUBDIRECTORY_PROPERTY + " for " + result.getArtifact(), e ); |
154 | | - } |
155 | 150 | } |
156 | 151 | } |
157 | 152 | catch (DependencyResolverException e) { |
158 | 153 | throw new MojoExecutionException( |
159 | 154 | "Couldn't resolve dependencies for artifact: " + e.getMessage(), e); |
160 | 155 | } |
161 | 156 | } |
| 157 | + |
| 158 | + private String getAppSubDirectoryProperty(Artifact artifact) { |
| 159 | + try { |
| 160 | + ProjectBuildingResult build = mavenProjectBuilder.build(artifact, // |
| 161 | + session.getProjectBuildingRequest()); |
| 162 | + Properties properties = build.getProject().getProperties(); |
| 163 | + String subdir = (String) properties.get(APP_SUBDIRECTORY_PROPERTY); |
| 164 | + return subdir; |
| 165 | + } |
| 166 | + catch (ProjectBuildingException e) { |
| 167 | + // TODO: log.debug( "Couldn't determine " + APP_SUBDIRECTORY_PROPERTY + " for " + artifact, e ); |
| 168 | + return null; |
| 169 | + } |
| 170 | + } |
162 | 171 | } |
0 commit comments