You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by rd...@apache.org on 2011/08/07 16:29:08 UTC
svn commit: r1154708 - in /incubator/rat/whisker/trunk/legacy/src:
main/java/org/apache/rat/whisker/legacy/app/
main/java/org/apache/rat/whisker/legacy/cli/
test/java/org/apache/rat/whisker/legacy/cli/
Author: rdonkin
Date: Sun Aug 7 14:29:07 2011
New Revision: 1154708
URL: http://svn.apache.org/viewvc?rev=1154708&view=rev
Log:
Set report and generate acts from the command line.
Modified:
incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java
incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java
incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/CommandLineOption.java
incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java
incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java
Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java?rev=1154708&r1=1154707&r2=1154708&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java Sun Aug 7 14:29:07 2011
@@ -24,7 +24,7 @@ package org.apache.rat.whisker.legacy.ap
public enum Act {
GENERATE,
- VALIDATE,
+ AUDIT,
REPORT,
TEMPLATE
Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java?rev=1154708&r1=1154707&r2=1154708&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java Sun Aug 7 14:29:07 2011
@@ -32,7 +32,7 @@ public class Whisker {
- private Act act = Act.GENERATE;
+ private Act act = Act.TEMPLATE;
private String base = "app";
private String licenseDescriptor = "org/apache/rat/whisker/samples/james/james.xml";
@@ -85,7 +85,7 @@ public class Whisker {
switch (act) {
case REPORT:
return report();
- case VALIDATE:
+ case AUDIT:
return validate();
case TEMPLATE:
return template();
Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/CommandLineOption.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/CommandLineOption.java?rev=1154708&r1=1154707&r2=1154708&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/CommandLineOption.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/CommandLineOption.java Sun Aug 7 14:29:07 2011
@@ -21,6 +21,7 @@ package org.apache.rat.whisker.legacy.cl
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
/**
@@ -28,17 +29,27 @@ import org.apache.commons.cli.Options;
*/
public enum CommandLineOption {
- LICENSE_DESCRIPTION("license-descriptor", 'l', "use given license descriptor", true, "file");
+ LICENSE_DESCRIPTION("license-descriptor", 'l', "use given license descriptor", true, "file", false),
+ ACT_TO_GENERATE("generate", 'g', "generate license and notice", false, null, true),
+ ACT_TO_AUDIT("audit", 'a', "report audit details", false, null, true);
/**
* Creates options for the command line.
* @return not null
*/
public static Options options() {
- Options options = new Options();
+ final Options options = new Options();
+ final OptionGroup acts = new OptionGroup();
+ acts.setRequired(true);
for (final CommandLineOption option: values()) {
- options.addOption(option.create());
+ final Option cliOption = option.create();
+ if (option.isAct) {
+ acts.addOption(cliOption);
+ } else {
+ options.addOption(cliOption);
+ }
}
+ options.addOptionGroup(acts);
return options;
}
@@ -48,17 +59,20 @@ public enum CommandLineOption {
private final String description;
private final boolean required;
private final String argument;
+ private final boolean isAct;
private CommandLineOption(final String longName,
final char shortName,
final String description,
final boolean required,
- final String argument) {
+ final String argument,
+ final boolean isAct) {
this.longName = longName;
this.shortName = shortName;
this.description = description;
this.required = required;
this.argument = argument;
+ this.isAct = isAct;
}
public String getLongName() {
@@ -92,4 +106,12 @@ public enum CommandLineOption {
public String getOptionValue(CommandLine commandLine) {
return commandLine.getOptionValue(getShortName());
}
+
+ /**
+ * @param commandLine
+ * @return
+ */
+ public boolean isSetOn(CommandLine commandLine) {
+ return commandLine.hasOption(getShortName());
+ }
}
\ No newline at end of file
Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java?rev=1154708&r1=1154707&r2=1154708&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java Sun Aug 7 14:29:07 2011
@@ -82,7 +82,12 @@ public class Main {
*/
private Whisker configure(final CommandLine commandLine) {
whisker.setLicenseDescriptor(CommandLineOption.LICENSE_DESCRIPTION.getOptionValue(commandLine));
- return whisker.setBase("war").setAct(Act.GENERATE);
+ if (CommandLineOption.ACT_TO_AUDIT.isSetOn(commandLine)) {
+ whisker.setAct(Act.AUDIT);
+ } else if (CommandLineOption.ACT_TO_GENERATE.isSetOn(commandLine)) {
+ whisker.setAct(Act.GENERATE);
+ }
+ return whisker.setBase("war");
}
public int run(final String[] args) throws Exception {
Modified: incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java?rev=1154708&r1=1154707&r2=1154708&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java Sun Aug 7 14:29:07 2011
@@ -20,7 +20,9 @@ package org.apache.rat.whisker.legacy.cl
import junit.framework.TestCase;
+import org.apache.commons.cli.AlreadySelectedException;
import org.apache.commons.cli.ParseException;
+import org.apache.rat.whisker.legacy.app.Act;
import org.apache.rat.whisker.legacy.app.Whisker;
/**
@@ -43,6 +45,40 @@ public class TestCommandParsing extends
subject = new Main(new Whisker());
}
+ public void testGenerateAndAuditAreMutuallyExclusive() throws Exception {
+ try {
+ subject.configure(
+ args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH",
+ longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()),
+ longOpt(CommandLineOption.ACT_TO_GENERATE.getLongName())));
+
+ fail("Expected audit and generate to together to throw exception");
+ } catch (AlreadySelectedException e) {
+ // expected
+ }
+ }
+
+ public void testSetGenerateAct() throws Exception {
+ checkSetActForOption(Act.GENERATE, CommandLineOption.ACT_TO_GENERATE);
+ }
+
+ public void testSetAuditAct() throws Exception {
+ checkSetActForOption(Act.AUDIT, CommandLineOption.ACT_TO_AUDIT);
+ }
+
+ /**
+ * @param act
+ * @param option
+ * @throws ParseException
+ */
+ private void checkSetActForOption(Act act, CommandLineOption option)
+ throws ParseException {
+ assertEquals(act + " arg should set property on Whisker", act, subject.configure(
+ args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", longOpt(option.getLongName()))).getAct());
+ assertEquals(act + "Audit arg should set property on Whisker", act, subject.configure(
+ args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", shortOpt(option.getShortName()))).getAct());
+ }
+
public void testSetLicenseDescriptorShortByCLI() throws Exception {
exerciseShortLicenseDescriptionWithPath("/some/path");
@@ -100,7 +136,7 @@ public class TestCommandParsing extends
*/
private void exerciseLicenseDescriptor(String aPath, String arg)
throws ParseException {
- assertEquals("Long license descriptor arg should set property on Whisker", aPath, subject.configure(args(arg, aPath)).getLicenseDescriptor());
+ assertEquals("License descriptor arg should set property on Whisker", aPath, subject.configure(args(arg, aPath, longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()))).getLicenseDescriptor());
}
private String[] args(String ...strings) {