Skip to content

Commit 90ba934

Browse files
committed
Discern appSubdirectory values more robustly
When a dependency POM fails to build, we should not fail, but rather just assume the appSubDirectory is unset, and get on with the copying.
1 parent af47011 commit 90ba934

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/main/java/org/scijava/maven/plugin/install/PopulateAppMojo.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.IOException;
3636
import java.util.Properties;
3737

38+
import org.apache.maven.artifact.Artifact;
3839
import org.apache.maven.plugin.MojoExecutionException;
3940
import org.apache.maven.plugins.annotations.Component;
4041
import org.apache.maven.plugins.annotations.Mojo;
@@ -128,35 +129,43 @@ public void execute() throws MojoExecutionException {
128129
Iterable<ArtifactResult> resolveDependencies = dependencyResolver
129130
.resolveDependencies(buildingRequest, coordinate, scopeFilter);
130131
for (ArtifactResult result : resolveDependencies) {
132+
Artifact artifact = result.getArtifact();
131133
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,
134136
deleteOtherVersionsPolicy);
135137
continue;
136138
}
137139
// Resolution of the subdirectory for dependencies is handled in installArtifact
138140
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);
142142

143-
installArtifact(result.getArtifact(), appDir, subdir, false, deleteOtherVersionsPolicy);
143+
installArtifact(artifact, appDir, subdir, false, deleteOtherVersionsPolicy);
144144
}
145145
}
146146
catch (IOException e) {
147147
throw new MojoExecutionException("Couldn't download artifact " +
148148
result.getArtifact() + ": " + e.getMessage(), e);
149149
}
150-
catch ( ProjectBuildingException e )
151-
{
152-
throw new MojoExecutionException( "Couldn't determine " +
153-
APP_SUBDIRECTORY_PROPERTY + " for " + result.getArtifact(), e );
154-
}
155150
}
156151
}
157152
catch (DependencyResolverException e) {
158153
throw new MojoExecutionException(
159154
"Couldn't resolve dependencies for artifact: " + e.getMessage(), e);
160155
}
161156
}
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+
}
162171
}

0 commit comments

Comments
 (0)