Skip to content

Commit

Permalink
refactor(cli): Move resource messages from core to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Feb 7, 2023
1 parent 9abb3a9 commit f64aca5
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 159 deletions.
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ allprojects {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

tasks.withType(JavaCompiler) {
options.compilerArgs += ['-Duser.language=en', '-Duser.country=US']
}
}

subprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,70 +30,4 @@ ERROR_CREATE_DIRECTORY = [JARVIZ-900] Could not create directory {}
ERROR_UNEXPECTED_WRITE = [JARVIZ-901] Unexpected error when writing to out
ERROR_UNEXPECTED = [JARVIZ-902] Unexpected error

ERROR_WRITE_FILE = Could not write to {}

bytecode.version.attribute = @|yellow Bytecode-Version|@: {}
bytecode.unversioned.classes.total = @|yellow Unversioned classes. Bytecode version|@: @|cyan {}|@ @|yellow total|@: @|cyan {}|@
bytecode.versioned.classes.total = @|yellow Versioned classes|@ @|cyan {}|@. @|yellow Bytecode version|@: @|cyan {}|@ @|yellow total|@: @|cyan {}|@
module.name = @|yellow name|@: {}
module.version = @|yellow version|@: {}
module.source = @|yellow source|@: {}
module.open = @|yellow open|@: {}
module.automatic = @|yellow automatic|@: {}
module.valid = @|yellow valid|@: {}
module.reason = @|yellow reason|@: {}
module.main.class = @|yellow main-class|@: {}
module.exports = @|yellow exports|@:
module.exports.qualified = @|yellow qualified exports|@:
module.exports.to = {} @|yellow to|@{}
module.requires = @|yellow requires|@:
module.opens = @|yellow opens|@:
module.opens.qualified = @|yellow qualified opens|@:
module.uses = @|yellow uses|@:
module.provides = @|yellow provides|@:
module.provides.with = {} @|yellow with|@{}
module.opens.to = {} @|yellow to|@{}
module.contains = @|yellow contains|@:

report.key.jarviz = jarviz
report.key.value = value
report.key.subject = subject
report.key.file = file
report.key.size = size
report.key.sha256 = sha256
report.key.services = services
report.key.service = service
report.key.implementations = implementations
report.key.implementation = implementation
report.key.manifest = manifest
report.key.name = name
report.key.version = version
report.key.source = source
report.key.automatic = automatic
report.key.valid = valid
report.key.reason = reason
report.key.attribute.name = attributeName
report.key.section.name = sectionName
report.key.module = module
report.key.opens = opens
report.key.open = open
report.key.main.class = mainClass
report.key.exports = exports
report.key.export = export
report.key.requires = requires
report.key.require = require
report.key.provides = provides
report.key.provider = provider
report.key.uses = uses
report.key.package = package
report.key.modifiers = modifiers
report.key.qualified = qualified
report.key.targets = targets
report.key.target = target
report.key.contains = contains
report.key.bytecode = bytecode
report.key.unversioned = unversioned
report.key.versioned = versioned
report.key.total = total
report.key.classes = classes
report.key.class = class
ERROR_WRITE_FILE = Could not write to {}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@CommandLine.Command(mixinStandardHelpOptions = true,
versionProvider = Versions.class,
resourceBundle = "org.kordamp.jarviz.cli.Messages")
abstract class AbstractCommand<C extends IO> implements Callable<Integer>, IO {
public abstract class AbstractCommand<C extends IO> extends BaseCommand implements Callable<Integer>, IO {
protected abstract C parent();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,16 @@ public static class Exclusive {
public URL url;
}

@CommandLine.Option(names = {"--cache-directory"})
@CommandLine.Option(names = {"--cache-directory"}, paramLabel = "<directory>")
public Path cache;

@CommandLine.ParentCommand
public C parent;

@CommandLine.Option(names = {"--report-path"})
@CommandLine.Option(names = {"--report-path"}, paramLabel = "<path>")
protected Path reportPath;

@CommandLine.Option(names = {"--report-format"},
paramLabel = "<format>")
@CommandLine.Option(names = {"--report-format"}, paramLabel = "<format>")
String[] reportFormats;

@Override
Expand Down Expand Up @@ -160,11 +159,11 @@ protected Formatter resolveFormatter(Format format) {
}

protected Node createRootNode(Path jarPath) {
return Node.root(RB.$("report.key.jarviz"))
.node(RB.$("report.key.subject"))
.node(RB.$("report.key.file")).value(jarPath.getFileName()).end()
.node(RB.$("report.key.size")).value(fileSize(jarPath)).end()
.node(RB.$("report.key.sha256")).value(sha256(jarPath)).end()
return Node.root($("report.key.jarviz"))
.node($("report.key.subject"))
.node($("report.key.file")).value(jarPath.getFileName()).end()
.node($("report.key.size")).value(fileSize(jarPath)).end()
.node($("report.key.sha256")).value(sha256(jarPath)).end()
.end();
}

Expand All @@ -179,7 +178,7 @@ protected void writeReport(String content, Format format) {
}

protected String $$(String key, Object... args) {
return colorize(RB.$(key, args));
return colorize($(key, args));
}

protected String $b(boolean val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@CommandLine.Command(mixinStandardHelpOptions = true,
versionProvider = Versions.class,
resourceBundle = "org.kordamp.jarviz.cli.Messages")
abstract class BaseCommand {
public abstract class BaseCommand {
static {
if (System.getenv().containsKey("JARVIZ_NO_COLOR")) {
System.setProperty("picocli.ansi", "false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public static int run(String... args) {
Main cmd = new Main();
CommandLine commandLine = new CommandLine(cmd);
commandLine.setCaseInsensitiveEnumValuesAllowed(true);
commandLine.setUsageHelpWidth(90);
commandLine.setUsageHelpLongOptionsMaxWidth(42);
cmd.out = commandLine.getOut();
cmd.err = commandLine.getErr();
return execute(commandLine, args);
Expand All @@ -80,6 +82,8 @@ public static int run(PrintWriter out, PrintWriter err, String... args) {
Main cmd = new Main();
CommandLine commandLine = new CommandLine(cmd);
commandLine.setCaseInsensitiveEnumValuesAllowed(true);
commandLine.setUsageHelpWidth(90);
commandLine.setUsageHelpLongOptionsMaxWidth(42);
commandLine.setOut(out);
commandLine.setErr(err);
cmd.out = out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.kordamp.jarviz.cli.bytecode;

import org.kordamp.jarviz.bundle.RB;
import org.kordamp.jarviz.cli.AbstractJarvizSubcommand;
import org.kordamp.jarviz.cli.internal.Colorizer;
import org.kordamp.jarviz.core.JarFileResolver;
Expand Down Expand Up @@ -45,10 +44,10 @@ public class BytecodeShow extends AbstractJarvizSubcommand<Bytecode> {
@CommandLine.Option(names = {"--details"})
public boolean details;

@CommandLine.Option(names = {"--bytecode-version"})
@CommandLine.Option(names = {"--bytecode-version"}, paramLabel = "<version>")
public Integer bytecodeVersion;

@CommandLine.Option(names = {"--java-version"})
@CommandLine.Option(names = {"--java-version"}, paramLabel = "<version>")
public Integer javaVersion;

@Override
Expand Down Expand Up @@ -149,14 +148,14 @@ private Node buildReport(Format format, Path jarPath, BytecodeVersions bytecodeV
if (bc == 0 && jv == 0) {
Set<Integer> manifestBytecode = bytecodeVersions.getManifestBytecode();
if (manifestBytecode.size() > 0) {
Node bytecode = root.array(RB.$("report.key.bytecode"));
Node bytecode = root.array($("report.key.bytecode"));
manifestBytecode.stream()
.map(String::valueOf)
.forEach(v -> {
if (format == Format.TXT) {
bytecode.node(v).end();
} else {
bytecode.collapsable(RB.$("report.key.version")).value(v).end();
bytecode.collapsable($("report.key.version")).value(v).end();
}
});
}
Expand Down Expand Up @@ -203,27 +202,27 @@ private void reportUnversioned(Node root, Map<Integer, List<String>> unversioned
if (!unversionedClasses.containsKey(bytecodeVersion)) return;

List<String> classes = unversionedClasses.get(bytecodeVersion);
Node unversioned = root.node(RB.$("report.key.unversioned"))
.node(RB.$("report.key.bytecode")).value(bytecodeVersion).end()
.node(RB.$("report.key.total")).value(classes.size()).end();
Node unversioned = root.node($("report.key.unversioned"))
.node($("report.key.bytecode")).value(bytecodeVersion).end()
.node($("report.key.total")).value(classes.size()).end();

if (details) {
unversioned.array(RB.$("report.key.classes"))
.collapsableChildren(RB.$("report.key.class"), classes);
unversioned.array($("report.key.classes"))
.collapsableChildren($("report.key.class"), classes);
}
}

private void reportVersioned(Node root, Map<Integer, List<String>> versionedClasses, Integer javaVersion, Integer bytecodeVersion) {
if (!versionedClasses.containsKey(bytecodeVersion)) return;

List<String> classes = versionedClasses.get(bytecodeVersion);
Node versioned = root.node(RB.$("report.key.versioned"))
.node(RB.$("report.key.bytecode")).value(bytecodeVersion).end()
.node(RB.$("report.key.total")).value(classes.size()).end();
Node versioned = root.node($("report.key.versioned"))
.node($("report.key.bytecode")).value(bytecodeVersion).end()
.node($("report.key.total")).value(classes.size()).end();

if (details) {
versioned.array(RB.$("report.key.classes"))
.collapsableChildren(RB.$("report.key.class"), classes);
versioned.array($("report.key.classes"))
.collapsableChildren($("report.key.class"), classes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.kordamp.jarviz.cli.manifest;

import org.kordamp.jarviz.bundle.RB;
import org.kordamp.jarviz.cli.AbstractJarvizSubcommand;
import org.kordamp.jarviz.core.JarFileResolver;
import org.kordamp.jarviz.core.processors.QueryManifestJarProcessor;
Expand All @@ -38,10 +37,10 @@
*/
@CommandLine.Command(name = "query")
public class ManifestQuery extends AbstractJarvizSubcommand<Manifest> {
@CommandLine.Option(names = {"--attribute-name"}, required = true)
@CommandLine.Option(names = {"--attribute-name"}, required = true, paramLabel = "<name>")
public String attributeName;

@CommandLine.Option(names = {"--section-name"})
@CommandLine.Option(names = {"--section-name"}, paramLabel = "<name>")
public String sectionName;

@Override
Expand Down Expand Up @@ -75,12 +74,12 @@ private Node buildReport(Path jarPath, String value) {
Node root = createRootNode(jarPath);

if (isNotBlank(sectionName)) {
root.node(RB.$("report.key.section.name")).value(sectionName).end();
root.node($("report.key.section.name")).value(sectionName).end();
}

root.node(RB.$("report.key.attribute.name"))
.node(RB.$("report.key.name")).value(attributeName).end()
.node(RB.$("report.key.value")).value(value).end();
root.node($("report.key.attribute.name"))
.node($("report.key.name")).value(attributeName).end()
.node($("report.key.value")).value(value).end();

return root;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ private void report(JarFileResolver<?> jarFileResolver, String manifest) {

private Node buildReport(Path jarPath, String manifest) {
return createRootNode(jarPath)
.node(RB.$("report.key.manifest")).value(manifest).end();
.node($("report.key.manifest")).value(manifest).end();
}
}
Loading

0 comments on commit f64aca5

Please sign in to comment.