You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/06/12 17:33:58 UTC
svn commit: r1492245 - in /sis/branches/JDK7: ./ application/sis-console/
application/sis-console/src/main/java/org/apache/sis/console/
application/sis-console/src/test/java/org/apache/sis/console/
application/sis-console/src/test/java/org/apache/sis/t...
Author: desruisseaux
Date: Wed Jun 12 15:33:57 2013
New Revision: 1492245
URL: http://svn.apache.org/r1492245
Log:
Complete the "metadata" command and add a test case.
Added:
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java (with props)
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java (with props)
Modified:
sis/branches/JDK7/application/sis-console/pom.xml
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/HelpSC.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/HelpSCTest.java
sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
sis/branches/JDK7/pom.xml
Modified: sis/branches/JDK7/application/sis-console/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/pom.xml?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/pom.xml (original)
+++ sis/branches/JDK7/application/sis-console/pom.xml Wed Jun 12 15:33:57 2013
@@ -89,7 +89,7 @@ Console application.
<configuration>
<instructions>
<Export-Package>
- org.apache.sis.cli
+ org.apache.sis.console
</Export-Package>
<Main-Class>org.apache.sis.console.Command</Main-Class>
</instructions>
@@ -109,6 +109,15 @@ Console application.
<version>${project.version}</version>
<!-- TODO: use test or runtime scope -->
</dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.opengis.wrapper</groupId>
+ <artifactId>geoapi-netcdf</artifactId>
+ <version>${geoapi.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/AboutSC.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -50,7 +50,10 @@ final class AboutSC extends SubCommand {
* Prints the information to the output stream.
*/
@Override
- public void run() {
+ public int run() {
+ if (hasUnexpectedFileCount(0, 0)) {
+ return Command.INVALID_ARGUMENT_EXIT_CODE;
+ }
final String configuration;
if (options.containsKey(Option.BRIEF)) {
configuration = Vocabulary.getResources(locale).getString(
@@ -64,5 +67,6 @@ final class AboutSC extends SubCommand {
}
out.println(configuration);
out.flush();
+ return 0;
}
}
Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/Command.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -29,17 +29,30 @@ import org.apache.sis.util.resources.Err
/**
- * Command line interface for Apache SIS.
- * The main method can be invoked from the command-line as below
- * (the filename needs to be completed with the actual version number):
+ * Command line interface for Apache SIS. The {@link #main(String[])} method accepts the following commands:
*
- * {@preformat java
- * java -jar target/binaries/sis-console.jar
- * }
+ * <ul>
+ * <li>{@code help} - Show a help overview.</li>
+ * <li>{@code about} - Show information about Apache SIS and system configuration.</li>
+ * <li>{@code metadata} - Show metadata information for the given file.</li>
+ * </ul>
*
- * "{@code target/binaries}" is the default location where SIS JAR files are grouped together
- * with their dependencies after a Maven build. This directory can be replaced by any path to
- * a directory providing the required dependencies.
+ * Each command can accepts an arbitrary amount of the following options:
+ *
+ * <ul>
+ * <li>{@code --locale} - The locale to use for the command output.</li>
+ * <li>{@code --timezone} - The timezone for the dates to be formatted.</li>
+ * <li>{@code --encoding} - The encoding to use for the command output.</li>
+ * <li>{@code --colors} - Whether colorized output shall be enabled.</li>
+ * <li>{@code --brief} - Whether the output should contains only brief information.</li>
+ * <li>{@code --verbose} - Whether the output should contains more detailed information.</li>
+ * <li>{@code --help} - Lists the options available for a specific command.</li>
+ * </ul>
+ *
+ * The {@code --locale}, {@code --timezone} and {@code --encoding} options apply to the command output sent
+ * to the {@linkplain System#out standard output stream}, but usually do not apply to the error messages sent
+ * to the {@linkplain System#err standard error stream}. The reason is that command output may be targeted to
+ * a client, while the error messages are usually for the operator.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
@@ -53,14 +66,22 @@ public final class Command {
public static final int INVALID_COMMAND_EXIT_CODE = 1;
/**
- * The code given to {@link System#exit(int)} when the program failed because of an illegal user argument.
+ * The code given to {@link System#exit(int)} when the program failed because of a unknown option.
+ * The set of valid options depend on the sub-command to execute.
*/
public static final int INVALID_OPTION_EXIT_CODE = 2;
/**
+ * The code given to {@link System#exit(int)} when the program failed because of an illegal user argument.
+ * The user arguments are everything which is not a command name or an option. They are typically file names,
+ * but can occasionally be other types like URL.
+ */
+ public static final int INVALID_ARGUMENT_EXIT_CODE = 3;
+
+ /**
* The code given to {@link System#exit(int)} when a file given in argument uses an unknown file format.
*/
- public static final int UNKNOWN_STORAGE_EXIT_CODE = 10;
+ public static final int UNKNOWN_STORAGE_EXIT_CODE = 4;
/**
* The code given to {@link System#exit(int)} when the program failed because of an {@link java.io.IOException}.
@@ -76,7 +97,7 @@ public final class Command {
* The code given to {@link System#exit(int)} when the program failed for a reason
* other than the ones enumerated in the above constants.
*/
- public static final int FAILURE_EXIT_CODE = 199;
+ public static final int OTHER_ERROR_EXIT_CODE = 199;
/**
* The sub-command name.
@@ -135,23 +156,28 @@ public final class Command {
}
/**
- * Runs the command. If an exception occurs, then the exception message is sent to the error output
- * stream before to be thrown. Callers can map the exception to a system exit code by the
- * {@link #exitCodeFor(Throwable)} method.
+ * Runs the command. If an exception occurs, then the exception message is sent to the error output stream
+ * before to be thrown. Callers can map the exception to a {@linkplain System#exit(int) system exit code}
+ * by the {@link #exitCodeFor(Throwable)} method.
*
+ * @return 0 on success, or an exit code if the command failed for a reason other than a Java exception.
* @throws Exception If an error occurred during the command execution. This is typically, but not limited, to
* {@link IOException}, {@link SQLException}, {@link DataStoreException} or {@link TransformException}.
*/
- public void run() throws Exception {
+ public int run() throws Exception {
+ if (command.hasContradictoryOptions(Option.BRIEF, Option.VERBOSE)) {
+ return INVALID_OPTION_EXIT_CODE;
+ }
if (command.options.containsKey(Option.HELP)) {
command.help(commandName);
} else try {
- command.run();
+ return command.run();
} catch (Exception e) {
command.out.flush();
command.err.println(Exceptions.formatChainedMessages(command.locale, null, e));
throw e;
}
+ return 0;
}
/**
@@ -160,19 +186,17 @@ public final class Command {
* constant is found.
*
* @param cause The exception for which to get the exit code.
- * @return The exit code as one of the {@code *_EXIT_CODE} constant, or {@link #FAILURE_EXIT_CODE} if unknown.
+ * @return The exit code as one of the {@code *_EXIT_CODE} constant, or {@link #OTHER_ERROR_EXIT_CODE} if unknown.
*/
public static int exitCodeFor(Throwable cause) {
while (cause != null) {
- if (cause instanceof IOException) {
- return IO_EXCEPTION_EXIT_CODE;
- }
- if (cause instanceof SQLException) {
- return SQL_EXCEPTION_EXIT_CODE;
- }
+ if (cause instanceof InvalidCommandException) return INVALID_COMMAND_EXIT_CODE;
+ if (cause instanceof InvalidOptionException) return INVALID_OPTION_EXIT_CODE;
+ if (cause instanceof IOException) return IO_EXCEPTION_EXIT_CODE;
+ if (cause instanceof SQLException) return SQL_EXCEPTION_EXIT_CODE;
cause = cause.getCause();
}
- return FAILURE_EXIT_CODE;
+ return OTHER_ERROR_EXIT_CODE;
}
/**
@@ -210,10 +234,14 @@ public final class Command {
System.exit(INVALID_OPTION_EXIT_CODE);
return;
}
+ int status;
try {
- c.run();
+ status = c.run();
} catch (Exception e) {
- System.exit(exitCodeFor(e));
+ status = exitCodeFor(e);
+ }
+ if (status != 0) {
+ System.exit(status);
}
}
}
Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/HelpSC.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/HelpSC.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/HelpSC.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/HelpSC.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -43,6 +43,14 @@ final class HelpSC extends SubCommand {
};
/**
+ * Copies the configuration of the given sub-command. This constructor is used
+ * for printing help about an other command.
+ */
+ HelpSC(final SubCommand parent) {
+ super(parent);
+ }
+
+ /**
* Creates the {@code "help"} sub-command.
*/
HelpSC(final int commandIndex, final String... args) throws InvalidOptionException {
@@ -53,20 +61,43 @@ final class HelpSC extends SubCommand {
* Prints the help instructions.
*/
@Override
- public void run() {
+ public int run() {
+ if (hasUnexpectedFileCount(0, 0)) {
+ return Command.INVALID_ARGUMENT_EXIT_CODE;
+ }
+ help(true, COMMANDS, EnumSet.allOf(Option.class));
+ return 0;
+ }
+
+ /**
+ * Implementation of {@link #run()}, also shared by {@link SubCommand#help(String)}.
+ *
+ * @param showHeader {@code true} for printing the "Apache SIS" header.
+ * @param commandNames The names of the commands to list.
+ * @param validOptions The options to list.
+ */
+ void help(final boolean showHeader, final String[] commandNames, final EnumSet<Option> validOptions) {
final ResourceBundle commands = ResourceBundle.getBundle("org.apache.sis.console.Commands", locale);
- final ResourceBundle options = ResourceBundle.getBundle("org.apache.sis.console.Options", locale);
+ final ResourceBundle options = ResourceBundle.getBundle("org.apache.sis.console.Options", locale);
final Vocabulary vocabulary = Vocabulary.getResources(locale);
- out.print("Apache SIS, ");
- out.println(commands.getString("SIS"));
- out.println(commands.getString("Usage"));
- out.println();
- out.print(vocabulary.getString(Vocabulary.Keys.Commands));
- out.println(':');
+ if (showHeader) {
+ out.print("Apache SIS, ");
+ out.println(commands.getString("SIS"));
+ out.println(commands.getString("Usage"));
+ out.println();
+ out.print(vocabulary.getString(Vocabulary.Keys.Commands));
+ out.println(':');
+ }
try {
final TableAppender table = new TableAppender(out, " ");
- for (final String command : COMMANDS) {
- table.append(" ").append(command);
+ for (final String command : commandNames) {
+ if (showHeader) {
+ table.append(" ");
+ }
+ table.append(command);
+ if (!showHeader) {
+ table.append(':');
+ }
table.nextColumn();
table.append(commands.getString(command));
table.nextLine();
@@ -75,7 +106,7 @@ final class HelpSC extends SubCommand {
out.println();
out.print(vocabulary.getString(Vocabulary.Keys.Options));
out.println(':');
- for (final Option option : Option.values()) {
+ for (final Option option : validOptions) {
final String name = option.name().toLowerCase(Locale.US);
table.append(" ").append(Option.PREFIX).append(name);
table.nextColumn();
Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -17,10 +17,16 @@
package org.apache.sis.console;
import java.util.EnumSet;
+import java.io.IOException;
import org.opengis.metadata.Metadata;
+import org.apache.sis.metadata.MetadataStandard;
+import org.apache.sis.metadata.ValueExistencePolicy;
import org.apache.sis.storage.DataStoreException;
import org.apache.sis.storage.StorageConnector;
import org.apache.sis.storage.netcdf.NetcdfStore;
+import org.apache.sis.util.collection.TableColumn;
+import org.apache.sis.util.collection.TreeTable;
+import org.apache.sis.util.collection.TreeTableFormat;
/**
@@ -43,21 +49,26 @@ final class MetadataSC extends SubComman
* Prints metadata information.
*
* @todo NetCDF data store is hard-coded for now. Will need a dynamic mechanism in the future.
+ *
+ * @throws DataStoreException If an error occurred while reading the NetCDF file.
+ * @throws IOException Should never happen, since we are appending to a print writer.
*/
@Override
- public void run() throws DataStoreException {
- if (files.size() != 1) {
- err.println("Needs a single file"); // TODO: localize, and need to return an error code.
- return;
+ public int run() throws DataStoreException, IOException {
+ if (hasUnexpectedFileCount(1, 1)) {
+ return Command.INVALID_ARGUMENT_EXIT_CODE;
}
final Metadata metadata;
try (NetcdfStore store = new NetcdfStore(new StorageConnector(files.get(0)))) {
metadata = store.getMetadata();
}
- if (metadata == null) {
- out.println("none"); // TODO: localize
- } else {
- out.println(metadata);
+ if (metadata != null) {
+ final TreeTable tree = MetadataStandard.ISO_19115.asTreeTable(metadata, ValueExistencePolicy.NON_EMPTY);
+ final TreeTableFormat format = new TreeTableFormat(locale, timezone);
+ format.setColumns(TableColumn.NAME, TableColumn.VALUE);
+ format.format(tree, out);
+ out.flush();
}
+ return 0;
}
}
Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/SubCommand.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -22,17 +22,13 @@ import java.util.Locale;
import java.util.EnumSet;
import java.util.EnumMap;
import java.util.TimeZone;
-import java.util.ResourceBundle;
import java.io.Console;
-import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import org.apache.sis.util.Locales;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.util.resources.Vocabulary;
-import org.apache.sis.io.TableAppender;
import org.apache.sis.internal.util.X364;
@@ -112,11 +108,28 @@ abstract class SubCommand {
/**
* Any remaining parameters that are not command name or option.
- * They are typically file names, but can occasionally be other type like URL.
+ * They are typically file names, but can occasionally be other types like URL.
*/
protected final List<String> files;
/**
+ * Copies the configuration of the given sub-command. This constructor is used
+ * only when a command needs to delegates part of its work to an other command.
+ */
+ SubCommand(final SubCommand parent) {
+ this.validOptions = parent.validOptions;
+ this.options = parent.options;
+ this.locale = parent.locale;
+ this.timezone = parent.timezone;
+ this.encoding = parent.encoding;
+ this.colors = parent.colors;
+ this.out = parent.out;
+ this.err = parent.err;
+ this.outputBuffer = parent.outputBuffer;
+ this.files = parent.files;
+ }
+
+ /**
* Creates a new sub-command with the given command-line arguments.
* The {@code arguments} array is the same array than the one given to the {@code main(String[])} method.
* The argument at index {@code commandIndex} is the name of this command, and will be ignored except for
@@ -217,40 +230,68 @@ abstract class SubCommand {
}
/**
+ * Checks if the user-provided {@linkplain #options} contains mutually exclusive options.
+ * If an inconsistency is found, then this method prints an error message to {@link #err}
+ * and returns {@code true}.
+ *
+ * <p>An example of a pair of mutually exclusive options is {@code --brief} and {@code --verbose}.</p>
+ *
+ * @param exclusive Pairs of mutually exclusive options.
+ * @return {@code true} if two mutually exclusive options exist.
+ */
+ final boolean hasContradictoryOptions(final Option... exclusive) {
+ for (int i=0; i<exclusive.length;) {
+ final Option o1 = exclusive[i++];
+ final Option o2 = exclusive[i++];
+ if (options.containsKey(o1) && options.containsKey(o2)) {
+ err.println(Errors.format(Errors.Keys.MutuallyExclusiveOptions_2,
+ o1.name().toLowerCase(Locale.US),
+ o2.name().toLowerCase(Locale.US)));
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Checks the size of the {@link #files} list. If the list has an unexpected size,
+ * then this method prints an error message to {@link #err} and returns {@code true}.
+ *
+ * @param min Minimal number of files.
+ * @param max Maximum number of files.
+ * @return {@code true} if the list size is not in the expected bounds.
+ */
+ final boolean hasUnexpectedFileCount(final int min, final int max) {
+ final int size = files.size();
+ final int expected, key;
+ if (size < min) {
+ expected = min;
+ key = Errors.Keys.TooFewArguments_2;
+ } else if (size > max) {
+ expected = max;
+ key = Errors.Keys.TooManyArguments_2;
+ } else {
+ return false;
+ }
+ err.println(Errors.format(key, expected, size));
+ return true;
+ }
+
+ /**
* Shows the help instructions for a specific command. This method is invoked
* instead of {@link #run()} if the the user provided the {@code --help} option.
*
* @param commandName The command name converted to lower cases.
*/
protected void help(final String commandName) {
- final ResourceBundle commands = ResourceBundle.getBundle("org.apache.sis.console.Commands", locale);
- final ResourceBundle options = ResourceBundle.getBundle("org.apache.sis.console.Options", locale);
- final Vocabulary vocabulary = Vocabulary.getResources(locale);
- out.print(commandName);
- out.print(": ");
- out.println(commands.getString(commandName));
- out.println();
- out.print(vocabulary.getString(Vocabulary.Keys.Options));
- out.println(':');
- final TableAppender table = new TableAppender(out, " ");
- for (final Option option : validOptions) {
- final String name = option.name().toLowerCase(Locale.US);
- table.append(" ").append(Option.PREFIX).append(name);
- table.nextColumn();
- table.append(options.getString(name));
- table.nextLine();
- }
- try {
- table.flush();
- } catch (IOException e) {
- throw new AssertionError(e); // Should never happen, because we are writing to a PrintWriter.
- }
+ new HelpSC(this).help(false, new String[] {commandName}, validOptions);
}
/**
* Executes the sub-command.
*
+ * @return 0 on success, or an exit code if the command failed for a reason other than a Java exception.
* @throws Exception If an error occurred while executing the sub-command.
*/
- public abstract void run() throws Exception;
+ public abstract int run() throws Exception;
}
Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/AboutSCTest.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -18,6 +18,7 @@ package org.apache.sis.console;
import org.apache.sis.util.Version;
import org.apache.sis.util.CharSequences;
+import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -26,13 +27,14 @@ import static org.apache.sis.test.TestUt
/**
- * Tests the {@link AboutSC} subcommand.
+ * Tests the {@link AboutSC} sub-command.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
* @version 0.3
* @module
*/
+@DependsOn(SubCommandTest.class)
public final strictfp class AboutSCTest extends TestCase {
/**
* Tests the sub-command without option.
Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/HelpSCTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/HelpSCTest.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/HelpSCTest.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/HelpSCTest.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -16,6 +16,7 @@
*/
package org.apache.sis.console;
+import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.Test;
@@ -23,13 +24,14 @@ import static org.junit.Assert.*;
/**
- * Tests the {@link HelpSC} subcommand.
+ * Tests the {@link HelpSC} sub-command.
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.3
* @version 0.3
* @module
*/
+@DependsOn(SubCommandTest.class)
public final strictfp class HelpSCTest extends TestCase {
/**
* Tests the sub-command without option.
Added: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java?rev=1492245&view=auto
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java (added)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.console;
+
+import java.net.URL;
+import org.opengis.wrapper.netcdf.IOTestCase;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link MetadataSC} sub-command.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+@DependsOn(SubCommandTest.class)
+public final strictfp class MetadataSCTest extends TestCase {
+ /**
+ * Tests the sub-command on a NetCDF file.
+ *
+ * @throws Exception Should never happen.
+ */
+ @Test
+ public void testNetCDF() throws Exception {
+ final URL url = IOTestCase.class.getResource(IOTestCase.NCEP);
+ assertNotNull(IOTestCase.NCEP, url);
+ final MetadataSC test = new MetadataSC(0, SubCommand.TEST, url.toString());
+ test.run();
+ final String result = test.outputBuffer.toString();
+ assertTrue("DefaultMetadata", result.startsWith("DefaultMetadata"));
+ assertTrue("ISO 19115-2", result.contains ("ISO 19115-2"));
+ assertTrue("Sea Surface Temperature Analysis Model", result.contains ("Sea Surface Temperature Analysis Model"));
+ assertTrue("GCMD Science Keywords", result.contains ("GCMD Science Keywords"));
+ assertTrue("NOAA/NWS/NCEP", result.contains ("NOAA/NWS/NCEP"));
+ }
+}
Propchange: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/MetadataSCTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java?rev=1492245&view=auto
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java (added)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.console;
+
+import java.util.EnumSet;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.concurrent.TimeUnit;
+import java.nio.charset.StandardCharsets;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
+
+
+/**
+ * Tests the {@link SubCommand} base class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class SubCommandTest extends TestCase {
+ /**
+ * A dummy sub-command for testing purpose.
+ */
+ private static final class Dummy extends SubCommand {
+ /**
+ * Creates a new sub-command for the given arguments and option values.
+ *
+ * @param validOptions The valid options.
+ * @param arguments The test arguments.
+ */
+ Dummy(final EnumSet<Option> validOptions, final String... arguments) throws InvalidOptionException {
+ super(0, arguments, validOptions);
+ }
+
+ /**
+ * Do nothing, since this method is not of interest for the enclosing JUnit test.
+ */
+ @Override
+ public int run() {
+ return 0;
+ }
+ }
+
+ /**
+ * Tests the {@code --locale} option.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testLocale() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--locale", "ja");
+ assertEquals(Option.LOCALE, getSingleton(c.options.keySet()));
+ assertSame("locale", Locale.JAPANESE, c.locale);
+ assertTrue("files.isEmpty()", c.files.isEmpty());
+ }
+
+ /**
+ * Tests the {@code --timezone} option.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testTimeZone() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--timezone", "JST");
+ assertEquals(Option.TIMEZONE, getSingleton(c.options.keySet()));
+ assertEquals("timezone", TimeZone.getTimeZone("JST"), c.timezone);
+ assertEquals("rawoffset", TimeUnit.HOURS.toMillis(9), c.timezone.getRawOffset());
+ assertTrue("files.isEmpty()", c.files.isEmpty());
+ }
+
+ /**
+ * Tests the {@code --encoding} option.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testEncoding() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--encoding", "UTF-16");
+ assertEquals(Option.ENCODING, getSingleton(c.options.keySet()));
+ assertEquals("encoding", StandardCharsets.UTF_16, c.encoding);
+ assertTrue("files.isEmpty()", c.files.isEmpty());
+ }
+
+ /**
+ * Tests passing a mix of different legal options.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ @DependsOnMethod({"testLocale", "testTimeZone", "testEncoding"})
+ public void testOptionMix() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST,
+ "--brief", "--locale", "ja", "--verbose", "--timezone", "JST");
+ assertEquals("options", EnumSet.of(
+ Option.BRIEF, Option.LOCALE, Option.VERBOSE, Option.TIMEZONE), c.options.keySet());
+
+ // Test specific values.
+ assertSame ("locale", Locale.JAPANESE, c.locale);
+ assertEquals("timezone", TimeZone.getTimeZone("JST"), c.timezone);
+ assertTrue("files.isEmpty()", c.files.isEmpty());
+ }
+
+ /**
+ * Tests passing an option with a missing value.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ @DependsOnMethod("testLocale")
+ public void testMissingOptionValue() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--brief"); // Should not comply.
+ assertEquals(Option.BRIEF, getSingleton(c.options.keySet()));
+ try {
+ new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--brief", "--locale");
+ fail("Expected InvalidOptionException");
+ } catch (InvalidOptionException e) {
+ final String message = e.getMessage();
+ assertTrue(message.contains("locale"));
+ }
+ }
+
+ /**
+ * Tests passing an unexpected option.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testUnexpectedOption() throws InvalidOptionException {
+ try {
+ new Dummy(EnumSet.of(Option.HELP, Option.BRIEF), SubCommand.TEST, "--brief", "--verbose", "--help");
+ fail("Expected InvalidOptionException");
+ } catch (InvalidOptionException e) {
+ final String message = e.getMessage();
+ assertTrue(message.contains("verbose"));
+ }
+ }
+
+ /**
+ * Tests {@link SubCommand#hasContradictoryOptions(Option[])}.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testHasContradictoryOptions() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "--brief", "--verbose");
+ assertTrue(c.hasContradictoryOptions(Option.BRIEF, Option.VERBOSE));
+ final String message = c.outputBuffer.toString();
+ assertTrue(message.contains("brief"));
+ assertTrue(message.contains("verbose"));
+ }
+
+ /**
+ * Tests {@link SubCommand#hasUnexpectedFileCount(int,int)}.
+ *
+ * @throws InvalidOptionException Should never happen.
+ */
+ @Test
+ public void testHasUnexpectedFileCount() throws InvalidOptionException {
+ final SubCommand c = new Dummy(EnumSet.allOf(Option.class), SubCommand.TEST, "MyFile.txt");
+ assertFalse(c.hasUnexpectedFileCount(0, 1));
+ assertEquals("", c.outputBuffer.toString());
+ assertFalse(c.hasUnexpectedFileCount(1, 2));
+ assertEquals("", c.outputBuffer.toString());
+ assertTrue(c.hasUnexpectedFileCount(2, 3));
+ final String message = c.outputBuffer.toString();
+ assertTrue(message.length() != 0);
+ }
+}
Propchange: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/console/SubCommandTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -30,8 +30,10 @@ import org.junit.BeforeClass;
* @module
*/
@Suite.SuiteClasses({
+ org.apache.sis.console.SubCommandTest.class,
org.apache.sis.console.HelpSCTest.class,
- org.apache.sis.console.AboutSCTest.class
+ org.apache.sis.console.AboutSCTest.class,
+ org.apache.sis.console.MetadataSCTest.class
})
public final strictfp class ConsoleTestSuite extends TestSuite {
/**
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -321,6 +321,11 @@ public final class Errors extends Indexe
public static final int MissingValueInColumn_1 = 77;
/**
+ * Options “{0}” and “{1}” are mutually exclusive.
+ */
+ public static final int MutuallyExclusiveOptions_2 = 103;
+
+ /**
* Argument ‘{0}’ shall not be negative. The given value was {1}.
*/
public static final int NegativeArgument_2 = 8;
@@ -461,6 +466,16 @@ public final class Errors extends Indexe
public static final int StreamIsForwardOnly_1 = 95;
/**
+ * Expected at least {0} argument{0,choice,1#|2#s}, but got {1}.
+ */
+ public static final int TooFewArguments_2 = 104;
+
+ /**
+ * Expected at most {0} argument{0,choice,1#|2#s}, but got {1}.
+ */
+ public static final int TooManyArguments_2 = 105;
+
+ /**
* Ordering between “{0}” and “{1}” elements is undefined.
*/
public static final int UndefinedOrderingForElements_2 = 70;
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties [ISO-8859-1] Wed Jun 12 15:33:57 2013
@@ -75,6 +75,7 @@ MissingRequiredModule_1 = This o
MissingValueForOption_1 = Missing value for option \u201c{0}\u201d.
MissingValueForProperty_1 = Missing value for property \u201c{0}\u201d.
MissingValueInColumn_1 = Missing value in the \u201c{0}\u201d column.
+MutuallyExclusiveOptions_2 = Options \u201c{0}\u201d and \u201c{1}\u201d are mutually exclusive.
NegativeArgument_2 = Argument \u2018{0}\u2019 shall not be negative. The given value was {1}.
NegativeArrayLength_1 = Can not create a \u201c{0}\u201d array of negative length.
NodeChildOfItself_1 = Node \u201c{0}\u201d can not be a child of itself.
@@ -104,6 +105,8 @@ RecursiveCreateCallForKey_1 = Recurs
RequireDecimalSeparator = A decimal separator is required.
StalledThread_1 = Thread \u201c{0}\u201d seems stalled.
StreamIsForwardOnly_1 = Can not move backward in the \u201c{0}\u201d stream.
+TooFewArguments_2 = Expected at least {0} argument{0,choice,1#|2#s}, but got {1}.
+TooManyArguments_2 = Expected at most {0} argument{0,choice,1#|2#s}, but got {1}.
UndefinedOrderingForElements_2 = Ordering between \u201c{0}\u201d and \u201c{1}\u201d elements is undefined.
UnexpectedChange_1 = Unexpected change in \u2018{0}\u2019.
UnexpectedEndOfFile_1 = Unexpected end of file while reading \u201c{0}\u201d.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties [ISO-8859-1] Wed Jun 12 15:33:57 2013
@@ -65,6 +65,7 @@ MissingRequiredModule_1 = Cette
MissingValueForOption_1 = Aucune valeur n\u2019a \u00e9t\u00e9 d\u00e9finie pour l\u2019option \u201c{0}\u201d.
MissingValueForProperty_1 = Aucune valeur n\u2019a \u00e9t\u00e9 d\u00e9finie pour la propri\u00e9t\u00e9 \u201c{0}\u201d.
MissingValueInColumn_1 = Il manque une valeur dans la colonne \u201c{0}\u201d.
+MutuallyExclusiveOptions_2 = Les options \u201c{0}\u201d et \u201c{1}\u201d sont mutuellement exclusives.
NegativeArgument_2 = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre n\u00e9gatif. La valeur donn\u00e9e \u00e9tait {1}.
NegativeArrayLength_1 = Ne peut pas cr\u00e9er un tableau \u201c{0}\u201d de longueur n\u00e9gative.
NodeChildOfItself_1 = Le n\u0153ud \u201c{0}\u201d ne peut pas \u00eatre un enfant de lui-m\u00eame.
@@ -93,6 +94,8 @@ RecursiveCreateCallForKey_1 = Appel
RequireDecimalSeparator = Un s\u00e9parateur d\u00e9cimal est requis.
StalledThread_1 = La t\u00e2che \u201c{0}\u201d semble bloqu\u00e9e.
StreamIsForwardOnly_1 = Ne peut pas reculer dans le flux de donn\u00e9es \u201c{0}\u201d.
+TooFewArguments_2 = Au moins {0} argument{0,choice,1# \u00e9tait attendu|2#s \u00e9taient attendus}, mais seulement {1} {1,choice,1#a \u00e9t\u00e9 sp\u00e9cifi\u00e9|2#ont \u00e9t\u00e9 sp\u00e9cifi\u00e9s}.
+TooManyArguments_2 = Au plus {0} argument{0,choice,1# \u00e9tait attendu|2#s \u00e9taient attendus}, mais {1} {1,choice,1#a \u00e9t\u00e9 sp\u00e9cifi\u00e9|2#ont \u00e9t\u00e9 sp\u00e9cifi\u00e9s}.
UndefinedOrderingForElements_2 = L\u2019ordre entre les \u00e9l\u00e9ments \u201c{0}\u201d et \u201c{1}\u201d n\u2019est pas d\u00e9fini.
UnexpectedChange_1 = Changement inattendu dans \u2018{0}\u2019.
UnexpectedEndOfFile_1 = Fin de fichier inattendue lors de la lecture de \u201c{0}\u201d.
Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/IndexedResourceBundle.java [UTF-8] Wed Jun 12 15:33:57 2013
@@ -67,7 +67,7 @@ public class IndexedResourceBundle exten
/**
* The path of the binary file containing resources, or {@code null} if there is no resources
- * of if the resources have already been loaded. The resources may be a file or an entry in a
+ * or if the resources have already been loaded. The resources may be a file or an entry in a
* JAR file.
*/
private URL resources;
Modified: sis/branches/JDK7/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1492245&r1=1492244&r2=1492245&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Wed Jun 12 15:33:57 2013
@@ -599,6 +599,10 @@ Apache SIS is a free software, Java lang
<packages>org.apache.sis.test*</packages>
</group>
<group>
+ <title>Applications</title>
+ <packages>org.apache.sis.console*:org.apache.sis.services*</packages>
+ </group>
+ <group>
<title>Data storage</title>
<packages>org.apache.sis.storage*:org.apache.sis.index*</packages>
</group>
@@ -608,7 +612,7 @@ Apache SIS is a free software, Java lang
</group>
<group>
<title>Referencing</title>
- <packages>org.apache.sis.core*:org.apache.sis.distance*:org.apache.sis.referencing*:org.apache.sis.parameter*</packages>
+ <packages>org.apache.sis.referencing*:org.apache.sis.parameter*</packages>
</group>
<group>
<title>Metadata</title>
@@ -616,7 +620,7 @@ Apache SIS is a free software, Java lang
</group>
<group>
<title>Utilities</title>
- <packages>org.apache.sis.math*:org.apache.sis.measure*:org.apache.sis.util*:org.apache.sis.io*:org.apache.sis.xml*</packages>
+ <packages>org.apache.sis.math*:org.apache.sis.measure*:org.apache.sis.util*:org.apache.sis.io*:org.apache.sis.xml*:org.apache.sis.setup*</packages>
</group>
</groups>