diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0fa50c4..7944a76 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,9 +33,16 @@ jobs: with: channel: 5.21/candidate - - name: Build and verify project + - name: Setup rockcraft run: | sudo snap install rockcraft --classic + + - name: Build and verify maven project + run: | + mvn install invoker:install invoker:run + + - name: Build and verify gradle project + run: | ./gradlew clean build -i - name: Publish Snapshots diff --git a/.gitignore b/.gitignore index 4c5d06c..eee66f5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .vscode # Ignore Gradle build output directory build +target diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..0cbabae --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + com.canonical + rockcraft-parent + 0.0.1 + pom + + 8 + 8 + 8 + UTF-8 + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + rockcraft + rockcraft-maven + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.5.0 + + + + diff --git a/rockcraft-maven/pom.xml b/rockcraft-maven/pom.xml new file mode 100644 index 0000000..8b99143 --- /dev/null +++ b/rockcraft-maven/pom.xml @@ -0,0 +1,151 @@ + + + com.canonical + rockcraft-parent + 0.0.1 + + + maven-plugin + + 3.8.0 + 3.13.1 + 3.9.9 + 3.15.0 + 6.0.0 + 5.12.0 + 4.0.0-beta-1 + + + 4.0.0 + rockcraft-maven-plugin + + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${mavenPluginVersion} + provided + + + org.apache.maven.plugin-tools + maven-plugin-tools-java + ${maven-plugin-tools.version} + provided + + + + org.apache.maven + maven-plugin-api + ${mavenVersion} + provided + + + org.apache.maven + maven-artifact + ${mavenVersion} + provided + + + org.apache.maven + maven-core + ${mavenVersion} + provided + + + org.apache.maven.shared + maven-shared-utils + 3.4.2 + provided + + + com.canonical + rockcraft + ${project.version} + + + org.yaml + snakeyaml + 2.3 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.11.1 + test + + + + + + + maven-gpg-plugin + 3.1.0 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + maven-invoker-plugin + ${maven-invoker-plugin.version} + + ${project.build.directory}/it + src/it/settings.xml + ${project.build.directory}/local-repo + + verify + ${skipTests} + true + + -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN + + + + integration-test + + install + run + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${maven-plugin-tools.version} + + + help-mojo + + helpmojo + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + unit/** + + + + + + + diff --git a/rockcraft-maven/src/it/basic-rock/foo/Foo.java b/rockcraft-maven/src/it/basic-rock/foo/Foo.java new file mode 100644 index 0000000..c1a0df9 --- /dev/null +++ b/rockcraft-maven/src/it/basic-rock/foo/Foo.java @@ -0,0 +1,8 @@ +package foo; + +public class Foo { + public Foo() { + System.out.println("Foo"); + } + +} diff --git a/rockcraft-maven/src/it/basic-rock/invoker.properties b/rockcraft-maven/src/it/basic-rock/invoker.properties new file mode 100644 index 0000000..beb82b1 --- /dev/null +++ b/rockcraft-maven/src/it/basic-rock/invoker.properties @@ -0,0 +1 @@ +invoker.goals=--no-transfer-progress install -X diff --git a/rockcraft-maven/src/it/basic-rock/pom.xml b/rockcraft-maven/src/it/basic-rock/pom.xml new file mode 100644 index 0000000..7747c35 --- /dev/null +++ b/rockcraft-maven/src/it/basic-rock/pom.xml @@ -0,0 +1,29 @@ + + foo + foo + 1 + 4.0.0 + + 21 + 21 + + + ${project.basedir}/target + ${project.basedir}/target/classes + ${project.basedir}/target/test-classes + + + com.canonical + rockcraft-maven-plugin + + + + create-rock + + + + + + + + diff --git a/rockcraft-maven/src/it/basic-rock/verify.bsh b/rockcraft-maven/src/it/basic-rock/verify.bsh new file mode 100644 index 0000000..04d9560 --- /dev/null +++ b/rockcraft-maven/src/it/basic-rock/verify.bsh @@ -0,0 +1,14 @@ +import java.io.*; + +File target = new File( basedir, "target" ); + +var files = target.listFiles(new FilenameFilter(){ + public boolean accept(File dir, String name) { + return name.equals("rockcraft.yaml"); + } +}); + +if ( files == null || files.length == 0 ) +{ + throw new FileNotFoundException( "Could not find generated rock file in " + rockOut ); +} diff --git a/rockcraft-maven/src/it/manual-create-rock-test/invoker.properties b/rockcraft-maven/src/it/manual-create-rock-test/invoker.properties new file mode 100644 index 0000000..02dab37 --- /dev/null +++ b/rockcraft-maven/src/it/manual-create-rock-test/invoker.properties @@ -0,0 +1 @@ + invoker.goals=--no-transfer-progress install diff --git a/rockcraft-maven/src/it/manual-create-rock-test/pom.xml b/rockcraft-maven/src/it/manual-create-rock-test/pom.xml new file mode 100644 index 0000000..9fe078a --- /dev/null +++ b/rockcraft-maven/src/it/manual-create-rock-test/pom.xml @@ -0,0 +1,47 @@ + + foo + foo + 1 + 4.0.0 + + 8 + 8 + + + ${project.basedir}/target + ${project.basedir}/target/classes + ${project.basedir}/target/test-classes + + + com.canonical + rockcraft-maven-plugin + + + + create-rock + build-rock + + + + + true + openjdk-17-jdk-headless + 17 + false + foo + readme.txt + https://github.com/vpa1977/chisel-releases + 24.04-openjdk-17 + + amd64 + arm64 + + + busybox_bins + dash_bins + + + + + + diff --git a/rockcraft-maven/src/it/manual-create-rock-test/readme.txt b/rockcraft-maven/src/it/manual-create-rock-test/readme.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/rockcraft-maven/src/it/manual-create-rock-test/readme.txt @@ -0,0 +1 @@ +1 diff --git a/rockcraft-maven/src/it/manual-create-rock-test/src/main/java/foo/Foo.java b/rockcraft-maven/src/it/manual-create-rock-test/src/main/java/foo/Foo.java new file mode 100644 index 0000000..c1a0df9 --- /dev/null +++ b/rockcraft-maven/src/it/manual-create-rock-test/src/main/java/foo/Foo.java @@ -0,0 +1,8 @@ +package foo; + +public class Foo { + public Foo() { + System.out.println("Foo"); + } + +} diff --git a/rockcraft-maven/src/it/settings.xml b/rockcraft-maven/src/it/settings.xml new file mode 100644 index 0000000..d8f01ca --- /dev/null +++ b/rockcraft-maven/src/it/settings.xml @@ -0,0 +1,34 @@ + + + + it-repo + + true + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + local.central + @localRepositoryUrl@ + + true + + + true + + + + + + diff --git a/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/AbstractRockMojo.java b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/AbstractRockMojo.java new file mode 100644 index 0000000..c1b6aa7 --- /dev/null +++ b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/AbstractRockMojo.java @@ -0,0 +1,85 @@ +/** + * Copyright 2024 Canonical Ltd. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.canonical.rockcraft.maven; + +import com.canonical.rockcraft.builder.RockcraftOptions; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.util.ArrayList; +import java.util.List; + +public class AbstractRockMojo extends AbstractMojo { + @Parameter(defaultValue = "${project}", readonly = true, required = true) + private MavenProject project; + + @Parameter(property = "buildPackage") + private String buildPackage = "openjdk-21-jdk"; + + @Parameter(property = "targetRelease") + private int targetRelease = 21; + + @Parameter(property = "jlink") + private boolean jlink = false; + + @Parameter(property = "summary") + private String summary = ""; + + @Parameter(property = "description") + private String description = null; + + @Parameter(property = "command") + private String command = ""; + + @Parameter(property = "source") + private String source; + + @Parameter(property = "branch") + private String branch; + + @Parameter(property = "architectures") + private RockcraftOptions.RockArchitecture[] architectures = new RockcraftOptions.RockArchitecture[0]; + + @Parameter(property = "slices") + private List slices = new ArrayList(); + + @Parameter(property = "docker") + private boolean docker = false; + + private RockcraftOptions options = new RockcraftOptions(); + + protected RockcraftOptions getOptions() { + return options; + } + + protected MavenProject getProject() { + return project; + } + + @Override + public void execute() throws MojoExecutionException { + options.setBuildPackage(buildPackage); + options.setTargetRelease(targetRelease); + options.setJlink(jlink); + options.setSummary(summary); + options.setDescription(description); + options.setCommand(command); + options.setSource(source); + options.setBranch(branch); + options.setArchitectures(architectures); + options.setSlices(slices); + } +} diff --git a/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/BuildRockMojo.java b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/BuildRockMojo.java new file mode 100644 index 0000000..0af3cd5 --- /dev/null +++ b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/BuildRockMojo.java @@ -0,0 +1,35 @@ +/** + * Copyright 2024 Canonical Ltd. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.canonical.rockcraft.maven; + +import com.canonical.rockcraft.builder.RockBuilder; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; + +import java.io.IOException; + +@Mojo(name = "build-rock", threadSafe = false, requiresProject = true, defaultPhase = LifecyclePhase.INSTALL) +public class BuildRockMojo extends AbstractRockMojo { + + public void execute() throws MojoExecutionException { + super.execute(); + try { + RockBuilder.buildRock(RockSettingsFactory.createRockProjectSettings(getProject()), getOptions()); + } catch (InterruptedException | IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + + } +} diff --git a/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/CreateRockMojo.java b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/CreateRockMojo.java new file mode 100644 index 0000000..9dd6a42 --- /dev/null +++ b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/CreateRockMojo.java @@ -0,0 +1,45 @@ +/** + * Copyright 2024 Canonical Ltd. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.canonical.rockcraft.maven; + +import com.canonical.rockcraft.builder.RockCrafter; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +@Mojo(name = "create-rock", threadSafe = false, requiresProject = true, defaultPhase = LifecyclePhase.PACKAGE) +public class CreateRockMojo extends AbstractRockMojo { + + @Override + public void execute() throws MojoExecutionException { + super.execute(); + + ArrayList jars = new ArrayList(); + jars.add(getProject().getArtifact().getFile()); + + if (jars.isEmpty()) { + throw new MojoExecutionException("No project artifacts found."); + } + RockCrafter rockCrafter = new RockCrafter(RockSettingsFactory.createRockProjectSettings(getProject()), getOptions(), jars); + try { + rockCrafter.writeRockcraft(); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } +} diff --git a/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/RockSettingsFactory.java b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/RockSettingsFactory.java new file mode 100644 index 0000000..17d207b --- /dev/null +++ b/rockcraft-maven/src/main/java/com/canonical/rockcraft/maven/RockSettingsFactory.java @@ -0,0 +1,40 @@ +/** + * Copyright 2024 Canonical Ltd. + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + *

+ * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.canonical.rockcraft.maven; + +import com.canonical.rockcraft.builder.RockProjectSettings; +import org.apache.maven.project.MavenProject; + +/** + * Creates RockProjectSettings from Maven project + */ +public class RockSettingsFactory { + + /** + * Constructs RockSettingsFactory + */ + RockSettingsFactory() {} + + /** + * Creates RockProjectSettings from Maven project + * + * @param project - Maven project + * @return RockProjectSettings + */ + public static final RockProjectSettings createRockProjectSettings(MavenProject project) { + return new RockProjectSettings("maven", project.getName(), + project.getVersion(), project.getBasedir().getAbsoluteFile().toPath(), + project.getArtifact().getFile().getParentFile().toPath()); + } +} diff --git a/rockcraft/pom.xml b/rockcraft/pom.xml new file mode 100644 index 0000000..3ab3847 --- /dev/null +++ b/rockcraft/pom.xml @@ -0,0 +1,23 @@ + + + com.canonical + rockcraft-parent + 0.0.1 + + + 4.0.0 + rockcraft + + + org.yaml + snakeyaml + 2.3 + + + org.junit.jupiter + junit-jupiter-engine + 5.11.1 + test + + +