-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of github.com:ortus-solutions-private/boxl…
…ang into development
- Loading branch information
Showing
24 changed files
with
710 additions
and
56 deletions.
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
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
43 changes: 43 additions & 0 deletions
43
compiler/src/main/java/ourtus/boxlang/executor/JavaClassByteCode.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* [BoxLang] | ||
* <p> | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
|
||
package ourtus.boxlang.executor; | ||
|
||
import javax.tools.SimpleJavaFileObject; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import java.net.URI; | ||
|
||
/** | ||
* JavaFileObject implementation | ||
*/ | ||
public class JavaClassByteCode extends SimpleJavaFileObject { | ||
|
||
protected ByteArrayOutputStream bos = new ByteArrayOutputStream(); | ||
|
||
public JavaClassByteCode( String name, Kind kind ) { | ||
super( URI.create( "string:///" + name.replace( '.', '/' ) | ||
+ kind.extension ), kind ); | ||
} | ||
|
||
public byte[] getBytes() { | ||
return bos.toByteArray(); | ||
} | ||
|
||
@Override | ||
public OutputStream openOutputStream() { | ||
return bos; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
compiler/src/main/java/ourtus/boxlang/executor/JavaDynamicClassLoader.java
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* [BoxLang] | ||
* <p> | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package ourtus.boxlang.executor; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
|
||
/** | ||
* Dynamic in Memory classloader | ||
*/ | ||
public class JavaDynamicClassLoader extends URLClassLoader { | ||
|
||
private JavaMemoryManager manager; | ||
|
||
public JavaDynamicClassLoader( URL[] urls, ClassLoader parent, JavaMemoryManager manager ) { | ||
super( urls, parent ); | ||
this.manager = manager; | ||
|
||
} | ||
|
||
@Override | ||
protected Class<?> findClass( String name ) throws ClassNotFoundException { | ||
|
||
Map<String, JavaClassByteCode> compiledClasses = manager | ||
.getBytesMap(); | ||
|
||
if ( compiledClasses.containsKey( name ) ) { | ||
byte[] bytes = compiledClasses.get( name ) | ||
.getBytes(); | ||
return defineClass( name, bytes, 0, bytes.length ); | ||
} else { | ||
return super.findClass( name ); | ||
} | ||
} | ||
|
||
/* | ||
* Required for Java Agents when this classloader is used as the system classloader | ||
*/ | ||
@SuppressWarnings( "unused" ) | ||
private void appendToClassPathForInstrumentation( String jarfile ) throws IOException { | ||
addURL( Paths.get( jarfile ).toRealPath().toUri().toURL() ); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
compiler/src/main/java/ourtus/boxlang/executor/JavaMemoryManager.java
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* [BoxLang] | ||
* <p> | ||
* Copyright [2023] [Ortus Solutions, Corp] | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package ourtus.boxlang.executor; | ||
|
||
import javax.tools.*; | ||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.Hashtable; | ||
import java.util.Map; | ||
|
||
|
||
/** | ||
* In Memory File Manager | ||
*/ | ||
public class JavaMemoryManager extends ForwardingJavaFileManager<JavaFileManager> { | ||
|
||
private final Map<String, JavaClassByteCode> compiledClasses; | ||
|
||
public JavaMemoryManager( StandardJavaFileManager standardFileManager ) { | ||
super( standardFileManager ); | ||
this.compiledClasses = new Hashtable<>(); | ||
} | ||
|
||
@Override | ||
public JavaFileObject getJavaFileForOutput( Location location, String className, JavaFileObject.Kind kind, | ||
FileObject sibling ) { | ||
|
||
JavaClassByteCode classAsBytes = new JavaClassByteCode( | ||
className, kind ); | ||
compiledClasses.put( className, classAsBytes ); | ||
|
||
return classAsBytes; | ||
} | ||
|
||
public Map<String, JavaClassByteCode> getBytesMap() { | ||
return compiledClasses; | ||
} | ||
} |
Oops, something went wrong.