Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce QuarkusProject and Quarkus project zipping in codegen #9631

Merged
merged 5 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,8 +14,8 @@
import org.aesh.command.option.Option;
import org.aesh.io.Resource;

import io.quarkus.cli.commands.writer.FileProjectWriter;
import io.quarkus.dependencies.Extension;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;

Expand All @@ -30,8 +31,8 @@ public class AddExtensionCommand implements Command<CommandInvocation> {
@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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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.devtools.project.QuarkusProject;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;

/**
Expand All @@ -36,29 +32,18 @@ public class ListExtensionsCommand implements Command<CommandInvocation> {
@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 {
if (help) {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,8 +14,8 @@
import org.aesh.command.option.Option;
import org.aesh.io.Resource;

import io.quarkus.cli.commands.writer.FileProjectWriter;
import io.quarkus.dependencies.Extension;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;

Expand All @@ -27,8 +28,8 @@ public class RemoveExtensionCommand implements Command<CommandInvocation> {
@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 {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.devtools.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 {

Expand Down Expand Up @@ -155,7 +150,7 @@ private BuildResult runTask(List<String> arguments) {
private void createProject(SourceType sourceType) throws IOException {
Map<String, Object> 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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void addExtension() {
.collect(toSet());

try {
new AddExtensions(getWriter(), getGradleBuildFile(), platformDescriptor())
new AddExtensions(getQuarkusProject())
.extensions(extensionsSet)
.execute();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.gradle.api.tasks.options.Option;

import io.quarkus.cli.commands.ListExtensions;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.writer.FileProjectWriter;
import io.quarkus.gradle.GradleBuildFileFromConnector;

public class QuarkusListExtensions extends QuarkusPlatformTask {
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +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.writer.FileProjectWriter;
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;
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.quarkus.maven;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -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.devtools.project.QuarkusProject;
import io.quarkus.platform.tools.MessageWriter;

/**
Expand Down Expand Up @@ -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<String> ext = new HashSet<>();
if (extensions != null && !extensions.isEmpty()) {
ext.addAll(extensions);
Expand All @@ -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()) {
Expand Down
Loading