Skip to content

Commit

Permalink
Refactor and Introduce ExtensionsManager in CodeGen
Browse files Browse the repository at this point in the history
This is part of quarkusio#8178

- Improved packages names and content
- Improved general readability and consistency
- Added ExtensionManager to define a high level way of managing (read/write) extensions in any QuarkusProject
- Removed most unsafe Gradle operations which were outside of the Gradle plugin (we need to figure out a way to improve the "generic" gradle support to make it compatible again..)
- Removed existing project support with the create command (throws an error)
- Removed compatibility with project without the Quarkus platform bom defined
  • Loading branch information
ia3andy committed Jun 4, 2020
1 parent 6cf7aea commit 69e427b
Show file tree
Hide file tree
Showing 74 changed files with 1,719 additions and 1,660 deletions.
8 changes: 4 additions & 4 deletions devtools/aesh/src/main/java/io/quarkus/cli/QuarkusCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
import org.aesh.command.validator.CommandValidatorException;
import org.aesh.command.validator.OptionValidatorException;

import io.quarkus.cli.commands.QuarkusCommand;
import io.quarkus.devtools.commands.handlers.QuarkusCommandHandler;

public class QuarkusCli {

public static void main(String[] args) throws CommandRegistryException {
CommandRuntime runtime = AeshCommandRuntimeBuilder
.builder()
.commandRegistry(AeshCommandRegistryBuilder.builder().command(QuarkusCommand.class).create())
.commandRegistry(AeshCommandRegistryBuilder.builder().command(QuarkusCommandHandler.class).create())
.build();

if (args.length > 0) {
StringBuilder sb = new StringBuilder(QuarkusCommand.COMMAND_NAME).append(" ");
StringBuilder sb = new StringBuilder(QuarkusCommandHandler.COMMAND_NAME).append(" ");
if (args.length == 1) {
sb.append(args[0]);
} else {
Expand Down Expand Up @@ -54,6 +54,6 @@ private static void showHelpIfNeeded(CommandRuntime runtime, Exception e) {
if (e != null) {
System.err.println(e.getMessage());
}
System.err.println(runtime.commandInfo(QuarkusCommand.COMMAND_NAME));
System.err.println(runtime.commandInfo(QuarkusCommandHandler.COMMAND_NAME));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Collections;
import java.util.List;

import io.quarkus.devtools.commands.AddExtensions;
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.file.Paths;
import java.util.HashMap;

import io.quarkus.devtools.commands.CreateProject;
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.nio.file.Paths;

import io.quarkus.devtools.commands.ListExtensions;
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.cli.commands;

import io.quarkus.devtools.commands.handlers.QuarkusCommandHandler;
import org.aesh.command.Command;
import org.aesh.command.CommandException;
import org.aesh.command.CommandResult;
Expand All @@ -10,7 +11,7 @@
/**
* @author <a href="mailto:[email protected]">Ståle Pedersen</a>
*/
@GroupCommandDefinition(name = QuarkusCommand.COMMAND_NAME, groupCommands = { ListExtensionsCommand.class,
@GroupCommandDefinition(name = QuarkusCommandHandler.COMMAND_NAME, groupCommands = { ListExtensionsCommand.class,
AddExtensionCommand.class,
CreateProjectCommand.class }, description = "<command> [<args>] \n\nThese are the common quarkus commands used in various situations")
public class QuarkusCommand implements Command<CommandInvocation> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Collections;
import java.util.List;

import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.commands.RemoveExtensions;
import org.aesh.command.Command;
import org.aesh.command.CommandDefinition;
import org.aesh.command.CommandException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class AddExtensionToModuleInMultiModuleProjectTest extends QuarkusGradleT
public void testBasicMultiModuleBuild() throws Exception {

final File projectDir = getProjectDir("add-extension-multi-module");

BuildResult build = GradleRunner.create()
.forwardOutput()
.withPluginClasspath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

import com.google.common.collect.ImmutableMap;

import io.quarkus.cli.commands.CreateProject;
import io.quarkus.devtools.commands.CreateProject;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.generators.SourceType;
import io.quarkus.devtools.project.codegen.SourceType;
import io.quarkus.platform.tools.config.QuarkusPlatformConfig;
import io.quarkus.test.devmode.util.DevModeTestUtils;

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

import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
Expand All @@ -13,33 +14,35 @@
import org.gradle.tooling.model.eclipse.EclipseExternalDependency;
import org.gradle.tooling.model.eclipse.EclipseProject;

import io.quarkus.devtools.buildfile.GradleBuildFile;
import io.quarkus.devtools.writer.ProjectWriter;
import io.quarkus.devtools.project.buildfile.AbstractGradleBuildFile;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;

public class GradleBuildFileFromConnector extends GradleBuildFile {
public class GradleBuildFileFromConnector extends AbstractGradleBuildFile {

private List<Dependency> dependencies = null;

public GradleBuildFileFromConnector(ProjectWriter writer) {
super(writer);
// we need to initialize here since there is no other single point of entry
public GradleBuildFileFromConnector(final Path projectFolderPath, final QuarkusPlatformDescriptor platformDescriptor) {
super(projectFolderPath, platformDescriptor);
}

public GradleBuildFileFromConnector(Path projectFolderPath, QuarkusPlatformDescriptor platformDescriptor,
Path rootProjectPath) {
super(projectFolderPath, platformDescriptor, rootProjectPath);
}

@Override
public List<Dependency> getDependencies() throws IOException {
if (dependencies == null) {
EclipseProject eclipseProject = null;
if (getBuildContent() != null) {
if (getWriter().hasFile()) {
try {
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(getWriter().getProjectFolder())
.connect();
eclipseProject = connection.getModel(EclipseProject.class);
} catch (BuildException e) {
// ignore this error.
e.printStackTrace();
}
try {
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(getProjectFolderPath().toFile())
.connect();
eclipseProject = connection.getModel(EclipseProject.class);
} catch (BuildException e) {
// ignore this error.
e.printStackTrace();
}
}
if (eclipseProject != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;

import io.quarkus.cli.commands.AddExtensions;
import io.quarkus.devtools.commands.AddExtensions;

public class QuarkusAddExtension extends QuarkusPlatformTask {

Expand Down Expand Up @@ -44,7 +45,7 @@ public void addExtension() {
.extensions(extensionsSet)
.execute();
} catch (Exception e) {
throw new GradleException("Failed to add extensions " + getExtensionsToAdd(), e);
throw new GradleException("Failed to add extensions " + getExtensionsToAdd() + " " + ExceptionUtils.getStackTrace(e), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import org.gradle.api.tasks.TaskAction;
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;
import io.quarkus.devtools.commands.ListExtensions;

public class QuarkusListExtensions extends QuarkusPlatformTask {

Expand Down Expand Up @@ -58,11 +55,7 @@ public QuarkusListExtensions() {
@TaskAction
public void listExtensions() {
try {
final GradleBuildFileFromConnector buildFileFromConnector = new GradleBuildFileFromConnector(
new FileProjectWriter(getProject().getProjectDir()));
QuarkusProject quarkusProject = QuarkusProject.of(getProject().getProjectDir().toPath(), platformDescriptor(),
buildFileFromConnector);
new ListExtensions(quarkusProject)
new ListExtensions(getQuarkusProject())
.all(isAll())
.format(getFormat())
.search(getSearchPattern())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.Internal;

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.devtools.project.buildfile.BuildFile;
import io.quarkus.gradle.GradleBuildFileFromConnector;
import io.quarkus.platform.descriptor.CombinedQuarkusPlatformDescriptor;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
import io.quarkus.platform.descriptor.resolver.json.QuarkusJsonPlatformDescriptorResolver;
Expand Down Expand Up @@ -66,12 +65,11 @@ protected QuarkusPlatformDescriptor platformDescriptor() {
}

@Internal
protected GradleBuildFile getGradleBuildFile() {
final ProjectWriter writer = new FileProjectWriter(getProject().getProjectDir());
protected BuildFile getGradleBuildFile() {
return getProject().getParent() == null
? new GradleBuildFile(writer)
: new GradleBuildFile(writer,
new FileProjectWriter(getProject().getRootProject().getProjectDir()));
? new GradleBuildFileFromConnector(getProject().getProjectDir().toPath(), platformDescriptor())
: new GradleBuildFileFromConnector(getProject().getProjectDir().toPath(), platformDescriptor(),
getProject().getRootProject().getProjectDir().toPath());
}

@Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.options.Option;

import io.quarkus.cli.commands.RemoveExtensions;
import io.quarkus.devtools.commands.RemoveExtensions;

public class QuarkusRemoveExtension extends QuarkusPlatformTask {

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.devtools.writer.FileProjectWriter;
import io.quarkus.devtools.project.codegen.writer.FileProjectWriter;

class GradleBuildFileTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import io.quarkus.cli.commands.AddExtensions;
import io.quarkus.cli.commands.QuarkusCommandOutcome;
import io.quarkus.devtools.commands.AddExtensions;
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.platform.tools.MessageWriter;

Expand All @@ -22,7 +22,7 @@
* parameters.
*/
@Mojo(name = "add-extension")
public class AddExtensionMojo extends BuildFileMojoBase {
public class AddExtensionMojo extends QuarkusProjectMojoBase {

/**
* The list of extensions to be added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@

import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.cli.commands.AddExtensions;
import io.quarkus.cli.commands.CreateProject;
import io.quarkus.devtools.commands.CreateProject;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.generators.SourceType;
import io.quarkus.devtools.project.codegen.SourceType;
import io.quarkus.maven.components.MavenVersionEnforcer;
import io.quarkus.maven.components.Prompter;
import io.quarkus.platform.descriptor.QuarkusPlatformDescriptor;
Expand Down Expand Up @@ -214,11 +212,6 @@ public void execute() throws MojoExecutionException {
success = createProject.execute().isSuccess();

File createdDependenciesBuildFile = new File(projectRoot, buildToolEnum.getDependenciesFile());
if (success) {
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import io.quarkus.cli.commands.ListExtensions;
import io.quarkus.devtools.commands.ListExtensions;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.platform.tools.MessageWriter;

Expand All @@ -15,7 +15,7 @@
* You can list all extension or just installable. Choose between 3 output formats: name, concise and full.
*/
@Mojo(name = "list-extensions", requiresProject = false)
public class ListExtensionsMojo extends BuildFileMojoBase {
public class ListExtensionsMojo extends QuarkusProjectMojoBase {

/**
* List all extensions or just the installable.
Expand Down
Loading

0 comments on commit 69e427b

Please sign in to comment.