Skip to content

Commit

Permalink
Merge pull request #46 from MontiCore/fix/mcpath-unqualified-files
Browse files Browse the repository at this point in the history
#4389 Fix MCPath finding of unqualified sym files
  • Loading branch information
luepges authored Nov 8, 2024
2 parents 6272849 + b0a381c commit 5c10837
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ Optional<URL> do_find(FindCacheKey k) {
// iterate MCPath entries and check whether folder path exists within these
for (Path p : getEntries()) {
if(p.toString().endsWith(".jar")){
String path = "/" + folderPath.replace('\\', '/') + "/" + fileNameRegEx;
String path = "";
if (!folderPath.isEmpty()) // Only prepend the folderPath if present
path = "/" + folderPath.replace('\\', '/');
path += "/" + fileNameRegEx;
if (k.fileExtRegEx.equals(".*sym")) {
// For .jar entries with a *.sym file extension regex, we cache the jar entries
jarSymCache.getUnchecked(p).getCandidates(path).map(uri -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.io.paths;

import de.se_rwth.commons.Files;
import de.se_rwth.commons.logging.Finding;
import de.se_rwth.commons.logging.Log;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -216,17 +216,16 @@ public void testCachedAmbiguous() {
}

@Test
public void testCachedSym() throws IOException {
public void testCachedSym(@TempDir File tempF) throws IOException {
// Test if the mcpath-jar-cache respects removal
Log.clearFindings();
File tempF = Files.createTempDir();
tempF.mkdirs();
File jar = new File(tempF, "test.jar");

FileOutputStream fout = new FileOutputStream(jar);
JarOutputStream jarOut = new JarOutputStream(fout);
jarOut.putNextEntry(new ZipEntry("de/mc/")); // Folders must end with "/".
jarOut.putNextEntry(new ZipEntry("de/mc/A.test.sym"));
jarOut.putNextEntry(new ZipEntry("B.test.sym"));
jarOut.write("{}".getBytes());
jarOut.closeEntry();

Expand All @@ -236,7 +235,8 @@ public void testCachedSym() throws IOException {
MCPath path = new MCPath();
path.addEntry(jar.toPath());

Assertions.assertTrue(path.find("de.mc.A", ".*sym").isPresent());
Assertions.assertTrue(path.find("de.mc.A", ".*sym").isPresent(), "Finding a qualified file failed");
Assertions.assertTrue(path.find("B", ".*sym").isPresent(), "Finding an unqualified file failed");
path.removeEntry(jar.toPath());
Assertions.assertFalse(path.find("de.mc.A", ".*sym").isPresent(), "removeEntry was not completed");
}
Expand Down

0 comments on commit 5c10837

Please sign in to comment.