66import org .slf4j .LoggerFactory ;
77
88import java .io .File ;
9+ import java .nio .file .Path ;
910import java .util .*;
1011
1112public class BuildArguments {
@@ -19,11 +20,19 @@ public class BuildArguments {
1920 private static final String TEST_JAR_INPUT = "t" ;
2021 private static final String TEST_JAR_INPUT_LONG = "testJarPath" ;
2122
23+ private static final String CONFIG_NAME = "c" ;
24+
25+ private static final String CONFIG_NAME_LONG = "config" ;
26+
2227 private final List <Pair <String , File >> jars = new ArrayList <>();
2328 private Optional <String > maybeOutput = Optional .empty ();
2429
2530 private Optional <Pair <String , File >> maybeTestJar = Optional .empty ();
2631
32+ private Optional <String > maybeConfig = Optional .empty ();
33+
34+ private final static String jarBasePath = "artifacts/output/" ;
35+
2736 /**
2837 * Parse command line args into variables
2938 *
@@ -38,17 +47,36 @@ public BuildArguments(String[] args) {
3847 CommandLine cmd ;
3948 try {
4049 cmd = parser .parse (options , args );
41- /* Parse JARs */
42- if (cmd .hasOption (JAR_INPUT )) {
43- jarPaths .addAll (Arrays .asList (cmd .getOptionValues (JAR_INPUT )));
44- }
4550
46- /* Parse test JAR */
47- if (cmd .hasOption (TEST_JAR_INPUT )) {
48- String testJarPath = cmd .getOptionValue (TEST_JAR_INPUT );
49- Pair <String , File > testJarPair = pathAndJarFile (testJarPath );
50- jars .add (testJarPair );
51- maybeTestJar = Optional .of (testJarPair );
51+ /* Get from configuration */
52+ if (cmd .hasOption (CONFIG_NAME )) {
53+ Optional <RepoTool > rt = RepoTool .obtainTool (cmd .getOptionValue (CONFIG_NAME ));
54+
55+ if (rt .isPresent ()) {
56+ String mainJar = getJarRelativePath (rt .get ().getMainJar ());
57+ jarPaths .add (mainJar );
58+
59+ String testJar = getJarRelativePath (rt .get ().getTestJar ());
60+ Pair <String , File > testJarPair = pathAndJarFile (testJar );
61+ jars .add (testJarPair );
62+ maybeTestJar = Optional .of (testJarPair );
63+ } else {
64+ LOGGER .error ("Unable to obtain RepoTool." );
65+ System .exit (1 );
66+ }
67+ } else {
68+ /* Parse JARs */
69+ if (cmd .hasOption (JAR_INPUT )) {
70+ jarPaths .addAll (Arrays .asList (cmd .getOptionValues (JAR_INPUT )));
71+ }
72+
73+ /* Parse test JAR */
74+ if (cmd .hasOption (TEST_JAR_INPUT )) {
75+ String testJarPath = cmd .getOptionValue (TEST_JAR_INPUT );
76+ Pair <String , File > testJarPair = pathAndJarFile (testJarPath );
77+ jars .add (testJarPair );
78+ maybeTestJar = Optional .of (testJarPair );
79+ }
5280 }
5381
5482 /* Parse output name */
@@ -69,17 +97,34 @@ public BuildArguments(String[] args) {
6997 .forEach (this .jars ::add );
7098 }
7199
100+ private static String getJarRelativePath (String jar ) {
101+ return jar .charAt (0 ) == '/' ? jar : Path .of (jarBasePath , jar ).toString ();
102+ }
103+
72104 private static Options getOptions () {
73105 Options options = new Options ();
106+ OptionGroup configOrMainJar = new OptionGroup ();
74107
75- options .addOption (
108+ configOrMainJar .isRequired ();
109+
110+ configOrMainJar .addOption (
111+ Option .builder (CONFIG_NAME )
112+ .longOpt (CONFIG_NAME_LONG )
113+ .hasArg (true )
114+ .desc ("[REQUIRED if -" +JAR_INPUT +" not specified] specify an output name for the bytecode" )
115+ .required (false )
116+ .build ());
117+
118+ configOrMainJar .addOption (
76119 Option .builder (JAR_INPUT )
77120 .longOpt (JAR_INPUT_LONG )
78121 .hasArg (true )
79- .desc ("[REQUIRED] specify one or more paths to JARs to analyze" )
80- .required (true )
122+ .desc ("[REQUIRED if -" + CONFIG_NAME + "not specified ] specify one or more paths to JARs to analyze" )
123+ .required (false )
81124 .build ());
82125
126+ options .addOptionGroup (configOrMainJar );
127+
83128 options .addOption (
84129 Option .builder (TEST_JAR_INPUT )
85130 .longOpt (TEST_JAR_INPUT_LONG )
@@ -110,6 +155,10 @@ public Optional<Pair<String, File>> getMaybeTestJar() {
110155 return maybeTestJar ;
111156 }
112157
158+ public Optional <String > getMaybeConfig () {
159+ return maybeConfig ;
160+ }
161+
113162 // Make sure the path is a path to a jar file
114163 private void validateJarSuffix (String jarPath ) {
115164 if (!jarPath .endsWith (JAR_SUFFIX )) {
0 commit comments