Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/gradle/org.jetbrains.kotlin-kotli…
Browse files Browse the repository at this point in the history
…n-script-runtime-1.9.23
  • Loading branch information
remkop authored Apr 9, 2024
2 parents abc293f + 6f6fc93 commit 12ad764
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
egress-policy: audit

- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4
Expand Down Expand Up @@ -135,7 +135,7 @@ jobs:
egress-policy: audit

- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633

- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@56b90f209b02bf6d1deae490e9ef18b21a389cd4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ jobs:
egress-policy: audit

- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v2
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@b374143c1149a9115d881581d29b8390bbcbb59c # v1
uses: github/codeql-action/init@05963f47d870e2cb19a537396c1f668a348c7d8f # v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -84,4 +84,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b374143c1149a9115d881581d29b8390bbcbb59c # v1
uses: github/codeql-action/analyze@05963f47d870e2cb19a537396c1f668a348c7d8f # v1
4 changes: 2 additions & 2 deletions .github/workflows/scorecards-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v2.4.0
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v2.4.0
with:
persist-credentials: false

Expand Down Expand Up @@ -59,6 +59,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@b374143c1149a9115d881581d29b8390bbcbb59c # v1.0.26
uses: github/codeql-action/upload-sarif@05963f47d870e2cb19a537396c1f668a348c7d8f # v1.0.26
with:
sarif_file: results.sarif
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Artifacts in this release are signed by Remko Popma (6601 E5C0 8DCC BB96).
* [#2102][#2107] Enhancement: `PropertiesDefaultProvider` should try to load properties from classpath (last). Thanks to [Lumír Návrat](https:/rimuln) for the pull request.
* [#2058] Bugfix: `defaultValue` should not be applied in addition to user-specified value for options with a custom `IParameterConsumer`. Thanks to [Staffan Arvidsson McShane](https:/StaffanArvidsson) for raising this.
* [#2148] Bugfix: Fix NPE in jline3 `Example.jar` as `ConfigurationPath` cannot be `null` anymore. Thanks to [llzen44](https:/llzen44) for the pull request.
* [#2232] Bugfix: fix bug for `Optional<T>` arguments with initial value. Thanks to [hq6](https:/hq6) for raising this.
* [#2171] Fix a few typos in CommandLine's JavaDoc. Thanks to [Michael Vorburger](https:/vorburger) for the pull request.
* [#2172] Fix broken build. Thanks to [Michael Vorburger](https:/vorburger) for the pull request.
* [#2174] Fix .gitattributes related CR/LF problems. Thanks to [Michael Vorburger](https:/vorburger) for the pull request.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {

dependencies {
classpath "org.asciidoctor:asciidoctor-gradle-jvm:$asciidoctorGradlePluginVersion"
classpath 'org.asciidoctor:asciidoctorj-pdf:2.3.9'
classpath 'org.asciidoctor:asciidoctorj-pdf:2.3.15'
classpath "org.beryx:badass-jar:2.0.0"
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:6.4.0'
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.30.0"
Expand Down Expand Up @@ -68,7 +68,7 @@ allprojects {
apply plugin: "net.ltgt.errorprone"

dependencies {
errorprone("com.google.errorprone:error_prone_core:2.23.0")
errorprone("com.google.errorprone:error_prone_core:2.26.1")
}

tasks.withType(JavaCompile).configureEach {
Expand Down
2 changes: 2 additions & 0 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,8 @@ assert(mixed.options == Arrays.asList("AAA", "BBB"))
----

=== Double dash (`--`)
Picocli offers built-in support for the End-of-Options delimiter (`--`), as defined in Guideline 10 of the link:https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02[POSIX Utility Syntax Guidelines].

When one of the command line arguments is just two dashes without any characters attached (`--`),
picocli interprets all following arguments as positional parameters, even arguments that match an option name.

Expand Down
6 changes: 6 additions & 0 deletions picocli-examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ normalization {
}

tasks.withType(Javadoc).all { enabled = false }
//tasks.named('compileKotlin', org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask.class) {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
compilerOptions {
freeCompilerArgs.add('-Xskip-metadata-version-check')
}
}
//tasks.withType(Javadoc) {
// options.addBooleanOption('Xdoclint:none', true)
//}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package picocli.examples.stdin;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.List;
import java.util.concurrent.Callable;

/**
* This example reads a file, or from standard input, and prints the first line.
*
* It follows the UNIX convention that tools should read from STDIN (standard input)
* when the end user specifies the `-` character instead of a file name.
*
* See POSIX Utility Syntax Guidelines, Guideline 13:
* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_02
*/
@Command(name = "firstline")
public class PrintFirstLine implements Callable<Integer> {

@Parameters(arity = "1..*")
List<File> files;

@Option(names = "--charset", description = "Charset of the file (or STDIN) to read. Default: ${DEFAULT_VALUE}")
Charset charset = Charset.defaultCharset();

public Integer call() throws Exception {
for (File file : files) {
printFirstLine(file);
}
return 0;
}

private void printFirstLine(File file) throws IOException {
try (BufferedReader reader = createReader(file)) {
String line = reader.readLine();
System.out.println(line);
}
}

private BufferedReader createReader(File file) throws IOException {
InputStream in = "-".equals(file.toString())
? System.in
: Files.newInputStream(file.toPath());
return new BufferedReader(new InputStreamReader(in, charset));
}

public static void main(String... args) {
int exitCode = new CommandLine(new PrintFirstLine()).execute(args);
//System.exit(exitCode); // prevents this method from being testable...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package picocli.examples.stdin;

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.contrib.java.lang.system.TextFromStandardInputStream;

import java.net.URL;

import static org.junit.Assert.*;

public class PrintFirstLineTest {

@Rule
public final SystemOutRule outRule = new SystemOutRule().enableLog().muteForSuccessfulTests();

@Rule
public final TextFromStandardInputStream systemInMock = TextFromStandardInputStream.emptyStandardInputStream();

@Test
public void testMain() {
URL resource = PrintFirstLineTest.class.getResource("/PrintFirstLineTest.txt");
String path = resource.getPath();
PrintFirstLine.main(path);
assertEquals("file line 1", outRule.getLog().trim());
}

@Test
public void testStandardInput() {
systemInMock.provideLines("stdin line1", "stdin line2", "stdin line3");
PrintFirstLine.main("-");
assertEquals("stdin line1", outRule.getLog().trim());
}
}
3 changes: 3 additions & 0 deletions picocli-examples/src/test/resources/PrintFirstLineTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
file line 1
file line 2
file line 3
10 changes: 10 additions & 0 deletions picocli-tests-java8/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Picocli Java 8 Tests

This subproject contains tests that use Java 8, and the JUnit 5 and System Lambda test frameworks.

This module does not publish any artifacts.

NOTE: only put tests here that require Java 8 and cannot be run in earlier versions of Java.

Tests that require Java 9 or later should be located in the `picocli-tests-java9plus` subproject.

34 changes: 34 additions & 0 deletions picocli-tests-java8/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
id 'java'
}

group 'info.picocli'
description 'Picocli Tests Requiring Java 8'
version "$projectVersion"

sourceCompatibility = 1.8
targetCompatibility = 1.8

test {
useJUnitPlatform()
}


dependencies {
api rootProject
testImplementation supportDependencies.junit5Api
testRuntimeOnly supportDependencies.junit5Engine
testImplementation supportDependencies.systemLambda
}

jar {
manifest {
attributes 'Specification-Title': 'Picocli Tests Requiring Java 8',
'Specification-Vendor' : 'Remko Popma',
'Specification-Version' : archiveVersion.get(),
'Implementation-Title' : 'Picocli Tests Requiring Java 8',
'Implementation-Vendor' : 'Remko Popma',
'Implementation-Version': archiveVersion.get(),
'Automatic-Module-Name' : 'info.picocli.tests.java8'
}
}
30 changes: 30 additions & 0 deletions picocli-tests-java8/src/test/java/picocli/Issue2232.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package picocli;

import org.junit.Test;
import picocli.CommandLine;
import picocli.CommandLine.*;

import java.io.File;
import java.util.Optional;

import static org.junit.Assert.*;

public class Issue2232 {
static class Tar {
@Option(names = { "-f", "--file" }, paramLabel = "ARCHIVE", description = "the archive file")
Optional<File> archive;

public Tar() {
archive = Optional.of(new File("helloworld"));
}
}

@Test
public void testDefault() {
Tar tar = new Tar();
System.out.println(tar.archive);
assertEquals(Optional.of(new File("helloworld")), tar.archive);
new CommandLine(tar).parseArgs();
assertEquals(Optional.of(new File("helloworld")), tar.archive);
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include 'picocli-groovy'
include 'picocli-examples'
include 'picocli-shell-jline2'
include 'picocli-codegen'
include 'picocli-tests-java8'

if (org.gradle.api.JavaVersion.current().isJava8Compatible()) {
include 'picocli-spring-boot-starter'
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13719,9 +13719,14 @@ private boolean applyDefault(IDefaultValueProvider defaultValueProvider, ArgSpec
arg.valueIsDefaultValue = true;
} else {
if (arg.typeInfo().isOptional()) {
if (tracer.isDebug()) {
tracer.debug("Applying Optional.empty() to %s on %s", arg, arg.scopeString());}
arg.setValue(getOptionalEmpty());
if (arg.hasInitialValue() && arg.initialValue() != null) {
if (tracer.isDebug()) {
tracer.debug("Leaving initial value %s for %s on %s", arg.initialValue(), arg, arg.scopeString());}
} else {
if (tracer.isDebug()) {
tracer.debug("Applying Optional.empty() to %s on %s", arg, arg.scopeString());}
arg.setValue(getOptionalEmpty());
}
arg.valueIsDefaultValue = true;
} else if (ArgSpec.UNSPECIFIED.equals(arg.originalDefaultValue)) {
tracer.debug("defaultValue not defined for %s", arg);
Expand Down

0 comments on commit 12ad764

Please sign in to comment.