@@ -100,6 +100,10 @@ public void parseCmdLine(String[] args) {
100
100
setupInfo .setMulti (true );
101
101
setupInfo .setThreads (parseInt (args , i ));
102
102
break ;
103
+ case "--output" :
104
+ setupInfo .setOutput (true );
105
+ setupInfo .setToOutputDirectory (parsePathName (args , i ));
106
+ break ;
103
107
default :
104
108
throw new CLIException (args [i ]);
105
109
}
@@ -157,24 +161,11 @@ private int parseInt(String[] args, int i) throws CLIException {
157
161
}
158
162
}
159
163
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
-
175
164
private Path parsePathName (String [] args , int i ) throws CLIException {
176
165
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 ]))) {
178
169
return Paths .get (args [i + 1 ]);
179
170
} else {
180
171
throw new CLIException (args [i ], "Invalid path" );
@@ -195,10 +186,12 @@ private Path parsePathName(String[] args, int i) throws CLIException {
195
186
* @throws IOException when there is an issue opening a file
196
187
*/
197
188
public Map <ArtifactIdent , Artifact > runAnalysis (String [] args ) throws URISyntaxException , IOException {
198
-
199
- //set up config from cli
200
189
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
+ }
202
195
203
196
if (setupInfo .isMulti ()) {
204
197
ActorSystem system = ActorSystem .create ("my-system" );
@@ -215,7 +208,6 @@ public Map<ArtifactIdent, Artifact> runAnalysis(String[] args) throws URISyntaxE
215
208
} catch (Exception e ) {
216
209
e .printStackTrace ();
217
210
}
218
-
219
211
} else {
220
212
if (setupInfo .getToCoordinates () == null ) {
221
213
indexProcessor ();
@@ -290,15 +282,15 @@ public List<Artifact> walkAllIndexes(IndexIterator indexIterator) throws IOExcep
290
282
while (indexIterator .hasNext ()) {
291
283
Artifact current = ArtifactFactory .createArtifact (indexIterator .next ());
292
284
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
+ }
296
290
}
291
+ processIndex (current );
297
292
}
298
293
299
- log .info ("{} artifacts collected." , artifacts .get (artifacts .size () - 1 ).getIndexInformation ().getIndex ());
300
- log .info ("{} unique Identifiers." , artifacts .size ());
301
-
302
294
if (setupInfo .isMulti ()) {
303
295
queueActorRef .tell (new IndexProcessingMessage ("Finished" ), ActorRef .noSender ());
304
296
}
@@ -323,6 +315,12 @@ public List<Artifact> walkPaginated(long take, IndexIterator indexIterator) thro
323
315
take += indexIterator .getIndex ();
324
316
while (indexIterator .hasNext () && indexIterator .getIndex () < take ) {
325
317
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
+ }
326
324
artifacts .add (current );
327
325
processIndex (current );
328
326
}
@@ -356,6 +354,12 @@ public List<Artifact> walkDates(long since, long until, IndexIterator indexItera
356
354
currentToSince = temp .getLastModified ();
357
355
if (currentToSince >= since && currentToSince < until ) {
358
356
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
+ }
359
363
artifacts .add (current );
360
364
processIndex (current );
361
365
}
@@ -392,6 +396,12 @@ public List<ArtifactIdent> lazyWalkAllIndexes(IndexIterator indexIterator) throw
392
396
while (indexIterator .hasNext ()) {
393
397
ArtifactIdent ident = indexIterator .next ().getIdent ();
394
398
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
+ }
395
405
processIndexIdentifier (ident );
396
406
}
397
407
@@ -418,6 +428,12 @@ public List<ArtifactIdent> lazyWalkPaginated(long take, IndexIterator indexItera
418
428
while (indexIterator .hasNext () && indexIterator .getIndex () < take ) {
419
429
ArtifactIdent ident = indexIterator .next ().getIdent ();
420
430
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
+ }
421
437
processIndexIdentifier (ident );
422
438
}
423
439
@@ -449,6 +465,12 @@ public List<ArtifactIdent> lazyWalkDates(long since, long until, IndexIterator i
449
465
if (currentToSince >= since && currentToSince < until ) {
450
466
ArtifactIdent ident = temp .getIdent ();
451
467
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
+ }
452
474
processIndexIdentifier (ident );
453
475
}
454
476
}
0 commit comments