Skip to content

Commit

Permalink
Added support for generating projects in existing directory
Browse files Browse the repository at this point in the history
  • Loading branch information
shannah committed Dec 29, 2023
1 parent c513e13 commit 89c282c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 105 deletions.
101 changes: 0 additions & 101 deletions .github/workflows/intellij-plugin-branch.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ProjectGeneratorRequestBuilder implements ProjectGeneratorRequest.P
@CommandLineParser.Help("Whether the repository should be private")
private boolean privateRepository;

@CommandLineParser.Help("Whether to use an existing directory")
private boolean useExistingDirectory;

@CommandLineParser.PositionalArg(1)
@CommandLineParser.Help("The fully-qualified main class name. If not specified, will be inferred from the package name and project name.")
private String magicArg;
Expand Down Expand Up @@ -80,6 +83,11 @@ public ProjectGeneratorRequest.Params setProjectName(String projectName) {
return this;
}

public ProjectGeneratorRequest.Params setUseExistingDirectory(boolean useExistingDirectory) {
this.useExistingDirectory = useExistingDirectory;
return this;
}

public String getProjectName() {
if (projectName != null) {
return projectName;
Expand Down Expand Up @@ -400,6 +408,11 @@ public boolean isPrivateRepository() {
return privateRepository;
}

@Override
public boolean isUseExistingDirectory() {
return useExistingDirectory;
}

private String getGithubUser() {
String repo = getGithubRepository();
if (repo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class ProjectGeneratorRequest {

private final boolean privateRepository;

private final boolean useExistingDirectory;

public File getParentDirectory() {
return parentDirectory;
}
Expand Down Expand Up @@ -71,6 +73,10 @@ public boolean isPrivateRepository() {
return privateRepository;
}

public boolean isUseExistingDirectory() {
return useExistingDirectory;
}

public interface Params {

@CommandLineParser.Help("The github repository to use. E.g. \"username/repo\". If not specified, will be inferred from the package name and project name.")
Expand All @@ -80,6 +86,10 @@ public interface Params {
@CommandLineParser.Alias("p")
boolean isPrivateRepository();

@CommandLineParser.Help("Use existing directory")
@CommandLineParser.Alias("e")
boolean isUseExistingDirectory();

@CommandLineParser.PositionalArg(1)
@CommandLineParser.Help("The fully-qualified main class name. If not specified, will be inferred from the package name and project name.")
String getMagicArg();
Expand Down Expand Up @@ -151,6 +161,8 @@ public interface Params {

Params setPrivateRepository(boolean privateRepository);

Params setUseExistingDirectory(boolean useExistingDirectory);

Params setExtensions(String[] extensions);

Params setWithCheerpj(boolean withCheerpj);
Expand All @@ -170,6 +182,7 @@ public ProjectGeneratorRequest(Params params) {
this.extensions = params.getExtensions();
this.githubRepository = params.getGithubRepository();
this.privateRepository = params.isPrivateRepository();
this.useExistingDirectory = params.isUseExistingDirectory();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public File generate(ProjectGeneratorRequest request) throws Exception {
request.getParentDirectory(),
stringUtils.camelCaseToLowerCaseWithSeparator(request.getProjectName(), "-")
);
if ( projectDir.exists() ) {
if (!request.isUseExistingDirectory() && projectDir.exists() ) {
throw new Exception("Project directory already exists: " + projectDir.getAbsolutePath());
}
projectDir.mkdirs();
Expand Down

0 comments on commit 89c282c

Please sign in to comment.