Skip to content

Commit

Permalink
Merge pull request #287 from aloubyansky/GAL-321
Browse files Browse the repository at this point in the history
[GAL-321] If the version of the feature-pack is missing from the config, look it up among the project deps
  • Loading branch information
aloubyansky authored Apr 30, 2020
2 parents 226aacd + 25ea3d3 commit c7db867
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ language: java
# see http://docs.travis-ci.com/user/workers/container-based-infrastructure/
sudo: false
jdk:
- oraclejdk8
- openjdk8
- openjdk11
cache:
directories:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2020 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,7 +27,9 @@

import javax.xml.stream.XMLStreamException;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -244,16 +246,56 @@ private void doProvision() throws MojoExecutionException, ProvisioningException
}
}

private Path resolveMaven(ArtifactCoordinate coordinate, MavenRepoManager resolver) throws MavenUniverseException {
private Path resolveMaven(ArtifactCoordinate coordinate, MavenRepoManager resolver) throws MavenUniverseException, MojoExecutionException {
final MavenArtifact artifact = new MavenArtifact();
artifact.setGroupId(coordinate.getGroupId());
artifact.setArtifactId(coordinate.getArtifactId());
artifact.setVersion(coordinate.getVersion());
String version = coordinate.getVersion();
if(isEmptyOrNull(version)) {
// first, we are looking for the artifact among the project deps
// direct dependencies may override the managed versions
for(Artifact a : project.getArtifacts()) {
if(coordinate.getArtifactId().equals(a.getArtifactId())
&& coordinate.getGroupId().equals(a.getGroupId())
&& coordinate.getExtension().equals(a.getType())
&& (coordinate.getClassifier() == null ? "" : coordinate.getClassifier())
.equals(a.getClassifier() == null ? "" : a.getClassifier())) {
version = a.getVersion();
break;
}
}
if(isEmptyOrNull(version)) {
// Now we are going to look for for among the managed dependencies
for (Dependency d : project.getDependencyManagement().getDependencies()) {
if (coordinate.getArtifactId().equals(d.getArtifactId())
&& coordinate.getGroupId().equals(d.getGroupId())
&& coordinate.getExtension().equals(d.getType())
&& (coordinate.getClassifier() == null ? "" : coordinate.getClassifier())
.equals(d.getClassifier() == null ? "" : d.getClassifier())) {
version = d.getVersion();
break;
}
}
if (isEmptyOrNull(version)) {
throw new MojoExecutionException(coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":"
+ (coordinate.getClassifier() == null ? "" : coordinate.getClassifier()) + ":"
+ coordinate.getExtension()
+ " was found among neither the project's dependencies nor the managed dependencies."
+ " To proceed, please, add the desired version of the feature-pack to the provisioning configuration"
+ " or the project dependencies, or the dependency management section of the Maven project");
}
}
}
artifact.setVersion(version);
artifact.setExtension(coordinate.getExtension());
artifact.setClassifier(coordinate.getClassifier());

resolver.resolve(artifact);

return artifact.getPath();
}

private boolean isEmptyOrNull(String version) {
return version == null || version.isEmpty();
}
}

0 comments on commit c7db867

Please sign in to comment.