Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ArgumentBuilder#transform #38

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b81e8b7
Fixes #10
May 2, 2018
1136ea1
[maven-release-plugin] prepare release jargo-parent-0.4.5
May 2, 2018
c7ad9bf
[maven-release-plugin] prepare for next development iteration
May 2, 2018
8af4165
Added ArgumentBuilder#transform. Fixes #1.
jontejj May 2, 2018
73ff413
Transformer fixes
jontejj May 3, 2018
252587f
Enabled arity/variableArity for transformed arguments
jontejj May 3, 2018
deec567
[maven-release-plugin] prepare release jargo-parent-0.4.6
jontejj May 3, 2018
96d9a7b
[maven-release-plugin] prepare for next development iteration
jontejj May 3, 2018
0e7b579
[maven-release-plugin] prepare release jargo-parent-0.4.7
jontejj May 3, 2018
df0e639
[maven-release-plugin] prepare for next development iteration
jontejj May 3, 2018
8a20734
Updated version as 0.4.7 was released
jontejj May 3, 2018
6714833
Arguments are parsed before any command is executed.
May 4, 2018
df9d8fd
[maven-release-plugin] prepare release jargo-parent-0.4.8
jontejj May 4, 2018
03e7a24
[maven-release-plugin] prepare for next development iteration
jontejj May 4, 2018
b2f645e
Updated version to 0.4.8
jontejj May 4, 2018
bfd7939
Missing arguments for commands are printed better. Fixes #12.
jontejj May 5, 2018
40f09f5
Better accessibility for main args from sub commands
jontejj May 5, 2018
9c7c5f5
Add more tests for end of options and help arguments
jontejj May 5, 2018
642c8fb
unique() works with repeated(). Fixes #9 (jontejj).
jontejj May 5, 2018
135ae7d
Increased test coverage
jontejj May 5, 2018
25d4867
[maven-release-plugin] prepare release jargo-parent-0.4.9
jontejj May 5, 2018
d97b598
[maven-release-plugin] prepare for next development iteration
jontejj May 5, 2018
7f4ef64
Update version to 0.4.9
jontejj May 5, 2018
5070bf2
Enable SecurityTest
jontejj May 6, 2018
8f63e53
Default values for main args can be accessed from commands
May 7, 2018
bdecff7
[maven-release-plugin] prepare release jargo-parent-0.4.10
May 7, 2018
7c89336
[maven-release-plugin] prepare for next development iteration
May 7, 2018
8f2c2a2
Default values for main commands/args are accessible from sub sub com…
May 7, 2018
b52a4d8
[maven-release-plugin] prepare release jargo-parent-0.4.11
May 7, 2018
c0450e1
[maven-release-plugin] prepare for next development iteration
May 7, 2018
40bfdaa
Exceptions from commands get proper usage. Fixes #43.
jontejj May 7, 2018
a32f9f5
Simplified commandEnum a bit
jontejj May 7, 2018
5167a70
[maven-release-plugin] prepare release jargo-parent-0.4.12
May 8, 2018
a30b7ea
[maven-release-plugin] prepare for next development iteration
May 8, 2018
ec4fd71
Tab-completions! Fixes #3.
jontejj May 7, 2018
9e58e9e
Fix environmentally unsafe test
jontejj May 28, 2018
345c828
Fixing SpotBugs errors found
jontejj May 28, 2018
7a29ab9
[maven-release-plugin] prepare release jargo-parent-0.4.13
jontejj May 28, 2018
e7ebd7c
[maven-release-plugin] prepare for next development iteration
jontejj May 28, 2018
fc137ef
Bump version
jontejj May 28, 2018
c83b217
Updated with info about tab-completions
jontejj May 28, 2018
f37997b
Avoid StackOverflowError for command names shared by several commands…
jontejj May 30, 2018
78ea85f
Make transform compatible with asPropertyMap. Fixes #45.
jontejj May 30, 2018
ed686bc
Fixes #47
jontejj May 30, 2018
11d0263
[maven-release-plugin] prepare release jargo-parent-0.4.14
jontejj May 30, 2018
95e0c7c
[maven-release-plugin] prepare for next development iteration
jontejj May 30, 2018
1703fed
Added code-scene snippet in readme.md
jontejj Nov 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions common-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>se.softhouse</groupId>
<artifactId>jargo-parent</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
</parent>
<artifactId>common-test</artifactId>
<description>Reusable classes to use from tests.</description>
Expand Down Expand Up @@ -32,7 +32,6 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.4.201502262128</version>
<executions>
<execution>
<!-- Not as strict requirements for test helping code -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ private Explanation()
* make the test fail for the wrong reasons.
*/
public static final String FAIL_FAST = "fail-fast during configuration phase";

public static final String TESTING_INVALID_CODE = "Invalid code";
}
90 changes: 67 additions & 23 deletions common-test/src/main/java/se/softhouse/common/testlib/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.reflect.Modifier.isPublic;
import static java.lang.reflect.Modifier.isStatic;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;

import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.concurrent.Immutable;

Expand All @@ -47,12 +52,14 @@ public static final class LaunchedProgram
private final String errors;
private final String output;
private final String debugInformation;
private final int exitCode;

private LaunchedProgram(String errors, String output, String debugInformation)
private LaunchedProgram(String errors, String output, String debugInformation, int exitCode)
{
this.errors = errors;
this.output = output;
this.debugInformation = debugInformation;
this.exitCode = exitCode;
}

/**
Expand All @@ -71,6 +78,14 @@ public String errors()
return errors;
}

/**
* @return the <a href="https://en.wikipedia.org/wiki/Exit_status">exit code/status</a> of the finished program
*/
public int exitCode()
{
return exitCode;
}

/**
* Returns information suitable to print in case of errors on a debug level
*/
Expand All @@ -91,25 +106,16 @@ private Launcher()
}

/**
* Runs {@code classWithMainMethod} in a separate process using the system property
* {@code java.home} to find java and {@code java.class.path} for the class path. This method
* will wait until program execution has finished.
* Like {@link #launch(Class, String...)} but with more configurable options
*
* @param classWithMainMethod a class with a static "main" method
* @param programArguments optional arguments to pass to the program
* @return output/errors from the executed program
* @throws IOException if an I/O error occurs while starting {@code classWithMainMethod} as a
* process
* @throws InterruptedException if the thread starting the program is
* {@link Thread#interrupted()} while waiting for the program to finish
* @throws IllegalArgumentException if {@code classWithMainMethod} doesn't have a public static
* main method
* @throws SecurityException if it's not possible to validate the existence of a main method in
* {@code classWithMainMethod} (or if {@link SecurityManager#checkExec checkExec}
* fails)
* @param envVariables variables to add to {@link ProcessBuilder#environment()}.
* @param additionalVmArgs the vm args to pass in
*/
public static LaunchedProgram launch(Class<?> classWithMainMethod, String ... programArguments) throws IOException, InterruptedException
public static LaunchedProgram launch(List<String> additionalVmArgs, Map<String, String> envVariables, Class<?> classWithMainMethod,
String ... programArguments) throws IOException, InterruptedException
{
checkNotNull(additionalVmArgs);
checkNotNull(envVariables);
checkNotNull(programArguments);
try
{
Expand All @@ -130,11 +136,35 @@ public static LaunchedProgram launch(Class<?> classWithMainMethod, String ... pr

List<String> args = Lists.newArrayList(jvm, "-cp", classPath);
args.addAll(vmArgs);
args.addAll(additionalVmArgs);
args.add(classWithMainMethod.getName());
args.addAll(Arrays.asList(programArguments));

String debugInformation = "\njvm: " + jvm + "\nvm args: " + vmArgs + "\nclasspath: " + classPath;
return execute(args, debugInformation);
return execute(args, envVariables, debugInformation);
}

/**
* Runs {@code classWithMainMethod} in a separate process using the system property
* {@code java.home} to find java and {@code java.class.path} for the class path. This method
* will wait until program execution has finished.
*
* @param classWithMainMethod a class with a static "main" method
* @param programArguments optional arguments to pass to the program
* @return output/errors from the executed program
* @throws IOException if an I/O error occurs while starting {@code classWithMainMethod} as a
* process
* @throws InterruptedException if the thread starting the program is
* {@link Thread#interrupted()} while waiting for the program to finish
* @throws IllegalArgumentException if {@code classWithMainMethod} doesn't have a public static
* main method
* @throws SecurityException if it's not possible to validate the existence of a main method in
* {@code classWithMainMethod} (or if {@link SecurityManager#checkExec checkExec}
* fails)
*/
public static LaunchedProgram launch(Class<?> classWithMainMethod, String ... programArguments) throws IOException, InterruptedException
{
return launch(emptyList(), emptyMap(), classWithMainMethod, programArguments);
}

/**
Expand All @@ -151,20 +181,34 @@ public static LaunchedProgram launch(Class<?> classWithMainMethod, String ... pr
*/
public static LaunchedProgram launch(String program, String ... programArguments) throws IOException, InterruptedException
{
return execute(Lists.asList(program, programArguments), "Failed to launch " + program);
return execute(Lists.asList(program, programArguments), emptyMap(), "Failed to launch " + program);
}

private static LaunchedProgram execute(List<String> args, String debugInformation) throws IOException, InterruptedException
/**
* Different JDKs behave differently, to have consistent results, let's clean it away
* No way to turn it off either: https://bugs.openjdk.java.net/browse/JDK-8039152
*/
private static final Pattern JVM_OUTPUT_CLEANER = Pattern.compile("Picked up _JAVA_OPTIONS.*\n");

private static LaunchedProgram execute(List<String> args, Map<String, String> envVariables, String debugInformation)
throws IOException, InterruptedException
{
Process program = new ProcessBuilder().command(args).start();
ProcessBuilder processBuilder = new ProcessBuilder().command(args);
processBuilder.environment().putAll(envVariables);
Process program = processBuilder.start();
Future<String> stdout = Streams.readAsynchronously(program.getInputStream());
Future<String> stderr = Streams.readAsynchronously(program.getErrorStream());
program.waitFor();
int exitCode = program.waitFor();
try
{
String output = stdout.get();
String errors = stderr.get();
return new LaunchedProgram(errors, output, debugInformation);
Matcher matcher = JVM_OUTPUT_CLEANER.matcher(errors);
if(matcher.find())
{
errors = matcher.replaceFirst("");
}
return new LaunchedProgram(errors, output, debugInformation, exitCode);
}
catch(ExecutionException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.NullPointerTester.Visibility;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public class EnumTesterTest
{
@Test
Expand Down Expand Up @@ -55,11 +57,12 @@ private enum InvalidEnum
ONE,
TWO;

@Override
@Override
public String toString()
{
return TWO.name();
}

}

@Test
Expand All @@ -78,18 +81,17 @@ public void testThatInvalidToStringIsDetected()
}
}

private enum InvalidValueOfEnum
private enum InvalidValueOfEnum{ONE,TWO
{
ONE,
TWO
{
@Override

@Override
@SuppressFBWarnings(value = "NP_TOSTRING_COULD_RETURN_NULL", justification = Explanation.TESTING_INVALID_CODE)
public String toString()
{
return null;
}
};
}

};}

@Test
public void testThatPackageProtectedValueOfIsNotCallable() throws ClassNotFoundException
Expand Down
11 changes: 6 additions & 5 deletions config/code-formatter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="100"/>
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="150"/>
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
Expand Down Expand Up @@ -156,7 +156,7 @@
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="next_line_shifted"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="true"/>
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="80"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="do not insert"/>
Expand All @@ -178,7 +178,7 @@
<setting id="org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause" value="common_lines"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="9"/>
<setting id="org.eclipse.jdt.core.compiler.source" value="10"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
Expand All @@ -200,7 +200,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_before_assignment_operator" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="9"/>
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="10"/>
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="next_line"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
Expand Down Expand Up @@ -270,7 +270,7 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="9"/>
<setting id="org.eclipse.jdt.core.compiler.compliance" value="10"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
Expand Down Expand Up @@ -312,4 +312,5 @@
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="do not insert"/>
</profile>

</profiles>
9 changes: 3 additions & 6 deletions config/eclipse.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
Recommended plugins:
Workspace mechanic (http://code.google.com/a/eclipselabs.org/p/workspacemechanic/)
From Marketplace:
AnyEdit Tools
EclEmma
Maven Integration for eclipse (m2eclipse)
Recommended plugins from Marketplace:
Workspace mechanic
Spotbugs

NOTE: As the workspace mechanic tasks modifies workspace global settings it's
recommended to develop in a fresh workspace.
34 changes: 34 additions & 0 deletions config/workspace-mechanic-tasks/format-comments.epf

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions jargo-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<parent>
<groupId>se.softhouse</groupId>
<artifactId>jargo-parent</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
</parent>
<artifactId>jargo-addons</artifactId>
<description>Code that could have been added to jargo if it didn't require third party dependencies.</description>
<dependencies>
<dependency>
<groupId>se.softhouse</groupId>
<artifactId>jargo</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
Expand All @@ -22,14 +22,14 @@
<dependency>
<groupId>se.softhouse</groupId>
<artifactId>common-test</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<!-- Reuses test classes in jargo without having to publish them on maven central -->
<dependency>
<groupId>se.softhouse</groupId>
<artifactId>jargo</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions jargo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>se.softhouse</groupId>
<artifactId>jargo-parent</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
</parent>
<artifactId>jargo</artifactId>
<description>An argument and options parser for java</description>
Expand Down Expand Up @@ -63,7 +63,7 @@
<dependency>
<groupId>se.softhouse</groupId>
<artifactId>common-test</artifactId>
<version>0.4.5-SNAPSHOT</version>
<version>0.4.15-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Loading