Skip to content

Commit

Permalink
Update the mx suite parsing to work with sources of GraalVM version 2…
Browse files Browse the repository at this point in the history
…3.1.0.
  • Loading branch information
entlicher committed Jan 29, 2024
1 parent 0c7c18d commit 9ab7f14
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions java/java.mx.project/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<arg value="clone"/>
<arg value="--depth=1"/>
<arg value="--branch"/>
<arg value="vm-22.3.0"/>
<arg value="vm-23.1.0"/>
<arg value="--single-branch"/>
<arg value="https://github.com/oracle/graal"/>
</exec>
Expand All @@ -41,7 +41,7 @@
<arg value="clone"/>
<arg value="--depth=1"/>
<arg value="--branch"/>
<arg value="6.7.0"/>
<arg value="6.46.1"/>
<arg value="--single-branch"/>
<arg value="https://github.com/graalvm/mx"/>
</exec>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ private MxSuite parseImpl(URL u) throws IOException {
if (line == null) {
break;
}
sb.append(jsonify(line)).append("\n");
line = line.replaceAll("(\\s*)#.*", "$1");
sb.append(line).append("\n");
}
}
String text = jsonify(sb.toString());
Object value;
try {
final JSONParser p = new JSONParser();
value = p.parse(sb.toString());
value = p.parse(text);
} catch (ParseException ex) {
throw new IOException("Cannot parse " + u, ex);
}
Expand All @@ -78,9 +80,8 @@ private MxSuite parseImpl(URL u) throws IOException {
}

private static String jsonify(String content) {
String text = content.replaceFirst("^suite *= *\\{", "{");
String text = content.replaceFirst("\\s*suite *= *\\{", "{");
text = text.replace("True", "true").replace("False", "false");
text = text.replaceAll("(\\s*)#.*", "$1");
text = text.replaceAll(",\\s*(\\]|\\})", "$1");
text = replaceQuotes("\"\"\"", text);
text = replaceQuotes("'''", text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
import static junit.framework.TestCase.assertTrue;
import org.netbeans.api.java.queries.BinaryForSourceQuery;
import org.netbeans.api.java.queries.SourceForBinaryQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.api.project.SourceGroup;
import org.netbeans.api.project.Sources;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;

Expand All @@ -50,31 +57,26 @@ public void testRootsForAnSdkJar() throws Exception {
FileObject fo = FileUtil.toFileObject(sdkSibling);
assertNotNull("project directory found", fo);

FileObject graalSdkJar = FileUtil.createData(fo, "mxbuild/dists/jdk1.8/graal-sdk.jar");
assertNotNull(graalSdkJar);

Project p = ProjectManager.getDefault().findProject(fo);
assertNotNull("project found", p);
assertEquals("It is suite project: " + p, "SuiteProject", p.getClass().getSimpleName());
Sources src = ProjectUtils.getSources(p);
List<FileObject> resultRoots = new ArrayList<>();
for (SourceGroup sourceGroup : src.getSourceGroups("java")) {
BinaryForSourceQuery.Result binaryResult = BinaryForSourceQuery.findBinaryRoots(sourceGroup.getRootFolder().toURL());
for (URL r : binaryResult.getRoots()) {
SourceForBinaryQuery.Result2 result2 = SourceForBinaryQuery.findSourceRoots2(r);
final FileObject[] rr = result2.getRoots();
resultRoots.addAll(Arrays.asList(rr));
}
}

final URL archiveURL = new URL("jar:" + graalSdkJar.toURL() + "!/");

SourceForBinaryQuery.Result2 result2 = SourceForBinaryQuery.findSourceRoots2(archiveURL);
final FileObject[] resultRoots = result2.getRoots();
assertTrue("There should be some roots", resultRoots.length > 0);
assertTrue("There should be some roots", !resultRoots.isEmpty());

Set<FileObject> expected = new HashSet<>();
for (FileObject ch : fo.getFileObject("src").getChildren()) {
if (ch.getNameExt().endsWith(".test")) {
// tests are not in graal-sdk.jar
continue;
}
if (ch.getNameExt().endsWith(".tck")) {
// TCK is not in graal-sdk.jar
continue;
}
if (ch.getNameExt().contains("org.graalvm.launcher")) {
// launcher is not in graal-sdk.jar
if (ch.getNameExt().equals("org.graalvm.launcher.native")) {
// Not a Java code
continue;
}
expected.add(ch);
Expand Down

0 comments on commit 9ab7f14

Please sign in to comment.