mocobeta commented on a change in pull request #470:
URL: https://github.com/apache/lucene/pull/470#discussion_r761263744



##########
File path: gradle/java/modules.gradle
##########
@@ -0,0 +1,169 @@
+import java.util.jar.JarFile
+import java.util.stream.Collectors
+
+/*
+ * 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.
+ */
+
+// Configure other things required for the java module system layer.
+
+allprojects {
+  plugins.withType(JavaPlugin) {
+    // Configure the version attribute.
+    tasks.withType(JavaCompile).configureEach{
+      it.options.javaModuleVersion.set(provider {
+        return project.version.toString()
+      })
+    }
+  }
+
+  // TODO: remove the hacks excluding java-module source folder from ecjLint 
and javadoc rendering.
+}
+
+configure(rootProject) {
+  // Show all module names (for ease of debugging)
+  tasks.register("showModuleNames", { showModuleTask ->
+    def allJarTasks = []
+
+    rootProject.subprojects.each { subproject ->
+      subproject.tasks.matching { it.name == 'jar' }.all {
+        allJarTasks.add it
+      }
+    }
+
+    dependsOn allJarTasks
+
+    doFirst {
+      allJarTasks.each { jarTask ->
+        File jarFile = jarTask.outputs.files.singleFile
+        try (def jar = new JarFile(jarFile)) {
+          logger.lifecycle(String.format(Locale.ROOT,
+              "%-50s -> %s",
+              jarFile.name,
+              jar.manifest.mainAttributes.getValue("Automatic-Module-Name")))
+        }
+      }
+    }
+  })
+}
+
+allprojects {
+  // Show all non-empty package names
+  plugins.withType(JavaPlugin) {
+    tasks.register("showPackageNames", { task ->
+      doFirst {
+        listPackageNames(sourceSets).each { println(it) }
+      }
+    })
+  }
+}
+
+allprojects {
+  // Show all service providers
+  plugins.withType(JavaPlugin) {
+    tasks.register("showServiceProviders", { task ->
+      doFirst {
+        def services = listServices(sourceSets)
+        services.each { entry -> {
+          println(entry.key)
+          entry.value.each { println("  ${it}") }
+        }}
+      }
+    })
+  }
+}
+
+allprojects {
+  plugins.withType(JavaPlugin) {
+    tasks.register("scaffoldModuleDescriptor", {
+      doFirst {
+        def moduleName = "org.apache" + project.path.replace('-', 
'_').replace(':', '.')
+        def pkgNames = listPackageNames(sourceSets)
+        def services = listServices(sourceSets)
+        def outFile = project.file("${getTemporaryDir()}/module-info.java")
+        outFile.withWriter("UTF-8", { writer ->
+          writer.write("module ${moduleName} {\n")
+          // write exports statements
+          pkgNames.each {pkg ->
+            writer.write("  exports ")
+            writer.write(pkg)
+            writer.write(";\n")
+          }
+          writer.write("\n")
+          // write provides statements
+          services.each { entry -> {
+            def service = entry.key
+            def providers = "      " + entry.value.join(",\n      ")
+            writer.write("  provides ")
+            writer.write(service)
+            writer.write(" with\n")
+            writer.write(providers)
+            writer.write(";\n")
+          }}
+          writer.write("\n")
+          // write uses statements

Review comment:
       Also we'll be able to delete this task once we complete adding the 
correct module-info to all modules; it's temporal just to generate skeletons 
and I don't think we should keep it on the main.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to