diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/AddExtensionCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/AddExtensionCommand.java index 67735d38392708..92085cb93fbe3a 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/AddExtensionCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/AddExtensionCommand.java @@ -46,7 +46,10 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command File pomFile = new File(pom.getAbsolutePath()); AddExtensions project = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()); - project.addExtensions(Collections.singleton(extension)); + AddExtensionResult result = project.addExtensions(Collections.singleton(extension)); + if (!result.succeeded()) { + throw new CommandException("Unable to add an extension matching " + extension); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/devtools/common-core/src/main/java/io/quarkus/dependencies/Extension.java b/devtools/common-core/src/main/java/io/quarkus/dependencies/Extension.java index 10f5932935a0ed..336af3bb3a8cdb 100644 --- a/devtools/common-core/src/main/java/io/quarkus/dependencies/Extension.java +++ b/devtools/common-core/src/main/java/io/quarkus/dependencies/Extension.java @@ -46,6 +46,7 @@ public class Extension { private String simplifiedArtifactId; private static final Pattern QUARKUS_PREFIX = Pattern.compile("^quarkus-"); + private String shortName; public Extension() { // Use by mapper. @@ -246,4 +247,13 @@ public boolean equals(Object obj) { public String getGuide() { return guide; } + + public String getShortName() { + return shortName; + } + + public Extension setShortName(String shortName) { + this.shortName = shortName; + return this; + } } diff --git a/devtools/common/src/main/filtered/extensions.json b/devtools/common/src/main/filtered/extensions.json index c39f310335eed1..ccd3e308aa28ba 100644 --- a/devtools/common/src/main/filtered/extensions.json +++ b/devtools/common/src/main/filtered/extensions.json @@ -10,6 +10,7 @@ }, { "name": "Arc", + "shortName": "CDI", "labels": [ "arc", "cdi", @@ -69,6 +70,7 @@ }, { "name": "Hibernate ORM", + "shortName": "JPA", "labels": [ "hibernate-orm", "jpa", @@ -105,6 +107,7 @@ }, { "name": "Hibernate Validator", + "shortName": "bean-validation", "labels": [ "hibernate-validator", "bean-validation", @@ -231,6 +234,7 @@ }, { "name": "RESTEasy", + "shortName": "jax-rs", "labels": [ "resteasy", "jaxrs", @@ -401,6 +405,7 @@ }, { "name": "SmallRye Reactive Messaging - Kafka Connector", + "shortName": "kafka", "labels": [ "kafka", "reactive-kafka" @@ -432,6 +437,7 @@ }, { "name": "Swagger UI", + "shortName": "swagger", "labels": [ "swagger-ui" ], @@ -441,6 +447,7 @@ }, { "name": "Undertow", + "shortName": "servlet", "labels": [ "undertow", "servlet" @@ -450,6 +457,7 @@ }, { "name": "Undertow WebSockets", + "shortName": "websockets", "labels": [ "undertow-websockets", "undertow-websocket", diff --git a/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensionResult.java b/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensionResult.java new file mode 100644 index 00000000000000..324e1d7d739b4c --- /dev/null +++ b/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensionResult.java @@ -0,0 +1,20 @@ +package io.quarkus.cli.commands; + +public class AddExtensionResult { + + private final boolean updated; + private final boolean succeeded; + + public AddExtensionResult(boolean updated, boolean succeeded) { + this.updated = updated; + this.succeeded = succeeded; + } + + public boolean isUpdated() { + return updated; + } + + public boolean succeeded() { + return succeeded; + } +} diff --git a/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java b/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java index 9465292a200d27..368941b317102a 100644 --- a/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java +++ b/devtools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java @@ -6,6 +6,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -18,9 +19,10 @@ import io.quarkus.maven.utilities.MojoUtils; public class AddExtensions { - private static String OK = "\u2705"; - private static String NOK = "\u274c"; - private static String NOOP = "\uD83D\uDC4D"; + private static final String OK = "\u2705"; + private static final String NOK = "\u274c"; + private static final String NOOP = "\uD83D\uDC4D"; + private Model model; private String pom; private ProjectWriter writer; @@ -31,57 +33,96 @@ public AddExtensions(final ProjectWriter writer, final String pom) throws IOExce this.pom = pom; } - public boolean addExtensions(final Set extensions) throws IOException { + /** + * Selection algorithm. + * + * @param query the query + * @param extensions the extension list + * @return the list of matching candidates and whether or not a match has been found. + */ + static SelectionResult select(String query, List extensions) { + String q = query.trim().toLowerCase(); + + // Try exact matches + Set matchesNameOrArtifactId = extensions.stream().filter(extension -> extension.getName().equalsIgnoreCase(q) + || matchesArtifactId(extension.getArtifactId(), q)).collect(Collectors.toSet()); + + if (matchesNameOrArtifactId.size() == 1) { + return new SelectionResult(matchesNameOrArtifactId, true); + } + + // Try short names + Set matchesShortName = extensions.stream().filter(extension -> matchesShortName(extension, q)) + .collect(Collectors.toSet()); + + if (matchesShortName.size() == 1) { + return new SelectionResult(matchesShortName, true); + } + + // find by labels + List matchesLabels = extensions.stream() + .filter(extension -> extension.labels().contains(q)).collect(Collectors.toList()); + + Set candidates = new LinkedHashSet<>(); + candidates.addAll(matchesNameOrArtifactId); + candidates.addAll(matchesShortName); + candidates.addAll(matchesLabels); + return new SelectionResult(candidates, false); + } + + private static boolean matchesShortName(Extension extension, String q) { + return q.equalsIgnoreCase(extension.getShortName()); + } + + private static boolean matchesArtifactId(String artifactId, String q) { + return (artifactId.equalsIgnoreCase(q) || + artifactId.equalsIgnoreCase("quarkus-" + q) || + artifactId.equalsIgnoreCase("quarkus-smallrye-" + q)); + } + + public AddExtensionResult addExtensions(final Set extensions) throws IOException { if (extensions == null || extensions.isEmpty()) { - return false; + return new AddExtensionResult(false, true); } boolean updated = false; + boolean success = true; List dependenciesFromBom = getDependenciesFromBom(); - for (String dependency : extensions) { - List matches = MojoUtils.loadExtensions().stream() - .filter(d -> { - boolean hasTag = d.labels().contains(dependency.trim().toLowerCase()); - boolean machName = d.getName() - .toLowerCase() - .contains(dependency.trim().toLowerCase()); - boolean matchArtifactId = d.getArtifactId() - .toLowerCase() - .contains(dependency.trim().toLowerCase()); - return hasTag || machName || matchArtifactId; - }) - .collect(Collectors.toList()); - - if (matches.size() > 1) { + for (String query : extensions) { + List registry = MojoUtils.loadExtensions(); + + SelectionResult result = select(query, registry); + + if (!result.matches()) { StringBuilder sb = new StringBuilder(); - sb.append(NOK) - .append(" Multiple extensions matching '" + dependency + "'"); - - matches.stream() - .forEach(extension -> sb.append(System.lineSeparator()).append(" * ") - .append(extension.managementKey())); - sb.append(System.lineSeparator()).append(" Be more specific e.g using the exact name or the full gav."); - System.out.println(sb); - } else if (matches.size() == 1) { - final Extension extension = matches.get(0); - - if (!MojoUtils.hasDependency(model, extension.getGroupId(), extension.getArtifactId())) { - System.out.println(OK + " Adding extension " + extension.managementKey()); - model.addDependency(extension - .toDependency(containsBOM(model) && - isDefinedInBom(dependenciesFromBom, extension))); - updated = true; + // We have 3 cases, we can still have a single candidate, but the match is on label + // or we have several candidates, or none + Set candidates = result.getExtensions(); + if (candidates.isEmpty() && query.contains(":")) { + updated = addExtensionAsGAV(query) || updated; + } else if (candidates.isEmpty()) { + // No matches at all. + print(NOK + " Cannot find a dependency matching '" + query + "', maybe a typo?"); + success = false; + } else if (candidates.size() == 1) { + sb.append(NOK).append(" One extension matching '").append(query).append("'"); + sb.append(System.lineSeparator()).append(" * ").append(candidates.iterator().next().managementKey()); + sb.append(System.lineSeparator()).append(" Use the exact name or the full GAV to add the extension"); + print(sb.toString()); + success = false; } else { - System.out.println(NOOP + " Skipping extension " + extension.managementKey() + ": already present"); + sb.append(NOK).append(" Multiple extensions matching '").append(query).append("'"); + result.getExtensions() + .forEach(extension -> sb.append(System.lineSeparator()).append(" * ") + .append(extension.managementKey())); + sb.append(System.lineSeparator()).append(" Be more specific e.g using the exact name or the full GAV."); + print(sb.toString()); + success = false; } - } else if (dependency.contains(":")) { - Dependency parsed = MojoUtils.parse(dependency); - System.out.println(OK + " Adding dependency " + parsed.getManagementKey()); - model.addDependency(parsed); - updated = true; - } else { - System.out.println(NOK + " Cannot find a dependency matching '" + dependency + "', maybe a typo?"); + } else { // Matches. + final Extension extension = result.getMatch(); + updated = addDependency(dependenciesFromBom, extension) || updated; } } @@ -91,7 +132,32 @@ public boolean addExtensions(final Set extensions) throws IOException { writer.write(pom, pomOutputStream.toString("UTF-8")); } - return updated; + return new AddExtensionResult(updated, success); + } + + private boolean addDependency(List dependenciesFromBom, Extension extension) { + if (!MojoUtils.hasDependency(model, extension.getGroupId(), extension.getArtifactId())) { + print(OK + " Adding extension " + extension.managementKey()); + model.addDependency(extension + .toDependency(containsBOM(model) && + isDefinedInBom(dependenciesFromBom, extension))); + return true; + } else { + // Don't set success to false as it's should be idempotent. + print(NOOP + " Skipping extension " + extension.managementKey() + ": already present"); + return false; + } + } + + private boolean addExtensionAsGAV(String query) { + Dependency parsed = MojoUtils.parse(query.trim().toLowerCase()); + print(OK + " Adding dependency " + parsed.getManagementKey()); + model.addDependency(parsed); + return true; + } + + private void print(String message) { + System.out.println(message); } private List getDependenciesFromBom() { @@ -100,7 +166,7 @@ private List getDependenciesFromBom() { .getDependencyManagement() .getDependencies(); } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); + throw new IllegalStateException("Unable to read the BOM file: " + e.getMessage(), e); } } diff --git a/devtools/common/src/main/java/io/quarkus/cli/commands/SelectionResult.java b/devtools/common/src/main/java/io/quarkus/cli/commands/SelectionResult.java new file mode 100644 index 00000000000000..f46e5740684b4b --- /dev/null +++ b/devtools/common/src/main/java/io/quarkus/cli/commands/SelectionResult.java @@ -0,0 +1,34 @@ +package io.quarkus.cli.commands; + +import java.util.Set; + +import io.quarkus.dependencies.Extension; + +public class SelectionResult { + + private final Set extensions; + private final boolean matches; + + public SelectionResult(Set extensions, boolean matches) { + this.extensions = extensions; + this.matches = matches; + } + + public Set getExtensions() { + return extensions; + } + + public boolean matches() { + return matches; + } + + public Extension getMatch() { + if (matches) { + if (extensions.isEmpty() || extensions.size() > 1) { + throw new IllegalStateException("Invalid selection result"); + } + return extensions.iterator().next(); + } + return null; + } +} diff --git a/devtools/common/src/test/java/io/quarkus/cli/commands/AddExtensionsTest.java b/devtools/common/src/test/java/io/quarkus/cli/commands/AddExtensionsTest.java index decc0eda1af119..aa20d9013ae825 100644 --- a/devtools/common/src/test/java/io/quarkus/cli/commands/AddExtensionsTest.java +++ b/devtools/common/src/test/java/io/quarkus/cli/commands/AddExtensionsTest.java @@ -4,20 +4,20 @@ import java.io.File; import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; +import java.util.*; import org.apache.maven.model.Model; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.dependencies.Extension; import io.quarkus.maven.utilities.MojoUtils; -public class AddExtensionsTest { +class AddExtensionsTest { @Test - public void addExtension() throws IOException { + void addSomeValidExtensions() throws IOException { final File pom = new File("target/extensions-test", "pom.xml"); CreateProjectTest.delete(pom.getParentFile()); @@ -29,17 +29,236 @@ public void addExtension() throws IOException { File pomFile = new File(pom.getAbsolutePath()); new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) - .addExtensions(new HashSet<>(asList("jdbc-postgre", "agroal", "quarkus-arc", " hibernate-validator"))); + .addExtensions(new HashSet<>(asList("jdbc-postgre", "agroal", "quarkus-arc", " hibernate-validator", + "commons-io:commons-io:2.6"))); Model model = MojoUtils.readPom(pom); hasDependency(model, "quarkus-agroal"); hasDependency(model, "quarkus-arc"); hasDependency(model, "quarkus-hibernate-validator"); - hasDependency(model, "quarkus-jdbc-postgresql"); + hasDependency(model, "commons-io", "commons-io", "2.6"); + doesNotHaveDependency(model, "quarkus-jdbc-postgresql"); + } + + @Test + void addMissingExtension() throws IOException { + final File pom = new File("target/extensions-test", "pom.xml"); + + CreateProjectTest.delete(pom.getParentFile()); + new CreateProject(new FileProjectWriter(pom.getParentFile())) + .groupId("org.acme") + .artifactId("add-extension-test") + .version("0.0.1-SNAPSHOT") + .doCreateProject(new HashMap<>()); + + File pomFile = new File(pom.getAbsolutePath()); + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + .addExtensions(new HashSet<>(asList("missing"))); + + Model model = MojoUtils.readPom(pom); + doesNotHaveDependency(model, "quarkus-missing"); + Assertions.assertFalse(result.succeeded()); + Assertions.assertFalse(result.isUpdated()); + } + + @Test + void addExtensionTwiceInOneBatch() throws IOException { + final File pom = new File("target/extensions-test", "pom.xml"); + + CreateProjectTest.delete(pom.getParentFile()); + new CreateProject(new FileProjectWriter(pom.getParentFile())) + .groupId("org.acme") + .artifactId("add-extension-test") + .version("0.0.1-SNAPSHOT") + .doCreateProject(new HashMap<>()); + + File pomFile = new File(pom.getAbsolutePath()); + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + .addExtensions(new HashSet<>(asList("agroal", "agroal"))); + + Model model = MojoUtils.readPom(pom); + hasDependency(model, "quarkus-agroal"); + Assertions.assertEquals(1, + model.getDependencies().stream().filter(d -> d.getArtifactId().equals("quarkus-agroal")).count()); + Assertions.assertTrue(result.isUpdated()); + Assertions.assertTrue(result.succeeded()); } @Test - public void addDuplicatedExtension() throws IOException { + void addExtensionTwiceInTwoBatches() throws IOException { + final File pom = new File("target/extensions-test", "pom.xml"); + + CreateProjectTest.delete(pom.getParentFile()); + new CreateProject(new FileProjectWriter(pom.getParentFile())) + .groupId("org.acme") + .artifactId("add-extension-test") + .version("0.0.1-SNAPSHOT") + .doCreateProject(new HashMap<>()); + + File pomFile = new File(pom.getAbsolutePath()); + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + .addExtensions(new HashSet<>(Collections.singletonList("agroal"))); + + Model model = MojoUtils.readPom(pom); + hasDependency(model, "quarkus-agroal"); + Assertions.assertEquals(1, + model.getDependencies().stream().filter(d -> d.getArtifactId().equals("quarkus-agroal")).count()); + Assertions.assertTrue(result.isUpdated()); + Assertions.assertTrue(result.succeeded()); + + AddExtensionResult result2 = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + .addExtensions(new HashSet<>(Collections.singletonList("agroal"))); + model = MojoUtils.readPom(pom); + hasDependency(model, "quarkus-agroal"); + Assertions.assertEquals(1, + model.getDependencies().stream().filter(d -> d.getArtifactId().equals("quarkus-agroal")).count()); + Assertions.assertFalse(result2.isUpdated()); + Assertions.assertTrue(result2.succeeded()); + } + + @Test + void addExistingAndMissingExtensions() throws IOException { + final File pom = new File("target/extensions-test", "pom.xml"); + + CreateProjectTest.delete(pom.getParentFile()); + new CreateProject(new FileProjectWriter(pom.getParentFile())) + .groupId("org.acme") + .artifactId("add-extension-test") + .version("0.0.1-SNAPSHOT") + .doCreateProject(new HashMap<>()); + + File pomFile = new File(pom.getAbsolutePath()); + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + .addExtensions(new HashSet<>(asList("missing", "agroal"))); + + Model model = MojoUtils.readPom(pom); + doesNotHaveDependency(model, "quarkus-missing"); + hasDependency(model, "quarkus-agroal"); + Assertions.assertFalse(result.succeeded()); + Assertions.assertTrue(result.isUpdated()); + } + + @Test + void testMultiMatchByLabels() { + Extension e1 = new Extension("org.acme", "e1", "1.0") + .setName("some complex seo unaware name") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "e2", "1.0") + .setName("some foo bar") + .setLabels(new String[] { "foo", "bar", "baz" }); + Extension e3 = new Extension("org.acme", "e3", "1.0") + .setName("unrelated") + .setLabels(new String[] { "bar" }); + + List extensions = asList(e1, e2, e3); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertFalse(matches.matches()); + Assertions.assertEquals(2, matches.getExtensions().size()); + } + + @Test + void testThatSingleLabelMatchIsNotAMatch() { + Extension e1 = new Extension("org.acme", "e1", "1.0") + .setName("e1") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "e2", "1.0") + .setName("e2") + .setLabels(new String[] { "bar", "baz" }); + + List extensions = asList(e1, e2); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertFalse(matches.matches()); + Assertions.assertEquals(1, matches.getExtensions().size()); + } + + @Test + void testMultiMatchByArtifactIdsAndNames() { + Extension e1 = new Extension("org.acme", "e1", "1.0") + .setName("foo") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "quarkus-foo", "1.0") + .setName("some foo bar") + .setLabels(new String[] { "foo", "bar", "baz" }); + Extension e3 = new Extension("org.acme", "e3", "1.0") + .setName("unrelated") + .setLabels(new String[] { "foo" }); + + List extensions = asList(e1, e2, e3); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertFalse(matches.matches()); + Assertions.assertEquals(3, matches.getExtensions().size()); + + } + + @Test + void testShortNameSelection() { + Extension e1 = new Extension("org.acme", "some-complex-seo-unaware-artifactid", "1.0") + .setName("some complex seo unaware name") + .setShortName("foo") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "some-foo-bar", "1.0") + .setName("some foo bar") + .setLabels(new String[] { "foo", "bar", "baz" }); + Extension e3 = new Extension("org.acme", "unrelated", "1.0") + .setName("unrelated") + .setLabels(new String[] { "foo" }); + + List extensions = asList(e1, e2, e3); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertTrue(matches.matches()); + Assertions.assertEquals(1, matches.getExtensions().size()); + Assertions.assertNotNull(matches.getMatch()); + Assertions.assertTrue(matches.getMatch().getArtifactId().equalsIgnoreCase("some-complex-seo-unaware-artifactid")); + } + + @Test + void testArtifactIdSelectionWithQuarkusPrefix() { + Extension e1 = new Extension("org.acme", "quarkus-foo", "1.0") + .setName("some complex seo unaware name") + .setShortName("foo") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "quarkus-foo-bar", "1.0") + .setName("some foo bar") + .setLabels(new String[] { "foo", "bar", "baz" }); + Extension e3 = new Extension("org.acme", "quarkus-unrelated", "1.0") + .setName("unrelated") + .setLabels(new String[] { "foo" }); + + List extensions = asList(e1, e2, e3); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertEquals(1, matches.getExtensions().size()); + Assertions.assertNotNull(matches.getMatch()); + Assertions.assertTrue(matches.getMatch().getArtifactId().equalsIgnoreCase("quarkus-foo")); + } + + @Test + void testArtifactIdSelectionWithQuarkusSmallRyePrefix() { + Extension e1 = new Extension("org.acme", "quarkus-smallrye-foo", "1.0") + .setName("some complex seo unaware name") + .setShortName("foo") + .setLabels(new String[] { "foo", "bar" }); + Extension e2 = new Extension("org.acme", "quarkus-foo-bar", "1.0") + .setName("some foo bar") + .setLabels(new String[] { "foo", "bar", "baz" }); + Extension e3 = new Extension("org.acme", "quarkus-unrelated", "1.0") + .setName("unrelated") + .setLabels(new String[] { "foo" }); + + List extensions = asList(e1, e2, e3); + Collections.shuffle(extensions); + SelectionResult matches = AddExtensions.select("foo", extensions); + Assertions.assertEquals(1, matches.getExtensions().size()); + Assertions.assertNotNull(matches.getMatch()); + Assertions.assertTrue(matches.getMatch().getArtifactId().equalsIgnoreCase("quarkus-smallrye-foo")); + } + + @Test + void addDuplicatedExtension() throws IOException { final File pom = new File("target/extensions-test", "pom.xml"); CreateProjectTest.delete(pom.getParentFile()); @@ -66,6 +285,14 @@ private void hasDependency(final Model model, final String artifactId) { d.getArtifactId().equals(artifactId))); } + private void hasDependency(final Model model, String groupId, String artifactId, String version) { + Assertions.assertTrue(model.getDependencies() + .stream() + .anyMatch(d -> d.getGroupId().equals(groupId) && + d.getArtifactId().equals(artifactId) && + d.getVersion().equals(version))); + } + private void doesNotHaveDependency(final Model model, final String artifactId) { Assertions.assertFalse(model.getDependencies() .stream() diff --git a/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java index d4c2f6eb8a3e7b..6b5c70cd4a785f 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java @@ -15,6 +15,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import io.quarkus.cli.commands.AddExtensionResult; import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.writer.FileProjectWriter; @@ -64,8 +65,11 @@ public void execute() throws MojoExecutionException { try { Model model = project.getOriginalModel().clone(); File pomFile = new File(model.getPomFile().getAbsolutePath()); - new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) .addExtensions(ext.stream().map(String::trim).collect(Collectors.toSet())); + if (!result.succeeded()) { + throw new MojoExecutionException("Unable to add extensions"); + } } catch (IOException e) { throw new MojoExecutionException("Unable to update the pom.xml file", e); } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java index 1ccdbd9ab2b282..0d718898de1565 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java @@ -52,6 +52,7 @@ import org.apache.maven.project.ProjectBuilder; import org.fusesource.jansi.Ansi; +import io.quarkus.cli.commands.AddExtensionResult; import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.CreateProject; import io.quarkus.cli.commands.writer.FileProjectWriter; @@ -160,8 +161,11 @@ public void execute() throws MojoExecutionException { File createdPomFile = new File(projectRoot, "pom.xml"); if (success) { File pomFile = new File(createdPomFile.getAbsolutePath()); - new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) + AddExtensionResult result = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), pomFile.getName()) .addExtensions(extensions); + if (!result.succeeded()) { + success = false; + } } createMavenWrapper(createdPomFile);