Skip to content

Commit

Permalink
Merge pull request #251 from guardrail-dev/1.x
Browse files Browse the repository at this point in the history
Prepare for 1.x
  • Loading branch information
blast-hardcheese authored Dec 27, 2023
2 parents 1369a88 + 44cad7d commit 4964537
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8', '11', '17' ]
java: [ '14', '17' ]
steps:
- uses: actions/checkout@v3
- name: Set up JDK
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 8
java-version: 14
server-id: ossrh
server-username: SONATYPE_USERNAME
server-password: SONATYPE_PASSWORD
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/tag-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '8' ]
steps:
- name: Publish release notes
uses: release-drafter/release-drafter@v5
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Add to your `pom.xml`:
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-maven-plugin</artifactId>
<version>Please use the latest available release!</version>
<dependencies>
<!-- List the guardrail modules you wish to use. For more, see the module lists here: https://guardrail.dev/ -->
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-dropwizard_2.13</artifactId> <!-- SpringMVC also available! -->
<version>...</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-async-http_2.13</artifactId>
<version>...</version>
</dependency>
</dependencies>
<executions>
<!-- This execution generates an API client from an OpenAPI spec file -->
<execution>
Expand Down
69 changes: 12 additions & 57 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<maven-settings.version>3.9.4</maven-settings.version>
<plexus-utils.version>3.5.1</plexus-utils.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.compat.version>2.12</scala.compat.version>
<scala.version>2.12.18</scala.version>
<scala.compat.version>2.13</scala.compat.version>
<scala.version>2.13.12</scala.version>
</properties>

<profiles>
Expand Down Expand Up @@ -176,53 +176,10 @@
<artifactId>plexus-utils</artifactId>
<version>${plexus-utils.version}</version>
</dependency>
<!-- guardrail modularization means versioning these all separately now. dependabot and scala-steward should do a good job. -->
<!-- Additionally, we will likely only want to depend on guardrail and guardrail-core,
letting the user specify which modules they want, to cut down on version churn -->
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-core_2.12</artifactId>
<version>0.75.3</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-async-http_2.12</artifactId>
<version>0.72.0</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-support_2.12</artifactId>
<version>0.73.1</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-dropwizard_2.12</artifactId>
<version>0.72.0</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-spring-mvc_2.12</artifactId>
<version>0.71.2</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-scala-support_2.12</artifactId>
<version>0.75.3</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-scala-akka-http_2.12</artifactId>
<version>0.76.0</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-scala-dropwizard_2.12</artifactId>
<version>0.72.0</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-scala-http4s_2.12</artifactId>
<version>0.76.1</version>
<artifactId>guardrail-core_${scala.compat.version}</artifactId>
<version>1.0.0-M1</version>
</dependency>
</dependencies>

Expand All @@ -231,21 +188,19 @@
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.6.3</version>
<version>4.8.1</version>
<configuration>
<recompileMode>incremental</recompileMode>
<args>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-Xexperimental</arg>
</args>
<charset>UTF-8</charset>
<compilerPlugins>
<compilerPlugin>
<groupId>org.spire-math</groupId>
<artifactId>kind-projector_${scala.compat.version}</artifactId>
<version>0.9.4</version>
<groupId>org.typelevel</groupId>
<artifactId>kind-projector_${scala.version}</artifactId>
<version>0.13.2</version>
</compilerPlugin>
</compilerPlugins>
</configuration>
Expand All @@ -271,8 +226,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>14</source>
<target>14</target>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -331,8 +286,8 @@
<streamLogsOnFailures>true</streamLogsOnFailures>
<properties>
<guardrail.plugin.version>${project.version}</guardrail.plugin.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
</properties>
<scriptVariables>
<projectVersion>0.0.1</projectVersion>
Expand Down
16 changes: 14 additions & 2 deletions src/it/codegen-java-vavr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -143,6 +143,18 @@
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-maven-plugin</artifactId>
<version>${guardrail.plugin.version}</version>
<dependencies>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-dropwizard_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-async-http_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-petstore</id>
Expand Down
16 changes: 14 additions & 2 deletions src/it/codegen-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -118,6 +118,18 @@
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-maven-plugin</artifactId>
<version>${guardrail.plugin.version}</version>
<dependencies>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-dropwizard_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-async-http_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-petstore-client</id>
Expand Down
13 changes: 10 additions & 3 deletions src/it/codegen-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.0</version>
<version>4.8.1</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -143,6 +143,13 @@
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-maven-plugin</artifactId>
<version>${guardrail.plugin.version}</version>
<dependencies>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-scala-akka-http_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-petstore-client</id>
Expand Down
16 changes: 14 additions & 2 deletions src/it/codegen-spring-mvc-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>14</source>
<target>14</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -165,6 +165,18 @@
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-maven-plugin</artifactId>
<version>${guardrail.plugin.version}</version>
<dependencies>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-spring-mvc_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
<dependency>
<groupId>dev.guardrail</groupId>
<artifactId>guardrail-java-async-http_2.13</artifactId>
<version>1.0.0-M1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>generate-petstore-spring-mvc-server</id>
Expand Down
49 changes: 24 additions & 25 deletions src/main/scala/dev/guardrail/AbstractGuardrailCodegenMojo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.apache.maven.plugins.annotations.{Component, Parameter}
import org.apache.maven.project.{DefaultProjectBuildingRequest, MavenProject}
import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate
import org.apache.maven.shared.transfer.artifact.resolve.{ArtifactResolver, ArtifactResolverException}
import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.io.AnsiColor
import scala.language.higherKinds
import scala.util.control.NonFatal
Expand All @@ -28,7 +28,10 @@ sealed abstract class Phase(val root: String)
object Main extends Phase("main")
object Test extends Phase("test")

abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo with GuardrailRunner {
abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo {
def guardrailModulePrefix: String

val runner = new GuardrailRunner() {}
@Parameter(defaultValue = "${project.build.directory}/generated-sources/guardrail-sources", property = "outputPath", required = true)
def outputPath: File

Expand Down Expand Up @@ -80,6 +83,8 @@ abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo w
@Parameter(property = "customExtraction")
var customExtraction: Boolean = _

val scalaCompatVersion: String = "2.13"

override def execute(): Unit = {
if (!outputPath.exists()) {
outputPath.mkdirs()
Expand Down Expand Up @@ -124,25 +129,25 @@ abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo w
case x => throw new MojoExecutionException(s"Unsupported codegen type: ${x}")
}

val arg = Args.empty.copy(
kind=_kind,
specPath=Some(_specPath.getCanonicalPath),
packageName=Option(packageName).map(_.trim.split('.').toList),
dtoPackage=Option(dtoPackage).toList.flatMap(_.split('.').filterNot(_.isEmpty).toList),
context=Context.empty.copy(
customExtraction=Option(customExtraction).getOrElse(Context.empty.customExtraction),
framework=Option(framework),
tracing=Option(tracing).getOrElse(Context.empty.tracing),
modules=Option(modules).fold(Context.empty.modules)(_.asScala.toList.map(_.toString))
),
imports=Option(customImports).fold[List[String]](List.empty)(_.asScala.toList.map(_.toString))
)
val arg = Args.empty
.withKind(_kind)
.withSpecPath(Some(_specPath.getCanonicalPath))
.withPackageName(Option(packageName).map(_.trim.split('.').toList))
.withDtoPackage(Option(dtoPackage).toList.flatMap(_.split('.').filterNot(_.isEmpty).toList))
.withContext(
Context.empty
.withCustomExtraction(Option(customExtraction).getOrElse(Context.empty.customExtraction))
.withFramework(Option(framework))
.withTracing(Option(tracing).getOrElse(Context.empty.tracing))
.withModules(Option(modules).fold(Context.empty.modules)(_.asScala.toList.map(_.toString)))
)
.withImports(Option(customImports).fold[List[String]](List.empty)(_.asScala.toList.map(_.toString)))

val logLevel = Option(System.getProperty("guardrail.loglevel")).flatMap(LogLevels.apply).getOrElse(LogLevels.Warning)

getLog.info(s"Generating ${_kind} from ${specDesc}")

guardrailTask(List((_language, arg)), outputPath)(logLevel)
guardrailTask(_language, arg, outputPath)(logLevel)
} catch {
case NonFatal(e) =>
getLog.error("Failed to generate client", e)
Expand All @@ -151,15 +156,9 @@ abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo w
}

type Language = String
def guardrailTask(tasks: List[(Language, Args)], sourceDir: java.io.File)(implicit logLevel: LogLevel): Seq[java.io.File] = {
val preppedTasks: Map[String, NonEmptyList[Args]] = tasks.foldLeft(Map.empty[String, NonEmptyList[Args]]) { case (acc, (language, args)) =>
val prepped = args.copy(outputPath=Some(sourceDir.getPath))
acc.updated(language, acc.get(language).fold(NonEmptyList.one(prepped))(_ :+ prepped))
}

def guardrailTask(language: String, arg: Args, sourceDir: java.io.File)(implicit logLevel: LogLevel): Seq[java.io.File] = {
val /*(logger,*/ paths/*)*/ =
guardrailRunner
.apply(preppedTasks)
runner.guardrailRunner(language, Array(arg.withOutputPath(Some(sourceDir.getPath))))
.fold[List[java.nio.file.Path]]({
case MissingArg(args, Error.ArgName(arg)) =>
getLog.error(s"Missing argument: ${AnsiColor.BOLD}${arg}${AnsiColor.RESET} (In block ${args})")
Expand All @@ -168,7 +167,7 @@ abstract class AbstractGuardrailCodegenMojo(phase: Phase) extends AbstractMojo w
getLog.error(s"""${AnsiColor.RED}Missing dependency:${AnsiColor.RESET}
|${AnsiColor.BOLD}<dependency>
| <groupId>dev.guardrail</groupId>
| <artifactId>${name}_2.12</artifactId>
| <artifactId>${guardrailModulePrefix}-${name}_${scalaCompatVersion}</artifactId>
| <version>Check latest version!</version>
|</dependency>${AnsiColor.RESET}
|""".stripMargin)
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/dev/guardrail/GuardrailCodegenMojo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import org.apache.maven.plugins.annotations.{LifecyclePhase, Mojo, Parameter}

@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
class GuardrailCodegenMojo extends AbstractGuardrailCodegenMojo(Main) {

val guardrailModulePrefix: String = "guardrail"

@Parameter(defaultValue = "${project.build.directory}/generated-sources/swagger-clients", property = "outputPath", required = true)
var outputPath: File = _
}
Loading

0 comments on commit 4964537

Please sign in to comment.