http://git-wip-us.apache.org/repos/asf/camel/blob/b1dfcabe/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/BomGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/BomGeneratorMojo.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/BomGeneratorMojo.java index aa97c73..e426f01 100644 --- a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/BomGeneratorMojo.java +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/BomGeneratorMojo.java @@ -22,8 +22,12 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.TreeSet; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; @@ -42,9 +46,15 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.apache.commons.io.IOUtils; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.model.Exclusion; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -90,6 +100,49 @@ public class BomGeneratorMojo extends AbstractMojo { */ protected DependencySet dependencies; + /** + * The conflict checks configured by the user + * + * @parameter + * @readonly + */ + protected ExternalBomConflictCheckSet checkConflicts; + + /** + * Used to look up Artifacts in the remote repository. + * + * @component role="org.apache.maven.artifact.factory.ArtifactFactory" + * @required + * @readonly + */ + protected ArtifactFactory artifactFactory; + + /** + * Used to look up Artifacts in the remote repository. + * + * @component role="org.apache.maven.artifact.resolver.ArtifactResolver" + * @required + * @readonly + */ + protected ArtifactResolver artifactResolver; + + /** + * List of Remote Repositories used by the resolver + * + * @parameter property="project.remoteArtifactRepositories" + * @readonly + * @required + */ + protected List remoteRepositories; + + /** + * Location of the local repository. + * + * @parameter property="localRepository" + * @readonly + * @required + */ + protected ArtifactRepository localRepository; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -98,6 +151,9 @@ public class BomGeneratorMojo extends AbstractMojo { List<Dependency> filteredDependencies = enhance(filter(mng.getDependencies())); + Set<String> externallyManagedDependencies = getExternallyManagedDependencies(); + checkConflictsWithExternalBoms(filteredDependencies, externallyManagedDependencies); + Document pom = loadBasePom(); // transform @@ -105,6 +161,10 @@ public class BomGeneratorMojo extends AbstractMojo { writePom(pom); + } catch (MojoFailureException ex) { + throw ex; + } catch (MojoExecutionException ex) { + throw ex; } catch (Exception ex) { throw new MojoExecutionException("Cannot generate the output BOM file", ex); } @@ -283,5 +343,74 @@ public class BomGeneratorMojo extends AbstractMojo { } + private void checkConflictsWithExternalBoms(Collection<Dependency> dependencies, Set<String> external) throws MojoFailureException { + Set<String> errors = new TreeSet<>(); + for (Dependency d : dependencies) { + String key = comparisonKey(d); + if (external.contains(key)) { + errors.add(key); + } + } + + if (errors.size() > 0) { + StringBuilder msg = new StringBuilder(); + msg.append("Found ").append(errors.size()).append(" conflicts between the current managed dependencies and the external BOMS:\n"); + for (String error : errors) { + msg.append(" - ").append(error).append("\n"); + } + + throw new MojoFailureException(msg.toString()); + } + } + + private Set<String> getExternallyManagedDependencies() throws Exception { + Set<String> provided = new HashSet<>(); + if (checkConflicts != null && checkConflicts.getBoms() != null) { + for (ExternalBomConflictCheck check : checkConflicts.getBoms()) { + Set<String> bomProvided = getProvidedDependencyManagement(check.getGroupId(), check.getArtifactId(), check.getVersion()); + provided.addAll(bomProvided); + } + } + + return provided; + } + + private Set<String> getProvidedDependencyManagement(String groupId, String artifactId, String version) throws Exception { + Artifact bom = resolveArtifact(groupId, artifactId, version, "pom"); + MavenProject bomProject = loadExternalProjectPom(bom.getFile()); + + Set<String> provided = new HashSet<>(); + if (bomProject.getDependencyManagement() != null && bomProject.getDependencyManagement().getDependencies() != null) { + for (Dependency dep : bomProject.getDependencyManagement().getDependencies()) { + provided.add(comparisonKey(dep)); + } + } + + return provided; + } + + private String comparisonKey(Dependency dependency) { + return dependency.getGroupId() + ":" + dependency.getArtifactId(); + } + + private Artifact resolveArtifact(String groupId, String artifactId, String version, String type) throws Exception { + + Artifact art = artifactFactory.createArtifact(groupId, artifactId, version, "runtime", type); + + artifactResolver.resolve(art, remoteRepositories, localRepository); + + return art; + } + + private MavenProject loadExternalProjectPom(File pomFile) throws Exception { + try (FileReader reader = new FileReader(pomFile)) { + MavenXpp3Reader mavenReader = new MavenXpp3Reader(); + Model model = mavenReader.read(reader); + + MavenProject project = new MavenProject(model); + project.setFile(pomFile); + return project; + } + } }
http://git-wip-us.apache.org/repos/asf/camel/blob/b1dfcabe/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java ---------------------------------------------------------------------- diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java new file mode 100644 index 0000000..07dbb46 --- /dev/null +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.maven.bom.generator; + +/** + * Information related to an external BOM dependency. Conflicts will be checked against it. + */ +public class ExternalBomConflictCheck { + + private String groupId; + + private String artifactId; + + private String version; + + public ExternalBomConflictCheck() { + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("ExternalBomConflictCheck{"); + sb.append("groupId='").append(groupId).append('\''); + sb.append(", artifactId='").append(artifactId).append('\''); + sb.append(", version='").append(version).append('\''); + sb.append('}'); + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1dfcabe/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java ---------------------------------------------------------------------- diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java new file mode 100644 index 0000000..447ecca --- /dev/null +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.maven.bom.generator; + +import java.util.HashSet; +import java.util.Set; + +/** + * A set of {@code ExternalBomConflictCheck} objects, + */ +public class ExternalBomConflictCheckSet { + + private Set<ExternalBomConflictCheck> boms = new HashSet<>(); + + public ExternalBomConflictCheckSet() { + } + + public Set<ExternalBomConflictCheck> getBoms() { + return boms; + } + + public void setBoms(Set<ExternalBomConflictCheck> boms) { + this.boms = boms; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("ExternalBomConflictCheckSet{"); + sb.append("boms=").append(boms); + sb.append('}'); + return sb.toString(); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/b1dfcabe/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootStarterMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootStarterMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootStarterMojo.java index 3cc0ce8..57880e3 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootStarterMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootStarterMojo.java @@ -80,7 +80,8 @@ public class SpringBootStarterMojo extends AbstractMojo { private static final String[] IGNORE_MODULES = { /* OSGi -> */ "camel-blueprint", "camel-core-osgi", "camel-eventadmin", "camel-paxlogging", /* Java EE -> */ "camel-cdi", "camel-ejb", - /* deprecated (and not working perfectly) -> */ "camel-swagger", "camel-mina", + /* deprecated (and not working perfectly) -> */ "camel-swagger", "camel-mina", "camel-ibatis", "camel-quartz", + /* currently incompatible */ "camel-jclouds", "camel-spark-rest", /* others (not managed) -> */ "camel-zipkin"}; private static final boolean IGNORE_TEST_MODULES = true; http://git-wip-us.apache.org/repos/asf/camel/blob/b1dfcabe/tooling/maven/camel-package-maven-plugin/src/main/resources/spring-boot-fix-dependencies.properties ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/spring-boot-fix-dependencies.properties b/tooling/maven/camel-package-maven-plugin/src/main/resources/spring-boot-fix-dependencies.properties index 9f12a08..a37285c 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/spring-boot-fix-dependencies.properties +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/spring-boot-fix-dependencies.properties @@ -30,6 +30,8 @@ camel-core=com.github.ben-manes.caffeine:caffeine camel-ahc=io.netty:netty-all:${ahc-netty-version} camel-ahc-ws=io.netty:netty-all:${ahc-netty-version} +camel-bam=org.hibernate:hibernate-entitymanager,org.apache.geronimo.specs:geronimo-jta_1.1_spec + camel-cassandraql=com.google.guava:guava:${cassandra-driver-guava-version} camel-github=org.eclipse.mylyn.github:org.eclipse.egit.github.core:${egit-github-core-version} @@ -44,15 +46,15 @@ camel-jetty9=org.hibernate:hibernate-validator,org.apache.camel:apt:${project.ve camel-jcr=org.apache.lucene:lucene-core:${lucene3-version} camel-jira=com.atlassian.jira:jira-rest-java-client -camel-jms=org.apache.geronimo.specs:geronimo-jms_1.1_spec:${geronimo-jms-spec-version} -camel-jpa=org.apache.geronimo.specs:geronimo-jpa_2.0_spec:${geronimo-jpa2-spec-version} +camel-jms=org.apache.geronimo.specs:geronimo-jms_1.1_spec +camel-jpa=org.apache.geronimo.specs:geronimo-jpa_2.0_spec camel-kubernetes=org.hibernate:hibernate-validator camel-netty4=org.hibernate:hibernate-validator camel-netty4-http=org.hibernate:hibernate-validator camel-scala=org.scala-lang:scala-library:${scala-version},org.scala-lang.modules:scala-xml_2.11:${scalaxml-version} -camel-sjms=org.apache.geronimo.specs:geronimo-jms_1.1_spec:${geronimo-jms-spec-version} +camel-sjms=org.apache.geronimo.specs:geronimo-jms_1.1_spec camel-spark-rest=org.hibernate:hibernate-validator camel-spring-boot=org.apache.camel:camel-core-starter camel-spring-ws=org.springframework.boot:spring-boot-starter-web:${spring-boot-version}