-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
298 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,50 @@ | ||
import java.util.Properties | ||
|
||
plugins { | ||
id("java") | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
`maven-publish` | ||
signing | ||
id("io.github.gradle-nexus.publish-plugin") version "1.1.0" | ||
} | ||
|
||
group = "org.glavo" | ||
version = "1.0-SNAPSHOT" | ||
loadMavenPublishProperties() | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
allprojects { | ||
apply { | ||
plugin("java") | ||
plugin("maven-publish") | ||
} | ||
|
||
dependencies { | ||
implementation("com.github.javaparser:javaparser-core:3.24.2") | ||
// implementation("com.github.javaparser:javaparser-symbol-solver-core:3.24.2") | ||
implementation("org.ow2.asm:asm:9.3") | ||
group = "org.glavo" | ||
version = "1.0"// + "-SNAPSHOT" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") | ||
} | ||
|
||
|
||
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1") | ||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1") | ||
} | ||
tasks.compileJava { | ||
sourceCompatibility = "1.8" | ||
targetCompatibility = "1.8" | ||
} | ||
|
||
tasks.getByName<Test>("test") { | ||
useJUnitPlatform() | ||
tasks.getByName<Test>("test") { | ||
useJUnitPlatform() | ||
} | ||
} | ||
|
||
tasks.compileJava { | ||
sourceCompatibility = "1.8" | ||
targetCompatibility = "1.8" | ||
description = "Compiler for module-info.java" | ||
|
||
dependencies { | ||
implementation("com.github.javaparser:javaparser-core:3.24.2") | ||
// implementation("com.github.javaparser:javaparser-symbol-solver-core:3.24.2") | ||
implementation("org.ow2.asm:asm:9.3") | ||
} | ||
|
||
tasks.jar { | ||
|
@@ -36,13 +53,115 @@ tasks.jar { | |
"Main-Class" to "org.glavo.mic.ModuleInfoCompiler" | ||
) | ||
} | ||
dependsOn(tasks.shadowJar) | ||
} | ||
|
||
tasks.shadowJar { | ||
// manifest.inheritFrom(project.tasks.getByName<Jar>("jar").manifest) | ||
|
||
relocate("org.objectweb.asm", "org.glavo.mic.asm") | ||
relocate("com.github.javaparser", "org.glavo.mic.javaparser") | ||
minimize() | ||
} | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
// withJavadocJar() | ||
} | ||
|
||
val javadocJar = tasks.create<Jar>("javadocJar") { | ||
group = "build" | ||
archiveClassifier.set("javadoc") | ||
} | ||
|
||
tasks.withType<GenerateModuleMetadata>().configureEach { | ||
enabled = false | ||
} | ||
|
||
configure<PublishingExtension> { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
groupId = project.group.toString() | ||
version = project.version.toString() | ||
artifactId = project.name | ||
from(components["java"]) | ||
artifact(javadocJar) | ||
|
||
pom { | ||
name.set(project.name) | ||
description.set(project.description) | ||
url.set("https://github.com/Glavo/GMIC") | ||
|
||
licenses { | ||
license { | ||
name.set("Apache-2.0") | ||
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id.set("glavo") | ||
name.set("Glavo") | ||
email.set("[email protected]") | ||
} | ||
} | ||
|
||
scm { | ||
url.set("https://github.com/Glavo/GMIC") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (rootProject.ext.has("signing.key")) { | ||
signing { | ||
useInMemoryPgpKeys( | ||
rootProject.ext["signing.keyId"].toString(), | ||
rootProject.ext["signing.key"].toString(), | ||
rootProject.ext["signing.password"].toString(), | ||
) | ||
sign(publishing.publications["maven"]) | ||
} | ||
} | ||
|
||
nexusPublishing { | ||
repositories { | ||
sonatype { | ||
stagingProfileId.set(rootProject.ext["sonatypeStagingProfileId"].toString()) | ||
username.set(rootProject.ext["sonatypeUsername"].toString()) | ||
password.set(rootProject.ext["sonatypePassword"].toString()) | ||
} | ||
} | ||
} | ||
|
||
fun loadMavenPublishProperties() { | ||
var secretPropsFile = project.rootProject.file("gradle/maven-central-publish.properties") | ||
if (!secretPropsFile.exists()) { | ||
secretPropsFile = | ||
file(System.getProperty("user.home")).resolve(".gradle").resolve("maven-central-publish.properties") | ||
} | ||
|
||
if (secretPropsFile.exists()) { | ||
// Read local.properties file first if it exists | ||
val p = Properties() | ||
secretPropsFile.reader().use { | ||
p.load(it) | ||
} | ||
|
||
p.forEach { (name, value) -> | ||
rootProject.ext[name.toString()] = value | ||
} | ||
} | ||
|
||
listOf( | ||
"sonatypeUsername" to "SONATYPE_USERNAME", | ||
"sonatypePassword" to "SONATYPE_PASSWORD", | ||
"sonatypeStagingProfileId" to "SONATYPE_STAGING_PROFILE_ID", | ||
"signing.keyId" to "SIGNING_KEY_ID", | ||
"signing.password" to "SIGNING_PASSWORD", | ||
"signing.key" to "SIGNING_KEY" | ||
).forEach { (p, e) -> | ||
if (!rootProject.ext.has(p)) { | ||
rootProject.ext[p] = System.getenv(e) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
plugins { | ||
`java-gradle-plugin` | ||
`maven-publish` | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
id("com.gradle.plugin-publish") version "1.0.0-rc-1" | ||
} | ||
|
||
dependencies { | ||
compileOnly(gradleApi()) | ||
implementation(rootProject) | ||
} | ||
|
||
tasks.jar { | ||
enabled = false | ||
dependsOn(tasks.shadowJar) | ||
} | ||
|
||
tasks.shadowJar { | ||
archiveClassifier.set(null as String?) | ||
|
||
relocate("org.objectweb.asm", "org.glavo.mic.plugin.asm") | ||
relocate("com.github.javaparser", "org.glavo.mic.plugin.javaparser") | ||
minimize() | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
create("kala-retro8") { | ||
id = "org.glavo.mic.plugin" | ||
displayName = "ModuleInfo Compiler" | ||
description = "" | ||
implementationClass = "kala.plugins.retro8.Retro8Plugin" | ||
} | ||
} | ||
} | ||
|
||
pluginBundle { | ||
website = "https://github.com/Glavo/kala-retro8" | ||
vcsUrl = "https://github.com/Glavo/kala-retro8.git" | ||
tags = listOf("java", "modules", "jpms", "modularity") | ||
} | ||
|
||
publishing { | ||
repositories { | ||
mavenLocal() | ||
} | ||
|
||
publications { | ||
this.create<MavenPublication>("pluginMaven") { | ||
groupId = project.group.toString() | ||
artifactId = project.name | ||
version = project.version.toString() | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
gradle-plugin/src/main/java/org/glavo/mic/plugin/CompileModuleInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.glavo.mic.plugin; | ||
|
||
import org.glavo.mic.ModuleInfoCompiler; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.OutputFile; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import java.io.*; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
||
public abstract class CompileModuleInfo extends DefaultTask { | ||
private int targetCompatibility = ModuleInfoCompiler.DEFAULT_TARGET_COMPATIBILITY; | ||
private String moduleVersion; | ||
private String moduleMainClass; | ||
private Charset encoding = StandardCharsets.UTF_8; | ||
|
||
@InputFile | ||
public abstract RegularFileProperty getSourceFile(); | ||
|
||
@OutputFile | ||
public abstract RegularFileProperty getTargetFile(); | ||
|
||
@Input | ||
public int getTargetCompatibility() { | ||
return targetCompatibility; | ||
} | ||
|
||
public void setTargetCompatibility(int targetCompatibility) { | ||
this.targetCompatibility = targetCompatibility; | ||
} | ||
|
||
@Input | ||
public String getModuleVersion() { | ||
return moduleVersion; | ||
} | ||
|
||
public void setModuleVersion(String moduleVersion) { | ||
this.moduleVersion = moduleVersion; | ||
} | ||
|
||
@Input | ||
public String getModuleMainClass() { | ||
return moduleMainClass; | ||
} | ||
|
||
public void setModuleMainClass(String moduleMainClass) { | ||
this.moduleMainClass = moduleMainClass; | ||
} | ||
|
||
@Input | ||
public Charset getEncoding() { | ||
return encoding; | ||
} | ||
|
||
public void setEncoding(Charset encoding) { | ||
this.encoding = encoding; | ||
} | ||
|
||
@TaskAction | ||
public void compile() throws IOException { | ||
File source = getSourceFile().getAsFile().get(); | ||
File target = getTargetFile().getAsFile().get(); | ||
|
||
target.getParentFile().mkdirs(); | ||
|
||
ModuleInfoCompiler compiler = new ModuleInfoCompiler(targetCompatibility, moduleVersion, moduleMainClass); | ||
|
||
try (Reader reader = new InputStreamReader(Files.newInputStream(source.toPath()), encoding); | ||
OutputStream output = Files.newOutputStream(target.toPath())) { | ||
compiler.compile(reader, output); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
gradle-plugin/src/main/java/org/glavo/mic/plugin/CompileModuleInfoPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.glavo.mic.plugin; | ||
|
||
import org.gradle.api.Plugin; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.plugins.JavaPlugin; | ||
import org.gradle.jvm.tasks.Jar; | ||
|
||
import java.io.File; | ||
|
||
public class CompileModuleInfoPlugin implements Plugin<Project> { | ||
@Override | ||
public void apply(Project project) { | ||
project.getPlugins().apply(JavaPlugin.class); | ||
|
||
CompileModuleInfo compileModuleInfo = project.getTasks().create("compileModuleInfo", CompileModuleInfo.class, task -> { | ||
task.getSourceFile().set(project.file("src/main/java/module-info.java")); | ||
task.getTargetFile().set(new File(project.getBuildDir(), "module-info/module-info.class")); | ||
}); | ||
|
||
Jar jarTask = (Jar) project.getTasks().getByName("jar"); | ||
jarTask.dependsOn(compileModuleInfo); | ||
jarTask.from(compileModuleInfo.getTargetFile()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
rootProject.name = "module-info-compiler" | ||
|
||
// include("gradle-plugin") |