Skip to content

Commit

Permalink
Fix for #223 (broken command line parsing) (#224)
Browse files Browse the repository at this point in the history
* Added test for reproducing #223

(cherry picked from commit 9734610)

* Fix of broken command line parsing (#223)

(cherry picked from commit 55dd217)
  • Loading branch information
ohecker authored Jan 16, 2024
1 parent 193edd9 commit 6045bfa
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public CommandLineOptions parse(String[] commandLineArgs) {
builder = Option.builder("l");
builder.longOpt("loadModel");
builder.hasArg();
builder.optionalArg(false);
builder.argName("filename");
description = "instead of reading raw license data and processing rules load the already "
+ "processed model from a previously saved file";
Expand All @@ -134,7 +133,6 @@ public CommandLineOptions parse(String[] commandLineArgs) {
builder = Option.builder("d");
builder.longOpt("diff");
builder.hasArg();
builder.optionalArg(false);
builder.argName("filename");
description = "create a diff report to the already processed model given by this filename";
builder.desc(description);
Expand Down Expand Up @@ -204,7 +202,7 @@ public CommandLineOptions parse(String[] commandLineArgs) {

/**
* Prints help information to standard output.
*
*
* @param options the {@link Options} object which describes the command line syntax
*/
private void printHelp(Options options) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.devonfw.tools.solicitor;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import com.devonfw.tools.solicitor.SolicitorCliProcessor.CommandLineOptions;

/**
* Tests for class {@link SolicitorCliProcessor}.
*
*/
class SolicitorCliProcessorTest {

@Test
void testCliParsingHelpOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-eug" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.help);

testCli = new String[] { "-h" };
clo = scp.parse(testCli);
assertTrue(clo.help);

testCli = new String[] { "--help" };
clo = scp.parse(testCli);
assertTrue(clo.help);
}

@Test
void testCliParsingEugOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.extractUserGuide);

testCli = new String[] { "-eug" };
clo = scp.parse(testCli);
assertTrue(clo.extractUserGuide);

testCli = new String[] { "--extractUserGuide" };
clo = scp.parse(testCli);
assertTrue(clo.extractUserGuide);
}

@Test
void testCliParsingWizOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.wizard);

testCli = new String[] { "-wiz", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.wizard);
assertEquals("arg", clo.targetDir);

testCli = new String[] { "--projectWizard", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.wizard);
assertEquals("arg", clo.targetDir);
}

@Test
void testCliParsingEcOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.extractConfig);

testCli = new String[] { "-ec", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.extractConfig);
assertEquals("arg", clo.targetDir);

testCli = new String[] { "--extractConfig", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.extractConfig);
assertEquals("arg", clo.targetDir);
}

@Test
void testCliParsingConfigOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertNull(clo.configUrl);

testCli = new String[] { "-c", "arg" };
clo = scp.parse(testCli);
assertEquals("arg", clo.configUrl);

testCli = new String[] { "--config"/* , "arg" */ };
// clo = scp.parse(testCli);
// assertEquals("arg", clo.configUrl);
}

@Test
void testCliParsingSaveModelOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.save);

testCli = new String[] { "-s", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.save);
assertEquals("arg", clo.pathForSave);

testCli = new String[] { "--saveModel", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.save);
assertEquals("arg", clo.pathForSave);

testCli = new String[] { "-s" };
clo = scp.parse(testCli);
assertTrue(clo.save);
assertNull(clo.pathForSave);

testCli = new String[] { "--saveModel" };
clo = scp.parse(testCli);
assertTrue(clo.save);
assertNull(clo.pathForSave);
}

@Test
void testCliParsingLoadModelOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.load);

testCli = new String[] { "-l", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.load);
assertEquals("arg", clo.pathForLoad);

testCli = new String[] { "--loadModel", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.load);
assertEquals("arg", clo.pathForLoad);
}

@Test
void testCliParsingDiffOption() {

SolicitorCliProcessor scp = new SolicitorCliProcessor();
String[] testCli = new String[] { "-h" };
CommandLineOptions clo = scp.parse(testCli);
assertFalse(clo.diff);

testCli = new String[] { "-d", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.diff);
assertEquals("arg", clo.pathForDiff);

testCli = new String[] { "--diff", "arg" };
clo = scp.parse(testCli);
assertTrue(clo.diff);
assertEquals("arg", clo.pathForDiff);
}
}
9 changes: 6 additions & 3 deletions documentation/master-solicitor.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ The determined content is available as `NormalizedLicense.effectiveNormalizedLic
=== Encoding of URLs
When creating the resource or filename for given URLs in the above steps the following encoding scheme will be applied to ensure that always a valid name can be created:

* If the scheme is `https` it will be replaced with `http`.
* If the scheme is `https` it will be replaced with `http`.
* All "non-word" characters (i.e. characters outside the set `[a-zA-Z_0-9]`) are replaced by underscores ("`_`").
* In case that the resulting filename exceeds a length of 250 it will be replaced by a new name concatenated from
** the first 40 characters of the (too) long filename
Expand Down Expand Up @@ -1433,8 +1433,8 @@ When using the Scancode integration the following values are used for field `App

[width="100%",cols="1,3",options="header"]
|====================
| Value | Description
| `ND:DISABLED` | No data available. Scancode integration disabled.
| Value | Description
| `ND:DISABLED` | No data available. Scancode integration disabled.
| `ND:NOT_AVAILABLE` | No data available. No scan results existing and no indication that attempting download/scanning has failed.
| `ND:PROCESSING_FAILED` | No data available. No scan results existing. Processing (downloading or scanning) had failed.
| `DA:WITH_ISSUES` | Data available. Issues were detected in the data which probably need to be curated.
Expand Down Expand Up @@ -1637,6 +1637,9 @@ Spring beans implementing this interface will be called at certain points in the
== Release Notes
Changes in 1.18.0::

Changes in 1.17.1::
* https://github.com/devonfw/solicitor/issues/223: Fixed a regression bug in Solicitor command line parsing which (within Version 1.16.0 and 1.17.0) prevents correct parsing of "l" and "d" options.

Changes in 1.17.0::
* https://github.com/devonfw/solicitor/issues/221: Provide status information on data obtained from Scancode in field `ApplicationComponent.dataStatus`. See <<dataStatus values of the Scancode integration>>.

Expand Down

0 comments on commit 6045bfa

Please sign in to comment.