This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
FIX 496 : Add support for CodeSource URL for GoloClassLoader #497
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ private Class<?> loadGoloFile(GoloClassLoader loader, Path path) { | |
try (InputStream is = Files.newInputStream(path)) { | ||
Path filename = path.getFileName(); | ||
if (filename != null) { | ||
return loader.load(filename.toString(), is); | ||
return loader.load(filename.toString(), is, path.toUri().toURL()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idem |
||
} else { | ||
throw new RuntimeException(message("not_regular_file", path)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,10 @@ | |
package org.eclipse.golo.compiler; | ||
|
||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.security.CodeSource; | ||
import java.security.ProtectionDomain; | ||
import java.security.cert.Certificate; | ||
import java.util.List; | ||
|
||
/** | ||
|
@@ -58,4 +62,25 @@ public synchronized Class<?> load(String goloSourceFilename, InputStream sourceC | |
} | ||
return lastClassIsModule; | ||
} | ||
|
||
/** | ||
* Compiles and loads the resulting JVM bytecode for a Golo source file. | ||
* This method declares a URL for the CodeSource of this class, which | ||
* is useful for retrieving the location at runtime. | ||
* | ||
* @param goloSourceFilename the source file name. | ||
* @param sourceCodeInputStream the source input stream. | ||
* @param sourceCodeLocation the source file location. | ||
* @return the class matching the Golo module defined in the source. | ||
* @throws GoloCompilationException if either of the compilation phase failed. | ||
*/ | ||
public synchronized Class<?> load(String goloSourceFilename, InputStream sourceCodeInputStream, URL sourceCodeLocation) throws GoloCompilationException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is copy/past from the previous one. You should refactor the previous one to call this one with a |
||
List<CodeGenerationResult> results = compiler.compile(goloSourceFilename, sourceCodeInputStream); | ||
Class<?> lastClassIsModule = null; | ||
for (CodeGenerationResult result : results) { | ||
byte[] bytecode = result.getBytecode(); | ||
lastClassIsModule = defineClass(null, bytecode, 0, bytecode.length, new ProtectionDomain(new CodeSource(sourceCodeLocation, (Certificate[])null), null)); | ||
} | ||
return lastClassIsModule; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build the
CodeSource
instance here (see the proposedload
refactoring). This will allows to construct aCertificate[]
from command line options if we ever need to.BTW, the file scanning facility should be extracted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yloiseau what do you mean by "extracted"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a mode generic method that scan (recursively) a directory and return golo files, maybe in the form of a
CodeSource
object, orPath
with a method to convert aPath
into aCodeSource
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the "extract method" refactoring...