mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 16:27:11 -07:00
Implements #52 : command line enhancements for project creation
This commit is contained in:
parent
6c2a9acf1c
commit
66f7d180b9
21 changed files with 1421 additions and 1326 deletions
|
@ -22,16 +22,16 @@ import static rife.bld.dependencies.Scope.test;
|
|||
* @since 1.9
|
||||
*/
|
||||
public class AppProjectBlueprint extends Project {
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName) {
|
||||
this(work, packageName, projectName, new VersionNumber(0,0,1));
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName, String baseName) {
|
||||
this(work, packageName, projectName, baseName, new VersionNumber(0,0,1));
|
||||
}
|
||||
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
public AppProjectBlueprint(File work, String packageName, String projectName, String baseName, VersionNumber versionNumber) {
|
||||
workDirectory = work;
|
||||
|
||||
pkg = packageName;
|
||||
name = projectName;
|
||||
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Main";
|
||||
mainClass = packageName + "." + baseName + "Main";
|
||||
version = versionNumber;
|
||||
|
||||
downloadSources = true;
|
||||
|
|
|
@ -21,16 +21,16 @@ import static rife.bld.dependencies.Repository.SONATYPE_SNAPSHOTS;
|
|||
* @since 1.5.20
|
||||
*/
|
||||
public class BaseProjectBlueprint extends Project {
|
||||
public BaseProjectBlueprint(File work, String packageName, String projectName) {
|
||||
this(work, packageName, projectName, new VersionNumber(0,0,1));
|
||||
public BaseProjectBlueprint(File work, String packageName, String projectName, String baseName) {
|
||||
this(work, packageName, projectName, baseName, new VersionNumber(0,0,1));
|
||||
}
|
||||
|
||||
public BaseProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
public BaseProjectBlueprint(File work, String packageName, String projectName, String baseName, VersionNumber versionNumber) {
|
||||
workDirectory = work;
|
||||
|
||||
pkg = packageName;
|
||||
name = projectName;
|
||||
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Main";
|
||||
mainClass = packageName + "." + baseName + "Main";
|
||||
version = versionNumber;
|
||||
|
||||
downloadSources = true;
|
||||
|
|
|
@ -22,16 +22,16 @@ import static rife.bld.dependencies.Scope.test;
|
|||
* @since 1.6
|
||||
*/
|
||||
public class LibProjectBlueprint extends Project {
|
||||
public LibProjectBlueprint(File work, String packageName, String projectName) {
|
||||
this(work, packageName, projectName, new VersionNumber(0,0,1));
|
||||
public LibProjectBlueprint(File work, String packageName, String projectName, String baseName) {
|
||||
this(work, packageName, projectName, baseName, new VersionNumber(0,0,1));
|
||||
}
|
||||
|
||||
public LibProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
public LibProjectBlueprint(File work, String packageName, String projectName, String baseName, VersionNumber versionNumber) {
|
||||
workDirectory = work;
|
||||
|
||||
pkg = packageName;
|
||||
name = projectName;
|
||||
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Lib";
|
||||
mainClass = packageName + "." + baseName + "Lib";
|
||||
version = versionNumber;
|
||||
|
||||
downloadSources = true;
|
||||
|
|
|
@ -23,16 +23,16 @@ import static rife.bld.dependencies.Scope.*;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class Rife2ProjectBlueprint extends WebProject {
|
||||
public Rife2ProjectBlueprint(File work, String packageName, String projectName) {
|
||||
this(work, packageName, projectName, new VersionNumber(0,0,1));
|
||||
public Rife2ProjectBlueprint(File work, String packageName, String projectName, String baseName) {
|
||||
this(work, packageName, projectName, baseName, new VersionNumber(0,0,1));
|
||||
}
|
||||
|
||||
public Rife2ProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
public Rife2ProjectBlueprint(File work, String packageName, String projectName, String baseName, VersionNumber versionNumber) {
|
||||
workDirectory = work;
|
||||
|
||||
pkg = packageName;
|
||||
name = projectName;
|
||||
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Site";
|
||||
mainClass = packageName + "." + baseName + "Site";
|
||||
uberJarMainClass = mainClass + "Uber";
|
||||
version = versionNumber;
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@ public class CreateAppHelp implements CommandHelp {
|
|||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new Java application project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
|
||||
Usage : ${topic} <package> <name> <base>
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
name The name of the project to create
|
||||
base The base name for generated project classes""", "${topic}", topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ public class CreateBaseHelp implements CommandHelp {
|
|||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new Java baseline project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
|
||||
Usage : ${topic} <package> <name> <base>
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
name The name of the project to create
|
||||
base The base name for generated project classes""", "${topic}", topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,11 @@ public class CreateHelp implements CommandHelp {
|
|||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new project from multiple choice.
|
||||
|
||||
Usage : ${topic} <type> <package> <name>
|
||||
|
||||
Usage : ${topic} <type> <package> <name> <base>
|
||||
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);
|
||||
name The name of the project to create
|
||||
base The base name for generated project classes""", "${topic}", topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ public class CreateLibHelp implements CommandHelp {
|
|||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new Java library project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
|
||||
Usage : ${topic} <package> <name> <base>
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
name The name of the project to create
|
||||
base The base name for generated project classes""", "${topic}", topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,10 @@ public class CreateRife2Help implements CommandHelp {
|
|||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
Creates a new RIFE2 web application project.
|
||||
|
||||
Usage : ${topic} <package> <name>
|
||||
|
||||
Usage : ${topic} <package> <name> <base>
|
||||
package The package of the project to create
|
||||
name The name of the project to create""", "${topic}", topic);
|
||||
name The name of the project to create
|
||||
base The base name for generated project classes""", "${topic}", topic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,11 +26,13 @@ import java.util.List;
|
|||
* @since 1.5
|
||||
*/
|
||||
public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<T, P>, P extends Project> extends AbstractOperation<AbstractCreateOperation<T, P>> {
|
||||
private String packageName_;
|
||||
private String projectName_;
|
||||
private String baseName_;
|
||||
|
||||
final String templateBase_;
|
||||
|
||||
File workDirectory_ = new File(System.getProperty("user.dir"));
|
||||
String packageName_;
|
||||
String projectName_;
|
||||
boolean downloadDependencies_;
|
||||
|
||||
P project_;
|
||||
|
@ -98,10 +100,11 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
|
||||
// standard names
|
||||
projectClassName_ = StringUtils.capitalize(project_.name());
|
||||
projectBuildName_ = projectBuildClassName(projectClassName_);
|
||||
projectMainName_ = projectMainClassName(projectClassName_);
|
||||
projectMainUberName_ = projectMainUberClassName(projectClassName_);
|
||||
projectTestName_ = projectTestClassName(projectClassName_);
|
||||
var base_name = baseName();
|
||||
projectBuildName_ = projectBuildClassName(base_name);
|
||||
projectMainName_ = projectMainClassName(base_name);
|
||||
projectMainUberName_ = projectMainUberClassName(base_name);
|
||||
projectTestName_ = projectTestClassName(base_name);
|
||||
|
||||
// create the main project structure
|
||||
ideaDirectory_ = new File(project_.workDirectory(), ".idea");
|
||||
|
@ -375,14 +378,18 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
public T fromArguments(List<String> arguments) {
|
||||
String package_name = null;
|
||||
String project_name = null;
|
||||
String base_name = null;
|
||||
if (!arguments.isEmpty()) {
|
||||
package_name = arguments.remove(0);
|
||||
}
|
||||
if (!arguments.isEmpty()) {
|
||||
project_name = arguments.remove(0);
|
||||
}
|
||||
if ((package_name == null || project_name == null) && System.console() == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the package and project names as the arguments.");
|
||||
if (!arguments.isEmpty()) {
|
||||
base_name = arguments.remove(0);
|
||||
}
|
||||
if ((package_name == null || project_name == null || base_name == null) && System.console() == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the package, project and base names as the arguments.");
|
||||
}
|
||||
|
||||
if (package_name == null || package_name.isEmpty()) {
|
||||
|
@ -391,16 +398,30 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
} else {
|
||||
System.out.println("Using package name: " + package_name);
|
||||
}
|
||||
|
||||
if (project_name == null || project_name.isEmpty()) {
|
||||
System.out.println("Please enter a project name (for instance: myapp):");
|
||||
System.out.println("Please enter a project name (for instance: my-app):");
|
||||
project_name = System.console().readLine();
|
||||
} else {
|
||||
System.out.println("Using project name: " + project_name);
|
||||
}
|
||||
|
||||
if (base_name == null || base_name.isEmpty()) {
|
||||
var default_base_name = generateBaseName(project_name);
|
||||
System.out.println("Please enter the base name for generated project classes (default: " + default_base_name + "):");
|
||||
base_name = System.console().readLine();
|
||||
if (base_name == null || base_name.trim().isEmpty()) {
|
||||
base_name = default_base_name;
|
||||
System.out.println("Using base name: " + base_name);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Using base name: " + base_name);
|
||||
}
|
||||
|
||||
return workDirectory(new File(System.getProperty("user.dir")))
|
||||
.packageName(package_name)
|
||||
.projectName(project_name)
|
||||
.baseName(base_name)
|
||||
.downloadDependencies(true);
|
||||
}
|
||||
|
||||
|
@ -445,7 +466,6 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
throw new OperationOptionException("ERROR: The package name is invalid.");
|
||||
}
|
||||
|
||||
packageName_ = name;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
@ -462,10 +482,26 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
throw new OperationOptionException("ERROR: The project name should not be blank.");
|
||||
}
|
||||
|
||||
if (!ValidityChecks.checkJavaIdentifier(projectName_)) {
|
||||
throw new OperationOptionException("ERROR: The project name is invalid.");
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the base name for the project classes to generate.
|
||||
*
|
||||
* @param name the base name
|
||||
* @return this operation instance
|
||||
* @since 2.2
|
||||
*/
|
||||
public T baseName(String name) {
|
||||
baseName_ = StringUtils.trim(name);
|
||||
if (baseName_.isEmpty()) {
|
||||
throw new OperationOptionException("ERROR: The base name should not be blank.");
|
||||
}
|
||||
projectName_ = name;
|
||||
|
||||
if (!ValidityChecks.checkJavaIdentifier(baseName_)) {
|
||||
throw new OperationOptionException("ERROR: The base name is invalid.");
|
||||
}
|
||||
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
|
@ -513,6 +549,33 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
|
|||
return projectName_;
|
||||
}
|
||||
|
||||
static String generateBaseName(String projectName) {
|
||||
if (projectName != null) {
|
||||
var base_name = projectName.trim();
|
||||
base_name = StringUtils.filterAsIdentifier(base_name);
|
||||
base_name = StringUtils.capitalize(base_name);
|
||||
return base_name;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the base name for the project classes to generate.
|
||||
* <p>
|
||||
* If no base name was provided, one will be generated from the project name.
|
||||
*
|
||||
* @return the base name
|
||||
* @since 2.2
|
||||
*/
|
||||
public String baseName() {
|
||||
if (baseName_ == null || baseName_.isEmpty()) {
|
||||
return generateBaseName(projectName());
|
||||
}
|
||||
|
||||
return baseName_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves whether dependencies will be downloaded at project creation.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,6 @@ public class CreateAppOperation extends AbstractCreateOperation<CreateAppOperati
|
|||
}
|
||||
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), baseName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ public class CreateBaseOperation extends AbstractCreateOperation<CreateBaseOpera
|
|||
}
|
||||
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BaseProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
return new BaseProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), baseName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class CreateLibOperation extends AbstractCreateOperation<CreateLibOperati
|
|||
}
|
||||
|
||||
protected Project createProjectBlueprint() {
|
||||
return new LibProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
return new LibProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), baseName());
|
||||
}
|
||||
|
||||
protected String projectMainClassName(String projectClassName) {
|
||||
|
|
|
@ -33,6 +33,7 @@ public class CreateOperation {
|
|||
String type = null;
|
||||
String package_name = null;
|
||||
String project_name = null;
|
||||
String base_name = null;
|
||||
if (!arguments.isEmpty()) {
|
||||
type = arguments.remove(0);
|
||||
}
|
||||
|
@ -42,8 +43,11 @@ public class CreateOperation {
|
|||
if (!arguments.isEmpty()) {
|
||||
project_name = arguments.remove(0);
|
||||
}
|
||||
if ((type == null || package_name == null || project_name == null) && System.console() == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the type, package and project names as the arguments.");
|
||||
if (!arguments.isEmpty()) {
|
||||
base_name = arguments.remove(0);
|
||||
}
|
||||
if ((package_name == null || project_name == null || base_name == null) && System.console() == null) {
|
||||
throw new OperationOptionException("ERROR: Expecting the package, project and base names as the arguments.");
|
||||
}
|
||||
|
||||
if (type == null || type.isEmpty()) {
|
||||
|
@ -87,21 +91,34 @@ public class CreateOperation {
|
|||
if (project_name == null || project_name.isEmpty()) {
|
||||
String name_example;
|
||||
if (LIB.equals(type)) {
|
||||
name_example = "mylib";
|
||||
name_example = "my-lib";
|
||||
} else if (RIFE2.equals(type)) {
|
||||
name_example = "mywebapp";
|
||||
name_example = "my-webapp";
|
||||
} else {
|
||||
name_example = "myapp";
|
||||
name_example = "my-app";
|
||||
}
|
||||
System.out.printf("Please enter a project name (for instance: %s):%n", name_example);
|
||||
System.out.println("Please enter a project name (for instance: " + name_example + ")");
|
||||
project_name = System.console().readLine();
|
||||
} else {
|
||||
System.out.println("Using project name: " + project_name);
|
||||
}
|
||||
|
||||
if (base_name == null || base_name.isEmpty()) {
|
||||
var default_base_name = AbstractCreateOperation.generateBaseName(project_name);
|
||||
System.out.println("Please enter the base name for generated project classes (default: " + default_base_name + "):");
|
||||
base_name = System.console().readLine();
|
||||
if (base_name == null || base_name.trim().isEmpty()) {
|
||||
base_name = default_base_name;
|
||||
System.out.println("Using base name: " + base_name);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Using base name: " + base_name);
|
||||
}
|
||||
|
||||
return create_operation.workDirectory(new File(System.getProperty("user.dir")))
|
||||
.packageName(package_name)
|
||||
.projectName(project_name)
|
||||
.baseName(base_name)
|
||||
.downloadDependencies(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ public class CreateRife2Operation extends AbstractCreateOperation<CreateRife2Ope
|
|||
}
|
||||
|
||||
protected Rife2ProjectBlueprint createProjectBlueprint() {
|
||||
return new Rife2ProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName());
|
||||
return new Rife2ProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), baseName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeConfigure() {
|
||||
super.executeConfigure();
|
||||
|
||||
projectMainName_ = projectClassName_ + "Site";
|
||||
projectMainName_ = baseName() + "Site";
|
||||
projectMainUberName_ = projectMainName_ + "Uber";
|
||||
srcMainWebappCssDirectory_ = new File(project_.srcMainWebappDirectory(), "css");
|
||||
srcMainWebappWebInfDirectory_ = new File(project_.srcMainWebappDirectory(), "WEB-INF");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue