forked from mercedes-benz/sechub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review changes for mercedes-benz#1620
- removed comment about SERVER - using now Java 11 - using distribution temurin - introduced an enum for main commands + generating now the help output
- Loading branch information
Showing
6 changed files
with
187 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...ub-pds-tools/src/main/java/com/mercedesbenz/sechub/pds/tools/MainPDSToolsCLICommands.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.pds.tools; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
|
||
public enum MainPDSToolsCLICommands implements PDSToolCLICommand { | ||
|
||
/* @formatter:off */ | ||
HELP(PDSToolsCLiConstants.CMD_HELP, "Show this help output."), | ||
|
||
GENERATE(PDSToolsCLiConstants.CMD_GENERATE,"Generate PDS test files.", | ||
|
||
new PDSToolCLICommandArgument("secHubConfigFilePath","path to the sechub config file used to generate."), | ||
new PDSToolCLICommandArgument("scanType","scan type - must be one of: "+generateScanTypeString()+"."), | ||
new PDSToolCLICommandArgument("targetFolderPath","When not defined, a temp folder will be created and used.",true) | ||
|
||
), | ||
/* @formatter:on */ | ||
|
||
; | ||
|
||
private static String generateScanTypeString() { | ||
StringBuilder sb = new StringBuilder(); | ||
|
||
ScanType type; | ||
for (Iterator<ScanType> it = PDSToolsCLiConstants.NO_REPORT_OR_UNKNOWN.iterator(); it.hasNext();) { | ||
type = it.next(); | ||
sb.append(type.getId()); | ||
if (it.hasNext()) { | ||
sb.append(", "); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
private String description; | ||
private List<PDSToolCLICommandArgument> arguments; | ||
private String commandString; | ||
|
||
private MainPDSToolsCLICommands(String commandString, String description, PDSToolCLICommandArgument... arguments) { | ||
this.description = description; | ||
this.commandString = commandString; | ||
if (arguments == null || arguments.length == 0) { | ||
this.arguments = new ArrayList<>(); | ||
} else { | ||
this.arguments = Arrays.asList(arguments); | ||
} | ||
} | ||
|
||
public String getCommandString() { | ||
return commandString; | ||
} | ||
|
||
public List<PDSToolCLICommandArgument> getArguments() { | ||
return arguments; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return description; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
sechub-pds-tools/src/main/java/com/mercedesbenz/sechub/pds/tools/PDSToolCLICommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.pds.tools; | ||
|
||
import java.util.List; | ||
|
||
public interface PDSToolCLICommand { | ||
|
||
public String getCommandString(); | ||
|
||
public String getDescription(); | ||
|
||
public List<PDSToolCLICommandArgument> getArguments(); | ||
} |
31 changes: 31 additions & 0 deletions
31
...-pds-tools/src/main/java/com/mercedesbenz/sechub/pds/tools/PDSToolCLICommandArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.pds.tools; | ||
|
||
public class PDSToolCLICommandArgument { | ||
|
||
private String name; | ||
private String description; | ||
private boolean optional; | ||
|
||
public PDSToolCLICommandArgument(String name, String description) { | ||
this(name, description, false); | ||
} | ||
|
||
public PDSToolCLICommandArgument(String name, String description, boolean optional) { | ||
this.name = name; | ||
this.description = description; | ||
this.optional = optional; | ||
} | ||
|
||
public boolean isOptional() { | ||
return optional; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
sechub-pds-tools/src/main/java/com/mercedesbenz/sechub/pds/tools/PDSToolsCLiConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
package com.mercedesbenz.sechub.pds.tools; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.mercedesbenz.sechub.commons.model.ScanType; | ||
|
||
public class PDSToolsCLiConstants { | ||
|
||
public static final String CMD_HELP = "--help"; | ||
public static final String CMD_GENERATE = "--generate"; | ||
|
||
public static final List<ScanType> NO_REPORT_OR_UNKNOWN = Collections.unmodifiableList(createAcceptedScanTypes()); | ||
|
||
private static List<ScanType> createAcceptedScanTypes() { | ||
List<ScanType> acceptedScanTypes = new ArrayList<>(); | ||
|
||
for (ScanType type : ScanType.values()) { | ||
switch (type) { | ||
case REPORT: | ||
case UNKNOWN: | ||
// we do not accept those types | ||
continue; | ||
default: | ||
acceptedScanTypes.add(type); | ||
|
||
} | ||
} | ||
return acceptedScanTypes; | ||
|
||
} | ||
} |