Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed Mar 1, 2024
1 parent 5358950 commit a823151
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ final void run(PrintStream out, Deque<String> args) {
* @param options any options extracted from the arguments
* @param parameters any parameters extracted from the arguments
*/
protected abstract void run(PrintStream out, Map<Option, String> options, List<String> parameters);
abstract void run(PrintStream out, Map<Option, String> options, List<String> parameters);

/**
* Whether the command is deprecated.
* @return whether the command is deprecated
*/
protected boolean isDeprecated() {
boolean isDeprecated() {
return false;
}

/**
* Returns the deprecation message.
* @return the deprecation message
*/
protected String getDeprecationMessage() {
String getDeprecationMessage() {
return null;
}

Expand All @@ -154,7 +154,7 @@ static Command find(Collection<? extends Command> commands, String name) {
/**
* Parameters that the command accepts.
*/
protected static final class Parameters {
static final class Parameters {

private final List<String> descriptions;

Expand All @@ -179,7 +179,7 @@ public String toString() {
* Factory method used if there are no expected parameters.
* @return a new {@link Parameters} instance
*/
protected static Parameters none() {
static Parameters none() {
return of();
}

Expand All @@ -189,7 +189,7 @@ protected static Parameters none() {
* @param descriptions the parameter descriptions
* @return a new {@link Parameters} instance with the given descriptions
*/
protected static Parameters of(String... descriptions) {
static Parameters of(String... descriptions) {
return new Parameters(descriptions);
}

Expand All @@ -198,7 +198,7 @@ protected static Parameters of(String... descriptions) {
/**
* Options that the command accepts.
*/
protected static final class Options {
static final class Options {

private final Option[] values;

Expand Down Expand Up @@ -239,7 +239,7 @@ Stream<Option> stream() {
* Factory method used if there are no expected options.
* @return a new {@link Options} instance
*/
protected static Options none() {
static Options none() {
return of();
}

Expand All @@ -249,7 +249,7 @@ protected static Options none() {
* @param values the option values
* @return a new {@link Options} instance with the given values
*/
protected static Options of(Option... values) {
static Options of(Option... values) {
return new Options(values);
}

Expand All @@ -260,7 +260,7 @@ protected static Options of(Option... values) {
* value (e.g. {@literal --log debug}) or a flag (e.g. {@literal
* --verbose}). It also can be both if the value is marked as optional.
*/
protected static final class Option {
static final class Option {

private final String name;

Expand Down Expand Up @@ -358,7 +358,7 @@ public String toString() {
* @param description a description of the option
* @return a new {@link Option} instance
*/
protected static Option flag(String name, String description) {
static Option flag(String name, String description) {
return new Option(name, null, description, false);
}

Expand All @@ -369,7 +369,7 @@ protected static Option flag(String name, String description) {
* @param description a description of the option
* @return a new {@link Option} instance
*/
protected static Option of(String name, String valueDescription, String description) {
static Option of(String name, String valueDescription, String description) {
return new Option(name, valueDescription, description, false);
}

Expand All @@ -381,7 +381,7 @@ protected static Option of(String name, String valueDescription, String descript
* @param optionalValue whether the value is optional
* @return a new {@link Option} instance
*/
protected static Option of(String name, String valueDescription, String description, boolean optionalValue) {
static Option of(String name, String valueDescription, String description, boolean optionalValue) {
return new Option(name, valueDescription, description, optionalValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class ExtractCommand extends Command {
}

@Override
public void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
try {
File destination = getWorkingDirectory(options);
Layers layers = getLayers(options);
Expand Down Expand Up @@ -137,7 +137,7 @@ private Layers getLayers(Map<Option, String> options) {
if (options.containsKey(LAYERS_OPTION)) {
return new RunnerAwareLayers(getLayersFromContext(), getRunnerFilename(options));
}
return new NoLayers();
return Layers.none();
}

private File getWorkingDirectory(Map<Option, String> options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ class ExtractLayersCommand extends Command {
}

@Override
protected boolean isDeprecated() {
boolean isDeprecated() {
return true;
}

@Override
protected String getDeprecationMessage() {
String getDeprecationMessage() {
return "Use '-Djarmode=tools extract --layers --launcher' instead.";
}

@Override
protected void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
Map<Option, String> rewrittenOptions = new HashMap<>();
if (options.containsKey(DESTINATION_OPTION)) {
rewrittenOptions.put(ExtractCommand.DESTINATION_OPTION, options.get(DESTINATION_OPTION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class HelpCommand extends Command {
}

@Override
protected void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
run(out, parameters);
}

void run(PrintStream out, List<String> parameters) {
String commandName = (parameters.isEmpty()) ? null : parameters.get(0);
if (commandName == null) {
printUsageAndCommands(null, out);
printUsageAndCommands(out);
return;
}
if (getName().equals(commandName)) {
Expand All @@ -63,11 +63,11 @@ void run(PrintStream out, List<String> parameters) {
}
Command command = Command.find(this.commands, commandName);
if (command == null) {
printUsageAndCommands(commandName, out);
}
else {
printCommandHelp(out, command, true);
printError(out, "Unknown command \"%s\"".formatted(commandName));
printUsageAndCommands(out);
return;
}
printCommandHelp(out, command, true);
}

void printCommandHelp(PrintStream out, Command command, boolean printDeprecationWarning) {
Expand Down Expand Up @@ -100,10 +100,7 @@ private String getUsage(Command command) {
return usage.toString();
}

private void printUsageAndCommands(String commandName, PrintStream out) {
if (commandName != null) {
printError(out, "Unknown command \"%s\"".formatted(commandName));
}
private void printUsageAndCommands(PrintStream out) {
out.println("Usage:");
out.println(" " + getJavaCommand());
out.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.boot.jarmode.layertools;

import java.util.Collections;
import java.util.Iterator;
import java.util.zip.ZipEntry;

Expand Down Expand Up @@ -65,4 +66,18 @@ static Layers get(Context context) {
return indexedLayers;
}

static Layers none() {
return new Layers() {
@Override
public Iterator<String> iterator() {
return Collections.emptyIterator();
}

@Override
public String getLayer(String entryName) {
return null;
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class ListCommand extends Command {
}

@Override
protected boolean isDeprecated() {
boolean isDeprecated() {
return true;
}

@Override
protected String getDeprecationMessage() {
String getDeprecationMessage() {
return "Use '-Djarmode=tools list-layers' instead.";
}

@Override
protected void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
this.delegate.run(out, options, parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ListLayersCommand extends Command {
}

@Override
public void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
printLayers(out, Layers.get(this.context));
}

Expand Down

This file was deleted.

0 comments on commit a823151

Please sign in to comment.