1+ import groovy.xml.XmlSlurper
2+ import groovy.xml.slurpersupport.GPathResult
3+ import groovy.xml.slurpersupport.NodeChild
4+ import java.io.ByteArrayOutputStream
5+
6+ plugins {
7+ `java- platform`
8+ `version- catalog`
9+ `maven- publish`
10+ // id("org.gradlex.java-ecosystem-capabilities-base") // only rules
11+ // id("org.gradlex.logging-capabilities") // logging extension
12+ }
13+
14+ layout.buildDirectory.set(layout.projectDirectory.asFile.parentFile.resolve(" target/gradle" ))
15+
16+ group = " org.scijava"
17+ version = " 0.13" // (effXml / "version").toString()
18+
19+ javaPlatform {
20+ allowDependencies()
21+ }
22+
23+ val computeCatalogAndPlatform = tasks.register<Exec >(" generateCatalog" ) {
24+
25+ workingDir = projectDir.parentFile
26+ commandLine(" sh" , " -c" , " mvn -B -f pom.xml help:effective-pom" )
27+ standardOutput = ByteArrayOutputStream ()
28+
29+ doLast {
30+ var output = standardOutput.toString()
31+ // clean output from dirty
32+ output = output.substringAfter(" \n\n " ).substringBefore(" \n\n " )
33+
34+ operator fun GPathResult.div (child : String ) = children().find { (it!! as NodeChild ).name() == child } as GPathResult
35+
36+ val xml = XmlSlurper ().parseText(output)
37+ val deps = xml / " dependencyManagement" / " dependencies"
38+ val bundles = mutableMapOf<String , ArrayList <String >>()
39+ val skip = listOf (" mpicbg" to " mpicbg_" )
40+ val cache = mutableSetOf<String >() // skip duplicates, such as org.bytedeco:ffmpeg
41+ for (dep in deps.children()) {
42+ val node = dep as NodeChild
43+ val g = node / " groupId"
44+ val a = node / " artifactId"
45+ val v = node / " version"
46+ val gav = " $g :$a :$v "
47+
48+ if ((" $g " to " $a " ) in skip || gav in cache)
49+ continue
50+
51+ cache + = gav
52+
53+ val camel = " $a " .split(' -' , ' _' )
54+ .joinToString(" " ) { if (it.isEmpty()) " " else it[0 ].uppercase() + it.substring(1 ).lowercase() }
55+ .replaceFirstChar { it.lowercase() }
56+
57+ fun getAlias (group : String ): String {
58+ val alias = " $group ." + when {
59+ camel.startsWith(group) -> camel.substringAfter(group).replaceFirstChar { it.lowercase() }.ifEmpty { group }
60+ else -> camel
61+ }
62+ bundles.getOrPut(group, ::ArrayList ) + = alias
63+ return alias
64+ }
65+
66+ val lastWordAsGroup = listOf (" org.scijava" , " net.imagej" , " net.imglib2" , " sc.fiji" , " org.janelia.saalfeldlab" )
67+ val alias = when (" $g " ) {
68+ in lastWordAsGroup -> getAlias(g.toString().substringAfterLast(' .' ))
69+ " io.scif" -> getAlias(" scifio" )
70+ else -> " $g .$camel "
71+ }
72+
73+ catalog.versionCatalog { library(alias, gav) }
74+
75+ dependencies {
76+ constraints {
77+ val ga = " $g :$a "
78+ if (ga in runtimeDeps || jogampNatives.any { it.startsWith(ga) })
79+ runtime(gav) // .also { println("runtime($dep)") }
80+ else
81+ api(gav) // .also{ println("api($dep)") }
82+ }
83+ }
84+ }
85+
86+ for ((alias, aliases) in bundles)
87+ catalog.versionCatalog { bundle(alias, aliases) }
88+ }
89+ }
90+
91+ publishing {
92+ publications {
93+ repositories {
94+ maven {
95+ name = " sciJava"
96+ // credentials(PasswordCredentials::class)
97+ // url = uri("https://maven.scijava.org/content/repositories/releases")
98+ url = uri(" repo" )
99+ }
100+ }
101+ create<MavenPublication >(" pomScijava" ) {
102+ from(components[" javaPlatform" ])
103+ }
104+ }
105+ }
106+
107+ tasks {
108+ // dependsOn runs only if the src is successful, finalizedBy not
109+ generateCatalogAsToml { dependsOn(computeCatalogAndPlatform) }
110+ val generateMetadataFileForPomScijavaPublication by getting { dependsOn(computeCatalogAndPlatform) }
111+ register(" generateCatalogAndPlatform" ) { dependsOn(generateMetadataFileForPomScijavaPublication, generateCatalogAsToml) }
112+ }
113+
114+ val runtimeDeps = listOf (" org.antlr:antlr-runtime" ,
115+ " xalan:serializer" ,
116+ " xalan:xalan" ,
117+ " com.github.vbmacher:java-cup-runtime" ,
118+ " nz.ac.waikato.cms.weka.thirdparty:java-cup-11b-runtime" ,
119+ " org.jogamp.gluegen:gluegen-rt-main" ,
120+ " org.jogamp.gluegen:gluegen-rt" ,
121+ " org.jogamp.joal:joal" ,
122+ " org.jogamp.jocl:jocl" ,
123+ " org.jogamp.jogl:jogl-all-main" ,
124+ " org.jogamp.jogl:jogl-all" ,
125+ " org.jogamp.jogl:jogl-all-noawt" ,
126+ " com.nativelibs4java:bridj" ,
127+ " org.bytedeco:ffmpeg" ,
128+ " org.bytedeco:hdf5" ,
129+ " org.bytedeco:leptonica" ,
130+ " org.bytedeco:openblas" ,
131+ " org.bytedeco:opencv" ,
132+ " org.bytedeco:tesseract" ,
133+ " org.jline:jline-native" ,
134+ " com.github.jnr:jffi" ,
135+ " org.jzy3d:jzy3d-native-jogl-awt" ,
136+ " org.jzy3d:jzy3d-native-jogl-swing" )
137+
138+ val jogampNatives = listOf (" org.jogamp.gluegen:gluegen-rt-natives-" ,
139+ " org.jogamp.jogl:jogl-all-natives-" ,
140+ " org.jogamp.gluegen:gluegen-rt-natives-" ,
141+ " org.jogamp.jogl:jogl-all-natives-" )
0 commit comments