Skip to content

Commit 85ae15d

Browse files
committed
Bump version + module name options
1 parent ffc7f6e commit 85ae15d

File tree

5 files changed

+102
-26
lines changed

5 files changed

+102
-26
lines changed

JRESOLVE_RELEASED_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024.07.24
1+
2024.07.27

JRESOLVE_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2024.07.24
1+
2024.07.27

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ make_reflect_config:
77
./mvnw -Ppicocli-codegen dependency:copy-dependencies
88
./mvnw package
99
java \
10-
--class-path target/dependency/picocli-codegen-4.7.5.jar:target/jresolve-cli-2024.07.24.jar:target/dependency/json-2023.12.23.jar:target/dependency/picocli-4.7.5.jar:target/dependency/purl-2023.11.07.jar:target/dependency/resolve-2024.05.26.jar \
10+
--class-path target/dependency/picocli-codegen-4.7.5.jar:target/jresolve-cli-2024.07.27.jar:target/dependency/json-2023.12.23.jar:target/dependency/picocli-4.7.5.jar:target/dependency/purl-2023.11.07.jar:target/dependency/resolve-2024.05.26.jar \
1111
picocli.codegen.aot.graalvm.ReflectionConfigGenerator \
1212
dev.mccue.resolve.cli.CliMain > reflect.json
1313

@@ -19,7 +19,7 @@ exe static='':
1919
native-image \
2020
--module-path target/dependency/json-2023.12.23.jar:target/dependency/picocli-4.7.5.jar:target/dependency/purl-2023.11.07.jar:target/dependency/resolve-2024.05.26.jar \
2121
-H:+UnlockExperimentalVMOptions -H:ReflectionConfigurationFiles=reflect.json -H:+ReportUnsupportedElementsAtRuntime \
22-
-jar target/jresolve-cli-2024.07.24.jar \
22+
-jar target/jresolve-cli-2024.07.27.jar \
2323
{{static}} jresolve
2424

2525
exe_windows:

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>dev.mccue</groupId>
88
<artifactId>jresolve-cli</artifactId>
9-
<version>2024.07.24</version>
9+
<version>2024.07.27</version>
1010

1111
<properties>
1212
<maven.compiler.source>21</maven.compiler.source>
@@ -227,7 +227,7 @@
227227
<overwriteExistingFiles>true</overwriteExistingFiles>
228228
<modules>
229229
<module>
230-
<file>target/jresolve-cli-2024.07.24-uber.jar</file>
230+
<file>target/jresolve-cli-2024.07.27-uber.jar</file>
231231
<moduleInfoFile>
232232
src/main/uberjar/module-info.java
233233
</moduleInfoFile>

src/main/java/dev/mccue/resolve/cli/CliMain.java

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323
import javax.xml.transform.stream.StreamResult;
2424
import javax.xml.transform.stream.StreamSource;
2525
import java.io.*;
26+
import java.lang.module.ModuleDescriptor;
2627
import java.lang.module.ModuleFinder;
28+
import java.lang.module.ModuleReference;
2729
import java.net.Authenticator;
2830
import java.net.PasswordAuthentication;
2931
import java.net.URI;
3032
import java.net.URISyntaxException;
3133
import java.net.http.HttpClient;
3234
import java.net.http.HttpRequest;
3335
import java.net.http.HttpResponse;
34-
import java.nio.file.Files;
35-
import java.nio.file.Path;
36-
import java.nio.file.Paths;
37-
import java.nio.file.StandardCopyOption;
36+
import java.nio.file.*;
37+
import java.nio.file.attribute.BasicFileAttributes;
3838
import java.util.*;
3939
import java.util.concurrent.Callable;
40-
import java.util.function.Consumer;
4140
import java.util.function.Function;
41+
import java.util.stream.Collectors;
4242

4343
@CommandLine.Command(
4444
name = "jresolve",
4545
mixinStandardHelpOptions = true,
46-
version = "v2024.07.24",
46+
version = "v2024.07.27",
4747
description = "Resolves dependencies for the JVM."
4848
)
4949
public final class CliMain implements Callable<Integer> {
@@ -107,9 +107,22 @@ public final class CliMain implements Callable<Integer> {
107107
)
108108
public File cachePath = null;
109109

110+
@CommandLine.Option(
111+
names = {"--use-module-names"},
112+
description = "Save files in the output directory using the module names the jars represent."
113+
)
114+
public boolean useModuleNames = false;
115+
116+
@CommandLine.Option(
117+
names = "--purge-output-directory",
118+
description = "Purges the specified output directory on run"
119+
)
120+
public boolean purgeOutputDirectory = false;
121+
110122
@CommandLine.Parameters(paramLabel = "dependencies", description = "Package urls of dependencies")
111123
public String[] dependencies = new String[]{};
112124

125+
113126
public CliMain(PrintWriter out, PrintWriter err) {
114127
this.out = out;
115128
this.err = err;
@@ -320,9 +333,10 @@ protected PasswordAuthentication getPasswordAuthentication() {
320333

321334
if (enrichPom != null) {
322335
var pomContents = Files.readString(enrichPom.toPath());
336+
var factory = DocumentBuilderFactory.newDefaultInstance();
323337
Document document;
324338
try {
325-
document = DocumentBuilderFactory.newDefaultInstance()
339+
document = factory
326340
.newDocumentBuilder()
327341
.parse(new InputSource(new StringReader(pomContents)));
328342
} catch (SAXException | IOException e) {
@@ -499,29 +513,91 @@ protected PasswordAuthentication getPasswordAuthentication() {
499513
}
500514
}
501515

516+
if (outputDirectory != null && purgeOutputDirectory) {
517+
Files.walkFileTree(outputDirectory.toPath(), new SimpleFileVisitor<>() {
518+
@Override
519+
public FileVisitResult visitFile(Path file,
520+
BasicFileAttributes attrs) throws IOException {
521+
Files.delete(file);
522+
return FileVisitResult.CONTINUE;
523+
}
524+
525+
@Override
526+
public FileVisitResult postVisitDirectory(Path dir,
527+
IOException e) throws IOException {
528+
if (e == null) {
529+
Files.delete(dir);
530+
return FileVisitResult.CONTINUE;
531+
} else {
532+
throw e;
533+
}
534+
}
535+
536+
});
537+
}
538+
502539
if (outputDirectory != null && (!deps.libraries().isEmpty() || !extraPaths.isEmpty())) {
503540
Files.createDirectories(outputDirectory.toPath());
504541

505542

506543
var artifacts = new LinkedHashMap<String, Path>();
507544

508-
Consumer<Path> addPath = (path) -> {
509-
var fileName = path.getFileName()
510-
.toString();
511-
if (artifacts.containsKey(fileName)) {
512-
err.println("Duplicate file: " + fileName + ". Need to rename.");
513-
err.flush();
514-
fileName = UUID.randomUUID() + "-" + fileName;
545+
Function<Path, Integer> addPath = (path) -> {
546+
if (useModuleNames) {
547+
var modules = ModuleFinder.of(path).findAll().toArray(ModuleReference[]::new);
548+
if (modules.length == 0) {
549+
err.println("No module found: " + path);
550+
err.flush();
551+
return 1;
552+
}
553+
if (modules.length > 1) {
554+
err.println("More than one module found: " + path);
555+
err.println(
556+
Arrays.stream(modules)
557+
.map(ModuleReference::descriptor)
558+
.map(ModuleDescriptor::name)
559+
.collect(Collectors.joining(", "))
560+
);
561+
err.flush();
562+
return 1;
563+
}
564+
565+
var module = modules[0];
566+
567+
var fileName = module.descriptor().name() + ".jar";
568+
if (artifacts.containsKey(fileName)) {
569+
err.println("Duplicate module: " + module.descriptor().name());
570+
err.flush();
571+
return 1;
572+
}
573+
artifacts.put(fileName, path);
574+
} else {
575+
var fileName = path.getFileName()
576+
.toString();
577+
if (artifacts.containsKey(fileName)) {
578+
err.println("Duplicate file: " + fileName + ". Need to rename.");
579+
err.flush();
580+
fileName = UUID.randomUUID() + "-" + fileName;
581+
}
582+
artifacts.put(fileName, path);
515583
}
516-
artifacts.put(fileName, path);
584+
585+
return 0;
517586
};
518587

519-
deps.libraries()
520-
.forEach((library, path) -> {
521-
addPath.accept(path);
522-
});
588+
for (var path : deps.libraries().values()) {
589+
int status = addPath.apply(path);
590+
if (status != 0) {
591+
return status;
592+
}
593+
}
523594

524-
extraPaths.forEach(addPath);
595+
for (var extraPath : extraPaths) {
596+
int status = addPath.apply(extraPath);
597+
if (status != 0) {
598+
return status;
599+
}
600+
}
525601

526602
artifacts.forEach((fileName, path) -> {
527603
try {

0 commit comments

Comments
 (0)