From 70c4bb304cd8494f3ffe0562685037923bb4a962 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Wed, 29 Apr 2020 16:57:24 +0200 Subject: [PATCH 1/2] [GAL-321] If the version of the feature-pack is missing from the config, look it up among the project deps --- .../maven/plugin/ProvisionStateMojo.java | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java index a212c2f53..28d972f40 100644 --- a/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java +++ b/maven-plugin/src/main/java/org/jboss/galleon/maven/plugin/ProvisionStateMojo.java @@ -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"); @@ -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; @@ -244,11 +246,47 @@ 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()); @@ -256,4 +294,8 @@ private Path resolveMaven(ArtifactCoordinate coordinate, MavenRepoManager resolv return artifact.getPath(); } + + private boolean isEmptyOrNull(String version) { + return version == null || version.isEmpty(); + } } From 25ea3d3d552b4384ed7e219fc0946cf11551d980 Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Thu, 30 Apr 2020 10:22:21 +0200 Subject: [PATCH 2/2] openjdk8 for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7c3453fc9..785ac275c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: