Skip to content

Commit eeaa517

Browse files
authored
Merge pull request #6 from sse-labs/development
Development
2 parents 32b34db + 7229abf commit eeaa517

14 files changed

+370
-67
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,7 @@ target
3030
.idea
3131

3232
# LastIndexProcessed
33-
lastIndexProcessed
33+
lastIndexProcessed
34+
35+
#maven resolution files
36+
maven-resolution-files

src/.DS_Store

6 KB
Binary file not shown.

src/main/.DS_Store

6 KB
Binary file not shown.

src/main/java/org/tudo/sse/CliInformation.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class CliInformation {
1515
private Path name;
1616
private Path toCoordinates;
1717
private Path toIndexPos;
18+
private boolean output;
19+
private Path toOutputDirectory;
1820
private boolean multi;
1921
private int threads;
2022

@@ -26,6 +28,8 @@ public CliInformation() {
2628
name = Paths.get("lastIndexProcessed");
2729
toCoordinates = null;
2830
toIndexPos = null;
31+
toOutputDirectory = null;
32+
output = false;
2933
multi = false;
3034
}
3135

@@ -100,4 +104,20 @@ public int getThreads() {
100104
public void setThreads(int threads) {
101105
this.threads = threads;
102106
}
107+
108+
public boolean isOutput() {
109+
return output;
110+
}
111+
112+
public void setOutput(boolean output) {
113+
this.output = output;
114+
}
115+
116+
public Path getToOutputDirectory() {
117+
return toOutputDirectory;
118+
}
119+
120+
public void setToOutputDirectory(Path toOutputDirectory) {
121+
this.toOutputDirectory = toOutputDirectory;
122+
}
103123
}

src/main/java/org/tudo/sse/Main.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import org.apache.logging.log4j.LogManager;
44
import org.apache.logging.log4j.Logger;
5+
import org.tudo.sse.model.Artifact;
6+
import org.tudo.sse.resolution.PomResolutionException;
7+
import org.tudo.sse.utils.GAUtils;
58

69
import java.io.IOException;
710
import java.net.URISyntaxException;
11+
import java.util.List;
812

913
public class Main {
1014

@@ -16,7 +20,7 @@ public static void main(String[] args) throws URISyntaxException {
1620
System.exit(1);
1721
}
1822

19-
OwnImplementation imp = new OwnImplementation();
23+
OwnImplementation imp = new OwnImplementation(false, true, false, true);
2024
try {
2125
imp.runAnalysis(args);
2226
} catch (IOException e) {

src/main/java/org/tudo/sse/MavenCentralAnalysis.java

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/main/java/org/tudo/sse/resolution/JarResolver.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
import java.io.DataInputStream;
2525
import java.io.IOException;
2626
import java.net.MalformedURLException;
27+
import java.net.URI;
2728
import java.net.URL;
2829
import java.io.InputStream;
30+
import java.nio.file.Files;
31+
import java.nio.file.Path;
2932
import java.util.*;
3033
import java.util.jar.JarInputStream;
3134

@@ -36,10 +39,26 @@
3639
* @see JarInformation
3740
*/
3841
public class JarResolver {
42+
private final Path pathToDirectory;
43+
private boolean output;
3944
private final Java16LibraryFramework cfReader = Project$.MODULE$.JavaClassFileReader(GlobalLogContext$.MODULE$, package$.MODULE$.BaseConfig());
4045
private static final MavenCentralRepository MavenRepo = MavenCentralRepository.getInstance();
4146
private static final Logger log = LogManager.getLogger(JarResolver.class);
4247

48+
public JarResolver() {
49+
output = false;
50+
pathToDirectory = null;
51+
}
52+
53+
public JarResolver(boolean output, Path pathToDirectory) {
54+
this.output = output;
55+
this.pathToDirectory = pathToDirectory;
56+
}
57+
58+
public void setOutput(boolean output) {
59+
this.output = output;
60+
}
61+
4362
/**
4463
* This method resolves jar artifacts from a given list of artifact identifiers.
4564
*
@@ -80,10 +99,8 @@ public Artifact parseJar(ArtifactIdent identifier) throws JarResolutionException
8099
}
81100

82101
try {
83-
boolean output = true;
84102
URL jarURL = identifier.getMavenCentralJarUri().toURL();
85103
InputStream jarInput = MavenRepo.openJarFileInputStream(identifier);
86-
//TODO: move output to mavenCentralAnalysis and into jarResolver constructor
87104
if(output) {
88105
var baos = new ByteArrayOutputStream();
89106
var buffer = new byte[32 * 1024];
@@ -98,7 +115,13 @@ public Artifact parseJar(ArtifactIdent identifier) throws JarResolutionException
98115
}
99116

100117
byte[] jarBytes = baos.toByteArray();
101-
//TODO: Write to a file
118+
119+
Path filePath = pathToDirectory.resolve(identifier.getGroupID() + "-" + identifier.getArtifactID() + "-" + identifier.getVersion() + ".jar");
120+
if(!Files.exists(filePath)) {
121+
Files.createFile(filePath);
122+
Files.write(filePath, jarBytes);
123+
}
124+
102125
jarInput = new ByteArrayInputStream(jarBytes);
103126
}
104127

0 commit comments

Comments
 (0)