From 1825a26c16ef7d835166e2b7ca11355c7d6f0e6a Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 23 Jan 2026 10:58:34 +0100 Subject: [PATCH 1/2] the packager now copies to a new folder instead of rewriting in place. --- .../lang/rascalcore/package/Packager.rsc | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc index b67301edc4..ad5818f1e8 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc @@ -33,30 +33,43 @@ import ParseTree; import Location; import util::Reflective; -void main(PathConfig pcfg = pathConfig(), loc sourceLookup = |unknown:///|) { +void main(PathConfig pcfg = pathConfig(), loc sourceLookup = |unknown:///|, loc relocatedClasses = pcfg.projectRoot + "/target/relocatedClasses") { if (!(sourceLookup?)) { throw "sourceLookup is not an optional parameter. The packager needs something like `|mvn://groupId--artifactId--version|`"; } - package(pcfg.srcs, pcfg.bin, sourceLookup); + package(pcfg.srcs, pcfg.bin, relocatedClasses, sourceLookup); } -void package(list[loc] srcs, loc bin, loc sourceLookup) { - packageSourceFiles(srcs, bin); - rewriteTypeFiles(srcs, bin, sourceLookup); +void package(list[loc] srcs, loc bin, loc relocated, loc sourceLookup) { + packageSourceFiles(srcs, relocated); + copyAllTargetFiles(bin, relocated); + rewriteTypeFiles(srcs, bin, relocated, sourceLookup); } -void packageSourceFiles(list[loc] srcs, loc bin) { +void packageSourceFiles(list[loc] srcs, loc relocated) { for (folder <- srcs, file <- find(folder, "rsc")) { - copy(file, bin + relativize(folder, file).path); + copy(file, relocated + relativize(folder, file).path); } } -void rewriteTypeFiles(list[loc] srcs, loc bin, loc sourceLookup) { - for (file <- find(bin, "tpl")) { +void copyAllTargetFiles(loc bin, loc relocated) { + // A pom file may include any thing (resources and classes) + // and we just copy everything just in case it is needed at runtime. + copy(bin, relocated, recursive = true); + + // But we remove the superfluous tpl files just in case. + // They will be rewritten and copied later again. + for (file <- find(relocated, "tpl")) { + remove(file); + } +} + +void rewriteTypeFiles(list[loc] srcs, loc bin, loc relocated, loc sourceLookup) { + for (folder <- srcs, file <- find(folder, "tpl")) { model = readBinaryValueFile(file); model = rewriteTypeModel(model, paths(srcs), sourceLookup); - writeBinaryValueFile(file, model); + writeBinaryValueFile(relocated + relative(folder, file), model); } } From 6af4afa7218502fb8e784b922078917315849437 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 23 Jan 2026 11:47:23 +0100 Subject: [PATCH 2/2] fixed typos and unfinished business --- .../compiler/lang/rascalcore/package/Packager.rsc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc index ad5818f1e8..e0a835e1a6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/package/Packager.rsc @@ -54,22 +54,24 @@ void packageSourceFiles(list[loc] srcs, loc relocated) { } void copyAllTargetFiles(loc bin, loc relocated) { + mkDirectory(relocated); + // A pom file may include any thing (resources and classes) // and we just copy everything just in case it is needed at runtime. copy(bin, relocated, recursive = true); // But we remove the superfluous tpl files just in case. // They will be rewritten and copied later again. - for (file <- find(relocated, "tpl")) { + for (loc file <- find(relocated, "tpl")) { remove(file); } } void rewriteTypeFiles(list[loc] srcs, loc bin, loc relocated, loc sourceLookup) { - for (folder <- srcs, file <- find(folder, "tpl")) { + for (loc file <- find(bin, "tpl")) { model = readBinaryValueFile(file); model = rewriteTypeModel(model, paths(srcs), sourceLookup); - writeBinaryValueFile(relocated + relative(folder, file), model); + writeBinaryValueFile(relocated + relativize(bin, file).path, model); } }