public class EnvCheck extends Object
The following items are discussed below:
the simplest invocation of the tool would be:java -Djava.security.policy=my_policy \ -jar install_dir/lib/start.jar mystart.config
Note that the entire command line, including thejava -jar install_dir/lib/envcheck.jar \ java -Djava.security.policy=my_policy \ -jar install_dir/lib/start.jar mystart.config
java
command,
is supplied as arguments to the tool. The java
command used to
run the tool may be different than the java
command invoked by
the command line under test. The first token in the command line being
analyzed must not begin with a '-' and must end with the string "java".
-traces
-explain
-explain
option is a hint that may result in the generation of additional output
describing the purpose and context of the check. An explanation is output
the first time its associated message is output, and is not repeated. It
is the responsibility of the individual plugin implementation to honor
this option.
-level
info|warning|error
localhost
in a codebase annotation.
java.util.logging.config.file
system property.
This option is used to set the level at which message records are generated. The default value is warning.
-plugin
file
META-INF/services/com.sun.jini.tool.envcheck.Plugin
, which
contains the class names of the plugins to run listed one per line.
Every class listed must implement the
com.sun.jini.tool.envcheck.Plugin
interface. This option
may be supplied zero or more times.
-security
isPlugOption
method of the
Plugin
interface.
main
method:
In this case, the tool is limited to performing validity checks on the classpath, policy, and codebase values identified by the system properties and options provided on the service command line. Thejava -jar install_dir/lib/envcheck.jar -level info -explain -traces \ java -cp mylib_dir/myservice.jar:/jini/lib/jsk-platform.jar \ -Djava.security.policy=my_policy \ -Djava.server.rmi.codebase=http://myhost/myservice-dl.jar \ myservice.MyServiceImpl
-level
,
-explain
, and -traces
options supplied will result
in the most verbose output possible from the tool.
The following example will analyze a command line used to start reggie using the service starter. The command being analyzed uses a policy and service starter configuration located in the working directory:
The tool can perform many more checks in this case because the bundled plugins include built-in knowledge about the service starter and its public configuration entries. The tool options used will minimize the output produced by the tool.java -jar install_dir/lib/envcheck.jar -level error \ java -Djava.security.policy=my_starterpolicy \ -jar install_dir/lib/start.jar reggie.config
If the command line being analyzed invokes the service starter, the tool will
create a Configuration
from the arguments of the command line
being analyzed. Failure to create the Configuration
will result
in termination of the tool, otherwise the
com.sun.jini.start.ServiceDescriptor
s provided by the
Configuration
are examined. The following checks are done for
each ServiceDescriptor
:
getPolicy
method returns a reference to a
policy file that is valid and accessible
AllPermissions
to all
protection domains
NonActivatableServiceDescriptor
and each
SharedActivatableServiceDescriptor
getServerConfigArgs
does not return
null
or an empty array
Configuration
can be constructed from those
args
Configuration
named
initialLookupGroups
does not have a value of
ALL_GROUPS
-security
option was specified:
javax.net.ssl.trustStore
is defined and
that the trust store it references is accessible
com.sun.jini.discovery.x500.trustStore
is defined, and if so that the trust store it references is
accessible
javax.net.ssl.keyStore
is defined, and
if so that the key store it references is accessible
SharedActivatableServiceDescriptor
:
Configuration
named
persistenceDirectory
refers to either an empty directory
or a non-existant directory
SharedActivationGroupDescriptor
:
jsk-policy.jar
is loaded from the extensions
directory
jsk-platform.jar
is in the classpath
java.util.logging.config.file
is defined in the
properties returned by calling getServerProperties
then
verify that the file it references is accessible
java.rmi.server.codebase
java.security.policy
jsk-policy
being loaded by the extension
class loader
jsk-platform
in the classpath
-security
was specified
Modifier and Type | Class and Description |
---|---|
(package private) static class |
EnvCheck.GetDescriptors
A subtask which returns the service descriptors and service
destructors supplied by the service starter configuration constructed
from
args . |
private class |
EnvCheck.Pipe
An I/O redirection pipe.
|
Modifier and Type | Field and Description |
---|---|
private String[] |
args
the command line arguments of the command being analyzed
|
private static ResourceBundle |
bundle
the localization resource bundle
|
(package private) String |
classpath
the classpath on the command line being checked
|
(package private) static String |
combinedClasspath
the classpath of the tool, including the plugins (updated in run)
|
private ServiceDescriptor[] |
descriptors
the
ServiceDescriptor s obtained from the starter config |
(package private) String |
jarToRun
the executable JAR file on the command line being checked
|
private String |
javaCmd
the java command on the command line being checked
|
(package private) String |
mainClass
the main class on the command line being checked
|
(package private) String[] |
options
the options on the command line being checked (never null)
|
(package private) static ArrayList |
pluginJarList
the list of plugins supplied via the -plugin option
|
private ArrayList |
pluginList
the list of plugins instances to run
|
(package private) ClassLoader |
pluginLoader
the class loader for loading plugins
|
private boolean |
printStackTraces
flag controlling the display of stack traces in the output
|
(package private) Properties |
properties
the properties on the command line being checked (never null)
|
Constructor and Description |
---|
EnvCheck() |
Modifier and Type | Method and Description |
---|---|
String |
checkFile(String prop,
String desc)
Check for the existence of a file identified by a property
supplied on the command line being analyzed.
|
private static void |
findPlugins(String[] cmdLine)
Search the command line for user supplied plugin definitions
and place them in the internal plugin list.
|
String[] |
getArgs()
Get the command line arguments of the command being analyzed.
|
String |
getClasspath()
Get the classpath provided by the command line being analyzed.
|
ServiceDescriptor[] |
getDescriptors()
Return the
ServiceDescriptor s contained in the service
starter configuration. |
SharedActivationGroupDescriptor |
getGroupDescriptor()
Return the
SharedActivationGroupDescriptor contained in the
service starter configuration. |
String |
getJarToRun()
Return the name of the executable JAR file supplied on the
command line being analyzed.
|
String |
getJavaCmd()
Return the
java command for the command line being analyzed. |
Properties |
getProperties()
Return a copy of the properties that were specified on the
command line being analyzed.
|
String |
getProperty(String key)
Return a property value that was specified on the command line being
analyzed.
|
private String |
getString(String key)
Helper to print a localized string
|
private String |
getString(String key,
String val)
Helper to print a localized string
|
private boolean |
isPluginOption(String arg)
Check whether
arg is a plugin specific option. |
Object |
launch(NonActivatableServiceDescriptor d,
SharedActivationGroupDescriptor gd,
String taskName)
Launch a subtask using the environment defined by the given service
descriptors.
|
Object |
launch(NonActivatableServiceDescriptor d,
SharedActivationGroupDescriptor gd,
String taskName,
String[] args)
Launch a subtask using the environment defined by the given service
descriptors.
|
Object |
launch(String task)
Launch a child VM using the
java command, properties, and
options supplied on the command line. |
Object |
launch(String javaCmd,
Properties props,
String[] opts,
String[] args)
Launch a subtask VM using the
java command given by
javaCmd . |
Object |
launch(String task,
String[] args)
Launch a child VM using the
java command, properties, and
options supplied on the command line being analyzed. |
private void |
loadConfiguration()
Instantiate the service starter configuration if the command line being
analyzed runs the service starter.
|
private void |
loadPlugins()
Load the plugin classes.
|
static void |
main(String[] args)
The entry point for the tool.
|
private void |
parseArgs(String[] cmdLine)
Parse the command line, identifying options for the tool and parsing
the VM, system properties, options, JAR/main class and arguments
for the command line being tested.
|
boolean |
printStacks()
Return the flag indicating whether to output stack traces that
result from a check.
|
private void |
run(String[] cmdLine)
Perform the runtime checks.
|
private static void |
usage()
Output the usage message.
|
private ArrayList pluginList
private boolean printStackTraces
private String[] args
private ServiceDescriptor[] descriptors
ServiceDescriptor
s obtained from the starter configprivate static ResourceBundle bundle
private String javaCmd
String[] options
Properties properties
String classpath
String mainClass
String jarToRun
static ArrayList pluginJarList
ClassLoader pluginLoader
static String combinedClasspath
public static void main(String[] args)
java.protocol.handler.pkgs
for the tool VM is set
to net.jini.url
to ensure that the tool can manipulate
HTTPMD URLs.args
- the command line argumentsprivate static void usage()
private String getString(String key)
key
- the resource keyprivate String getString(String key, String val)
key
- the resource keyval
- the value parameter expected by the messageprivate static void findPlugins(String[] cmdLine)
cmdLine
- the original command line argsprivate void parseArgs(String[] cmdLine)
-plugin
option
is ignored by this parser since they must have been processed
earlier.cmdLine
- the original command line argumentspublic ServiceDescriptor[] getDescriptors()
ServiceDescriptor
s contained in the service
starter configuration. If the command being analyzed does not invoke the
service starter, a zero-length array will be returned.public SharedActivationGroupDescriptor getGroupDescriptor()
SharedActivationGroupDescriptor
contained in the
service starter configuration. Returns null
if there is no
such descriptor, or if the command being analyzed does not invoke the
service starter.SharedActivationGroupDescriptor
or
null
private void run(String[] cmdLine)
combinedClasspath
to make the classes available to subtasks.
Load the plugins and parse the command line. The plugins must be
available to the parser so that plugin specific options can be checked
for. Load the service starter configuration if the service starter is
being invoked. Execute all of the plugin classes in the order loaded.cmdLine
- the original command line argumentsprivate boolean isPluginOption(String arg)
arg
is a plugin specific option. The
isPluginOption
method of every plugin is called in
case an option is shared among multiple plugins.arg
- the argument to checktrue
if any plugin's isPluginOption
method returns true
private void loadConfiguration()
start.jar
and
if that file resides in the same directory as a file named
jsk-platform.jar
. Extract and save all of the service
descriptors and service destructors from the configuration. If a
ConfigurationException
is thrown the tool will exit. If
there are no ServiceDescriptor
or
ServiceDestructor
entries supplied by the configuration a
error is generated and a normal return is done. The instantiation of
the configuration is done in a child process using the VM, properties,
options and arguments supplied in the command line under test.private void loadPlugins()
META-INF/services/com.sun.jini.tool.envcheck.Plugin
are
read; each such resource is expected to contain a list of plugin class
names, one per line (white space is trimmed). The corresponding classes
are loaded and saved. Any other exceptions thrown while processing
the plugin JAR files will cause the tool to exit.public String[] getArgs()
public boolean printStacks()
public Object launch(String task, String[] args)
java
command, properties, and
options supplied on the command line being analyzed. If an executable JAR
file was specified, the classpath of the child VM consists of the JAR
file name augmented with the classpath of the tool and plugins. If a main
class was specified, the classpath of the child VM consists of the
-cp/-classpath
option value of the command line being
analyzed augmented with the classpath of the tool and plugins.task
- the class name of the task to launch, which must implement
the SubVMTask
interfaceargs
- the arguments to pass to the main method of the taskSystem.out
stream.public Object launch(String task)
java
command, properties, and
options supplied on the command line. If an executable JAR file was
specified, the classpath of the child VM consists of the JAR file name
augmented with the classpath of the tool and plugins. If a main class was
specified, the classpath of the child VM consists of the
-cp/-classpath
option value of the command line being
analyzed augmented with the classpath of the tool and plugins.task
- the class name of the task to launch, which must implement
the SubVMTask
interfaceSystem.out
stream.public String getProperty(String key)
key
- the name of the propertynull
if undefinedpublic Properties getProperties()
public Object launch(String javaCmd, Properties props, String[] opts, String[] args)
java
command given by
javaCmd
. If javaCmd
is null
, the
command to run is derived from the value of the java.home
property of the tool VM. The first value in args
must name
a class that implements the SubVMTask
interface. The
props
and opts
arrays must contain fully
formatted command line values for properties and options
(i.e. "-Dfoo=bar" or "-opt"). opts
must include a
-cp
or -classpath
option and its value must
completely specify the classpath required to run the subtask.javaCmd
- the java
command to execute, or
null
to create another instance of the
tool VMprops
- properties to define, which may be null
or
emptyopts
- options to define, which must include a classpath
definitionargs
- arguments to pass to the child VMSystem.out
stream.IllegalArgumentException
- if opts
does not
include a classpath definition, or if args[0]
does not contain the name of a class that implements
SubVMTask
public Object launch(NonActivatableServiceDescriptor d, SharedActivationGroupDescriptor gd, String taskName)
launch(d, g, taskName, null)
.d
- the services descriptor, which may be null
gd
- the group descriptor, which may be null
taskName
- the name of the subtask to runSystem.out
stream.public Object launch(NonActivatableServiceDescriptor d, SharedActivationGroupDescriptor gd, String taskName, String[] args)
If d
and gd
are both null
, then
calling this method is equivalent to calling
launch(taskName, args)
.
If d
is null
and gd
is
non-null
then the properties are taken from
gd.getServerProperties()
and the
java.security.policy
property is added or replaced with the
value of gd.getPolicy()
. The options are taken from
gd.getServerOptions()
, but any -cp/-classpath
option is discarded; a -cp
option is added that is the value
of gd.getClasspath()
augmented with the classpath of the
tool and plugins. If gd.getServerCommand()
is
non-null
, its value is used to invoke the child VM;
otherwise the java
command of the command line being
analyzed is used. The arguments passed to the child VM consist of an
array whose first element is taskName
and whose remaining
elements are taken from args
.
If d
is not null
, but gd
is
null
, then if d
is an instance of
SharedActivatableServiceDescriptor
an
IllegalArgumentException
is thrown. Otherwise the properties
and options are taken from the command line being analyzed. The
java.security.policy
property is added or replaced using the
value of d.getPolicy()
. The -cp/-classpath
option is replaced with the value of d.getImportCodebase()
augmented with the classpath of the tool and plugins. The arguments
passed to the child VM consist of taskName
followed by
args
if args
is non-null
, or
followed by d.getServerConfigArgs()
otherwise. The VM is
invoked using the java
command of the command line being
analyzed.
if d
and gd
are both non-null
then
if d
is an instance of
SharedActivatableServiceDescriptor
then the properties,
options, and java
command are taken from
gd.getServerProperties()
,
gd.getServerOptions()
, and
gd.getServerCommand()
; however, if the value of
gd.getServerCommand()
is null
, the
java
command is taken from the command line being
analysed. If d
is not an instance of
SharedActivatableServiceDescriptor
then the properties,
options, and java
command are taken from the command line
being analyzed. In all cases the java.security.policy
property is added or replaced using the value of
d.getPolicy()
. The -cp/-classpath
option is
added or replaced with the value of d.getImportCodebase()
augmented with the value of the classpath of the tool and plugins. The
arguments passed to the child VM consist of taskName
followed by args
if args
is
non-null
, or followed by
d.getServerConfigArgs()
otherwise.
d
- the service descriptor, which may be null
gd
- the group descriptor, which may be null
taskName
- the name of the subtask to runargs
- the arguments to pass to the child VM, which may be
null
System.out
stream.public String getJavaCmd()
java
command for the command line being analyzed.java
commandpublic String checkFile(String prop, String desc)
prop
- the name of the propertydesc
- a brief description of the filenull
if undefinedpublic String getJarToRun()
null
if the command line
did not specify one.public String getClasspath()
getJarToRun()
returns a non-null
value then
its value is returned. Otherwise the value supplied by the command
line -cp/-classpath
option is returned.Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.