Skip to content

Commit

Permalink
8286654: Add an optional description accessor on ToolProvider interface
Browse files Browse the repository at this point in the history
Reviewed-by: jjg, darcy, lancea
  • Loading branch information
sormuras authored and jddarcy committed May 19, 2022
1 parent ac6a7d7 commit 655500a
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 18 deletions.
26 changes: 25 additions & 1 deletion src/java.base/share/classes/java/util/spi/ToolProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -63,6 +63,30 @@ public interface ToolProvider {
*/
String name();

/**
* {@return a short description of the tool, or an empty
* {@code Optional} if no description is available}
*
* @apiNote It is recommended that the description fits into a single
* line in order to allow creating concise overviews like the following:
* <pre>{@code
* jar
* Create, manipulate, and extract an archive of classes and resources.
* javac
* Read Java declarations and compile them into class files.
* jlink
* Assemble a set of modules (...) into a custom runtime image.
* }
* </pre>
*
* @implSpec This implementation returns an empty {@code Optional}.
*
* @since 19
*/
default Optional<String> description() {
return Optional.empty();
}

/**
* Runs an instance of the tool, returning zero for a successful run.
* Any non-zero return value indicates a tool-specific error during the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,8 +26,11 @@
package com.sun.tools.javac.main;

import java.io.PrintWriter;
import java.util.Optional;
import java.util.spi.ToolProvider;

import com.sun.tools.javac.util.JavacMessages;

/**
* An implementation of the {@link java.util.spi.ToolProvider ToolProvider} SPI,
* providing access to JDK Java compiler, javac.
Expand All @@ -41,6 +44,11 @@ public String name() {
return "javac";
}

public Optional<String> description() {
JavacMessages messages = new JavacMessages(Main.javacBundleName);
return Optional.of(messages.getLocalizedString("javac.description"));
}

public int run(PrintWriter out, PrintWriter err, String... args) {
Main compiler = new Main("javac", out, err);
return compiler.compile(args).exitCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,10 @@
# questions.
#

## tool

javac.description=read Java class and interface definitions and compile them into bytecode and class files

## standard options

javac.opt.g=\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,13 +26,18 @@
package sun.tools.jar;

import java.io.PrintWriter;
import java.util.Optional;
import java.util.spi.ToolProvider;

public class JarToolProvider implements ToolProvider {
public String name() {
return "jar";
}

public Optional<String> description() {
return Optional.of(Main.getMsg("jar.description"));
}

public int run(PrintWriter out, PrintWriter err, String... args) {
boolean ok = new Main(out, err, name()).run(args);
return ok ? 0 : 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,10 @@
# questions.
#

## tool

jar.description=create an archive for classes and resources, and manipulate or restore individual classes or resources from an archive

error.multiple.main.operations=\
You may not specify more than one '-cuxtid' options
error.cant.open=\
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,7 +25,11 @@

package jdk.javadoc.internal.tool;

import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.JavacMessages;
import java.io.PrintWriter;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.spi.ToolProvider;

/**
Expand All @@ -43,6 +47,13 @@ public String name() {
return "javadoc";
}

// @Override - commented out due to interim builds of javadoc with JDKs < 19.
public Optional<String> description() {
JavacMessages messages = JavacMessages.instance(new Context());
messages.add(locale -> ResourceBundle.getBundle("jdk.javadoc.internal.tool.resources.javadoc", locale));
return Optional.of(messages.getLocalizedString("javadoc.description"));
}

@Override
public int run(PrintWriter out, PrintWriter err, String... args) {
return Main.execute(args, out, err);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,8 @@
# questions.
#

javadoc.description=generate HTML pages of API documentation from Java source files

main.errors={0} errors
main.error={0} error
main.warnings={0} warnings
Expand Down
8 changes: 7 additions & 1 deletion src/jdk.jdeps/share/classes/com/sun/tools/javap/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,7 @@
package com.sun.tools.javap;

import java.io.PrintWriter;
import java.util.Optional;
import java.util.spi.ToolProvider;

/**
Expand Down Expand Up @@ -65,6 +66,11 @@ public String name() {
return "javap";
}

public Optional<String> description() {
JavapTask t = new JavapTask();
return Optional.of(t.getMessage("javap.description"));
}

public int run(PrintWriter out, PrintWriter err, String... args) {
return Main.run(args, out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# questions.
#

javap.description=disassemble one or more class files

err.prefix=Error:

err.bad.constant.pool=error while reading constant pool for {0}: {1}
Expand Down
7 changes: 6 additions & 1 deletion src/jdk.jdeps/share/classes/com/sun/tools/jdeps/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,7 @@
package com.sun.tools.jdeps;

import java.io.*;
import java.util.Optional;
import java.util.spi.ToolProvider;

/**
Expand Down Expand Up @@ -69,6 +70,10 @@ public String name() {
return "jdeps";
}

public Optional<String> description() {
return Optional.of(JdepsTask.getMessage("jdeps.description"));
}

public int run(PrintWriter out, PrintWriter err, String... args) {
return Main.run(args, out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
# questions.
#

jdeps.description=launch the Java class dependency analyzer

main.usage.summary=\
Usage: {0} <options> <path ...>]\n\
use --help for a list of possible options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,7 @@
package jdk.tools.jlink.internal;

import java.io.*;
import java.util.Optional;
import java.util.spi.ToolProvider;

public class Main {
Expand Down Expand Up @@ -61,6 +62,12 @@ public String name() {
return "jlink";
}

@Override
public Optional<String> description() {
TaskHelper taskHelper = new TaskHelper(TaskHelper.JLINK_BUNDLE);
return Optional.of(taskHelper.getMessage("jlink.desciption"));
}

@Override
public int run(PrintWriter out, PrintWriter err, String... args) {
return Main.run(out, err, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,8 @@
# questions.
#

jlink.description=assemble and optimize a set of modules and their dependencies into a custom runtime image

main.usage.summary=\
Usage: {0} <options> --module-path <modulepath> --add-modules <module>[,<module>...]\n\
\Use --help for a list of possible options
Expand Down
2 changes: 1 addition & 1 deletion src/jdk.jlink/share/classes/jdk/tools/jmod/JmodTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ private String version() {
return System.getProperty("java.version");
}

private static String getMessage(String key, Object... args) {
static String getMessage(String key, Object... args) {
try {
return MessageFormat.format(ResourceBundleHelper.bundle.getString(key), args);
} catch (MissingResourceException e) {
Expand Down
8 changes: 7 additions & 1 deletion src/jdk.jlink/share/classes/jdk/tools/jmod/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,7 @@
package jdk.tools.jmod;

import java.io.*;
import java.util.Optional;
import java.util.spi.ToolProvider;

public class Main {
Expand Down Expand Up @@ -55,6 +56,11 @@ public String name() {
return "jmod";
}

@Override
public Optional<String> description() {
return Optional.of(JmodTask.getMessage("jmod.description"));
}

@Override
public int run(PrintWriter out, PrintWriter err, String... args) {
return Main.run(out, err, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,6 +23,8 @@
# questions.
#

jmod.description=create JMOD files and list the content of existing JMOD files

main.usage.summary=\
Usage: {0} (create|extract|list|describe|hash) <OPTIONS> <jmod-file>\n\
use --help for a list of possible options
Expand Down Expand Up @@ -115,5 +117,3 @@ warn.invalid.arg=Invalid classname or pathname not exist: {0}
warn.no.module.hashes=No hashes recorded: no module specified for hashing depends on {0}
warn.ignore.entry=ignoring entry {0}, in section {1}
warn.ignore.duplicate.entry=ignoring duplicate entry {0}, in section {1}


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,6 +26,7 @@
package jdk.jpackage.internal;

import java.io.PrintWriter;
import java.util.Optional;
import java.util.spi.ToolProvider;

/**
Expand All @@ -40,6 +41,10 @@ public String name() {
return "jpackage";
}

public Optional<String> description() {
return Optional.of(jdk.jpackage.main.Main.I18N.getString("jpackage.description"));
}

public synchronized int run(
PrintWriter out, PrintWriter err, String... args) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#
#

jpackage.description=package a self-contained Java application

param.copyright.default=Copyright (C) {0,date,YYYY}
param.description.default=None
param.vendor.default=Unknown
Expand Down
2 changes: 1 addition & 1 deletion src/jdk.jpackage/share/classes/jdk/jpackage/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class Main {

private static final ResourceBundle I18N = ResourceBundle.getBundle(
public static final ResourceBundle I18N = ResourceBundle.getBundle(
"jdk.jpackage.internal.resources.MainResources");

/**
Expand Down

0 comments on commit 655500a

Please sign in to comment.