mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-26 16:38:11 -07:00
Updated version to 1.9.0-SNAPSHOT.
Renamed blank project creation to app. Revised project creation descriptions. Added ability to have command aliases. Preserve compatibility with create-blank command through an alias.
This commit is contained in:
parent
86d81c9c51
commit
d8c0170dc0
38 changed files with 186 additions and 92 deletions
|
@ -25,6 +25,15 @@ public @interface BuildCommand {
|
|||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* When provided, specifies an alias for the build command that can be
|
||||
* different from the method name.
|
||||
*
|
||||
* @return a string representing an alias for the build command
|
||||
* @since 1.9
|
||||
*/
|
||||
String alias() default "";
|
||||
|
||||
/**
|
||||
* When provided, specifies a short description about the command.
|
||||
*
|
||||
|
|
|
@ -42,6 +42,7 @@ public class BuildExecutor {
|
|||
private final HierarchicalProperties properties_;
|
||||
private List<String> arguments_ = Collections.emptyList();
|
||||
private Map<String, CommandDefinition> buildCommands_ = null;
|
||||
private Map<String, String> buildAliases_ = null;
|
||||
private final AtomicReference<String> currentCommandName_ = new AtomicReference<>();
|
||||
private final AtomicReference<CommandDefinition> currentCommandDefinition_ = new AtomicReference<>();
|
||||
private int exitStatus_ = 0;
|
||||
|
@ -294,6 +295,7 @@ public class BuildExecutor {
|
|||
public Map<String, CommandDefinition> buildCommands() {
|
||||
if (buildCommands_ == null) {
|
||||
var build_commands = new TreeMap<String, CommandDefinition>();
|
||||
var build_aliases = new HashMap<String, String>();
|
||||
|
||||
Class<?> klass = getClass();
|
||||
|
||||
|
@ -311,6 +313,11 @@ public class BuildExecutor {
|
|||
name = annotation_name;
|
||||
}
|
||||
|
||||
var annotation_alias = annotation.alias();
|
||||
if (annotation_alias != null && !annotation_alias.isEmpty()) {
|
||||
build_aliases.put(annotation_alias, name);
|
||||
}
|
||||
|
||||
if (!build_commands.containsKey(name)) {
|
||||
var build_help = annotation.help();
|
||||
CommandHelp command_help = null;
|
||||
|
@ -343,11 +350,27 @@ public class BuildExecutor {
|
|||
}
|
||||
|
||||
buildCommands_ = build_commands;
|
||||
buildAliases_ = build_aliases;
|
||||
}
|
||||
|
||||
return buildCommands_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the command aliases that can be executed by this {@code BuildExecutor}.
|
||||
*
|
||||
* @return a map containing the alias and the associated name of the build command
|
||||
* @see BuildCommand
|
||||
* @since 1.9
|
||||
*/
|
||||
public Map<String, String> buildAliases() {
|
||||
if (buildAliases_ == null) {
|
||||
buildCommands();
|
||||
}
|
||||
|
||||
return buildAliases_;
|
||||
}
|
||||
|
||||
private static class AnnotatedCommandHelp implements CommandHelp {
|
||||
private final String summary_;
|
||||
private final String description_;
|
||||
|
@ -383,6 +406,15 @@ public class BuildExecutor {
|
|||
var matched_command = command;
|
||||
var definition = buildCommands().get(command);
|
||||
|
||||
// try to find an alias
|
||||
if (definition == null) {
|
||||
var aliased_command = buildAliases().get(command);
|
||||
if (aliased_command != null) {
|
||||
matched_command = aliased_command;
|
||||
definition = buildCommands().get(aliased_command);
|
||||
}
|
||||
}
|
||||
|
||||
// try to find a match for the provided command amongst
|
||||
// the ones that are known
|
||||
if (definition == null) {
|
||||
|
|
|
@ -17,7 +17,7 @@ import rife.bld.operations.*;
|
|||
public class Cli extends BuildExecutor {
|
||||
private final CreateOperation createOperation_ = new CreateOperation();
|
||||
private final CreateBaseOperation createBaseOperation_ = new CreateBaseOperation();
|
||||
private final CreateBlankOperation createBlankOperation_ = new CreateBlankOperation();
|
||||
private final CreateAppOperation createAppOperation_ = new CreateAppOperation();
|
||||
private final CreateLibOperation createLibOperation_ = new CreateLibOperation();
|
||||
private final CreateRife2Operation createRife2Operation_ = new CreateRife2Operation();
|
||||
private final UpgradeOperation upgradeOperation_ = new UpgradeOperation();
|
||||
|
@ -36,15 +36,15 @@ public class Cli extends BuildExecutor {
|
|||
}
|
||||
|
||||
/**
|
||||
* The standard {@code create-blank} command.
|
||||
* The standard {@code create-app} command.
|
||||
*
|
||||
* @throws Exception when an error occurred during the creation process
|
||||
* @since 1.5
|
||||
* @since 1.9
|
||||
*/
|
||||
@BuildCommand(value = "create-blank", help = CreateBlankHelp.class)
|
||||
public void createBlank()
|
||||
@BuildCommand(value = "create-app", alias = "create-blank", help = CreateAppHelp.class)
|
||||
public void createApp()
|
||||
throws Exception {
|
||||
createBlankOperation_.executeOnce(() -> createBlankOperation_.fromArguments(arguments()));
|
||||
createAppOperation_.executeOnce(() -> createAppOperation_.fromArguments(arguments()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,17 +16,17 @@ import static rife.bld.dependencies.Repository.SONATYPE_SNAPSHOTS;
|
|||
import static rife.bld.dependencies.Scope.test;
|
||||
|
||||
/**
|
||||
* Provides the dependency information required to create a new blank project.
|
||||
* Provides the dependency information required to create a new app project.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5
|
||||
* @since 1.9
|
||||
*/
|
||||
public class BlankProjectBlueprint extends Project {
|
||||
public BlankProjectBlueprint(File work, String packageName, String projectName) {
|
||||
public class AppProjectBlueprint extends Project {
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName) {
|
||||
this(work, packageName, projectName, new VersionNumber(0,0,1));
|
||||
}
|
||||
|
||||
public BlankProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
workDirectory = work;
|
||||
|
||||
pkg = packageName;
|
|
@ -8,19 +8,19 @@ import rife.bld.CommandHelp;
|
|||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* Provides help for the create-blank command.
|
||||
* Provides help for the create-app command.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5
|
||||
* @since 1.9
|
||||
*/
|
||||
public class CreateBlankHelp implements CommandHelp {
|
||||
public class CreateAppHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new blank Java project with standard commands";
|
||||
return "Creates a new Java application project";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new blank Java project with standard commands.
|
||||
Creates a new Java application project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
package The package of the project to create
|
|
@ -8,19 +8,19 @@ import rife.bld.CommandHelp;
|
|||
import rife.tools.StringUtils;
|
||||
|
||||
/**
|
||||
* Provides help for the create-blank command.
|
||||
* Provides help for the create-base command.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5.20
|
||||
*/
|
||||
public class CreateBaseHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new baseline Java project with minimal commands";
|
||||
return "Creates a new Java baseline project";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new baseline Java project with minimal commands.
|
||||
Creates a new Java baseline project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
package The package of the project to create
|
||||
|
|
|
@ -15,15 +15,15 @@ import rife.tools.StringUtils;
|
|||
*/
|
||||
public class CreateHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new project";
|
||||
return "Creates a new project from multiple choice";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new project.
|
||||
Creates a new project from multiple choice.
|
||||
|
||||
Usage : ${topic} <type> <package> <name>
|
||||
type The type of project to create (base, blank, lib, rife2)
|
||||
type The type of project to create (app, base, lib, rife2)
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ import rife.tools.StringUtils;
|
|||
*/
|
||||
public class CreateLibHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new Java library with minimal commands";
|
||||
return "Creates a new Java library project";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new library Java project with minimal commands.
|
||||
Creates a new Java library project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
package The package of the project to create
|
||||
|
|
|
@ -15,12 +15,12 @@ import rife.tools.StringUtils;
|
|||
*/
|
||||
public class CreateRife2Help implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Creates a new RIFE2 project";
|
||||
return "Creates a new RIFE2 web application project";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new RIFE2 project.
|
||||
Creates a new RIFE2 web application project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
package The package of the project to create
|
||||
|
|
26
src/main/java/rife/bld/operations/CreateAppOperation.java
Normal file
26
src/main/java/rife/bld/operations/CreateAppOperation.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.operations;
|
||||
|
||||
import rife.bld.Project;
|
||||
import rife.bld.blueprints.AppProjectBlueprint;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Creates a new app project structure.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.8
|
||||
*/
|
||||
public class CreateAppOperation extends AbstractCreateOperation<CreateAppOperation, Project> {
|
||||
public CreateAppOperation() {
|
||||
super("bld.app.");
|
||||
}
|
||||
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.operations;
|
||||
|
||||
import rife.bld.Project;
|
||||
import rife.bld.blueprints.BlankProjectBlueprint;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Creates a new blank project structure.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.5
|
||||
*/
|
||||
public class CreateBlankOperation extends AbstractCreateOperation<CreateBlankOperation, Project> {
|
||||
public CreateBlankOperation() {
|
||||
super("bld.blank.");
|
||||
}
|
||||
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
|||
public class CreateOperation {
|
||||
|
||||
private static final String BASE = "base";
|
||||
private static final String BLANK = "blank";
|
||||
private static final String APP = "app";
|
||||
private static final String LIB = "lib";
|
||||
private static final String RIFE2 = "rife2";
|
||||
|
||||
|
@ -48,14 +48,14 @@ public class CreateOperation {
|
|||
|
||||
if (type == null || type.isEmpty()) {
|
||||
System.out.println("Please enter a number for the project type:");
|
||||
System.out.printf(" 1: %s%n", BASE);
|
||||
System.out.printf(" 2: %s%n", BLANK);
|
||||
System.out.printf(" 3: %s%n", LIB);
|
||||
System.out.printf(" 4: %s%n", RIFE2);
|
||||
System.out.printf(" 1: %s (Java baseline project)%n", BASE);
|
||||
System.out.printf(" 2: %s (Java application project)%n", APP);
|
||||
System.out.printf(" 3: %s (Java library project)%n", LIB);
|
||||
System.out.printf(" 4: %s (RIFE2 web application)%n", RIFE2);
|
||||
var number = System.console().readLine();
|
||||
switch (Integer.parseInt(number)) {
|
||||
case 1 -> type = BASE;
|
||||
case 2 -> type = BLANK;
|
||||
case 2 -> type = APP;
|
||||
case 3 -> type = LIB;
|
||||
case 4 -> type = RIFE2;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public class CreateOperation {
|
|||
AbstractCreateOperation<?, ?> create_operation = null;
|
||||
switch (type) {
|
||||
case BASE -> create_operation = new CreateBaseOperation();
|
||||
case BLANK -> create_operation = new CreateBlankOperation();
|
||||
case APP -> create_operation = new CreateAppOperation();
|
||||
case LIB -> create_operation = new CreateLibOperation();
|
||||
case RIFE2 -> create_operation = new CreateRife2Operation();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue