Skip to content

Commit

Permalink
Add language plugin executors form gradle and maven
Browse files Browse the repository at this point in the history
- add the executors
- add integration tests

fixes #303
  • Loading branch information
pawelprazak committed Jan 29, 2024
1 parent dae9cfb commit 4c5e219
Show file tree
Hide file tree
Showing 28 changed files with 1,682 additions and 7 deletions.
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ upsert-gh-release:
# Cleans everything, including the local ivy, git untracked files, and kills all java processes
power-wash: clean-all
rm -rf ~/.ivy2/local/org.virtuslab/
rm -rf ~/.m2/repository/org/virtuslab/
git clean -i -d -x -e ".idea"
killall -9 java

Expand Down
151 changes: 148 additions & 3 deletions integration-tests/LanguagePluginTest.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import besom.integration.common.*
import munit.Slow
import os.*

import scala.concurrent.duration.Duration

//noinspection ScalaWeakerAccess,TypeAnnotation,ScalaFileName
class LanguagePluginTest extends munit.FunSuite {
override def munitTests(): Seq[Test] = super
.munitTests()
.filterNot(tagsWhen(envVarOpt("CI").contains("true"))(LocalOnly))
.filterNot(tags(Slow))

override val munitTimeout = Duration(5, "min")

val wd = os.pwd / "integration-tests"
val resourcesDir = wd / "resources"
val executorsDir = resourcesDir / "executors"
Expand Down Expand Up @@ -41,8 +45,127 @@ class LanguagePluginTest extends munit.FunSuite {
| )
|""".stripMargin

val gradleBuildFile =
s"""|plugins {
| scala
| application
|}
|
|repositories {
| mavenLocal()
| mavenCentral()
|}
|
|dependencies {
| implementation("org.scala-lang:scala3-library_3:3.3.1")
| implementation("org.virtuslab:besom-core_3:0.1.1-SNAPSHOT")
| implementation("org.virtuslab:besom-fake-standard-resource_3:1.2.3-TEST")
| implementation("org.virtuslab:besom-fake-external-resource_3:2.3.4-TEST")
| if (project.hasProperty("besomBootstrapJar")) runtimeOnly(files(project.property("besomBootstrapJar") as String))
|}
|
|application {
| mainClass.set(
| if (project.hasProperty("mainClass")) {
| project.property("mainClass") as String
| } else {
| "besom.languageplugin.test.pulumiapp.run"
| }
| )
|}
|""".stripMargin

val mavenPomFile =
s"""|<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
| <modelVersion>4.0.0</modelVersion>
|
| <groupId>org.virtuslab.example</groupId>
| <artifactId>infra</artifactId>
| <version>1.0-SNAPSHOT</version>
|
| <properties>
| <encoding>UTF-8</encoding>
| <maven.compiler.target>$javaVersion</maven.compiler.target>
| <maven.compiler.release>$javaVersion</maven.compiler.release>
| <mainClass>$${project.groupId}.$${project.artifactId}.run</mainClass>
| </properties>
|
| <profiles>
| <profile>
| <!-- This profile is used to run the project with the besom bootstrap jar -->
| <id>default-pulumi-java-sdk-dependency</id>
| <activation>
| <property>
| <name>besomBootstrapJar</name>
| </property>
| </activation>
| <dependencies>
| <dependency>
| <groupId>org.virtuslab</groupId>
| <artifactId>besom-bootstrap_3</artifactId>
| <version>$coreVersion</version>
| <scope>system</scope>
| <systemPath>$${besomBootstrapJar}</systemPath>
| </dependency>
| </dependencies>
| </profile>
| </profiles>
|
| <dependencies>
| <dependency>
| <groupId>org.scala-lang</groupId>
| <artifactId>scala3-library_3</artifactId>
| <version>$scalaVersion</version>
| </dependency>
| <dependency>
| <groupId>org.virtuslab</groupId>
| <artifactId>besom-core_3</artifactId>
| <version>$coreVersion</version>
| </dependency>
| <dependency>
| <groupId>org.virtuslab</groupId>
| <artifactId>besom-fake-standard-resource_3</artifactId>
| <version>1.2.3-TEST</version>
| </dependency>
| <dependency>
| <groupId>org.virtuslab</groupId>
| <artifactId>besom-fake-external-resource_3</artifactId>
| <version>2.3.4-TEST</version>
| </dependency>
| </dependencies>
|
| <build>
| <sourceDirectory>src/main/scala</sourceDirectory>
| <plugins>
| <plugin>
| <groupId>net.alchim31.maven</groupId>
| <artifactId>scala-maven-plugin</artifactId>
| <version>4.8.1</version>
| <executions>
| <execution>
| <goals>
| <goal>compile</goal>
| <goal>testCompile</goal>
| </goals>
| </execution>
| </executions>
| </plugin>
| <plugin>
| <groupId>org.apache.maven.plugins</groupId>
| <artifactId>maven-wrapper-plugin</artifactId>
| <version>3.2.0</version>
| <configuration>
| <mavenVersion>3.9.6</mavenVersion>
| </configuration>
| </plugin>
| </plugins>
| </build>
|</project>
|""".stripMargin

def publishLocalResourcePlugin(pluginName: String) =
scalaCli.publishLocal(".").call(cwd = resourcesDir / pluginName)
scalaCli.publishLocalMaven(".").call(cwd = resourcesDir / pluginName)

def publishLocalResourcePlugins() =
publishLocalResourcePlugin("fake-standard-resource-plugin")
Expand Down Expand Up @@ -73,7 +196,7 @@ class LanguagePluginTest extends munit.FunSuite {
)
)

def testExecutor(ctx: pulumi.FixtureContext, pluginsJson: String) =
def testExecutor(ctx: pulumi.FixtureContext, pluginsJson: String = "") =
if pluginsJson.nonEmpty then
val actual = PulumiPluginJSON.listFrom(pluginsJson)
assert {
Expand Down Expand Up @@ -125,6 +248,8 @@ class LanguagePluginTest extends munit.FunSuite {
end testExecutor

override def beforeAll(): Unit =
scalaCli.publishLocalMaven("besom-json")
scalaCli.publishLocalMaven("core")
publishLocalResourcePlugins()

FunFixture[pulumi.FixtureContext](
Expand Down Expand Up @@ -154,7 +279,27 @@ class LanguagePluginTest extends munit.FunSuite {
),
teardown = pulumi.fixture.teardown
).test("sbt".tag(LocalOnly)) { ctx =>
testExecutor(ctx, "") // we skip bootstrap test for sbt due to practical reasons for now
testExecutor(ctx)
}

FunFixture[pulumi.FixtureContext](
setup = pulumi.fixture.setup(
executorsDir / "gradle",
projectFiles = Map("build.gradle.kts" -> gradleBuildFile)
),
teardown = pulumi.fixture.teardown
).test("gradle") { ctx =>
testExecutor(ctx)
}

FunFixture[pulumi.FixtureContext](
setup = pulumi.fixture.setup(
executorsDir / "maven",
projectFiles = Map("pom.xml" -> mavenPomFile)
),
teardown = pulumi.fixture.teardown
).test("maven") { ctx =>
testExecutor(ctx)
}

FunFixture[pulumi.FixtureContext](
Expand Down
16 changes: 16 additions & 0 deletions integration-tests/integration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,22 @@ object scalaCli {
"--javac-opt=-J-XX:+UseParallelGC",
additional
)

def publishLocalMaven(additional: os.Shellable*) = pproc(
"scala-cli",
"--power",
"publish",
s"--publish-repository=file://${os.home}/.m2/repository",
"--sources=false",
"--doc=false",
"--suppress-experimental-feature-warning",
"--suppress-directives-in-multiple-files-warning",
"--server=false",
"--javac-opt=-verbose",
"--javac-opt=-J-XX:MaxHeapSize=32G",
"--javac-opt=-J-XX:+UseParallelGC",
additional
)
}

object codegen {
Expand Down
9 changes: 9 additions & 0 deletions integration-tests/resources/executors/gradle/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf
*.cmd text eol=crlf
6 changes: 6 additions & 0 deletions integration-tests/resources/executors/gradle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
9 changes: 9 additions & 0 deletions integration-tests/resources/executors/gradle/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: language-plugin-test
description: gradle executor test
runtime:
name: scala
options:
# language host debugging options, for full list of options:
# ~/.pulumi/plugins/language-scala-v0.1.0/pulumi-language-scala -h
v: 0
logtostderr: true
27 changes: 27 additions & 0 deletions integration-tests/resources/executors/gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
scala
application
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation("org.scala-lang:scala3-library_3:3.3.1")
implementation("org.virtuslab:besom-core_3:0.1.1-SNAPSHOT")
implementation("org.virtuslab:besom-fake-standard-resource_3:1.2.3-TEST")
implementation("org.virtuslab:besom-fake-external-resource_3:2.3.4-TEST")
if (project.hasProperty("besomBootstrapJar")) runtimeOnly(files(project.property("besomBootstrapJar") as String))
}

application {
mainClass.set(
if (project.hasProperty("mainClass")) {
project.property("mainClass") as String
} else {
"besom.languageplugin.test.pulumiapp.run"
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 4c5e219

Please sign in to comment.