Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
evanchooly committed Aug 27, 2023
1 parent 59b5b0a commit a1db59f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 76 deletions.
30 changes: 11 additions & 19 deletions mojo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@
<groupId>com.antwerkz.super-expressive</groupId>
<artifactId>super-expressive</artifactId>
<version>0.2.0</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-exec</artifactId>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.github.zafarkhaja</groupId>
<artifactId>java-semver</artifactId>
Expand Down Expand Up @@ -112,25 +123,6 @@
<artifactId>logback-classic</artifactId>
</dependency>

<!--
<dependency>
<groupId>org.apache.maven.its</groupId>
<artifactId>maven-core-it-support</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>3.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-verifier</artifactId>
<version>2.0.0-M1</version>
<scope>test</scope>
</dependency>
-->
</dependencies>

</project>
76 changes: 33 additions & 43 deletions mojo/src/main/kotlin/com/antwerkz/build/GradleInvocationMojo.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.antwerkz.build

import java.io.File
import java.io.FileOutputStream
import java.lang.Compiler.command
import org.apache.maven.plugin.AbstractMojo
import org.apache.maven.plugin.MojoExecutionException
import org.apache.maven.plugins.annotations.Component
import org.apache.maven.plugins.annotations.Mojo
import org.apache.maven.plugins.annotations.Parameter
import org.apache.maven.project.MavenProject
import org.codehaus.plexus.logging.Logger
import org.zeroturnaround.exec.ProcessExecutor
import org.zeroturnaround.exec.stream.LogOutputStream

@Mojo(name = "gradle")
class GradleInvocationMojo : AbstractMojo() {
companion object {
private val baseCommand =
listOf(
"java",
"-Xmx64m",
"-Xms64m",
"-Dorg.gradle.appname=gradlew",
"-cp",
"gradle/wrapper/gradle-wrapper.jar",
"org.gradle.wrapper.GradleWrapperMain",
"--no-daemon",
"--console",
"plain"
)
Expand All @@ -28,51 +33,36 @@ class GradleInvocationMojo : AbstractMojo() {

@Parameter(defaultValue = "\${project}", required = true, readonly = true)
lateinit var project: MavenProject

@Parameter lateinit var task: GradleTask
@Parameter(defaultValue = "true") var log = true

@Parameter(defaultValue = "true") var quiet = true

/*
<configuration>
<executable>java</executable>
<workingDirectory>${project.basedir}</workingDirectory>
<arguments>
<argument>-cp</argument>
<argument>gradle/wrapper/gradle-wrapper.jar</argument>
<argument>org.gradle.wrapper.GradleWrapperMain</argument>
<argument>classes</argument>
</arguments>
<useMavenLogger>true</useMavenLogger>
</configuration>
*/
override fun execute() {
var command = baseCommand
if (quiet) {
command += "--quiet"
}
command += listOf("-i", task.name, *task.args.toTypedArray())
logger.debug("executing command: ${command.joinToString(" ")}")
ProcessExecutor()
.command(command)
.directory(project.basedir)
.redirectOutput(
object : LogOutputStream() {
override fun processLine(line: String) {
if (!quiet) {
logger.info("> ${line}")
}
}
}
command += listOf(task.name, *task.args.toTypedArray())
val executor = ProcessExecutor().command(command).directory(project.basedir)
if (log) {
logger.info(
"invoking gradle:\n\tdirectory: ${project.basedir}\n\tcommand: ${command.joinToString(" ")}"
)
.redirectError(
object : LogOutputStream() {
override fun processLine(line: String) {
logger.error("[error] > ${line}")
}
}
)
.execute()
val infoLogFile = File(project.basedir, "build/graven/${task.name}-info.log")
infoLogFile.parentFile.mkdirs()
logger.info("Logging enabled. See build/graven for details.")
executor
.redirectOutput(FileOutputStream(infoLogFile))
.redirectError(
FileOutputStream(File(project.basedir, "build/graven/${task.name}-error.log"))
)
}
val execute = executor.execute()

if (execute.exitValue != 0) {
if (log) {
throw MojoExecutionException("gradle run failed. check logs in build/graven/")
} else {
throw MojoExecutionException(
"gradle run failed. enabling logging to see the gradle output."
)
}
}
}
}
34 changes: 20 additions & 14 deletions mojo/src/main/kotlin/com/antwerkz/build/ReplacementMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.antwerkz.build
import com.antwerkz.expression.RegularExpression
import com.antwerkz.expression.toRegex
import java.io.File
import java.io.IOException
import java.nio.charset.Charset
import java.util.Properties
import org.apache.maven.model.Dependency
Expand Down Expand Up @@ -75,8 +76,9 @@ class ReplacementMojo : AbstractMojo() {
.split(",")
.map { it.trim() }
.forEach {
val file = File(it)
val file = File(project.basedir, it)

logger.info("Updating ${file}")
if (file.exists()) {
file.writeText(
file
Expand All @@ -97,20 +99,24 @@ class ReplacementMojo : AbstractMojo() {
}

private fun updateGradleWrapper() {
val file = File("gradle/wrapper/gradle-wrapper.properties")

file.writeText(
file
.readLines(Charset.defaultCharset())
.map { line: String ->
if (line.startsWith("distributionUrl=", ignoreCase = true)) {
"""distributionUrl=https://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip"""
} else {
line
val file = File(project.basedir, "gradle/wrapper/gradle-wrapper.properties")

try {
file.writeText(
file
.readLines(Charset.defaultCharset())
.map { line: String ->
if (line.startsWith("distributionUrl=", ignoreCase = true)) {
"""distributionUrl=https://services.gradle.org/distributions/gradle-${gradleVersion}-bin.zip"""
} else {
line
}
}
}
.joinToString("\n")
)
.joinToString("\n")
)
} catch (e: IOException) {
throw e
}
}
}

Expand Down

0 comments on commit a1db59f

Please sign in to comment.