+ * 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
+
+
+