diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..741e781 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,34 @@ +name: Java CI with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + name: Native build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '17' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + native-image-job-reports: 'true' + # Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies. + # See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + - name: Build with Gradle Wrapper + run: ./gradlew build nativeCompile nativeTest + - name: Upload binary + uses: actions/upload-artifact@v4 + with: + name: ecore2emfatic-${{ matrix.os }} + path: build/native/nativeCompile/ecore2emfatic* diff --git a/.github/workflows/release-jar.yml b/.github/workflows/release-jar.yml new file mode 100644 index 0000000..739ebea --- /dev/null +++ b/.github/workflows/release-jar.yml @@ -0,0 +1,29 @@ +name: Github Packages Release Builds +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + server-id: github + settings-path: ${{ github.workspace }} # location for the settings.xml file + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + - name: Build with Gradle + run: ./gradlew build + - name: Publish package + run: ./gradlew publish + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-native.yml b/.github/workflows/release-native.yml new file mode 100644 index 0000000..d2648f5 --- /dev/null +++ b/.github/workflows/release-native.yml @@ -0,0 +1,41 @@ +name: Native Release Builds +on: + push: + tags: [ "[0-9]+.[0-9]+.[0-9]+" ] + +jobs: + build: + name: Native release build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + - uses: graalvm/setup-graalvm@v1 + with: + java-version: '17' + distribution: 'graalvm' + github-token: ${{ secrets.GITHUB_TOKEN }} + native-image-job-reports: 'true' + - name: Setup Gradle + uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 + - name: Build with Gradle Wrapper + run: ./gradlew build nativeCompile nativeTest + - name: Upload release asset (Unix) + if: ${{ matrix.os != 'windows-latest' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + zip -j ${{ matrix.os }}-ecore2emfatic.zip build/native/nativeCompile/ecore2emfatic* + gh release upload $GITHUB_REF_NAME ${{ matrix.os }}-ecore2emfatic.zip + - name: Upload release asset (Windows) + if: ${{ matrix.os == 'windows-latest' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + Compress-Archive -Path build/native/nativeCompile/ecore2emfatic* -DestinationPath ${{ matrix.os }}-ecore2emfatic.zip + gh release upload ${{ github.ref_name }} ${{ matrix.os }}-ecore2emfatic.zip diff --git a/README.md b/README.md index a2606f3..8ed3828 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ It is recommended to use [SDKMAN](https://sdkman.io/) for installing and managin To produce Emfatic sources from an `.ecore` file, using the all-in-one JAR file in `build/libs/*-all.jar`: ```sh -java -jar path/to/Ecore2Emfatic-VERSION-all.jar path/to/your.ecore +java -jar path/to/ecore2emfatic-VERSION-all.jar path/to/your.ecore ``` When using one of the native binaries, this can be simplified to: ```sh -path/to/Ecore2Emfatic path/to/your.ecore +path/to/ecore2emfatic path/to/your.ecore ``` ## Using native binaries as a Git filter @@ -34,13 +34,13 @@ In order to compute differences between `.ecore` file versions using a Git `text In Linux/Mac: ```sh -cp build/native/nativeCompile/Ecore2Emfatic /folder/in/PATH +cp build/native/nativeCompile/ecore2emfatic /folder/in/PATH ``` You will then need to define the `ecore` differencing algorithm: ```sh -git config --global diff.ecore.textconv Ecore2Emfatic +git config --global diff.ecore.textconv ecore2emfatic ``` You can then use this conversion from any Git repository, by adding a `.gitattributes` file to its root folder with this content: @@ -71,18 +71,18 @@ index 84da8c9..f611dd1 100644 If your `.ecore` files import other metamodels through URIs, you can provide mappings from URIs to specific `.ecore` files or folders via the `--from` and `--to` options: ```sh -path/to/Ecore2Emfatic --from platform:/resource --to path/to/base/folder your.ecore +path/to/ecore2emfatic --from platform:/resource --to path/to/base/folder your.ecore ``` You can specify multiple pairs of `--from` and `--to` options, as in: ```sh -path/to/Ecore2Emfatic --from A --to B --from C --to D your.ecore +path/to/ecore2emfatic --from A --to B --from C --to D your.ecore ``` If you are using this tool as a `textconv` filter via Git, you would need to provide these options in your repository's configuration. For example: ```sh -git config diff.ecore.textconv "Ecore2Emfatic --from A --to B" +git config diff.ecore.textconv "ecore2emfatic --from A --to B" ``` diff --git a/build.gradle b/build.gradle index 22a84ef..e3f15e5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,10 @@ plugins { id("com.github.johnrengelman.shadow") version "8.1.1" id("io.micronaut.application") version "4.0.4" + id("maven-publish") } -version = "0.1" +version = "0.1.0" group = "org.eclipse.emfatic.cli" repositories { @@ -18,7 +19,6 @@ dependencies { implementation("io.micronaut.serde:micronaut-serde-jackson") implementation("org.eclipse.emfatic:org.eclipse.emfatic.core:1.1.0") implementation("org.eclipse.platform:org.eclipse.core.resources:3.13.700") - testImplementation('org.hamcrest:hamcrest:2.2') runtimeOnly("ch.qos.logback:logback-classic") } @@ -38,5 +38,20 @@ micronaut { } } - - +publishing { + publications { + library(MavenPublication) { + from components.java + } + } + repositories { + maven { + name = "GitHubPackages" + url = "https://maven.pkg.github.com/epsilonlabs/ecore2emfatic-cli" + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } +} diff --git a/settings.gradle b/settings.gradle index 9707616..fc77aee 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ -rootProject.name="Ecore2Emfatic" +rootProject.name="ecore2emfatic" diff --git a/src/main/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommand.java b/src/main/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommand.java index 2287172..4dfb081 100644 --- a/src/main/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommand.java +++ b/src/main/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommand.java @@ -39,7 +39,7 @@ EStringToStringMapEntryImpl[].class, ETypeParameter[].class }) -@Command(name = "Ecore2Emfatic", description = "Generates Emfatic sources from an .ecore file", mixinStandardHelpOptions = true) +@Command(name = "ecore2emfatic", description = "Generates Emfatic sources from an .ecore file", mixinStandardHelpOptions = true) public class Ecore2EmfaticCommand implements Runnable { static class URIMapping { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2654a4b..6b4c966 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ #Tue May 21 17:03:57 BST 2024 -micronaut.application.name=ecore2Emfatic +micronaut.application.name=ecore2emfatic diff --git a/src/test/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommandTest.java b/src/test/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommandTest.java index 1bd9d91..1562bac 100644 --- a/src/test/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommandTest.java +++ b/src/test/java/org/eclipse/emfatic/cli/Ecore2EmfaticCommandTest.java @@ -12,8 +12,7 @@ import io.micronaut.configuration.picocli.PicocliRunner; import io.micronaut.context.ApplicationContext; import io.micronaut.context.env.Environment; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.PrintStream; @@ -29,12 +28,17 @@ public void testStandaloneMetamodel() throws Exception { try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) { String[] args = new String[] { "src/test/resources/OO.ecore" }; PicocliRunner.run(Ecore2EmfaticCommand.class, ctx, args); - assertThat("Should see a PackageableElement in the output", - baos.toString(), containsString("PackageableElement")); + assertContains("Should see a PackageableElement in the output", baos.toString(), "PackageableElement"); } } - @Test + private void assertContains(String reason, String text, String substring) { + if (!text.contains(substring)) { + fail(String.format("%s, but did not contain '%s':\n%s", reason, substring, text)); + } + } + + @Test public void testMetamodelWithPlatformImport() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); @@ -46,8 +50,8 @@ public void testMetamodelWithPlatformImport() throws Exception { "src/test/resources/platformImport/example2/ColoredTree.ecore" }; PicocliRunner.run(Ecore2EmfaticCommand.class, ctx, args); - assertThat("Should see 'extends Trees.Tree' in the output", - baos.toString(), containsString("extends Trees.Tree")); + assertContains("Should see 'extends Trees.Tree' in the output", + baos.toString(), "extends Trees.Tree"); } } }