From 555c7c79f82a01a2318e424650c7cde06d28b236 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Wed, 27 May 2020 13:19:05 +0200 Subject: [PATCH 1/5] Introduce QuarkusProject in codegen to reduce ProjectWriter and BuildTool coupling This is part of #8178 This is a good one :-), things starts to get nicer and cleaner (but not quite there yet ^^).. --- .../cli/commands/AddExtensionCommand.java | 30 +++-- .../cli/commands/CreateProjectCommand.java | 5 +- .../cli/commands/ListExtensionsCommand.java | 31 ++--- .../cli/commands/RemoveExtensionCommand.java | 31 +++-- .../gradle/QuarkusPluginFunctionalTest.java | 17 +-- .../gradle/tasks/QuarkusAddExtension.java | 2 +- .../gradle/tasks/QuarkusListExtensions.java | 17 ++- .../gradle/tasks/QuarkusPlatformTask.java | 11 +- .../gradle/tasks/QuarkusRemoveExtension.java | 2 +- .../io/quarkus/maven/AddExtensionMojo.java | 17 +-- .../io/quarkus/maven/BuildFileMojoBase.java | 15 +-- .../io/quarkus/maven/CreateProjectMojo.java | 26 ++--- .../io/quarkus/maven/ListExtensionsMojo.java | 9 +- .../io/quarkus/maven/RemoveExtensionMojo.java | 18 +-- .../quarkus/cli/commands/AddExtensions.java | 23 +--- .../quarkus/cli/commands/CreateProject.java | 38 ++---- .../commands/CreateProjectCommandHandler.java | 7 +- .../quarkus/cli/commands/ListExtensions.java | 9 +- .../ListExtensionsCommandHandler.java | 11 +- .../commands/QuarkusCommandInvocation.java | 48 +++----- .../cli/commands/RemoveExtensions.java | 20 +--- .../quarkus/cli/commands/file/BuildFile.java | 2 +- .../cli/commands/file/GradleBuildFile.java | 2 +- .../cli/commands/file/MavenBuildFile.java | 4 +- .../commands/project}/BuildTool.java | 5 +- .../cli/commands/project/QuarkusProject.java | 60 ++++++++++ .../cli/commands/writer/ZipProjectWriter.java | 85 -------------- .../rest/BasicRestProjectGenerator.java | 3 +- .../cli/commands/AddGradleExtensionsTest.java | 16 +-- .../cli/commands/AddMavenExtensionsTest.java | 12 +- .../cli/commands/CreateProjectTest.java | 110 +++++++++--------- .../cli/commands/ListExtensionsTest.java | 54 ++++----- .../commands/RemoveGradleExtensionsTest.java | 18 +-- .../commands/RemoveMavenExtensionsTest.java | 17 ++- .../rest/BasicRestProjectGeneratorTest.java | 26 +++-- 35 files changed, 334 insertions(+), 467 deletions(-) rename independent-projects/tools/common/src/main/java/io/quarkus/{generators => cli/commands/project}/BuildTool.java (95%) create mode 100644 independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java delete mode 100644 independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ZipProjectWriter.java 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 6bb59cf7253d8..d221c3d369481 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 @@ -1,6 +1,7 @@ package io.quarkus.cli.commands; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -13,7 +14,7 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.dependencies.Extension; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; @@ -30,8 +31,8 @@ public class AddExtensionCommand implements Command { @Option(shortName = 'e', required = true, description = "Name of the extension that will be added to the project") private String extension; - @Argument(required = true, description = "Path to the project pom the extension will be added") - private Resource pom; + @Argument(description = "path to the project", required = true) + private Resource path; @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { @@ -45,20 +46,17 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command commandInvocation.println("Can not find any extension named: " + extension); return CommandResult.SUCCESS; } - if (pom.isLeaf()) { - try { - final File pomFile = new File(pom.getAbsolutePath()); - AddExtensions project = new AddExtensions(new FileProjectWriter(pomFile.getParentFile()), platformDescr) - .extensions(Collections.singleton(extension)); - QuarkusCommandOutcome result = project.execute(); - if (!result.isSuccess()) { - throw new CommandException("Unable to add an extension matching " + extension); - } - } catch (Exception e) { - throw new CommandException("Unable to add an extension matching " + extension, e); + try { + final Path projectPath = Paths.get(path.getAbsolutePath()); + AddExtensions project = new AddExtensions(QuarkusProject.resolveExistingProject(projectPath, + platformDescr)).extensions(Collections.singleton(extension)); + QuarkusCommandOutcome result = project.execute(); + if (!result.isSuccess()) { + throw new CommandException("Unable to add an extension matching " + extension); } + } catch (Exception e) { + throw new CommandException("Unable to add an extension matching " + extension, e); } - } return CommandResult.SUCCESS; diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/CreateProjectCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/CreateProjectCommand.java index 265cfba9e8670..68596a7b528cf 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/CreateProjectCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/CreateProjectCommand.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import java.io.File; import java.io.IOException; +import java.nio.file.Paths; import java.util.HashMap; import org.aesh.command.Command; @@ -11,7 +11,6 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.writer.FileProjectWriter; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; /** @@ -43,7 +42,7 @@ public CommandResult execute(CommandInvocation commandInvocation) { if (path != null) { try { - boolean status = new CreateProject(new FileProjectWriter(new File(path.getAbsolutePath())), + boolean status = new CreateProject(Paths.get(path.getAbsolutePath()), QuarkusPlatformConfig.getGlobalDefault().getPlatformDescriptor()) .groupId(groupid) .artifactId(artifactid) diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java index 7f8163d1b8a43..09e83b87d7e12 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java @@ -1,21 +1,17 @@ package io.quarkus.cli.commands; -import java.io.File; -import java.io.IOException; +import java.nio.file.Paths; import org.aesh.command.Command; import org.aesh.command.CommandDefinition; import org.aesh.command.CommandException; import org.aesh.command.CommandResult; import org.aesh.command.invocation.CommandInvocation; +import org.aesh.command.option.Argument; import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.file.MavenBuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; /** @@ -36,7 +32,7 @@ public class ListExtensionsCommand implements Command { @Option(shortName = 's', hasValue = true, description = "Search filter on extension list. The format is based on Java Pattern.") private String searchPattern; - @Option(shortName = 'p', description = "path to the project") + @Argument(description = "path to the project", required = true) private Resource path; public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { @@ -44,21 +40,10 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command commandInvocation.println(commandInvocation.getHelpInfo("quarkus list-extensions")); } else { try { - BuildFile buildFile = null; - ProjectWriter writer = null; - if (path != null) { - File projectDirectory = new File(path.getAbsolutePath()); - writer = new FileProjectWriter(projectDirectory); - if (new File(projectDirectory, "build.gradle").exists() - || new File(projectDirectory, "build.gradle.kts").exists()) { - buildFile = new GradleBuildFile(writer); - } else { - buildFile = new MavenBuildFile(writer); - } - } - new ListExtensions(writer, buildFile, QuarkusPlatformConfig.getGlobalDefault().getPlatformDescriptor()) - .all(all).format(format).search(searchPattern); - } catch (IOException e) { + new ListExtensions(QuarkusProject.resolveExistingProject(Paths.get(path.getAbsolutePath()), + QuarkusPlatformConfig.getGlobalDefault().getPlatformDescriptor())) + .all(all).format(format).search(searchPattern); + } catch (Exception e) { throw new CommandException("Unable to list extensions", e); } } diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java index 5427387a67544..d617a2063c190 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java @@ -1,6 +1,7 @@ package io.quarkus.cli.commands; -import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collections; import java.util.List; @@ -13,7 +14,7 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.dependencies.Extension; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; @@ -27,8 +28,8 @@ public class RemoveExtensionCommand implements Command { @Option(shortName = 'e', required = true, description = "Name of the extension that will be removed from the project") private String extension; - @Argument(required = true, description = "Path to the project pom the extension will be removed from") - private Resource pom; + @Argument(description = "path to the project", required = true) + private Resource path; @Override public CommandResult execute(CommandInvocation commandInvocation) throws CommandException, InterruptedException { @@ -42,21 +43,17 @@ public CommandResult execute(CommandInvocation commandInvocation) throws Command commandInvocation.println("Can not find any extension named: " + extension); return CommandResult.SUCCESS; } - if (pom.isLeaf()) { - try { - final File pomFile = new File(pom.getAbsolutePath()); - RemoveExtensions project = new RemoveExtensions(new FileProjectWriter(pomFile.getParentFile()), - platformDescr) - .extensions(Collections.singleton(extension)); - QuarkusCommandOutcome result = project.execute(); - if (!result.isSuccess()) { - throw new CommandException("Unable to remove an extension matching " + extension); - } - } catch (Exception e) { - throw new CommandException("Unable to remove an extension matching " + extension, e); + try { + final Path projectPath = Paths.get(path.getAbsolutePath()); + RemoveExtensions project = new RemoveExtensions(QuarkusProject.resolveExistingProject(projectPath, + platformDescr)).extensions(Collections.singleton(extension)); + QuarkusCommandOutcome result = project.execute(); + if (!result.isSuccess()) { + throw new CommandException("Unable to remove an extension matching " + extension); } + } catch (Exception e) { + throw new CommandException("Unable to remove an extension matching " + extension, e); } - } return CommandResult.SUCCESS; diff --git a/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java b/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java index e364d8e5e60bf..85ddb2ff5ae78 100644 --- a/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java +++ b/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java @@ -6,18 +6,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.google.common.collect.ImmutableMap; -import io.quarkus.deployment.util.FileUtil; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; -import io.quarkus.platform.tools.config.QuarkusPlatformConfig; -import io.quarkus.test.devmode.util.DevModeTestUtils; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; @@ -27,10 +19,13 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; +import com.google.common.collect.ImmutableMap; + import io.quarkus.cli.commands.CreateProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.generators.SourceType; +import io.quarkus.platform.tools.config.QuarkusPlatformConfig; +import io.quarkus.test.devmode.util.DevModeTestUtils; public class QuarkusPluginFunctionalTest extends QuarkusGradleTestBase { @@ -155,7 +150,7 @@ private BuildResult runTask(List arguments) { private void createProject(SourceType sourceType) throws IOException { Map context = new HashMap<>(); context.put("path", "/greeting"); - assertThat(new CreateProject(new FileProjectWriter(projectRoot), + assertThat(new CreateProject(projectRoot.toPath(), QuarkusPlatformConfig.getGlobalDefault().getPlatformDescriptor()) .groupId("com.acme.foo") .artifactId("foo") diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusAddExtension.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusAddExtension.java index 96a65f61d4a39..d640818576b84 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusAddExtension.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusAddExtension.java @@ -40,7 +40,7 @@ public void addExtension() { .collect(toSet()); try { - new AddExtensions(getWriter(), getGradleBuildFile(), platformDescriptor()) + new AddExtensions(getQuarkusProject()) .extensions(extensionsSet) .execute(); } catch (Exception e) { diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java index 05645ede916bf..f5f3c721be38e 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java @@ -7,6 +7,8 @@ import org.gradle.api.tasks.options.Option; import io.quarkus.cli.commands.ListExtensions; +import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.cli.commands.writer.FileProjectWriter; import io.quarkus.gradle.GradleBuildFileFromConnector; public class QuarkusListExtensions extends QuarkusPlatformTask { @@ -56,12 +58,15 @@ public QuarkusListExtensions() { @TaskAction public void listExtensions() { try { - new ListExtensions(getWriter(), new GradleBuildFileFromConnector(getWriter()), - platformDescriptor()) - .all(isAll()) - .format(getFormat()) - .search(getSearchPattern()) - .execute(); + final GradleBuildFileFromConnector buildFileFromConnector = new GradleBuildFileFromConnector( + new FileProjectWriter(getProject().getProjectDir())); + QuarkusProject quarkusProject = QuarkusProject.of(getProject().getProjectDir().toPath(), platformDescriptor(), + buildFileFromConnector); + new ListExtensions(quarkusProject) + .all(isAll()) + .format(getFormat()) + .search(getSearchPattern()) + .execute(); } catch (Exception e) { throw new GradleException("Unable to list extensions", e); } diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java index ac76d1aa9b084..5fcfdab8bdcaf 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java @@ -11,7 +11,9 @@ import org.gradle.api.tasks.Internal; import io.quarkus.cli.commands.file.GradleBuildFile; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.platform.descriptor.CombinedQuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver; @@ -65,14 +67,15 @@ protected QuarkusPlatformDescriptor platformDescriptor() { @Internal protected GradleBuildFile getGradleBuildFile() { + final ProjectWriter writer = new FileProjectWriter(getProject().getProjectDir()); return getProject().getParent() == null - ? new GradleBuildFile(getWriter()) - : new GradleBuildFile(getWriter(), + ? new GradleBuildFile(writer) + : new GradleBuildFile(writer, new FileProjectWriter(getProject().getRootProject().getProjectDir())); } @Internal - protected FileProjectWriter getWriter() { - return new FileProjectWriter(getProject().getProjectDir()); + protected QuarkusProject getQuarkusProject() { + return QuarkusProject.of(getProject().getProjectDir().toPath(), platformDescriptor(), getGradleBuildFile()); } } diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusRemoveExtension.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusRemoveExtension.java index 2c646851a4e62..482ed669a8cbc 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusRemoveExtension.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusRemoveExtension.java @@ -39,7 +39,7 @@ public void removeExtension() { .map(String::trim) .collect(toSet()); try { - new RemoveExtensions(getWriter(), getGradleBuildFile(), platformDescriptor()) + new RemoveExtensions(getQuarkusProject()) .extensions(extensionsSet) .execute(); } catch (Exception e) { 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 f0edefb59652e..d0b4ac53431bd 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java @@ -1,6 +1,5 @@ package io.quarkus.maven; -import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -13,10 +12,7 @@ import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.QuarkusCommandOutcome; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** @@ -49,15 +45,8 @@ protected void validateParameters() throws MojoExecutionException { } @Override - public void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatformDescriptor platformDescr, MessageWriter log) + public void doExecute(final QuarkusProject quarkusProject, final MessageWriter log) throws MojoExecutionException { - if (buildFile == null) { - try { - buildFile = BuildTool.MAVEN.createBuildFile(writer); - } catch (IOException e) { - throw new MojoExecutionException("Failed to initialize the project's build descriptor", e); - } - } Set ext = new HashSet<>(); if (extensions != null && !extensions.isEmpty()) { ext.addAll(extensions); @@ -68,7 +57,7 @@ public void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatform } try { - final QuarkusCommandOutcome outcome = new AddExtensions(writer, buildFile, platformDescr) + final QuarkusCommandOutcome outcome = new AddExtensions(quarkusProject) .extensions(ext.stream().map(String::trim).collect(Collectors.toSet())) .execute(); if (!outcome.isSuccess()) { diff --git a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java index 8c79d2104cb57..9eba672cfcfc7 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java @@ -20,10 +20,10 @@ import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.GradleBuildFile; import io.quarkus.cli.commands.file.MavenBuildFile; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.platform.descriptor.CombinedQuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver; @@ -72,12 +72,14 @@ public void execute() throws MojoExecutionException { final MessageWriter log = new MojoMessageWriter(getLog()); QuarkusPlatformDescriptor platformDescr = null; + BuildTool buildTool = null; BuildFile buildFile = null; try (FileProjectWriter fileProjectWriter = new FileProjectWriter(project.getBasedir())) { if (project.getFile() != null) { // Maven project final MavenBuildFile mvnBuild = new MavenBuildFile(fileProjectWriter); - buildFile = mvnBuild; + buildTool = BuildTool.MAVEN; + buildFile = new MavenBuildFile(fileProjectWriter); final List descrArtifactList = new ArrayList<>(2); for (Dependency dep : mvnBuild.getManagedDependencies()) { @@ -112,14 +114,14 @@ public void execute() throws MojoExecutionException { } else if (new File(project.getBasedir(), "build.gradle").exists() || new File(project.getBasedir(), "build.gradle.kts").exists()) { // Gradle project - buildFile = new GradleBuildFile(fileProjectWriter); + buildTool = BuildTool.GRADLE; } if (platformDescr == null) { platformDescr = CreateUtils.resolvePlatformDescriptor(bomGroupId, bomArtifactId, bomVersion, mvn, getLog()); } - doExecute(fileProjectWriter, buildFile, platformDescr, log); + doExecute(QuarkusProject.of(project.getBasedir().toPath(), platformDescr, buildTool), log); } catch (IOException e) { throw new MojoExecutionException("Failed to initialize project reading tools", e); } finally { @@ -169,8 +171,7 @@ private Artifact resolveJsonOrNull(MavenArtifactResolver mvn, String bomGroupId, protected void validateParameters() throws MojoExecutionException { } - protected abstract void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatformDescriptor platformDescr, - MessageWriter log) + protected abstract void doExecute(QuarkusProject quarkusProject, MessageWriter log) throws MojoExecutionException; private String resolveValue(String expr, BuildFile buildFile) throws IOException { 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 75c3cf391d5ca..99edf9fca6d29 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java @@ -48,9 +48,8 @@ import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.CreateProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.generators.SourceType; import io.quarkus.maven.components.MavenVersionEnforcer; import io.quarkus.maven.components.Prompter; @@ -186,6 +185,7 @@ public void execute() throws MojoExecutionException { } boolean success; + final Path projectFolderPath = projectRoot.toPath(); try { sanitizeExtensions(); final SourceType sourceType = CreateProject.determineSourceType(extensions); @@ -199,9 +199,7 @@ public void execute() throws MojoExecutionException { Arrays.asList(BuildTool.values()).stream().map(BuildTool::toString).collect(Collectors.toList())); throw new IllegalArgumentException("Choose a valid build tool. Accepted values are: " + validBuildTools); } - - final FileProjectWriter projectWriter = new FileProjectWriter(projectRoot); - final CreateProject createProject = new CreateProject(projectWriter, platform) + final CreateProject createProject = new CreateProject(projectFolderPath, platform) .buildTool(buildToolEnum) .groupId(projectGroupId) .artifactId(projectArtifactId) @@ -217,13 +215,14 @@ public void execute() throws MojoExecutionException { File createdDependenciesBuildFile = new File(projectRoot, buildToolEnum.getDependenciesFile()); if (success) { - success = new AddExtensions(projectWriter, buildToolEnum, platform).extensions(extensions).execute() + success = new AddExtensions(QuarkusProject.of(projectFolderPath, platform, buildToolEnum)) + .extensions(extensions).execute() .isSuccess(); } if (BuildTool.MAVEN.equals(buildToolEnum)) { createMavenWrapper(createdDependenciesBuildFile, ToolsUtils.readQuarkusProperties(platform)); } else if (BuildTool.GRADLE.equals(buildToolEnum)) { - createGradleWrapper(platform, projectWriter); + createGradleWrapper(platform, projectFolderPath); } } catch (Exception e) { throw new MojoExecutionException("Failed to generate Quarkus project", e); @@ -236,10 +235,9 @@ public void execute() throws MojoExecutionException { } } - private void createGradleWrapper(QuarkusPlatformDescriptor platform, - ProjectWriter writer) { + private void createGradleWrapper(QuarkusPlatformDescriptor platform, Path projectFolderPath) { try { - writer.mkdirs("gradle/wrapper"); + Files.createDirectories(projectFolderPath.resolve("gradle/wrapper")); for (String filename : CreateUtils.GRADLE_WRAPPER_FILES) { byte[] fileContent = platform.loadResource(Paths.get(CreateUtils.GRADLE_WRAPPER_PATH, filename).toString(), @@ -248,12 +246,12 @@ private void createGradleWrapper(QuarkusPlatformDescriptor platform, is.read(buffer); return buffer; }); - final Path destination = writer.getProjectFolder().toPath().resolve(filename); + final Path destination = projectFolderPath.resolve(filename); Files.write(destination, fileContent); } - new File(writer.getProjectFolder(), "gradlew").setExecutable(true); - new File(writer.getProjectFolder(), "gradlew.bat").setExecutable(true); + projectFolderPath.resolve("gradlew").toFile().setExecutable(true); + projectFolderPath.resolve("gradlew.bat").toFile().setExecutable(true); } catch (IOException e) { getLog().error("Unable to copy Gradle wrapper from platform descriptor", e); } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java index 6eb444087e1fb..842724ba0264d 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java @@ -5,9 +5,7 @@ import org.apache.maven.plugins.annotations.Parameter; import io.quarkus.cli.commands.ListExtensions; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** @@ -39,10 +37,9 @@ public class ListExtensionsMojo extends BuildFileMojoBase { protected String searchPattern; @Override - public void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatformDescriptor platformDescr, MessageWriter log) - throws MojoExecutionException { + public void doExecute(final QuarkusProject quarkusProject, final MessageWriter log) throws MojoExecutionException { try { - new ListExtensions(writer, buildFile, platformDescr) + new ListExtensions(quarkusProject) .all(all) .format(format) .search(searchPattern) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java index bd4482b1a2aa0..2b011f3eb8a98 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java @@ -1,6 +1,5 @@ package io.quarkus.maven; -import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -13,10 +12,7 @@ import io.quarkus.cli.commands.QuarkusCommandOutcome; import io.quarkus.cli.commands.RemoveExtensions; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** @@ -49,16 +45,8 @@ protected void validateParameters() throws MojoExecutionException { } @Override - public void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatformDescriptor platformDescr, MessageWriter log) - throws MojoExecutionException { + public void doExecute(final QuarkusProject quarkusProject, final MessageWriter log) throws MojoExecutionException { - if (buildFile == null) { - try { - buildFile = BuildTool.MAVEN.createBuildFile(writer); - } catch (IOException e) { - throw new MojoExecutionException("Failed to initialize the project's build descriptor", e); - } - } Set ext = new HashSet<>(); if (extensions != null && !extensions.isEmpty()) { ext.addAll(extensions); @@ -69,7 +57,7 @@ public void doExecute(ProjectWriter writer, BuildFile buildFile, QuarkusPlatform } try { - final QuarkusCommandOutcome outcome = new RemoveExtensions(writer, buildFile, platformDescr) + final QuarkusCommandOutcome outcome = new RemoveExtensions(quarkusProject) .extensions(ext.stream().map(String::trim).collect(Collectors.toSet())) .execute(); if (!outcome.isSuccess()) { diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java index 1d4b941cdb597..d75936449307c 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java @@ -1,15 +1,8 @@ package io.quarkus.cli.commands; -import static com.google.common.base.Preconditions.checkNotNull; - -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.MavenBuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; -import java.io.IOException; import java.util.Set; /** @@ -23,18 +16,8 @@ public class AddExtensions { private final QuarkusCommandInvocation invocation; - public AddExtensions(final ProjectWriter writer, QuarkusPlatformDescriptor platformDescr) throws IOException { - this(writer, new MavenBuildFile(writer), platformDescr); - } - - public AddExtensions(final ProjectWriter writer, final BuildTool buildTool, QuarkusPlatformDescriptor platformDescr) - throws IOException { - this(writer, buildTool.createBuildFile(writer), platformDescr); - } - - public AddExtensions(final ProjectWriter writer, final BuildFile buildFile, QuarkusPlatformDescriptor platformDescr) { - checkNotNull(buildFile, "buildFile is required"); - invocation = new QuarkusCommandInvocation(platformDescr, writer, buildFile); + public AddExtensions(final QuarkusProject quarkusProject) { + this.invocation = new QuarkusCommandInvocation(quarkusProject); } public AddExtensions extensions(Set extensions) { diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java index 6f2617955354b..53fd82f091813 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java @@ -9,12 +9,12 @@ import static io.quarkus.generators.ProjectGenerator.PROJECT_VERSION; import static io.quarkus.generators.ProjectGenerator.SOURCE_TYPE; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.generators.SourceType; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -33,16 +33,15 @@ public class CreateProject { private static final Pattern JAVA_VERSION_PATTERN = Pattern.compile("(?:1\\.)?(\\d+)(?:\\..*)?"); - private final ProjectWriter writer; + private final Path projectFolderPath; private final QuarkusPlatformDescriptor platformDescr; private String javaTarget; - private BuildFile buildFile; private BuildTool buildTool = BuildTool.MAVEN; private Map values = new HashMap<>(); - public CreateProject(final ProjectWriter writer, QuarkusPlatformDescriptor platformDescr) { - this.writer = checkNotNull(writer, "writer is required"); + public CreateProject(final Path projectFolderPath, QuarkusPlatformDescriptor platformDescr) { + this.projectFolderPath = checkNotNull(projectFolderPath, "writer is required"); this.platformDescr = checkNotNull(platformDescr, "platformDescr is required"); } @@ -82,12 +81,6 @@ public CreateProject className(String className) { return this; } - public CreateProject buildFile(BuildFile buildFile) { - this.buildFile = buildFile; - this.buildTool(buildFile.getBuildTool()); - return this; - } - /** * @deprecated in 1.3.0.CR */ @@ -135,26 +128,11 @@ public QuarkusCommandOutcome execute() throws QuarkusCommandException { setValue(JAVA_TARGET, "11"); } - final BuildFile computeBuildFile = computeBuildFile(); - final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(values, platformDescr, writer, - computeBuildFile); + final QuarkusProject quarkusProject = QuarkusProject.of(projectFolderPath, platformDescr, buildTool); + final QuarkusCommandInvocation invocation = new QuarkusCommandInvocation(quarkusProject, values); return new CreateProjectCommandHandler().execute(invocation); } - private BuildFile computeBuildFile() throws QuarkusCommandException { - if (buildFile != null) { - return buildFile; - } - if (buildTool != null) { - try { - return buildTool.createBuildFile(writer); - } catch (final IOException e) { - throw new QuarkusCommandException("Failed to create project", e); - } - } - throw new QuarkusCommandException("Either BuildTool or BuildFile must be defined"); - } - public static SourceType determineSourceType(Set extensions) { Optional sourceType = extensions.stream() .map(SourceType::parse) diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java index 52b3caec87fdf..1cff787afcd35 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java @@ -3,6 +3,7 @@ import static io.quarkus.generators.ProjectGenerator.*; import io.quarkus.cli.commands.file.BuildFile; +import io.quarkus.cli.commands.writer.FileProjectWriter; import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.generators.ProjectGeneratorRegistry; import io.quarkus.generators.SourceType; @@ -20,10 +21,8 @@ public class CreateProjectCommandHandler implements QuarkusCommand { @Override public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException { - final ProjectWriter projectWriter = invocation.getProjectWriter(); - if (projectWriter == null) { - throw new IllegalStateException("Project writer has not been provided"); - } + final ProjectWriter projectWriter = new FileProjectWriter( + invocation.getQuarkusProject().getProjectFolderPath().toFile()); if (!projectWriter.init()) { return QuarkusCommandOutcome.failure(); } diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java index c1d8f98eb00de..ded612145d7b0 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java @@ -1,8 +1,6 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; import java.io.IOException; @@ -22,9 +20,8 @@ public class ListExtensions { private final QuarkusCommandInvocation invocation; private final ListExtensionsCommandHandler handler = new ListExtensionsCommandHandler(); - public ListExtensions(final ProjectWriter writer, final BuildFile buildFile, QuarkusPlatformDescriptor platformDescr) - throws IOException { - this.invocation = new QuarkusCommandInvocation(platformDescr, writer, buildFile); + public ListExtensions(final QuarkusProject quarkusProject) { + this.invocation = new QuarkusCommandInvocation(quarkusProject); } public ListExtensions all(boolean all) { diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java index 4e7995ba29f61..514a5089f583d 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java @@ -65,7 +65,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws currentFormatter = this::conciseFormatter; } - final BuildFile buildFile = getBuildFileSafe(invocation); + final BuildFile buildFile = invocation.getBuildFile(); loadedExtensions.forEach(extension -> display(extension, installed, all, currentFormatter, buildFile)); if (buildFile != null) { @@ -91,15 +91,6 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws return QuarkusCommandOutcome.success(); } - private BuildFile getBuildFileSafe(QuarkusCommandInvocation invocation) { - try { - return invocation.getBuildFile(); - } catch (Exception e) { - invocation.log.debug("Unable to get build file. Error is %s ", e.getMessage()); - return null; - } - } - Map findInstalled(QuarkusCommandInvocation invocation) throws IOException { return invocation.getBuildFile().findInstalled(); } diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java index 6853e34405dff..bd5005b1c7b0e 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java @@ -3,61 +3,51 @@ import static com.google.common.base.Preconditions.checkNotNull; import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.DefaultMessageWriter; import io.quarkus.platform.tools.MessageWriter; import java.util.HashMap; import java.util.Map; -public class QuarkusCommandInvocation extends ValueMap { +public final class QuarkusCommandInvocation extends ValueMap { - protected final QuarkusPlatformDescriptor platformDescr; - protected final MessageWriter log; - private final BuildFile buildFile; - private final ProjectWriter writer; + private final QuarkusProject quarkusProject; + private final MessageWriter log; - public QuarkusCommandInvocation(QuarkusPlatformDescriptor platformDescr, ProjectWriter writer, - BuildFile buildFile) { - this(new HashMap<>(), platformDescr, writer, buildFile, new DefaultMessageWriter()); + public QuarkusCommandInvocation(QuarkusProject quarkusProject) { + this(quarkusProject, new HashMap<>()); } - public QuarkusCommandInvocation(Map values, QuarkusPlatformDescriptor platformDescr, ProjectWriter writer, - BuildFile buildFile) { - this(values, platformDescr, writer, buildFile, new DefaultMessageWriter()); + public QuarkusCommandInvocation(final QuarkusProject quarkusProject, final Map values) { + this(quarkusProject, values, new DefaultMessageWriter()); } - public QuarkusCommandInvocation(Map values, QuarkusPlatformDescriptor platformDescr, ProjectWriter writer, - BuildFile buildFile, MessageWriter log) { + public QuarkusCommandInvocation(final QuarkusProject quarkusProject, final Map values, + final MessageWriter log) { super(values); - this.platformDescr = checkNotNull(platformDescr, "platformDescr is required"); + this.quarkusProject = checkNotNull(quarkusProject, "quarkusProject is required"); this.log = checkNotNull(log, "log is required"); - this.writer = checkNotNull(writer, "writer is required"); - this.buildFile = checkNotNull(buildFile, "buildFile is required"); } public QuarkusCommandInvocation(QuarkusCommandInvocation original) { - super(original.values); - this.platformDescr = original.platformDescr; - this.log = original.log; - this.buildFile = original.buildFile; - this.writer = original.writer; + this(original.quarkusProject, original.values, original.log); } - public MessageWriter getMessageWriter() { + public QuarkusProject getQuarkusProject() { + return quarkusProject; + } + + public MessageWriter log() { return log; } public QuarkusPlatformDescriptor getPlatformDescriptor() { - return platformDescr; + return quarkusProject.getDescriptor(); } public BuildFile getBuildFile() { - return buildFile; - } - - public ProjectWriter getProjectWriter() { - return writer; + return quarkusProject.getBuildFile(); } } diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java index e23b8edcfff01..7882a1882daf9 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java @@ -1,12 +1,8 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; -import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; -import java.io.IOException; import java.util.Set; /** @@ -20,18 +16,8 @@ public class RemoveExtensions { private final QuarkusCommandInvocation invocation; - public RemoveExtensions(final ProjectWriter writer, QuarkusPlatformDescriptor platformDescr) throws IOException { - this(writer, BuildTool.MAVEN, platformDescr); - } - - public RemoveExtensions(final ProjectWriter writer, final BuildTool buildTool, QuarkusPlatformDescriptor platformDescr) - throws IOException { - this(writer, buildTool.createBuildFile(writer), platformDescr); - } - - public RemoveExtensions(final ProjectWriter writer, final BuildFile buildFile, QuarkusPlatformDescriptor platformDescr) - throws IOException { - invocation = new QuarkusCommandInvocation(platformDescr, writer, buildFile); + public RemoveExtensions(final QuarkusProject quarkusProject) { + invocation = new QuarkusCommandInvocation(quarkusProject); } public RemoveExtensions extensions(Set extensions) { diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java index 8c1ce02ee9274..e21b6b6e91895 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java @@ -5,9 +5,9 @@ import static java.util.stream.Collectors.toList; import io.quarkus.cli.commands.Printer; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; -import io.quarkus.generators.BuildTool; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.QuarkusDependencyPredicate; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java index 308863a642fe4..81db70c94d099 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java @@ -1,8 +1,8 @@ package io.quarkus.cli.commands.file; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; -import io.quarkus.generators.BuildTool; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.ToolsUtils; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java index 64d6aa328fc88..658cd81640840 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java @@ -3,9 +3,9 @@ import static io.quarkus.maven.utilities.MojoUtils.configuration; import static io.quarkus.maven.utilities.MojoUtils.plugin; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; -import io.quarkus.generators.BuildTool; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.MojoUtils.Element; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; @@ -33,7 +33,7 @@ public class MavenBuildFile extends BuildFile { private Model model; - public MavenBuildFile(ProjectWriter writer) throws IOException { + public MavenBuildFile(ProjectWriter writer) { super(writer, BuildTool.MAVEN); } diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/generators/BuildTool.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java similarity index 95% rename from independent-projects/tools/common/src/main/java/io/quarkus/generators/BuildTool.java rename to independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java index 1440f30ad1f9c..dceb81fa369eb 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/generators/BuildTool.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java @@ -1,4 +1,4 @@ -package io.quarkus.generators; +package io.quarkus.cli.commands.project; import static com.google.common.base.Preconditions.checkNotNull; @@ -6,7 +6,6 @@ import io.quarkus.cli.commands.file.GradleBuildFile; import io.quarkus.cli.commands.file.MavenBuildFile; import io.quarkus.cli.commands.writer.ProjectWriter; -import java.io.IOException; /** * An enum of build tools, such as Maven and Gradle. @@ -54,7 +53,7 @@ public String getBuildDirectory() { return buildDirectory; } - public BuildFile createBuildFile(final ProjectWriter writer) throws IOException { + public BuildFile createBuildFile(final ProjectWriter writer) { checkNotNull(writer, "writer is required"); switch (this) { case GRADLE: diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java new file mode 100644 index 0000000000000..c183e1e4327a6 --- /dev/null +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java @@ -0,0 +1,60 @@ +package io.quarkus.cli.commands.project; + +import static com.google.common.base.Preconditions.checkNotNull; + +import io.quarkus.cli.commands.file.BuildFile; +import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; +import java.nio.file.Path; + +public final class QuarkusProject { + + private final Path projectFolderPath; + private final BuildFile buildFile; + private final QuarkusPlatformDescriptor descriptor; + + private QuarkusProject(final Path projectFolderPath, final QuarkusPlatformDescriptor descriptor, + final BuildFile buildFile) { + this.projectFolderPath = checkNotNull(projectFolderPath, "projectFolderPath is required"); + this.descriptor = checkNotNull(descriptor, "descriptor is required"); + this.buildFile = checkNotNull(buildFile, "buildFile is required"); + } + + public static QuarkusProject of(final Path projectFolderPath, final QuarkusPlatformDescriptor descriptor, + final BuildTool buildTool) { + final BuildFile buildFile = buildTool.createBuildFile(new FileProjectWriter(projectFolderPath.toFile())); + return of(projectFolderPath, descriptor, buildFile); + } + + public static QuarkusProject of(final Path projectFolderPath, final QuarkusPlatformDescriptor descriptor, + final BuildFile buildFile) { + return new QuarkusProject(projectFolderPath, descriptor, buildFile); + } + + public static QuarkusProject resolveExistingProject(final Path projectFolderPath, + final QuarkusPlatformDescriptor descriptor) { + if (projectFolderPath.resolve("pom.xml").toFile().exists()) { + return of(projectFolderPath, descriptor, BuildTool.MAVEN); + } else if (projectFolderPath.resolve("build.gradle").toFile().exists() + || projectFolderPath.resolve("build.gradle.kts").toFile().exists()) { + return of(projectFolderPath, descriptor, BuildTool.GRADLE); + } + throw new IllegalStateException("This is neither a Maven or Gradle project"); + } + + public Path getProjectFolderPath() { + return projectFolderPath; + } + + public BuildFile getBuildFile() { + return buildFile; + } + + public BuildTool getBuildTool() { + return buildFile.getBuildTool(); + } + + public QuarkusPlatformDescriptor getDescriptor() { + return descriptor; + } +} diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ZipProjectWriter.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ZipProjectWriter.java deleted file mode 100644 index 3ec4e7a6e6475..0000000000000 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ZipProjectWriter.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * - */ -package io.quarkus.cli.commands.writer; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; - -/** - * ProjectWriter implementation to create a zip. - */ -public class ZipProjectWriter implements ProjectWriter { - private final ZipOutputStream zos; - private final Map contentByPath = new LinkedHashMap<>(); - private final List dirs = new ArrayList<>(); - - public ZipProjectWriter(final ZipOutputStream zip) { - zos = zip; - } - - @Override - public String mkdirs(String path) throws IOException { - if (path.length() == 0) { - return ""; - } - String dirPath = path; - if (!dirPath.endsWith("/")) { - dirPath = dirPath + "/"; - } - if (dirs.contains(dirPath)) { - return dirPath; - } - ZipEntry ze = new ZipEntry(dirPath); - zos.putNextEntry(ze); - zos.closeEntry(); - dirs.add(dirPath); - return path; - } - - @Override - public void write(String path, String content) throws IOException { - byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); - contentByPath.put(path, contentBytes); - } - - @Override - public byte[] getContent(String path) { - return contentByPath.get(path); - } - - @Override - public boolean exists(String path) { - return contentByPath.containsKey(path); - } - - @Override - public void close() throws IOException { - for (Entry entry : contentByPath.entrySet()) { - ZipEntry ze = new ZipEntry(entry.getKey()); - zos.putNextEntry(ze); - zos.write(entry.getValue()); - zos.closeEntry(); - } - - } - - @Override - public File getProjectFolder() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean hasFile() { - return false; - } - -} diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java b/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java index 557c7f8a26a69..83917b7d3c6cf 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java @@ -1,11 +1,10 @@ package io.quarkus.generators.rest; -import static io.quarkus.generators.ProjectGenerator.JAVA_TARGET; import static java.lang.String.format; import io.quarkus.cli.commands.QuarkusCommandInvocation; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; import io.quarkus.generators.ProjectGenerator; import io.quarkus.generators.SourceType; import io.quarkus.maven.utilities.MojoUtils; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java index feef0d0bb0cbc..50c6ba209740e 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java @@ -1,8 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import java.io.IOException; import java.nio.file.Files; import java.util.HashSet; @@ -19,9 +18,8 @@ void addExtensionTwiceInTwoBatches() throws IOException { @Override protected List createProject() throws IOException, QuarkusCommandException { CreateProjectTest.delete(getProjectPath().toFile()); - final FileProjectWriter writer = new FileProjectWriter(getProjectPath().toFile()); - new CreateProject(writer, getPlatformDescriptor()) - .buildFile(new GradleBuildFile(writer)) + new CreateProject(getProjectPath(), getPlatformDescriptor()) + .buildTool(BuildTool.GRADLE) .groupId("org.acme") .artifactId("add-gradle-extension-test") .version("0.0.1-SNAPSHOT") @@ -36,7 +34,7 @@ protected List readProject() throws IOException { @Override protected QuarkusCommandOutcome addExtensions(final List extensions) throws IOException, QuarkusCommandException { - return new AddExtensions(new FileProjectWriter(getProjectPath().toFile()), BuildTool.GRADLE, getPlatformDescriptor()) + return new AddExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @@ -53,4 +51,8 @@ private static String getBuildFileDependencyString(final String groupId, final S final String versionPart = version != null ? ":" + version : ""; return " implementation '" + groupId + ":" + artifactId + versionPart + "'"; } + + private QuarkusProject getQuarkusProject() { + return QuarkusProject.of(getProjectPath(), getPlatformDescriptor(), BuildTool.GRADLE); + } } diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java index 59395e1adbb27..f8293b65a5c22 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java @@ -1,6 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; import java.io.IOException; @@ -15,7 +16,8 @@ class AddMavenExtensionsTest extends AbstractAddExtensionsTest { protected Model createProject() throws IOException, QuarkusCommandException { final File pom = getProjectPath().resolve("pom.xml").toFile(); CreateProjectTest.delete(getProjectPath().toFile()); - new CreateProject(new FileProjectWriter(getProjectPath().toFile()), getPlatformDescriptor()) + new CreateProject(getProjectPath(), getPlatformDescriptor()) + .buildTool(BuildTool.MAVEN) .groupId("org.acme") .artifactId("add-maven-extension-test") .version("0.0.1-SNAPSHOT") @@ -30,7 +32,7 @@ protected Model readProject() throws IOException { @Override protected QuarkusCommandOutcome addExtensions(List extensions) throws IOException, QuarkusCommandException { - return new AddExtensions(new FileProjectWriter(getProjectPath().toFile()), getPlatformDescriptor()) + return new AddExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @@ -42,4 +44,8 @@ protected long countDependencyOccurrences(final Model project, final String grou d.getArtifactId().equals(artifactId) && Objects.equals(d.getVersion(), version)).count(); } + + private QuarkusProject getQuarkusProject() { + return QuarkusProject.of(getProjectPath(), getPlatformDescriptor(), BuildTool.MAVEN); + } } diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java index 1e00b20f0d115..40686de1059e8 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java @@ -4,14 +4,11 @@ import static org.assertj.core.api.Assertions.contentOf; import static org.junit.jupiter.api.Assertions.assertTrue; +import io.quarkus.cli.commands.project.BuildTool; import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ZipProjectWriter; -import io.quarkus.generators.BuildTool; import io.quarkus.generators.ProjectGenerator; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -28,8 +25,6 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import java.util.zip.ZipOutputStream; import org.apache.maven.model.Model; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -155,7 +150,7 @@ public void createOnTopPomWithResource() throws Exception { final File pom = new File(testDir, "pom.xml"); MojoUtils.write(model, pom); - final QuarkusCommandOutcome result = new CreateProject(new FileProjectWriter(testDir), getPlatformDescriptor()) + final QuarkusCommandOutcome result = new CreateProject(testDir.toPath(), getPlatformDescriptor()) .groupId("something.is") .artifactId("wrong") .version("1.0.0-SNAPSHOT") @@ -199,7 +194,7 @@ public void createOnTopPomWithSpringController() throws Exception { final File pom = new File(testDir, "pom.xml"); MojoUtils.write(model, pom); - final QuarkusCommandOutcome result = new CreateProject(new FileProjectWriter(testDir), getPlatformDescriptor()) + final QuarkusCommandOutcome result = new CreateProject(testDir.toPath(), getPlatformDescriptor()) .groupId("something.is") .artifactId("wrong") .version("1.0.0-SNAPSHOT") @@ -236,7 +231,7 @@ public void createNewWithCustomizations() throws Exception { delete(testDir); testDir.mkdirs(); - final QuarkusCommandOutcome result = new CreateProject(new FileProjectWriter(testDir), getPlatformDescriptor()) + final QuarkusCommandOutcome result = new CreateProject(testDir.toPath(), getPlatformDescriptor()) .groupId("org.acme") .artifactId("acme") .version("1.0.0-SNAPSHOT") @@ -272,7 +267,7 @@ void createMultipleTimes() throws InterruptedException { List> collect = IntStream.range(0, 20).boxed().map(i -> (Callable) () -> { File tempDir = Files.createTempDirectory("test").toFile(); FileProjectWriter write = new FileProjectWriter(tempDir); - final QuarkusCommandOutcome result = new CreateProject(new FileProjectWriter(tempDir), getPlatformDescriptor()) + final QuarkusCommandOutcome result = new CreateProject(tempDir.toPath(), getPlatformDescriptor()) .groupId("org.acme") .artifactId("acme") .version("1.0.0-SNAPSHOT") @@ -302,58 +297,61 @@ public static void delete(final File file) throws IOException { Files.exists(file.toPath()), "Directory still exists"); } - @Test - public void createZip() throws Exception { - final File file = new File("target/zip"); - delete(file); - file.mkdirs(); - File zipFile = new File(file, "project.zip"); - try (FileOutputStream fos = new FileOutputStream(zipFile); - ZipOutputStream zos = new ZipOutputStream(fos); - ZipProjectWriter zipWriter = new ZipProjectWriter(zos)) { - final QuarkusCommandOutcome result = new CreateProject(zipWriter, getPlatformDescriptor()) - .groupId("org.acme") - .artifactId("basic-rest") - .version("1.0.0-SNAPSHOT") - .execute(); - assertTrue(result.isSuccess()); - } - assertTrue(zipFile.exists()); - File unzipProject = new File(file, "unzipProject"); - try (FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = new ZipInputStream(fis)) { - ZipEntry zipEntry = zis.getNextEntry(); - byte[] buffer = new byte[1024]; - while (zipEntry != null) { - File newFile = newFile(unzipProject, zipEntry); - if (zipEntry.isDirectory()) { - newFile.mkdirs(); - } else { - new File(newFile.getParent()).mkdirs(); - FileOutputStream fos = new FileOutputStream(newFile); - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } - fos.close(); - } - zipEntry = zis.getNextEntry(); - } - zis.closeEntry(); - } - final File gitignore = new File(unzipProject, ".gitignore"); - assertTrue(gitignore.exists()); - final String gitignoreContent = new String(Files.readAllBytes(gitignore.toPath()), StandardCharsets.UTF_8); - assertTrue(gitignoreContent.contains("\ntarget/\n")); - } + // FIXME Zip (previously done by ZipProjectWriter) for Quarkus projects is going to be replaced by a way to zip the project folder, we can make this test work again once this is done + /** + * @Test + * public void createZip() throws Exception { + * final File file = new File("target/zip"); + * delete(file); + * file.mkdirs(); + * File zipFile = new File(file, "project.zip"); + * try (FileOutputStream fos = new FileOutputStream(zipFile); + * ZipOutputStream zos = new ZipOutputStream(fos); + * ZipProjectWriter zipWriter = new ZipProjectWriter(zos)) { + * final QuarkusCommandOutcome result = new CreateProject(zipWriter, getPlatformDescriptor()) + * .groupId("org.acme") + * .artifactId("basic-rest") + * .version("1.0.0-SNAPSHOT") + * .execute(); + * assertTrue(result.isSuccess()); + * } + * assertTrue(zipFile.exists()); + * File unzipProject = new File(file, "unzipProject"); + * try (FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = new ZipInputStream(fis)) { + * ZipEntry zipEntry = zis.getNextEntry(); + * byte[] buffer = new byte[1024]; + * while (zipEntry != null) { + * File newFile = newFile(unzipProject, zipEntry); + * if (zipEntry.isDirectory()) { + * newFile.mkdirs(); + * } else { + * new File(newFile.getParent()).mkdirs(); + * FileOutputStream fos = new FileOutputStream(newFile); + * int len; + * while ((len = zis.read(buffer)) > 0) { + * fos.write(buffer, 0, len); + * } + * fos.close(); + * } + * zipEntry = zis.getNextEntry(); + * } + * zis.closeEntry(); + * } + * final File gitignore = new File(unzipProject, ".gitignore"); + * assertTrue(gitignore.exists()); + * final String gitignoreContent = new String(Files.readAllBytes(gitignore.toPath()), StandardCharsets.UTF_8); + * assertTrue(gitignoreContent.contains("\ntarget/\n")); + * } + **/ private void createProject(final File file, String groupId, String artifactId, String version) - throws IOException, QuarkusCommandException { + throws QuarkusCommandException { createProject(BuildTool.MAVEN, file, groupId, artifactId, version); } private void createProject(BuildTool buildTool, File file, String groupId, String artifactId, String version) - throws IOException, QuarkusCommandException { - final QuarkusCommandOutcome result = new CreateProject(new FileProjectWriter(file), getPlatformDescriptor()) + throws QuarkusCommandException { + final QuarkusCommandOutcome result = new CreateProject(file.toPath(), getPlatformDescriptor()) .buildTool(buildTool) .groupId(groupId) .artifactId(artifactId) diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java index f360a406a33df..5d86bf108c866 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java @@ -5,9 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; -import io.quarkus.cli.commands.file.MavenBuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.QuarkusDependencyPredicate; import java.io.ByteArrayOutputStream; @@ -15,6 +14,7 @@ import java.io.IOException; import java.io.PrintStream; import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashSet; import java.util.Map; import org.apache.maven.model.Dependency; @@ -26,10 +26,10 @@ public class ListExtensionsTest extends PlatformAwareTestBase { @Test public void listWithBom() throws Exception { - final FileProjectWriter writer = createNewProject(new File("target/list-extensions-test", "pom.xml")); - addExtensions(writer, "commons-io:commons-io:2.5", "Agroal"); + final QuarkusProject project = createNewProject(new File("target/list-extensions-test", "pom.xml")); + addExtensions(project, "commons-io:commons-io:2.5", "Agroal"); - final ListExtensions listExtensions = new ListExtensions(writer, new MavenBuildFile(writer), getPlatformDescriptor()); + final ListExtensions listExtensions = new ListExtensions(project); final Map installed = listExtensions.findInstalled(); @@ -44,10 +44,10 @@ public void listWithBom() throws Exception { */ @Test public void listWithBomExtensionWithSpaces() throws Exception { - final FileProjectWriter writer = createNewProject(new File("target/list-extensions-test", "pom.xml")); - addExtensions(writer, "resteasy", " hibernate-validator "); + final QuarkusProject quarkusProject = createNewProject(new File("target/list-extensions-test", "pom.xml")); + addExtensions(quarkusProject, "resteasy", " hibernate-validator "); - final ListExtensions listExtensions = new ListExtensions(writer, new MavenBuildFile(writer), getPlatformDescriptor()); + final ListExtensions listExtensions = new ListExtensions(quarkusProject); final Map installed = listExtensions.findInstalled(); @@ -58,7 +58,7 @@ public void listWithBomExtensionWithSpaces() throws Exception { @Test public void listWithoutBom() throws Exception { final File pom = new File("target/list-extensions-test", "pom.xml"); - final FileProjectWriter writer = createNewProject(pom); + final QuarkusProject quarkusProject = createNewProject(pom); Model model = readPom(pom); @@ -69,7 +69,7 @@ public void listWithoutBom() throws Exception { MojoUtils.write(model, pom); - addExtensions(writer, "commons-io:commons-io:2.5", "Agroal"); + addExtensions(quarkusProject, "commons-io:commons-io:2.5", "Agroal"); model = readPom(pom); @@ -77,7 +77,7 @@ public void listWithoutBom() throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final PrintStream printStream = new PrintStream(baos, false, "UTF-8")) { System.setOut(printStream); - new ListExtensions(writer, new MavenBuildFile(writer), getPlatformDescriptor()) + new ListExtensions(quarkusProject) .all(true) .format("full") .execute(); @@ -118,14 +118,14 @@ public void listWithoutBom() throws Exception { @Test public void searchUnexpected() throws Exception { - final FileProjectWriter writer = createNewProject(new File("target/list-extensions-test", "pom.xml")); - addExtensions(writer, "commons-io:commons-io:2.5", "Agroal"); + final QuarkusProject quarkusProject = createNewProject(new File("target/list-extensions-test", "pom.xml")); + addExtensions(quarkusProject, "commons-io:commons-io:2.5", "Agroal"); final PrintStream out = System.out; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final PrintStream printStream = new PrintStream(baos, false, "UTF-8")) { System.setOut(printStream); - new ListExtensions(writer, new MavenBuildFile(writer), getPlatformDescriptor()) + new ListExtensions(quarkusProject) .all(true) .format("full") .search("unexpectedSearch") @@ -140,14 +140,14 @@ public void searchUnexpected() throws Exception { @Test public void searchRest() throws Exception { - final FileProjectWriter writer = createNewProject(new File("target/list-extensions-test", "pom.xml")); - addExtensions(writer, "commons-io:commons-io:2.5", "Agroal"); + final QuarkusProject quarkusProject = createNewProject(new File("target/list-extensions-test", "pom.xml")); + addExtensions(quarkusProject, "commons-io:commons-io:2.5", "Agroal"); final PrintStream out = System.out; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final PrintStream printStream = new PrintStream(baos, false, "UTF-8")) { System.setOut(printStream); - new ListExtensions(writer, new MavenBuildFile(writer), getPlatformDescriptor()) + new ListExtensions(quarkusProject) .all(true) .format("full") .search("Rest") @@ -161,26 +161,26 @@ public void searchRest() throws Exception { @Test void testListExtensionsWithoutAPomFile() throws IOException { - final FileProjectWriter writer = new FileProjectWriter(Files.createTempDirectory("proj").toFile()); - ListExtensions listExtensions = new ListExtensions(writer, - BuildTool.MAVEN.createBuildFile(writer), getPlatformDescriptor()); + final Path tempDirectory = Files.createTempDirectory("proj"); + ListExtensions listExtensions = new ListExtensions( + QuarkusProject.of(tempDirectory, getPlatformDescriptor(), BuildTool.MAVEN)); assertThat(listExtensions.findInstalled()).isEmpty(); } - private void addExtensions(FileProjectWriter writer, String... extensions) throws Exception { - new AddExtensions(writer, getPlatformDescriptor()) + private void addExtensions(QuarkusProject quarkusProject, String... extensions) throws Exception { + new AddExtensions(quarkusProject) .extensions(new HashSet<>(asList(extensions))) .execute(); } - private FileProjectWriter createNewProject(final File pom) throws IOException, QuarkusCommandException { + private QuarkusProject createNewProject(final File pom) throws IOException, QuarkusCommandException { CreateProjectTest.delete(pom.getParentFile()); - final FileProjectWriter writer = new FileProjectWriter(pom.getParentFile()); - new CreateProject(writer, getPlatformDescriptor()) + final Path projectFolderPath = pom.getParentFile().toPath(); + new CreateProject(projectFolderPath, getPlatformDescriptor()) .groupId("org.acme") .artifactId("add-extension-test") .version("0.0.1-SNAPSHOT") .execute(); - return writer; + return QuarkusProject.of(projectFolderPath, getPlatformDescriptor(), BuildTool.MAVEN); } } diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java index 5662d6cda2343..74a75d73b19f1 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java @@ -1,8 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.generators.BuildTool; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import java.io.IOException; import java.nio.file.Files; import java.util.HashSet; @@ -19,9 +18,8 @@ void addExtensionTwiceInTwoBatches() throws IOException { @Override protected List createProject() throws IOException, QuarkusCommandException { CreateProjectTest.delete(getProjectPath().toFile()); - final FileProjectWriter writer = new FileProjectWriter(getProjectPath().toFile()); - new CreateProject(writer, getPlatformDescriptor()) - .buildFile(new GradleBuildFile(writer)) + new CreateProject(getProjectPath(), getPlatformDescriptor()) + .buildTool(BuildTool.GRADLE) .groupId("org.acme") .artifactId("add-gradle-extension-test") .version("0.0.1-SNAPSHOT") @@ -36,7 +34,7 @@ protected List readProject() throws IOException { @Override protected QuarkusCommandOutcome addExtensions(final List extensions) throws IOException, QuarkusCommandException { - return new AddExtensions(new FileProjectWriter(getProjectPath().toFile()), BuildTool.GRADLE, getPlatformDescriptor()) + return new AddExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @@ -44,7 +42,7 @@ protected QuarkusCommandOutcome addExtensions(final List extensions) thr @Override protected QuarkusCommandOutcome removeExtensions(final List extensions) throws IOException, QuarkusCommandException { - return new RemoveExtensions(new FileProjectWriter(getProjectPath().toFile()), BuildTool.GRADLE, getPlatformDescriptor()) + return new RemoveExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @@ -57,6 +55,10 @@ protected long countDependencyOccurrences(final List buildFile, final St .count(); } + private QuarkusProject getQuarkusProject() { + return QuarkusProject.of(getProjectPath(), getPlatformDescriptor(), BuildTool.GRADLE); + } + private static String getBuildFileDependencyString(final String groupId, final String artifactId, final String version) { final String versionPart = version != null ? ":" + version : ""; return " implementation '" + groupId + ":" + artifactId + versionPart + "'"; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java index 00fbc1ad1da3c..6e8f30f6004bb 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java @@ -1,6 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; import java.io.IOException; @@ -15,7 +16,7 @@ class RemoveMavenExtensionsTest extends AbstractRemoveExtensionsTest { protected Model createProject() throws IOException, QuarkusCommandException { final File pom = getProjectPath().resolve("pom.xml").toFile(); CreateProjectTest.delete(getProjectPath().toFile()); - new CreateProject(new FileProjectWriter(getProjectPath().toFile()), getPlatformDescriptor()) + new CreateProject(getProjectPath(), getPlatformDescriptor()) .groupId("org.acme") .artifactId("add-maven-extension-test") .version("0.0.1-SNAPSHOT") @@ -29,15 +30,15 @@ protected Model readProject() throws IOException { } @Override - protected QuarkusCommandOutcome removeExtensions(List extensions) throws IOException, QuarkusCommandException { - return new RemoveExtensions(new FileProjectWriter(getProjectPath().toFile()), getPlatformDescriptor()) + protected QuarkusCommandOutcome removeExtensions(List extensions) throws QuarkusCommandException { + return new RemoveExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @Override - protected QuarkusCommandOutcome addExtensions(List extensions) throws IOException, QuarkusCommandException { - return new AddExtensions(new FileProjectWriter(getProjectPath().toFile()), getPlatformDescriptor()) + protected QuarkusCommandOutcome addExtensions(List extensions) throws QuarkusCommandException { + return new AddExtensions(getQuarkusProject()) .extensions(new HashSet<>(extensions)) .execute(); } @@ -49,4 +50,8 @@ protected long countDependencyOccurrences(final Model project, final String grou d.getArtifactId().equals(artifactId) && Objects.equals(d.getVersion(), version)).count(); } + + private QuarkusProject getQuarkusProject() { + return QuarkusProject.of(getProjectPath(), getPlatformDescriptor(), BuildTool.MAVEN); + } } diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java index 07023678de5e3..557ec4c4e6080 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java @@ -21,14 +21,14 @@ import io.quarkus.bootstrap.util.IoUtils; import io.quarkus.cli.commands.PlatformAwareTestBase; import io.quarkus.cli.commands.QuarkusCommandInvocation; +import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.cli.commands.writer.FileProjectWriter; import io.quarkus.cli.commands.writer.ProjectWriter; -import io.quarkus.generators.BuildTool; import io.quarkus.generators.SourceType; import io.quarkus.maven.utilities.MojoUtils; -import java.io.File; -import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -62,12 +62,12 @@ void generateMultipleTimes() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(20); final BasicRestProjectGenerator basicRestProjectGenerator = new BasicRestProjectGenerator(); List> collect = IntStream.range(0, 20).boxed().map(i -> (Callable) () -> { - final File file = Files.createTempDirectory("test").toFile(); - try (FileProjectWriter writer = new FileProjectWriter(file)) { + final Path path = Files.createTempDirectory("test"); + try (FileProjectWriter writer = new FileProjectWriter(path.toFile())) { basicRestProjectGenerator.generate(writer, - createQuarkusCommandInvocation(writer)); + createQuarkusCommandInvocation(path)); } finally { - IoUtils.recursiveDelete(file.toPath()); + IoUtils.recursiveDelete(path); } latch.countDown(); return null; @@ -80,12 +80,13 @@ void generateMultipleTimes() throws InterruptedException { @DisplayName("Should generate project files with basic context") void generateFilesWithJaxRsResource() throws Exception { final ProjectWriter mockWriter = mock(ProjectWriter.class); + final Path mockProjectPath = mock(Path.class); final BasicRestProjectGenerator basicRestProjectGenerator = new BasicRestProjectGenerator(); when(mockWriter.mkdirs(anyString())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0, String.class)); basicRestProjectGenerator.generate(mockWriter, - createQuarkusCommandInvocation(mockWriter)); + createQuarkusCommandInvocation(mockProjectPath)); verify(mockWriter, times(10)).mkdirs(anyString()); verify(mockWriter, times(3)).mkdirs(""); @@ -120,11 +121,12 @@ void generateFilesWithJaxRsResource() throws Exception { @DisplayName("Should generate project files with basic spring web context") void generateFilesWithSpringControllerResource() throws Exception { final ProjectWriter mockWriter = mock(ProjectWriter.class); + final Path mockProjectPath = mock(Path.class); final BasicRestProjectGenerator basicRestProjectGenerator = new BasicRestProjectGenerator(); when(mockWriter.mkdirs(anyString())).thenAnswer(invocationOnMock -> invocationOnMock.getArgument(0, String.class)); - QuarkusCommandInvocation springContext = createQuarkusCommandInvocation(mockWriter); + QuarkusCommandInvocation springContext = createQuarkusCommandInvocation(mockProjectPath); springContext.setValue(IS_SPRING, Boolean.TRUE); basicRestProjectGenerator.generate(mockWriter, springContext); @@ -135,9 +137,9 @@ void generateFilesWithSpringControllerResource() throws Exception { } - private QuarkusCommandInvocation createQuarkusCommandInvocation(ProjectWriter writer) throws IOException { - return new QuarkusCommandInvocation(BASIC_PROJECT_CONTEXT, getPlatformDescriptor(), - writer, BuildTool.MAVEN.createBuildFile(writer)); + private QuarkusCommandInvocation createQuarkusCommandInvocation(Path projectPath) { + return new QuarkusCommandInvocation(QuarkusProject.of(projectPath, getPlatformDescriptor(), BuildTool.MAVEN), + BASIC_PROJECT_CONTEXT); } } From 6b304180d91f3c569b1b8beab6ce88b4ae1fa268 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Wed, 27 May 2020 13:57:56 +0200 Subject: [PATCH 2/5] Clean package structure --- .../io/quarkus/cli/commands/AddExtensionCommand.java | 2 +- .../io/quarkus/cli/commands/ListExtensionsCommand.java | 2 +- .../quarkus/cli/commands/RemoveExtensionCommand.java | 2 +- .../io/quarkus/gradle/QuarkusPluginFunctionalTest.java | 2 +- .../quarkus/gradle/GradleBuildFileFromConnector.java | 4 ++-- .../io/quarkus/gradle/tasks/QuarkusListExtensions.java | 4 ++-- .../io/quarkus/gradle/tasks/QuarkusPlatformTask.java | 8 ++++---- .../java/io/quarkus/gradle/GradleBuildFileTest.java | 2 +- .../main/java/io/quarkus/maven/AddExtensionMojo.java | 2 +- .../main/java/io/quarkus/maven/BuildFileMojoBase.java | 10 +++++----- .../main/java/io/quarkus/maven/CreateProjectMojo.java | 4 ++-- .../main/java/io/quarkus/maven/ListExtensionsMojo.java | 2 +- .../java/io/quarkus/maven/RemoveExtensionMojo.java | 2 +- .../java/io/quarkus/cli/commands/AddExtensions.java | 2 +- .../cli/commands/AddExtensionsCommandHandler.java | 2 +- .../java/io/quarkus/cli/commands/CreateProject.java | 4 ++-- .../cli/commands/CreateProjectCommandHandler.java | 6 +++--- .../java/io/quarkus/cli/commands/ListExtensions.java | 2 +- .../cli/commands/ListExtensionsCommandHandler.java | 4 ++-- .../quarkus/cli/commands/QuarkusCommandInvocation.java | 4 ++-- .../java/io/quarkus/cli/commands/RemoveExtensions.java | 2 +- .../cli/commands/RemoveExtensionsCommandHandler.java | 2 +- .../file => devtools/buildfile}/BuildFile.java | 6 +++--- .../file => devtools/buildfile}/GradleBuildFile.java | 6 +++--- .../file => devtools/buildfile}/MavenBuildFile.java | 6 +++--- .../{cli/commands => devtools}/project/BuildTool.java | 10 +++++----- .../commands => devtools}/project/QuarkusProject.java | 6 +++--- .../writer/FileProjectWriter.java | 2 +- .../commands => devtools}/writer/ProjectWriter.java | 2 +- .../java/io/quarkus/generators/ProjectGenerator.java | 2 +- .../generators/rest/BasicRestProjectGenerator.java | 4 ++-- .../quarkus/cli/commands/AddGradleExtensionsTest.java | 4 ++-- .../quarkus/cli/commands/AddMavenExtensionsTest.java | 4 ++-- .../io/quarkus/cli/commands/CreateProjectTest.java | 4 ++-- .../io/quarkus/cli/commands/ListExtensionsTest.java | 4 ++-- .../cli/commands/RemoveGradleExtensionsTest.java | 4 ++-- .../cli/commands/RemoveMavenExtensionsTest.java | 4 ++-- .../generators/rest/BasicRestProjectGeneratorTest.java | 8 ++++---- 38 files changed, 75 insertions(+), 75 deletions(-) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands/file => devtools/buildfile}/BuildFile.java (97%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands/file => devtools/buildfile}/GradleBuildFile.java (99%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands/file => devtools/buildfile}/MavenBuildFile.java (98%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands => devtools}/project/BuildTool.java (86%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands => devtools}/project/QuarkusProject.java (93%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands => devtools}/writer/FileProjectWriter.java (98%) rename independent-projects/tools/common/src/main/java/io/quarkus/{cli/commands => devtools}/writer/ProjectWriter.java (93%) 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 d221c3d369481..f28858c67e830 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 @@ -14,8 +14,8 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java index 09e83b87d7e12..380c4f6d04a95 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/ListExtensionsCommand.java @@ -11,7 +11,7 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; /** diff --git a/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java b/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java index d617a2063c190..cc3b718276cfc 100644 --- a/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java +++ b/devtools/aesh/src/main/java/io/quarkus/cli/commands/RemoveExtensionCommand.java @@ -14,8 +14,8 @@ import org.aesh.command.option.Option; import org.aesh.io.Resource; -import io.quarkus.cli.commands.project.QuarkusProject; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; diff --git a/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java b/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java index 85ddb2ff5ae78..38cfcc6d75e9e 100644 --- a/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java +++ b/devtools/gradle/src/functionalTest/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableMap; import io.quarkus.cli.commands.CreateProject; -import io.quarkus.cli.commands.project.BuildTool; +import io.quarkus.devtools.project.BuildTool; import io.quarkus.generators.SourceType; import io.quarkus.platform.tools.config.QuarkusPlatformConfig; import io.quarkus.test.devmode.util.DevModeTestUtils; diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/GradleBuildFileFromConnector.java b/devtools/gradle/src/main/java/io/quarkus/gradle/GradleBuildFileFromConnector.java index ad8a05bfd42e4..01c4102868f7b 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/GradleBuildFileFromConnector.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/GradleBuildFileFromConnector.java @@ -13,8 +13,8 @@ import org.gradle.tooling.model.eclipse.EclipseExternalDependency; import org.gradle.tooling.model.eclipse.EclipseProject; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.buildfile.GradleBuildFile; +import io.quarkus.devtools.writer.ProjectWriter; public class GradleBuildFileFromConnector extends GradleBuildFile { diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java index f5f3c721be38e..833679f5c61dd 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusListExtensions.java @@ -7,8 +7,8 @@ import org.gradle.api.tasks.options.Option; import io.quarkus.cli.commands.ListExtensions; -import io.quarkus.cli.commands.project.QuarkusProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.devtools.project.QuarkusProject; +import io.quarkus.devtools.writer.FileProjectWriter; import io.quarkus.gradle.GradleBuildFileFromConnector; public class QuarkusListExtensions extends QuarkusPlatformTask { diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java index 5fcfdab8bdcaf..3433f111bb2ce 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusPlatformTask.java @@ -10,10 +10,10 @@ import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.tasks.Internal; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.project.QuarkusProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.buildfile.GradleBuildFile; +import io.quarkus.devtools.project.QuarkusProject; +import io.quarkus.devtools.writer.FileProjectWriter; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.platform.descriptor.CombinedQuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver; diff --git a/devtools/gradle/src/test/java/io/quarkus/gradle/GradleBuildFileTest.java b/devtools/gradle/src/test/java/io/quarkus/gradle/GradleBuildFileTest.java index c2c7f63177d3f..899513bec48f5 100644 --- a/devtools/gradle/src/test/java/io/quarkus/gradle/GradleBuildFileTest.java +++ b/devtools/gradle/src/test/java/io/quarkus/gradle/GradleBuildFileTest.java @@ -20,7 +20,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.devtools.writer.FileProjectWriter; class GradleBuildFileTest { 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 d0b4ac53431bd..115d681b095af 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/AddExtensionMojo.java @@ -12,7 +12,7 @@ import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.QuarkusCommandOutcome; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** diff --git a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java index 9eba672cfcfc7..3a0e7d63467bf 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java @@ -19,11 +19,11 @@ import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.MavenBuildFile; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.buildfile.MavenBuildFile; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; +import io.quarkus.devtools.writer.FileProjectWriter; import io.quarkus.platform.descriptor.CombinedQuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver; 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 99edf9fca6d29..b560894b9ac45 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java @@ -48,8 +48,8 @@ import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.cli.commands.AddExtensions; import io.quarkus.cli.commands.CreateProject; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.generators.SourceType; import io.quarkus.maven.components.MavenVersionEnforcer; import io.quarkus.maven.components.Prompter; diff --git a/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java index 842724ba0264d..64486a685a6fa 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/ListExtensionsMojo.java @@ -5,7 +5,7 @@ import org.apache.maven.plugins.annotations.Parameter; import io.quarkus.cli.commands.ListExtensions; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** diff --git a/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java index 2b011f3eb8a98..827f258f59243 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/RemoveExtensionMojo.java @@ -12,7 +12,7 @@ import io.quarkus.cli.commands.QuarkusCommandOutcome; import io.quarkus.cli.commands.RemoveExtensions; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.MessageWriter; /** diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java index d75936449307c..b0b1462bae823 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensions.java @@ -1,6 +1,6 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; import java.util.Set; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java index 34c1637acc9bd..89b368280a333 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.BuildFile; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.buildfile.BuildFile; import java.io.IOException; import java.util.Collections; import java.util.LinkedHashSet; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java index 53fd82f091813..0f01b9bc452fc 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProject.java @@ -9,8 +9,8 @@ import static io.quarkus.generators.ProjectGenerator.PROJECT_VERSION; import static io.quarkus.generators.ProjectGenerator.SOURCE_TYPE; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.generators.SourceType; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import java.io.IOException; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java index 1cff787afcd35..3bd04bea6cd84 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/CreateProjectCommandHandler.java @@ -2,9 +2,9 @@ import static io.quarkus.generators.ProjectGenerator.*; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.writer.FileProjectWriter; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.generators.ProjectGeneratorRegistry; import io.quarkus.generators.SourceType; import io.quarkus.generators.rest.BasicRestProjectGenerator; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java index ded612145d7b0..6f9fd3adbc438 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensions.java @@ -1,6 +1,6 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; import java.io.IOException; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java index 514a5089f583d..4f5f1fe82ea24 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/ListExtensionsCommandHandler.java @@ -1,8 +1,8 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.GradleBuildFile; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.buildfile.GradleBuildFile; import java.io.IOException; import java.util.List; import java.util.Map; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java index bd5005b1c7b0e..3f2de476c5a9e 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/QuarkusCommandInvocation.java @@ -2,8 +2,8 @@ import static com.google.common.base.Preconditions.checkNotNull; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.DefaultMessageWriter; import io.quarkus.platform.tools.MessageWriter; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java index 7882a1882daf9..5e6c2b6de8ed5 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensions.java @@ -1,6 +1,6 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.platform.tools.ToolsConstants; import io.quarkus.platform.tools.ToolsUtils; import java.util.Set; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensionsCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensionsCommandHandler.java index b6beeda430cf4..24aea2fa73a71 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensionsCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/RemoveExtensionsCommandHandler.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.file.BuildFile; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.buildfile.BuildFile; import java.io.IOException; import java.util.Collections; import java.util.List; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/BuildFile.java similarity index 97% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/BuildFile.java index e21b6b6e91895..725e0a2e5e8d1 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/BuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/BuildFile.java @@ -1,13 +1,13 @@ -package io.quarkus.cli.commands.file; +package io.quarkus.devtools.buildfile; import static com.google.common.base.Preconditions.checkNotNull; import static io.quarkus.maven.utilities.MojoUtils.credentials; import static java.util.stream.Collectors.toList; import io.quarkus.cli.commands.Printer; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.QuarkusDependencyPredicate; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/GradleBuildFile.java similarity index 99% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/GradleBuildFile.java index 81db70c94d099..e148e30bfe82e 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/GradleBuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/GradleBuildFile.java @@ -1,8 +1,8 @@ -package io.quarkus.cli.commands.file; +package io.quarkus.devtools.buildfile; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import io.quarkus.platform.tools.ToolsUtils; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/MavenBuildFile.java similarity index 98% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/MavenBuildFile.java index 658cd81640840..df55a72c8e6bd 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/file/MavenBuildFile.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/buildfile/MavenBuildFile.java @@ -1,11 +1,11 @@ -package io.quarkus.cli.commands.file; +package io.quarkus.devtools.buildfile; import static io.quarkus.maven.utilities.MojoUtils.configuration; import static io.quarkus.maven.utilities.MojoUtils.plugin; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.writer.ProjectWriter; import io.quarkus.dependencies.Extension; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.MojoUtils.Element; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/BuildTool.java similarity index 86% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/BuildTool.java index dceb81fa369eb..0987465b3c1b3 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/BuildTool.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/BuildTool.java @@ -1,11 +1,11 @@ -package io.quarkus.cli.commands.project; +package io.quarkus.devtools.project; import static com.google.common.base.Preconditions.checkNotNull; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.file.GradleBuildFile; -import io.quarkus.cli.commands.file.MavenBuildFile; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.buildfile.GradleBuildFile; +import io.quarkus.devtools.buildfile.MavenBuildFile; +import io.quarkus.devtools.writer.ProjectWriter; /** * An enum of build tools, such as Maven and Gradle. diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java similarity index 93% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java index c183e1e4327a6..9e2648fefebe8 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/project/QuarkusProject.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java @@ -1,9 +1,9 @@ -package io.quarkus.cli.commands.project; +package io.quarkus.devtools.project; import static com.google.common.base.Preconditions.checkNotNull; -import io.quarkus.cli.commands.file.BuildFile; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.devtools.buildfile.BuildFile; +import io.quarkus.devtools.writer.FileProjectWriter; import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor; import java.nio.file.Path; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/FileProjectWriter.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/FileProjectWriter.java similarity index 98% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/FileProjectWriter.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/FileProjectWriter.java index 7f2cd30d32156..35e4a2d4e1e52 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/FileProjectWriter.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/FileProjectWriter.java @@ -1,7 +1,7 @@ /** * */ -package io.quarkus.cli.commands.writer; +package io.quarkus.devtools.writer; import java.io.File; import java.io.IOException; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ProjectWriter.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/ProjectWriter.java similarity index 93% rename from independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ProjectWriter.java rename to independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/ProjectWriter.java index 9230d111b30a7..45e75607edac7 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/writer/ProjectWriter.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/writer/ProjectWriter.java @@ -1,7 +1,7 @@ /** * */ -package io.quarkus.cli.commands.writer; +package io.quarkus.devtools.writer; import java.io.Closeable; import java.io.File; diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/generators/ProjectGenerator.java b/independent-projects/tools/common/src/main/java/io/quarkus/generators/ProjectGenerator.java index 1579d6c9a1971..518e86f0505c2 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/generators/ProjectGenerator.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/generators/ProjectGenerator.java @@ -1,7 +1,7 @@ package io.quarkus.generators; import io.quarkus.cli.commands.QuarkusCommandInvocation; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.writer.ProjectWriter; import java.io.IOException; public interface ProjectGenerator { diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java b/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java index 83917b7d3c6cf..9578e9be6f54f 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java @@ -3,8 +3,8 @@ import static java.lang.String.format; import io.quarkus.cli.commands.QuarkusCommandInvocation; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.generators.ProjectGenerator; import io.quarkus.generators.SourceType; import io.quarkus.maven.utilities.MojoUtils; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java index 50c6ba209740e..f080c5fffff4a 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddGradleExtensionsTest.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import java.io.IOException; import java.nio.file.Files; import java.util.HashSet; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java index f8293b65a5c22..57ee06f705246 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/AddMavenExtensionsTest.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; import java.io.IOException; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java index 40686de1059e8..194b7c10bc9ba 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java @@ -4,8 +4,8 @@ import static org.assertj.core.api.Assertions.contentOf; import static org.junit.jupiter.api.Assertions.assertTrue; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.writer.FileProjectWriter; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.writer.FileProjectWriter; import io.quarkus.generators.ProjectGenerator; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java index 5d86bf108c866..cd039e61c49a6 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/ListExtensionsTest.java @@ -5,8 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import io.quarkus.maven.utilities.QuarkusDependencyPredicate; import java.io.ByteArrayOutputStream; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java index 74a75d73b19f1..2348a72ba3361 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveGradleExtensionsTest.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import java.io.IOException; import java.nio.file.Files; import java.util.HashSet; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java index 6e8f30f6004bb..57971f118a4ed 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/RemoveMavenExtensionsTest.java @@ -1,7 +1,7 @@ package io.quarkus.cli.commands; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.maven.utilities.MojoUtils; import java.io.File; import java.io.IOException; diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java index 557ec4c4e6080..1ca8d1441dc64 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/generators/rest/BasicRestProjectGeneratorTest.java @@ -21,10 +21,10 @@ import io.quarkus.bootstrap.util.IoUtils; import io.quarkus.cli.commands.PlatformAwareTestBase; import io.quarkus.cli.commands.QuarkusCommandInvocation; -import io.quarkus.cli.commands.project.BuildTool; -import io.quarkus.cli.commands.project.QuarkusProject; -import io.quarkus.cli.commands.writer.FileProjectWriter; -import io.quarkus.cli.commands.writer.ProjectWriter; +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.QuarkusProject; +import io.quarkus.devtools.writer.FileProjectWriter; +import io.quarkus.devtools.writer.ProjectWriter; import io.quarkus.generators.SourceType; import io.quarkus.maven.utilities.MojoUtils; import java.nio.file.Files; From 658d730226e43c155dc16fb43c4f1989c144bc96 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 28 May 2020 09:55:40 +0200 Subject: [PATCH 3/5] Fix multiple close overriding modification when adding extensions --- .../src/main/java/io/quarkus/maven/BuildFileMojoBase.java | 8 -------- .../quarkus/cli/commands/AddExtensionsCommandHandler.java | 1 - 2 files changed, 9 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java index 3a0e7d63467bf..961abc3440c53 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/BuildFileMojoBase.java @@ -124,14 +124,6 @@ public void execute() throws MojoExecutionException { doExecute(QuarkusProject.of(project.getBasedir().toPath(), platformDescr, buildTool), log); } catch (IOException e) { throw new MojoExecutionException("Failed to initialize project reading tools", e); - } finally { - if (buildFile != null) { - try { - buildFile.close(); - } catch (IOException e) { - log.debug("Failed to close %s", buildFile, e); - } - } } } diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java index 89b368280a333..6541aa6992b7c 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/cli/commands/AddExtensionsCommandHandler.java @@ -35,7 +35,6 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws final BuildFile buildFile = invocation.getBuildFile(); try { for (String query : extensions) { - if (query.contains(":")) { // GAV case. updated = buildFile.addExtensionAsGAV(query) || updated; From 8a3c24d4718d24d8f8743ddc91425b132209c069 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 28 May 2020 10:54:45 +0200 Subject: [PATCH 4/5] Minor refactor in QuarkusProject --- .../devtools/project/QuarkusProject.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java index 9e2648fefebe8..8d6ef03e40831 100644 --- a/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/QuarkusProject.java @@ -33,13 +33,11 @@ public static QuarkusProject of(final Path projectFolderPath, final QuarkusPlatf public static QuarkusProject resolveExistingProject(final Path projectFolderPath, final QuarkusPlatformDescriptor descriptor) { - if (projectFolderPath.resolve("pom.xml").toFile().exists()) { - return of(projectFolderPath, descriptor, BuildTool.MAVEN); - } else if (projectFolderPath.resolve("build.gradle").toFile().exists() - || projectFolderPath.resolve("build.gradle.kts").toFile().exists()) { - return of(projectFolderPath, descriptor, BuildTool.GRADLE); + final BuildTool buildTool = resolveExistingProjectBuildTool(projectFolderPath); + if (buildTool == null) { + throw new IllegalStateException("This is neither a Maven or Gradle project"); } - throw new IllegalStateException("This is neither a Maven or Gradle project"); + return of(projectFolderPath, descriptor, buildTool); } public Path getProjectFolderPath() { @@ -57,4 +55,14 @@ public BuildTool getBuildTool() { public QuarkusPlatformDescriptor getDescriptor() { return descriptor; } + + private static BuildTool resolveExistingProjectBuildTool(Path projectFolderPath) { + if (projectFolderPath.resolve("pom.xml").toFile().exists()) { + return BuildTool.MAVEN; + } else if (projectFolderPath.resolve("build.gradle").toFile().exists() + || projectFolderPath.resolve("build.gradle.kts").toFile().exists()) { + return BuildTool.GRADLE; + } + return null; + } } From 2e7b78b331d7c4422dfa86d122f4af1dd3b1865a Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 28 May 2020 10:55:51 +0200 Subject: [PATCH 5/5] Introduce QuarkusProjectCompress to zip QuarkusProject --- independent-projects/tools/common/pom.xml | 4 + .../compress/QuarkusProjectCompress.java | 91 ++++++++++++ .../cli/commands/CreateProjectTest.java | 61 -------- .../compress/QuarkusProjectCompressTest.java | 135 ++++++++++++++++++ independent-projects/tools/pom.xml | 6 + 5 files changed, 236 insertions(+), 61 deletions(-) create mode 100644 independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/compress/QuarkusProjectCompress.java create mode 100644 independent-projects/tools/common/src/test/java/io/quarkus/devtools/project/compress/QuarkusProjectCompressTest.java diff --git a/independent-projects/tools/common/pom.xml b/independent-projects/tools/common/pom.xml index bd14aa52c6cb4..533c21b0773bf 100644 --- a/independent-projects/tools/common/pom.xml +++ b/independent-projects/tools/common/pom.xml @@ -39,6 +39,10 @@ io.quarkus quarkus-platform-descriptor-api + + org.apache.commons + commons-compress + org.apache.maven maven-plugin-api diff --git a/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/compress/QuarkusProjectCompress.java b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/compress/QuarkusProjectCompress.java new file mode 100644 index 0000000000000..ec693726f96c9 --- /dev/null +++ b/independent-projects/tools/common/src/main/java/io/quarkus/devtools/project/compress/QuarkusProjectCompress.java @@ -0,0 +1,91 @@ +package io.quarkus.devtools.project.compress; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; +import io.quarkus.devtools.project.QuarkusProject; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import org.apache.commons.compress.archivers.zip.UnixStat; +import org.apache.commons.compress.archivers.zip.X5455_ExtendedTimestamp; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; +import org.apache.commons.compress.archivers.zip.ZipExtraField; +import org.apache.commons.compress.archivers.zip.ZipLong; + +public final class QuarkusProjectCompress { + + private static final List EXECUTABLES = ImmutableList.of( + "gradlew", + "gradlew.bat", + "mvnw", + "mvnw.bat"); + + @VisibleForTesting + static final int DIR_UNIX_MODE = UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM; + + private QuarkusProjectCompress() { + } + + public static void zip(final QuarkusProject quarkusProject, final Path targetZipPath, final boolean includeProjectFolder) + throws IOException { + zip(quarkusProject, targetZipPath, includeProjectFolder, null); + } + + public static void zip(final QuarkusProject quarkusProject, final Path targetZipPath, final boolean includeProjectFolder, + final Long withSpecificFilesTime) throws IOException { + try (final ZipArchiveOutputStream zaos = new ZipArchiveOutputStream(Files.newOutputStream(targetZipPath))) { + final Path projectFolderPath = quarkusProject.getProjectFolderPath(); + Files.walk(projectFolderPath) + .filter((path) -> includeProjectFolder || !projectFolderPath.equals(path)) + .forEach((path) -> { + try { + String entryName = projectFolderPath.relativize(path).toString().replace('\\', '/'); + if (includeProjectFolder) { + entryName = projectFolderPath.getFileName() + "/" + entryName; + } + int unixMode; + if (Files.isDirectory(path)) { + entryName += "/"; + unixMode = DIR_UNIX_MODE; + } else { + unixMode = getFileUnixMode(isExecutable(entryName)); + } + final ZipArchiveEntry entry = new ZipArchiveEntry(path.toFile(), entryName); + entry.setUnixMode(unixMode); + if (withSpecificFilesTime != null) { + entry.setExtraFields(new ZipExtraField[] { getTimestamp(withSpecificFilesTime) }); + } + zaos.putArchiveEntry(entry); + if (!Files.isDirectory(path)) { + Files.copy(path, zaos); + } + zaos.closeArchiveEntry(); + } catch (final IOException e) { + throw new UncheckedIOException(e); + } + }); + } + } + + @VisibleForTesting + static int getFileUnixMode(boolean isExecutable) { + return UnixStat.FILE_FLAG | (isExecutable ? 0755 : UnixStat.DEFAULT_FILE_PERM); + } + + @VisibleForTesting + static boolean isExecutable(final String entryName) { + return EXECUTABLES.stream().anyMatch(entryName::contains); + } + + private static X5455_ExtendedTimestamp getTimestamp(final long time) { + final X5455_ExtendedTimestamp timestamp = new X5455_ExtendedTimestamp(); + final ZipLong zipTime = new ZipLong(time / 1000); + timestamp.setCreateTime(zipTime); + timestamp.setModifyTime(zipTime); + timestamp.setAccessTime(zipTime); + return timestamp; + } +} diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java index 194b7c10bc9ba..44cbd56da51ea 100644 --- a/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java +++ b/independent-projects/tools/common/src/test/java/io/quarkus/cli/commands/CreateProjectTest.java @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; -import java.util.zip.ZipEntry; import org.apache.maven.model.Model; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DisplayName; @@ -297,53 +296,6 @@ public static void delete(final File file) throws IOException { Files.exists(file.toPath()), "Directory still exists"); } - // FIXME Zip (previously done by ZipProjectWriter) for Quarkus projects is going to be replaced by a way to zip the project folder, we can make this test work again once this is done - /** - * @Test - * public void createZip() throws Exception { - * final File file = new File("target/zip"); - * delete(file); - * file.mkdirs(); - * File zipFile = new File(file, "project.zip"); - * try (FileOutputStream fos = new FileOutputStream(zipFile); - * ZipOutputStream zos = new ZipOutputStream(fos); - * ZipProjectWriter zipWriter = new ZipProjectWriter(zos)) { - * final QuarkusCommandOutcome result = new CreateProject(zipWriter, getPlatformDescriptor()) - * .groupId("org.acme") - * .artifactId("basic-rest") - * .version("1.0.0-SNAPSHOT") - * .execute(); - * assertTrue(result.isSuccess()); - * } - * assertTrue(zipFile.exists()); - * File unzipProject = new File(file, "unzipProject"); - * try (FileInputStream fis = new FileInputStream(zipFile); ZipInputStream zis = new ZipInputStream(fis)) { - * ZipEntry zipEntry = zis.getNextEntry(); - * byte[] buffer = new byte[1024]; - * while (zipEntry != null) { - * File newFile = newFile(unzipProject, zipEntry); - * if (zipEntry.isDirectory()) { - * newFile.mkdirs(); - * } else { - * new File(newFile.getParent()).mkdirs(); - * FileOutputStream fos = new FileOutputStream(newFile); - * int len; - * while ((len = zis.read(buffer)) > 0) { - * fos.write(buffer, 0, len); - * } - * fos.close(); - * } - * zipEntry = zis.getNextEntry(); - * } - * zis.closeEntry(); - * } - * final File gitignore = new File(unzipProject, ".gitignore"); - * assertTrue(gitignore.exists()); - * final String gitignoreContent = new String(Files.readAllBytes(gitignore.toPath()), StandardCharsets.UTF_8); - * assertTrue(gitignoreContent.contains("\ntarget/\n")); - * } - **/ - private void createProject(final File file, String groupId, String artifactId, String version) throws QuarkusCommandException { createProject(BuildTool.MAVEN, file, groupId, artifactId, version); @@ -359,17 +311,4 @@ private void createProject(BuildTool buildTool, File file, String groupId, Strin .execute(); assertTrue(result.isSuccess()); } - - private static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { - File destFile = new File(destinationDir, zipEntry.getName()); - - String destDirPath = destinationDir.getCanonicalPath(); - String destFilePath = destFile.getCanonicalPath(); - - if (!destFilePath.startsWith(destDirPath + File.separator)) { - throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); - } - - return destFile; - } } diff --git a/independent-projects/tools/common/src/test/java/io/quarkus/devtools/project/compress/QuarkusProjectCompressTest.java b/independent-projects/tools/common/src/test/java/io/quarkus/devtools/project/compress/QuarkusProjectCompressTest.java new file mode 100644 index 0000000000000..33b014420a00c --- /dev/null +++ b/independent-projects/tools/common/src/test/java/io/quarkus/devtools/project/compress/QuarkusProjectCompressTest.java @@ -0,0 +1,135 @@ +package io.quarkus.devtools.project.compress; + +import static io.quarkus.devtools.project.compress.QuarkusProjectCompress.DIR_UNIX_MODE; +import static io.quarkus.devtools.project.compress.QuarkusProjectCompress.zip; +import static org.apache.commons.io.FileUtils.contentEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import io.quarkus.cli.commands.CreateProject; +import io.quarkus.cli.commands.CreateProjectTest; +import io.quarkus.cli.commands.PlatformAwareTestBase; +import io.quarkus.cli.commands.QuarkusCommandException; +import io.quarkus.cli.commands.QuarkusCommandOutcome; +import io.quarkus.devtools.project.QuarkusProject; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import org.junit.jupiter.api.Test; + +class QuarkusProjectCompressTest extends PlatformAwareTestBase { + + @Test + public void createZip() throws Exception { + // Given a Quarkus project + final Path testDir = Paths.get("target/zip"); + CreateProjectTest.delete(testDir.toFile()); + testDir.toFile().mkdirs(); + Path zip = testDir.resolve("project.zip"); + + final Path projectPath = createProject(testDir); + + // When zipping without including the project directory + zip(QuarkusProject.resolveExistingProject(projectPath, getPlatformDescriptor()), zip, false); + assertTrue(zip.toFile().exists()); + + // Then the zip content is valid + final Path unzipProject = testDir.resolve("unzipProject"); + unzip(zip, unzipProject); + + checkUnzipped(projectPath, unzipProject); + } + + @Test + public void createZipWithParentFolder() throws Exception { + // Given a Quarkus project + final Path testDir = Paths.get("target/zip"); + CreateProjectTest.delete(testDir.toFile()); + testDir.toFile().mkdirs(); + Path zip = testDir.resolve("project.zip"); + + final Path projectPath = createProject(testDir); + + // When zipping without including the project directory + zip(QuarkusProject.resolveExistingProject(projectPath, getPlatformDescriptor()), zip, true); + assertTrue(zip.toFile().exists()); + + // Then the zip content is valid and included in a parent folder + final Path unzipProject = testDir.resolve("unzipProject"); + unzip(zip, unzipProject); + + checkUnzipped(projectPath, unzipProject.resolve(projectPath.getFileName())); + } + + @Test + void checkUnixMode() { + assertEquals(DIR_UNIX_MODE, 040755); + assertEquals(QuarkusProjectCompress.getFileUnixMode(true), 0100755); + assertEquals(QuarkusProjectCompress.getFileUnixMode(false), 0100644); + } + + private void checkUnzipped(Path projectPath, Path unzipProject) throws IOException { + assertTrue(contentEquals(unzipProject.resolve(".gitignore").toFile(), projectPath.resolve(".gitignore").toFile())); + assertTrue(contentEquals(unzipProject.resolve("pom.xml").toFile(), projectPath.resolve("pom.xml").toFile())); + } + + private Path createProject(Path testDir) throws QuarkusCommandException, IOException { + final Path projectPath = testDir.resolve("project"); + final QuarkusCommandOutcome result = new CreateProject(projectPath, getPlatformDescriptor()) + .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; + } + + private static void unzip(final Path zipPath, final Path outputDir) throws IOException { + try (FileInputStream fis = new FileInputStream(zipPath.toFile()); ZipInputStream zis = new ZipInputStream(fis)) { + ZipEntry zipEntry = zis.getNextEntry(); + byte[] buffer = new byte[1024]; + while (zipEntry != null) { + File newFile = createEntryFile(outputDir.toFile(), zipEntry); + if (zipEntry.isDirectory()) { + newFile.mkdirs(); + } else { + new File(newFile.getParent()).mkdirs(); + FileOutputStream fos = new FileOutputStream(newFile); + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + fos.close(); + } + zipEntry = zis.getNextEntry(); + } + zis.closeEntry(); + } + } + + private static File createEntryFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); + + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); + + if (!destFilePath.startsWith(destDirPath + File.separator)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } + + return destFile; + } + +} diff --git a/independent-projects/tools/pom.xml b/independent-projects/tools/pom.xml index 72f76687299e0..4ab04fce0faec 100644 --- a/independent-projects/tools/pom.xml +++ b/independent-projects/tools/pom.xml @@ -44,6 +44,7 @@ 4.0.3 1.1.2 5.6.1 + 1.20 3.3.2.Final 3.6.3 3.3.3 @@ -59,6 +60,11 @@ + + org.apache.commons + commons-compress + ${commons-compress.version} + com.eclipsesource.minimal-json minimal-json