Skip to content

Commit

Permalink
Fix #1426 Dependency parity checks are now done by Quarkus extension-…
Browse files Browse the repository at this point in the history
…descriptor mojo
  • Loading branch information
ppalaga committed Jul 16, 2020
1 parent 9a933a5 commit cb53f18
Showing 1 changed file with 1 addition and 67 deletions.
68 changes: 1 addition & 67 deletions tooling/scripts/validate-dependencies.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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 */
Expand All @@ -39,78 +38,13 @@ if (pomXml.exists()) {
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()) {
if (!badDeps.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())
}

boolean isDeploymentArtifactId(String artifactId) {
return artifactId.endsWith("-deployment")
}
String toRuntimeArtifactId(String deploymentArtifactId) {
return deploymentArtifactId.substring(0, deploymentArtifactId.length() - "-deployment".length())
}

0 comments on commit cb53f18

Please sign in to comment.