@@ -100,6 +100,10 @@ public void parseCmdLine(String[] args) {
100100 setupInfo .setMulti (true );
101101 setupInfo .setThreads (parseInt (args , i ));
102102 break ;
103+ case "--output" :
104+ setupInfo .setOutput (true );
105+ setupInfo .setToOutputDirectory (parsePathName (args , i ));
106+ break ;
103107 default :
104108 throw new CLIException (args [i ]);
105109 }
@@ -157,24 +161,11 @@ private int parseInt(String[] args, int i) throws CLIException {
157161 }
158162 }
159163
160- private boolean parseBoolean (String [] args , int i ) throws CLIException {
161- if (i + 1 < args .length ) {
162- String toParse = args [i + 1 ];
163- if (toParse .toLowerCase ().charAt (0 ) == 't' ) {
164- return true ;
165- } else if (toParse .toLowerCase ().charAt (0 ) == 'f' ) {
166- return false ;
167- } else {
168- throw new CLIException (args [i ]);
169- }
170- } else {
171- throw new CLIException (args [i ]);
172- }
173- }
174-
175164 private Path parsePathName (String [] args , int i ) throws CLIException {
176165 if (i + 1 < args .length ) {
177- if (Files .exists (Paths .get (args [i + 1 ])) || args [i ].equals ("--name" )) {
166+ if (Files .isRegularFile (Paths .get (args [i + 1 ])) || args [i ].equals ("--name" )) {
167+ return Paths .get (args [i + 1 ]);
168+ } else if (args [i ].equals ("--output" ) && Files .isDirectory (Paths .get (args [i + 1 ]))) {
178169 return Paths .get (args [i + 1 ]);
179170 } else {
180171 throw new CLIException (args [i ], "Invalid path" );
@@ -195,10 +186,12 @@ private Path parsePathName(String[] args, int i) throws CLIException {
195186 * @throws IOException when there is an issue opening a file
196187 */
197188 public Map <ArtifactIdent , Artifact > runAnalysis (String [] args ) throws URISyntaxException , IOException {
198-
199- //set up config from cli
200189 parseCmdLine (args );
201- resolverFactory = new ResolverFactory (processTransitives );
190+ if (setupInfo .isOutput ()) {
191+ resolverFactory = new ResolverFactory (setupInfo .isOutput (), setupInfo .getToOutputDirectory (), processTransitives );
192+ } else {
193+ resolverFactory = new ResolverFactory (processTransitives );
194+ }
202195
203196 if (setupInfo .isMulti ()) {
204197 ActorSystem system = ActorSystem .create ("my-system" );
@@ -215,7 +208,6 @@ public Map<ArtifactIdent, Artifact> runAnalysis(String[] args) throws URISyntaxE
215208 } catch (Exception e ) {
216209 e .printStackTrace ();
217210 }
218-
219211 } else {
220212 if (setupInfo .getToCoordinates () == null ) {
221213 indexProcessor ();
@@ -290,15 +282,15 @@ public List<Artifact> walkAllIndexes(IndexIterator indexIterator) throws IOExcep
290282 while (indexIterator .hasNext ()) {
291283 Artifact current = ArtifactFactory .createArtifact (indexIterator .next ());
292284 artifacts .add (current );
293- processIndex (current );
294- if (artifacts .size () % 500000 == 0 ) {
295- log .info ("{} artifacts have been parsed." , artifacts .size ());
285+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
286+ Path filePath = setupInfo .getToOutputDirectory ().resolve (current .getIdent ().getGroupID () + "-" + current .getIdent ().getArtifactID () + "-" + current .getIdent ().getVersion () + ".txt" );
287+ if (!Files .exists (filePath )) {
288+ Files .createFile (filePath );
289+ }
296290 }
291+ processIndex (current );
297292 }
298293
299- log .info ("{} artifacts collected." , artifacts .get (artifacts .size () - 1 ).getIndexInformation ().getIndex ());
300- log .info ("{} unique Identifiers." , artifacts .size ());
301-
302294 if (setupInfo .isMulti ()) {
303295 queueActorRef .tell (new IndexProcessingMessage ("Finished" ), ActorRef .noSender ());
304296 }
@@ -323,6 +315,12 @@ public List<Artifact> walkPaginated(long take, IndexIterator indexIterator) thro
323315 take += indexIterator .getIndex ();
324316 while (indexIterator .hasNext () && indexIterator .getIndex () < take ) {
325317 Artifact current = ArtifactFactory .createArtifact (indexIterator .next ());
318+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
319+ Path filePath = setupInfo .getToOutputDirectory ().resolve (current .getIdent ().getGroupID () + "-" + current .getIdent ().getArtifactID () + "-" + current .getIdent ().getVersion () + ".txt" );
320+ if (!Files .exists (filePath )) {
321+ Files .createFile (filePath );
322+ }
323+ }
326324 artifacts .add (current );
327325 processIndex (current );
328326 }
@@ -356,6 +354,12 @@ public List<Artifact> walkDates(long since, long until, IndexIterator indexItera
356354 currentToSince = temp .getLastModified ();
357355 if (currentToSince >= since && currentToSince < until ) {
358356 Artifact current = ArtifactFactory .createArtifact (indexIterator .next ());
357+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
358+ Path filePath = setupInfo .getToOutputDirectory ().resolve (current .getIdent ().getGroupID () + "-" + current .getIdent ().getArtifactID () + "-" + current .getIdent ().getVersion () + ".txt" );
359+ if (!Files .exists (filePath )) {
360+ Files .createFile (filePath );
361+ }
362+ }
359363 artifacts .add (current );
360364 processIndex (current );
361365 }
@@ -392,6 +396,12 @@ public List<ArtifactIdent> lazyWalkAllIndexes(IndexIterator indexIterator) throw
392396 while (indexIterator .hasNext ()) {
393397 ArtifactIdent ident = indexIterator .next ().getIdent ();
394398 idents .add (ident );
399+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
400+ Path filePath = setupInfo .getToOutputDirectory ().resolve (ident .getGroupID () + "-" + ident .getArtifactID () + "-" + ident .getVersion () + ".txt" );
401+ if (!Files .exists (filePath )) {
402+ Files .createFile (filePath );
403+ }
404+ }
395405 processIndexIdentifier (ident );
396406 }
397407
@@ -418,6 +428,12 @@ public List<ArtifactIdent> lazyWalkPaginated(long take, IndexIterator indexItera
418428 while (indexIterator .hasNext () && indexIterator .getIndex () < take ) {
419429 ArtifactIdent ident = indexIterator .next ().getIdent ();
420430 idents .add (ident );
431+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
432+ Path filePath = setupInfo .getToOutputDirectory ().resolve (ident .getGroupID () + "-" + ident .getArtifactID () + "-" + ident .getVersion () + ".txt" );
433+ if (!Files .exists (filePath )) {
434+ Files .createFile (filePath );
435+ }
436+ }
421437 processIndexIdentifier (ident );
422438 }
423439
@@ -449,6 +465,12 @@ public List<ArtifactIdent> lazyWalkDates(long since, long until, IndexIterator i
449465 if (currentToSince >= since && currentToSince < until ) {
450466 ArtifactIdent ident = temp .getIdent ();
451467 idents .add (ident );
468+ if (setupInfo .isOutput () && !resolvePom && !resolveJar ) {
469+ Path filePath = setupInfo .getToOutputDirectory ().resolve (ident .getGroupID () + "-" + ident .getArtifactID () + "-" + ident .getVersion () + ".txt" );
470+ if (!Files .exists (filePath )) {
471+ Files .createFile (filePath );
472+ }
473+ }
452474 processIndexIdentifier (ident );
453475 }
454476 }
0 commit comments