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);
}
}
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);
}
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;
}
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());
}
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();
}
Aggregations