Ensure file paths passed to STGroup[File] are absolute

- gracefully handle grammars without source fileNames
This commit is contained in:
Joseph Smith 2018-04-23 18:55:23 -05:00
parent 6ffc59d63c
commit 8ce79eec81
6 changed files with 13 additions and 9 deletions

View File

@ -11,7 +11,7 @@
<artifactId>oss-parent</artifactId>
<version>9</version>
</parent>
<groupId>org.antlr</groupId>
<groupId>solussd</groupId>
<artifactId>antlr4-master</artifactId>
<version>4.7.2-SNAPSHOT</version>
<packaging>pom</packaging>

View File

@ -7,7 +7,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.antlr</groupId>
<groupId>solussd</groupId>
<artifactId>antlr4-master</artifactId>
<version>4.7.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>

View File

@ -7,7 +7,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.antlr</groupId>
<groupId>solussd</groupId>
<artifactId>antlr4-master</artifactId>
<version>4.7.2-SNAPSHOT</version>
</parent>
@ -29,7 +29,7 @@
<dependency>
<groupId>org.antlr</groupId>
<artifactId>ST4</artifactId>
<version>4.0.8</version>
<version>4.0.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.abego.treelayout</groupId>

View File

@ -838,7 +838,7 @@ public class Tool {
// or just or the relative path recorded for the parent grammar. This means
// that when we write the tokens files, or the .java files for imported grammars
// taht we will write them in the correct place.
if (fileNameWithPath.lastIndexOf(File.separatorChar) == -1) {
if ((fileNameWithPath == null) || (fileNameWithPath.lastIndexOf(File.separatorChar) == -1)) {
// No path is included in the file name, so make the file
// directory the same as the parent grammar (which might sitll be just ""
// but when it is not, we will write the file in the correct place.

View File

@ -26,6 +26,8 @@ import org.stringtemplate.v4.STGroupFile;
import org.stringtemplate.v4.StringRenderer;
import org.stringtemplate.v4.misc.STMessage;
import java.net.URL;
/** */
public abstract class Target {
/** For pure strings of Java 16-bit Unicode char, how can we display
@ -504,9 +506,10 @@ public abstract class Target {
public boolean templatesExist() {
String groupFileName = CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION;
URL url = Thread.currentThread().getContextClassLoader().getResource(groupFileName);
STGroup result = null;
try {
result = new STGroupFile(groupFileName);
result = new STGroupFile(url.getPath());
}
catch (IllegalArgumentException iae) {
result = null;
@ -517,9 +520,11 @@ public abstract class Target {
protected STGroup loadTemplates() {
String groupFileName = CodeGenerator.TEMPLATE_ROOT + "/" + getLanguage() + "/" + getLanguage() + STGroup.GROUP_FILE_EXTENSION;
URL url = Thread.currentThread().getContextClassLoader().getResource(groupFileName);
STGroup result = null;
try {
result = new STGroupFile(groupFileName);
result = new STGroupFile(url.getPath());
}
catch (IllegalArgumentException iae) {
gen.tool.errMgr.toolError(ErrorType.MISSING_CODE_GEN_TEMPLATES,

View File

@ -231,8 +231,7 @@ public class ErrorManager {
setFormat("antlr"); // recurse on this rule, trying the default message format
return;
}
format = new STGroupFile(fileName, "UTF-8");
format = new STGroupFile(url, "UTF-8", '<', '>');
format.load();
if ( !initSTListener.errors.isEmpty() ) {