Skip to content

Commit

Permalink
Fix #635 Dependency parity check
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga authored and lburgazzoli committed Jan 23, 2020
1 parent fc29217 commit 8fb71a4
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 12 deletions.
4 changes: 4 additions & 0 deletions extensions/ahc/deployment/pom.xml
Expand Up @@ -48,6 +48,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-http-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-ahc-deployment</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/core-cloud/deployment/pom.xml
Expand Up @@ -42,6 +42,10 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-caffeine-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/core/runtime/pom.xml
Expand Up @@ -60,6 +60,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-common</artifactId>
</dependency>

<!-- camel -->
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions extensions/ftp/runtime/pom.xml
Expand Up @@ -58,6 +58,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsch</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-file</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions extensions/kotlin/deployment/pom.xml
Expand Up @@ -42,8 +42,8 @@

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/kotlin/runtime/pom.xml
Expand Up @@ -50,6 +50,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-core-engine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions extensions/servlet/deployment/pom.xml
Expand Up @@ -41,10 +41,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-deployment</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/support/aws/deployment/pom.xml
Expand Up @@ -47,6 +47,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-aws</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions extensions/support/aws/runtime/pom.xml
Expand Up @@ -48,8 +48,8 @@

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
4 changes: 4 additions & 0 deletions extensions/support/spring/deployment/pom.xml
Expand Up @@ -49,6 +49,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-commons-logging-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-spring</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 4 additions & 0 deletions extensions/support/xml/deployment/pom.xml
Expand Up @@ -45,6 +45,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jaxb-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-xml</artifactId>
Expand Down
90 changes: 86 additions & 4 deletions tooling/scripts/validate-dependencies.groovy
Expand Up @@ -14,21 +14,103 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.nio.file.Path
import java.nio.file.Paths

final List<String> badDeps = []
final List<String> parityViolations = []
final File pomXml = new File(project.basedir, "pom.xml")

/* groupIds that contain extensions */
final Set<String> extensionGroupIds = ["org.apache.camel.quarkus", "io.quarkus"] as Set
/* artifactIds from groups contained in extensionGroupIds that are not extensions */
final Set<String> nonExtensionArtifactIds = [] as Set

final Path treeRootDir = Paths.get(project.properties['camel.quarkus.project.root'])
final Path relativePomPath = treeRootDir.relativize(pomXml.toPath().normalize())

if (pomXml.exists()) {
def pomXmlProject = new XmlParser().parseText(pomXml.getText('UTF-8'))
pomXmlProject.dependencies.dependency
.findAll {
!it.version.text().isEmpty()
}
.each {
badDeps << "in ${project.basedir}/pom.xml : ${it.groupId.text()}:${it.artifactId.text()}"
badDeps << "in ${relativePomPath} : ${it.groupId.text()}:${it.artifactId.text()}"
}

/* Enforce the dependency parity between runtime and deployment modules */
final String deploymentArtifactId = pomXmlProject.artifactId.text()
if (isDeploymentArtifactId(deploymentArtifactId)) {
final String runtimeArtifactId = toRuntimeArtifactId(deploymentArtifactId)

if (pomXmlProject.dependencies.dependency.findAll { runtimeArtifactId.equals(it.artifactId.text()) }.size() == 0) {
parityViolations << "${relativePomPath} must depend on ${runtimeArtifactId}"
}

final Set<Tuple2> expectedRuntimeDeps = [] as LinkedHashSet
pomXmlProject.dependencies.dependency
.findAll {
isDeploymentArtifactId(it.artifactId.text()) && !it.scope
}
.each {
expectedRuntimeDeps.add(new Tuple2(it.groupId.text(), toRuntimeArtifactId(it.artifactId.text())))
}

final Set<Tuple2> actualRuntimeDeps = [] as LinkedHashSet
final File runtimePomXml = new File(project.basedir, "../runtime/pom.xml")

final Path relativeRuntimePomPath = treeRootDir.relativize(runtimePomXml.toPath().toAbsolutePath().normalize())

def runtimeProject = new XmlParser().parseText(runtimePomXml.getText('UTF-8'))
runtimeProject.dependencies.dependency
.findAll {
extensionGroupIds.contains(it.groupId.text()) &&
!nonExtensionArtifactIds.contains(it.artifactId.text()) &&
!it.scope
}
.each {
actualRuntimeDeps.add(new Tuple2(it.groupId.text(), it.artifactId.text()))
}

// println "expectedRuntimeDeps: " + expectedRuntimeDeps
// println "actualRuntimeDeps: " + actualRuntimeDeps

expectedRuntimeDeps
.findAll {
!actualRuntimeDeps.contains(it)
}
.each {
parityViolations << "${relativeRuntimePomPath} is missing ${it.first}:${it.second} dependency?"
}

actualRuntimeDeps
.findAll {
!expectedRuntimeDeps.contains(it)
}
.each {
parityViolations << "${relativePomPath} is missing ${it.first}:${it.second}-deployment dependency?"
}

}
}

if (!badDeps.isEmpty() || !parityViolations.isEmpty()) {
final StringBuilder msg = new StringBuilder()
if (!badDeps.isEmpty()) {
msg.append("\nRemove explicit version from the following dependencies and rather manage them in one of the BOMs:\n\n "
+ badDeps.join("\n "))
}
if (!parityViolations.isEmpty()) {
msg.append("\nViolations in the parity between deployment module dependencies and runtime module dependencies:\n\n "
+ parityViolations.join("\n "))
}
throw new RuntimeException(msg.toString())
}

if (!badDeps.isEmpty()) {
throw new RuntimeException("\nRemove explicit version from the following dependencies and rather manage them in one of the BOMs:\n\n "
+ badDeps.join("\n "))
boolean isDeploymentArtifactId(String artifactId) {
return artifactId.endsWith("-deployment")
}
String toRuntimeArtifactId(String deploymentArtifactId) {
return deploymentArtifactId.substring(0, deploymentArtifactId.length() - "-deployment".length())
}

0 comments on commit 8fb71a4

Please sign in to comment.