Search in sources :

Example 1 with QuarkusCommandOutcome

use of io.quarkus.devtools.commands.data.QuarkusCommandOutcome in project quarkus by quarkusio.

the class RemoveExtensionsCommandHandler method execute.

@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
    final Set<String> extensionsQuery = invocation.getValue(RemoveExtensions.EXTENSIONS, Collections.emptySet());
    if (extensionsQuery.isEmpty()) {
        return QuarkusCommandOutcome.success().setValue(RemoveExtensions.OUTCOME_UPDATED, false);
    }
    final List<ArtifactCoords> extensionsToRemove = computeCoordsFromQuery(invocation, extensionsQuery);
    if (extensionsToRemove == null) {
        return new QuarkusCommandOutcome(false).setValue(RemoveExtensions.OUTCOME_UPDATED, false);
    }
    final ExtensionManager extensionManager = invocation.getValue(EXTENSION_MANAGER, invocation.getQuarkusProject().getExtensionManager());
    try {
        final Set<ArtifactKey> keys = extensionsToRemove.stream().map(ArtifactCoords::getKey).collect(Collectors.toSet());
        final UninstallResult result = extensionManager.uninstall(keys);
        result.getUninstalled().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + " has been uninstalled"));
        return new QuarkusCommandOutcome(true).setValue(RemoveExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
    } catch (IOException e) {
        throw new QuarkusCommandException("Failed to remove extensions", e);
    }
}
Also used : ArtifactCoords(io.quarkus.maven.ArtifactCoords) UninstallResult(io.quarkus.devtools.project.extensions.ExtensionManager.UninstallResult) ArtifactKey(io.quarkus.maven.ArtifactKey) ExtensionManager(io.quarkus.devtools.project.extensions.ExtensionManager) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) IOException(java.io.IOException) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 2 with QuarkusCommandOutcome

use of io.quarkus.devtools.commands.data.QuarkusCommandOutcome in project quarkus by quarkusio.

the class AddExtensionsCommandHandler method execute.

@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
    final Set<String> extensionsQuery = invocation.getValue(AddExtensions.EXTENSIONS, Collections.emptySet());
    if (extensionsQuery.isEmpty()) {
        return QuarkusCommandOutcome.success().setValue(AddExtensions.OUTCOME_UPDATED, false);
    }
    final ExtensionManager extensionManager = invocation.getValue(EXTENSION_MANAGER, invocation.getQuarkusProject().getExtensionManager());
    try {
        ExtensionInstallPlan extensionInstallPlan = planInstallation(invocation, extensionsQuery);
        if (extensionInstallPlan.isInstallable()) {
            final InstallResult result = extensionManager.install(extensionInstallPlan);
            result.getInstalledPlatforms().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Platform " + a.getGroupId() + ":" + a.getArtifactId() + " has been installed"));
            result.getInstalledManagedExtensions().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + " has been installed"));
            result.getInstalledIndependentExtensions().forEach(a -> invocation.log().info(MessageIcons.OK_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + ":" + a.getVersion() + " has been installed"));
            result.getAlreadyInstalled().forEach(a -> invocation.log().info(MessageIcons.NOOP_ICON + " Extension " + a.getGroupId() + ":" + a.getArtifactId() + " was already installed"));
            return new QuarkusCommandOutcome(true).setValue(AddExtensions.OUTCOME_UPDATED, result.isSourceUpdated());
        } else if (!extensionInstallPlan.getUnmatchedKeywords().isEmpty()) {
            invocation.log().info(ERROR_ICON + " Nothing installed because keyword(s) '" + String.join("', '", extensionInstallPlan.getUnmatchedKeywords()) + "' were not matched in the catalog.");
        } else {
            invocation.log().info(NOK_ICON + " The provided keyword(s) did not match any extension from the catalog.");
        }
    } catch (MultipleExtensionsFoundException m) {
        StringBuilder sb = new StringBuilder();
        sb.append(ERROR_ICON + " Multiple extensions matching '").append(m.getKeyword()).append("'");
        m.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.");
        invocation.log().info(sb.toString());
    } catch (IOException e) {
        throw new QuarkusCommandException("Failed to add extensions", e);
    }
    return new QuarkusCommandOutcome(false).setValue(AddExtensions.OUTCOME_UPDATED, false);
}
Also used : Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ArtifactKey(io.quarkus.maven.ArtifactKey) QuarkusCommandInvocation(io.quarkus.devtools.commands.data.QuarkusCommandInvocation) ERROR_ICON(io.quarkus.devtools.messagewriter.MessageIcons.ERROR_ICON) ArtifactCoords(io.quarkus.maven.ArtifactCoords) ExtensionOrigin(io.quarkus.registry.catalog.ExtensionOrigin) List(java.util.List) NOK_ICON(io.quarkus.devtools.messagewriter.MessageIcons.NOK_ICON) ExtensionInstallPlan(io.quarkus.devtools.project.extensions.ExtensionInstallPlan) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) MessageIcons(io.quarkus.devtools.messagewriter.MessageIcons) InstallResult(io.quarkus.devtools.project.extensions.ExtensionManager.InstallResult) ExtensionPredicate(io.quarkus.platform.catalog.predicate.ExtensionPredicate) EXTENSION_MANAGER(io.quarkus.devtools.commands.AddExtensions.EXTENSION_MANAGER) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) Extension(io.quarkus.registry.catalog.Extension) Collections(java.util.Collections) AddExtensions(io.quarkus.devtools.commands.AddExtensions) ExtensionManager(io.quarkus.devtools.project.extensions.ExtensionManager) ExtensionCatalog(io.quarkus.registry.catalog.ExtensionCatalog) ExtensionInstallPlan(io.quarkus.devtools.project.extensions.ExtensionInstallPlan) ExtensionManager(io.quarkus.devtools.project.extensions.ExtensionManager) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) IOException(java.io.IOException) InstallResult(io.quarkus.devtools.project.extensions.ExtensionManager.InstallResult) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException)

Example 3 with QuarkusCommandOutcome

use of io.quarkus.devtools.commands.data.QuarkusCommandOutcome in project quarkus by quarkusio.

the class QuarkusProjectCompressTest method createProject.

private Path createProject(Path testDir) throws QuarkusCommandException, IOException {
    final Path projectPath = testDir.resolve("project");
    final QuarkusProject project = QuarkusProjectHelper.getProject(projectPath, BuildTool.MAVEN);
    final QuarkusCommandOutcome result = new CreateProject(project).groupId("org.acme").artifactId("basic-rest").version("1.0.0-SNAPSHOT").execute();
    // Create a fake wrapper
    Files.write(projectPath.resolve("mvnw"), "testmvnw".getBytes());
    projectPath.resolve("mvnw").toFile().setExecutable(true);
    Files.write(projectPath.resolve("mvnw.bat"), "testmvnw".getBytes());
    projectPath.resolve("mvnw.bat").toFile().setExecutable(true);
    assertTrue(result.isSuccess());
    return projectPath;
}
Also used : Path(java.nio.file.Path) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) QuarkusProject(io.quarkus.devtools.project.QuarkusProject) CreateProject(io.quarkus.devtools.commands.CreateProject)

Example 4 with QuarkusCommandOutcome

use of io.quarkus.devtools.commands.data.QuarkusCommandOutcome in project quarkus by quarkusio.

the class CreateProjectTest method assertCreateProject.

private void assertCreateProject(CreateProject createProject) throws QuarkusCommandException {
    final QuarkusCommandOutcome result = createProject.quarkusPluginVersion("2.3.5").execute();
    assertTrue(result.isSuccess());
}
Also used : QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome)

Example 5 with QuarkusCommandOutcome

use of io.quarkus.devtools.commands.data.QuarkusCommandOutcome in project quarkus by quarkusio.

the class CreateProjectTest method createMultipleTimes.

@Test
@Timeout(3)
@DisplayName("Should create correctly multiple times in parallel with multiple threads")
void createMultipleTimes() throws InterruptedException {
    final ExecutorService executorService = Executors.newFixedThreadPool(4);
    final CountDownLatch latch = new CountDownLatch(15);
    List<Callable<Void>> collect = IntStream.range(0, 15).boxed().map(i -> (Callable<Void>) () -> {
        File tempDir = Files.createTempDirectory("test").toFile();
        FileProjectWriter write = new FileProjectWriter(tempDir);
        final QuarkusProject project = QuarkusProjectHelper.getProject(tempDir.toPath(), BuildTool.MAVEN);
        final QuarkusCommandOutcome result = new CreateProject(project).groupId("org.acme").artifactId("acme").version("1.0.0-SNAPSHOT").className("org.acme.MyResource").execute();
        assertTrue(result.isSuccess());
        latch.countDown();
        write.close();
        tempDir.delete();
        return null;
    }).collect(Collectors.toList());
    executorService.invokeAll(collect);
    latch.await();
}
Also used : PROP_COMPILER_PLUGIN_VERSION(io.quarkus.platform.tools.ToolsConstants.PROP_COMPILER_PLUGIN_VERSION) IntStream(java.util.stream.IntStream) MojoUtils(io.quarkus.maven.utilities.MojoUtils) Arrays(java.util.Arrays) BuildTool(io.quarkus.devtools.project.BuildTool) SnapshotTesting(io.quarkus.devtools.testing.SnapshotTesting) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) QuarkusProject(io.quarkus.devtools.project.QuarkusProject) QuarkusProjectHelper(io.quarkus.devtools.project.QuarkusProjectHelper) Callable(java.util.concurrent.Callable) HashSet(java.util.HashSet) SnapshotTesting.checkMatches(io.quarkus.devtools.testing.SnapshotTesting.checkMatches) PROP_SUREFIRE_PLUGIN_VERSION(io.quarkus.platform.tools.ToolsConstants.PROP_SUREFIRE_PLUGIN_VERSION) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) FileProjectWriter(io.quarkus.devtools.project.codegen.writer.FileProjectWriter) PlatformAwareTestBase(io.quarkus.devtools.testing.PlatformAwareTestBase) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) Properties(java.util.Properties) Files(java.nio.file.Files) SnapshotTesting.checkContains(io.quarkus.devtools.testing.SnapshotTesting.checkContains) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Executors(java.util.concurrent.Executors) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) QuarkusCommandException(io.quarkus.devtools.commands.data.QuarkusCommandException) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) Model(org.apache.maven.model.Model) ExecutorService(java.util.concurrent.ExecutorService) QuarkusCommandOutcome(io.quarkus.devtools.commands.data.QuarkusCommandOutcome) QuarkusProject(io.quarkus.devtools.project.QuarkusProject) CountDownLatch(java.util.concurrent.CountDownLatch) FileProjectWriter(io.quarkus.devtools.project.codegen.writer.FileProjectWriter) File(java.io.File) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

QuarkusCommandOutcome (io.quarkus.devtools.commands.data.QuarkusCommandOutcome)27 Test (org.junit.jupiter.api.Test)10 QuarkusCommandException (io.quarkus.devtools.commands.data.QuarkusCommandException)8 QuarkusProject (io.quarkus.devtools.project.QuarkusProject)8 QuarkusCommandInvocation (io.quarkus.devtools.commands.data.QuarkusCommandInvocation)7 ArtifactCoords (io.quarkus.maven.ArtifactCoords)6 IOException (java.io.IOException)6 ExtensionCatalog (io.quarkus.registry.catalog.ExtensionCatalog)5 List (java.util.List)5 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 AddExtensions (io.quarkus.devtools.commands.AddExtensions)3 InfoCommandHandler (io.quarkus.devtools.commands.handlers.InfoCommandHandler)3 MessageIcons (io.quarkus.devtools.messagewriter.MessageIcons)3 Extension (io.quarkus.registry.catalog.Extension)3 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 LegacySupport (io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartData.LegacySupport)2 CreateProject (io.quarkus.devtools.commands.CreateProject)2