Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File path handling fixes #2280

Merged
merged 11 commits into from
Nov 13, 2018
Merged

File path handling fixes #2280

merged 11 commits into from
Nov 13, 2018

Conversation

solussd
Copy link
Contributor

@solussd solussd commented Apr 24, 2018

Ensure file paths passed to STGroup[File] are absolute

See: walmartlabs/lacinia#175

@solussd
Copy link
Contributor Author

solussd commented Apr 24, 2018

I don't understand the CI failure, any insight would be appreciated.

solussd added a commit to solussd/stringtemplate4 that referenced this pull request Apr 24, 2018
- Changes necessary to support classpath resources in a variety of
different deployment scenarios

See Antlr4 PR: antlr/antlr4#2280
solussd and others added 3 commits April 24, 2018 17:43
@parrt
Copy link
Member

parrt commented Oct 23, 2018

@solussd looks like we have some build errors

@parrt
Copy link
Member

parrt commented Nov 6, 2018

@solussd looks like build errors in the Target.java file you changed:

[ERROR] /C:/projects/antlr4/tool/src/org/antlr/v4/codegen/Target.java:[512,50] incompatible types: java.net.URL cannot be converted to java.lang.String
[ERROR] /C:/projects/antlr4/tool/src/org/antlr/v4/codegen/Target.java:[527,50] incompatible types: java.net.URL cannot be converted to java.lang.String

@solussd
Copy link
Contributor Author

solussd commented Nov 6, 2018

@parrt This PR depends on changes here: antlr/stringtemplate4#199

That PR was closed as "fixed" in another PR, but the other PR didn't implement a constructor for STGroupFile that takes a URL.

@parrt
Copy link
Member

parrt commented Nov 6, 2018

Ah. Can i just add public STGroupFile(URL url) { this(url, "UTF-8",'<', '>'); }?

@solussd
Copy link
Contributor Author

solussd commented Nov 6, 2018

That could be sufficient. I can test tomorrow morning w/ my AWS Lambda use case if you add that constructor.

@solussd
Copy link
Contributor Author

solussd commented Nov 6, 2018

I had rewritten the constructors so they all bottom out in loadGroupURL instead of loadGroupFile.

@parrt
Copy link
Member

parrt commented Nov 7, 2018

While moving the constructors would mean it uses a different style so we should move those back. I'm trying to build but am being unsuccessful now with later versions of Java. tools.jar apparently no longer exists. damn them! any idea what happened to the Java compiler objects? are they in a public API somewhere now?

@solussd
Copy link
Contributor Author

solussd commented Nov 7, 2018

@parrt I'm not sure, sorry. W.r.t. the constructors, I didn't change the interface to the existing ones, I just consolidated the implementation under the URL one.

@ewanmellor
Copy link
Contributor

@parrt I've got a change to fix the tools.jar issue, I'll post that in a little while.

ewanmellor added a commit to ewanmellor/antlr4 that referenced this pull request Nov 8, 2018
This is in different locations on JDK 9 and up.  maven-jdk-tools-wrapper
does the right thing on all JDK releases.

This was mentioned in a side comment on PR antlr#2280.
@parrt
Copy link
Member

parrt commented Nov 9, 2018

Actually, it's no problem. I forgot we require java 1.7 so it's gotta be there.

@parrt
Copy link
Member

parrt commented Nov 9, 2018

Hi @solussd i have added the ctor to ST4: antlr/stringtemplate4@b5a82e0

I hope to release ST4 this weekend so please let me know :) thanks!

ewanmellor added a commit to ewanmellor/antlr4 that referenced this pull request Nov 11, 2018
This is in different locations on JDK 9 and up.  maven-jdk-tools-wrapper
does the right thing on all JDK releases.

This was mentioned in a side comment on PR antlr#2280.
@solussd
Copy link
Contributor Author

solussd commented Nov 13, 2018

@parrt works with updated ST4. Thanks!

@parrt
Copy link
Member

parrt commented Nov 13, 2018

@solussd cool. ok, so you still want this merged though right? Can you tell me more about the issue you're solving? Also, shouldn't that ST4 maven ref be 4.1 to get the release version?

@solussd
Copy link
Contributor Author

solussd commented Nov 13, 2018

@parrt yes, this PR. I’ve updated it. Yes, it looks like 4.1 has what I need. Will update in a moment.

The issue was executing on AWS lambda- file paths were being constructed such that some resources were not locateable when the deployment jar was unpacked in the directory AWS Lambda unpacks it.

@parrt
Copy link
Member

parrt commented Nov 13, 2018

Ok. also i'm not sure you can add others to contrib list. they need to add commits for their own name.

@solussd
Copy link
Contributor Author

solussd commented Nov 13, 2018

@parrt I did that to fix a merge conflict, technically, they were already there (though git might show it as being added in the diff of this PR).

@parrt
Copy link
Member

parrt commented Nov 13, 2018

ah. thanks

STGroup result = null;
try {
result = new STGroupFile(groupFileName);
result = new STGroupFile(url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me as though STGroupFile's ctor calls getURL() which does exactly that getResource thing. What additional functionality are you providing? i.e., where does ST4 go wrong? Maybe we shoulda fixed that in ST4 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe is related to when it is called. I’d have to dig into it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also possible the PR you merged into ST4 instead of mine (199) makes this unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah. cool. if you have time, could you find the minimal changeset that works? I'm terrified of changing this stuff in the tool!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested without the classloader in ANTLR (instead letting ST4 + getURL do the context class loader lookup) and it works. PR updated to what I believe is a minimal changeset.

- URL constructor unnecessary
@@ -397,7 +397,7 @@ public void processNonCombinedGrammar(Grammar g, boolean gencode) {

if ( generate_ATN_dot ) generateATNs(g);

if ( g.tool.getNumErrors()==0 ) generateInterpreterData(g);
if (gencode && g.tool.getNumErrors()==0 ) generateInterpreterData(g);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, looking good but do we need this tweak for gencode? I'm worried someone might rely on it.

Copy link
Contributor Author

@solussd solussd Nov 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a safe change to me– code is still generated when executed from the cli, but won't generate code when executed programmatically. I think there was an issue with it writing files in a readonly environment (e.g., deployed as a Lambda).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sounds good. thanks for your perseverance and hard work on this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking at it!

@parrt parrt added this to the 4.7.2 milestone Nov 13, 2018
@parrt parrt merged commit 11d6013 into antlr:master Nov 13, 2018
ewanmellor added a commit to ewanmellor/antlr4 that referenced this pull request Nov 15, 2018
This is in different locations on JDK 9 and up.  maven-jdk-tools-wrapper
does the right thing on all JDK releases.

This was mentioned in a side comment on PR antlr#2280.
ewanmellor added a commit to ewanmellor/antlr4 that referenced this pull request Nov 15, 2018
This is in different locations on JDK 9 and up.  maven-jdk-tools-wrapper
does the right thing on all JDK releases.

This was mentioned in a side comment on PR antlr#2280.
kahunamoore added a commit to kahunamoore/clj-antlr that referenced this pull request Jan 23, 2019
Fixes file/path open problem on AWS lambda, see:

antlr/antlr4#2280
antlr/antlr4@11d6013

Needed by an open Lacinia issue:

walmartlabs/lacinia#175 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants