├── .gitignore ├── relproxy_test_itsnat ├── .gitignore ├── conf │ └── conf_relproxy.properties ├── src │ └── main │ │ ├── webapp │ │ ├── META-INF │ │ │ └── context.xml │ │ ├── WEB-INF │ │ │ ├── lib │ │ │ │ └── ItsNat-1.3.1.jar │ │ │ ├── groovyex │ │ │ │ ├── code │ │ │ │ │ └── example │ │ │ │ │ │ └── groovyex │ │ │ │ │ │ ├── City.groovy │ │ │ │ │ │ ├── FalseDB.groovy │ │ │ │ │ │ ├── GroovyExampleLoadListener.groovy │ │ │ │ │ │ ├── GroovyExampleDocument.groovy │ │ │ │ │ │ └── groovy_servlet_init.groovy │ │ │ │ └── pages │ │ │ │ │ └── groovyex.html │ │ │ ├── javaex │ │ │ │ ├── code2 │ │ │ │ │ └── example │ │ │ │ │ │ └── javaex │ │ │ │ │ │ └── JProxyExampleAux.java │ │ │ │ ├── code │ │ │ │ │ └── example │ │ │ │ │ │ └── javaex │ │ │ │ │ │ ├── JProxyExampleAuxIgnored.java │ │ │ │ │ │ ├── JProxyExampleDocumentBase.java │ │ │ │ │ │ ├── JProxyExampleLoadListener.java │ │ │ │ │ │ └── JProxyExampleDocument.java │ │ │ │ └── pages │ │ │ │ │ └── javaex.html │ │ │ └── web.xml │ │ ├── jsp │ │ │ ├── test_jproxy_stop.jsp │ │ │ └── test_jproxy_start.jsp │ │ └── index.html │ │ └── java │ │ └── example │ │ ├── javaex │ │ ├── City.java │ │ ├── hotreload │ │ │ └── JProxyExampleAux2.java │ │ ├── nothotreload │ │ │ ├── JProxyExampleAuxIgnored2.java │ │ │ └── JProxyExampleAuxIgnored3.java │ │ ├── FalseDB.java │ │ └── JProxyExampleServlet.java │ │ └── groovyex │ │ └── ItsNatGroovyServlet.java ├── build.gradle ├── sync.xml └── nb-configuration.xml └── relproxy ├── ant └── maven-ant-tasks-2.1.3.jar ├── src ├── main │ ├── asciidoc │ │ ├── images │ │ │ ├── browser_1.png │ │ │ ├── browser_2.png │ │ │ ├── browser_3.png │ │ │ ├── module_conf.png │ │ │ ├── publishing.png │ │ │ ├── filesync_conf.png │ │ │ ├── server_options.png │ │ │ ├── edit_web_module.png │ │ │ ├── install_filesync1.png │ │ │ └── filesync_force_file_sync.png │ │ └── css │ │ │ └── better_toc.css │ ├── cmd_examples │ │ ├── README.txt │ │ ├── fixesforunix.sh │ │ ├── ex_java_shell_interactive_launcher.sh │ │ ├── ex_java_shell_launcher.sh │ │ ├── ex_java_shell_snippet_launcher.sh │ │ ├── ex_java_shell_launcher_2.sh │ │ ├── ex_java_shell_launcher_complete_class.sh │ │ ├── ex_java_shell_launcher_normal_class.sh │ │ ├── ex_java_shell_launcher_complete_class_2.sh │ │ └── ex_java_shell_snippet_launcher_complete_class.sh │ └── java │ │ └── com │ │ └── innowhere │ │ └── relproxy │ │ ├── impl │ │ ├── jproxy │ │ │ ├── core │ │ │ │ ├── clsmgr │ │ │ │ │ ├── comp │ │ │ │ │ │ ├── jfo │ │ │ │ │ │ │ ├── JProxyJavaFileObjectInput.java │ │ │ │ │ │ │ ├── JavaFileObjectInputSourceInMemory.java │ │ │ │ │ │ │ ├── JavaFileObjectInputSourceInFile.java │ │ │ │ │ │ │ ├── JavaFileObjectInputClassInJar.java │ │ │ │ │ │ │ ├── JavaFileObjectInputClassInFile.java │ │ │ │ │ │ │ ├── JavaFileObjectInputClassInMemory.java │ │ │ │ │ │ │ ├── JavaFileObjectOutputClass.java │ │ │ │ │ │ │ ├── JavaFileObjectInputSourceBase.java │ │ │ │ │ │ │ └── JavaFileObjectInputClassInFileSystem.java │ │ │ │ │ │ ├── JProxyCompilationException.java │ │ │ │ │ │ └── JProxyCompilerContext.java │ │ │ │ │ ├── srcunit │ │ │ │ │ │ ├── SourceScriptRoot.java │ │ │ │ │ │ ├── SourceFileJavaNormal.java │ │ │ │ │ │ ├── SourceScriptRootFileJavaExt.java │ │ │ │ │ │ ├── SourceUnit.java │ │ │ │ │ │ ├── SourceScriptRootFileOtherExt.java │ │ │ │ │ │ ├── SourceScriptRootFile.java │ │ │ │ │ │ └── SourceScriptRootInMemory.java │ │ │ │ │ ├── cldesc │ │ │ │ │ │ ├── ClassDescriptorInner.java │ │ │ │ │ │ ├── ClassDescriptorSourceFileJava.java │ │ │ │ │ │ ├── ClassDescriptorSourceFileRegistry.java │ │ │ │ │ │ ├── ClassDescriptor.java │ │ │ │ │ │ └── ClassDescriptorSourceUnit.java │ │ │ │ │ └── FolderSourceList.java │ │ │ │ ├── JProxyInvocationHandler.java │ │ │ │ ├── JProxyVersionedObject.java │ │ │ │ └── JProxyImpl.java │ │ │ ├── screngine │ │ │ │ ├── BindingsImpl.java │ │ │ │ ├── JProxyScriptEngineImpl.java │ │ │ │ └── JProxyScriptEngineDelegateImpl.java │ │ │ ├── shell │ │ │ │ ├── inter │ │ │ │ │ ├── CommandError.java │ │ │ │ │ ├── Keyboard.java │ │ │ │ │ ├── WindowUnicodeKeyboard.java │ │ │ │ │ ├── MacOSXUnicodeKeyboard.java │ │ │ │ │ ├── CommandSave.java │ │ │ │ │ ├── LinuxUnicodeKeyboard.java │ │ │ │ │ ├── KeyboardUsingClipboard.java │ │ │ │ │ ├── CommandDelete.java │ │ │ │ │ ├── CommandInsert.java │ │ │ │ │ ├── CommandEdit.java │ │ │ │ │ ├── CommandCodeChangerBase.java │ │ │ │ │ ├── CommandLoad.java │ │ │ │ │ ├── Command.java │ │ │ │ │ └── CommandOther.java │ │ │ │ ├── JProxyShellClassLoader.java │ │ │ │ ├── JProxyShellCodeSnippetImpl.java │ │ │ │ ├── JProxyShellInteractiveImpl.java │ │ │ │ └── JProxyShellScriptFileImpl.java │ │ │ ├── JProxyDefaultImpl.java │ │ │ └── JProxyConfigImpl.java │ │ ├── GenericProxyConfigBaseImpl.java │ │ ├── gproxy │ │ │ ├── core │ │ │ │ ├── GProxyInvocationHandler.java │ │ │ │ ├── GProxyImpl.java │ │ │ │ └── GProxyVersionedObject.java │ │ │ ├── GProxyConfigImpl.java │ │ │ └── GProxyDefaultImpl.java │ │ ├── FileExt.java │ │ ├── GenericProxyImpl.java │ │ └── GenericProxyInvocationHandler.java │ │ ├── gproxy │ │ ├── package.html │ │ ├── GProxyGroovyScriptEngine.java │ │ ├── GProxyConfig.java │ │ └── GProxy.java │ │ ├── jproxy │ │ ├── package.html │ │ ├── JProxyCompilerListener.java │ │ ├── JProxyShell.java │ │ ├── JProxyDiagnosticsListener.java │ │ ├── JProxyScriptEngineFactory.java │ │ ├── JProxyInputSourceFileExcludedListener.java │ │ ├── JProxyScriptEngine.java │ │ └── JProxy.java │ │ ├── package.html │ │ ├── RelProxy.java │ │ ├── RelProxyException.java │ │ └── RelProxyOnReloadListener.java └── test │ ├── resources │ ├── example_java_shell │ ├── example_normal_class.java │ ├── example_java_shell_complete_class │ └── example │ │ └── javashellex │ │ └── JProxyShellExample.java │ └── java │ └── com │ └── innowhere │ └── relproxy │ └── jproxy │ ├── util │ └── JProxyTestUtil.java │ ├── JProxyJavaShellInteractiveTest.java │ ├── JProxyCodeSnippetTest.java │ ├── JProxyJavaShellTest.java │ ├── JProxyJavaShellNormalClassTest.java │ ├── JProxyJavaShellCompleteClassTest.java │ └── JProxyCodeSnippetCompleteClassTest.java ├── test_cmd ├── test_java_shell_interactive_launcher.sh ├── test_java_shell_launcher.sh ├── test_java_shell_launcher_2.sh ├── test_java_shell_launcher_complete_class.sh ├── test_java_shell_launcher_normal_class.sh ├── test_java_shell_launcher_complete_class_2.sh ├── test_java_shell_snippet_launcher.sh ├── setupjava.sh ├── test_java_shell_snippet_launcher_complete_class.sh ├── fixesforunix.sh ├── _shared_test_java_shell_inter_and_snippet_launcher.sh └── _shared_test_java_shell_launcher.sh ├── .gitignore ├── conf └── conf.properties ├── bin └── jproxysh └── CHANGES.txt /.gitignore: -------------------------------------------------------------------------------- 1 | /relproxy_dist_tmp/ 2 | /build/ 3 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /tmp 3 | .gradle/ 4 | 5 | conf/conf_local.properties 6 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/conf/conf_relproxy.properties: -------------------------------------------------------------------------------- 1 | 2 | webapp_folder=relproxy_test_itsnat-0.1-SNAPSHOT 3 | -------------------------------------------------------------------------------- /relproxy/ant/maven-ant-tasks-2.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/ant/maven-ant-tasks-2.1.3.jar -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/browser_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/browser_1.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/browser_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/browser_2.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/browser_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/browser_3.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/module_conf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/module_conf.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/publishing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/publishing.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/filesync_conf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/filesync_conf.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/server_options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/server_options.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/edit_web_module.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/edit_web_module.png -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/install_filesync1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/install_filesync1.png -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/META-INF/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_interactive_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_inter_and_snippet_launcher.sh 4 | 5 | jproxysh 6 | 7 | -------------------------------------------------------------------------------- /relproxy/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /build 3 | /docs_internal 4 | /tmp 5 | .classpath 6 | .project 7 | .settings/ 8 | # .gradle/ 9 | 10 | conf/conf_local.properties 11 | -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/images/filesync_force_file_sync.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy/src/main/asciidoc/images/filesync_force_file_sync.png -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/lib/ItsNat-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jmarranz/relproxy/HEAD/relproxy_test_itsnat/src/main/webapp/WEB-INF/lib/ItsNat-1.3.1.jar -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_launcher.sh 4 | 5 | $PROJECT/src/test/resources/example_java_shell "HELLO " "WORLD!" 6 | 7 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_launcher_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_launcher.sh 4 | 5 | jproxysh $PROJECT/src/test/resources/example_java_shell "HELLO " "WORLD!" 6 | 7 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/README.txt: -------------------------------------------------------------------------------- 1 | 2 | These files cannot be executed here, they will be copied to the distribution files able to be executed as examples of the final distribution form of RelProxy. 3 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_launcher_complete_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_launcher.sh 4 | 5 | $PROJECT/src/test/resources/example_java_shell_complete_class "HELLO " "WORLD!" 6 | 7 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_launcher_normal_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_launcher.sh 4 | 5 | jproxysh $PROJECT/src/test/resources/example_normal_class.java "HELLO " "WORLD!" 6 | 7 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_launcher_complete_class_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_launcher.sh 4 | 5 | jproxysh $PROJECT/src/test/resources/example_java_shell_complete_class "HELLO " "WORLD!" 6 | 7 | -------------------------------------------------------------------------------- /relproxy/src/main/asciidoc/css/better_toc.css: -------------------------------------------------------------------------------- 1 | /* Truco para añadir al menu lateral izdo una bolita a cada item */ 2 | 3 | ul.sectlevel1 { list-style-type: square !important; } 4 | ul.sectlevel2 { list-style-type: circle !important; } 5 | -------------------------------------------------------------------------------- /relproxy/src/test/resources/example_java_shell: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env jproxysh 2 | 3 | String msg = args[0] + args[1]; 4 | System.out.println(msg); 5 | 6 | System.out.println("example_java_shell 1 "); 7 | 8 | example.javashellex.JProxyShellExample.exec(); 9 | 10 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_snippet_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_inter_and_snippet_launcher.sh 4 | 5 | jproxysh -c 'System.out.print("This code snippet says: ");' \ 6 | 'System.out.println("Hello World!!");' 7 | 8 | -------------------------------------------------------------------------------- /relproxy/test_cmd/setupjava.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo Note: execute this script with source cmd: source setupjava.sh 4 | 5 | # Change JAVA_HOME to your own installation folder 6 | 7 | export JAVA_HOME="/c/Archivos de programa/Java/jdk1.7.0_45/" 8 | 9 | echo Defined JAVA_HOME as $JAVA_HOME 10 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JProxyJavaFileObjectInput.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public interface JProxyJavaFileObjectInput 8 | { 9 | public String getBinaryName(); 10 | } 11 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/code/example/groovyex/City.groovy: -------------------------------------------------------------------------------- 1 | package example.groovyex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | class City 8 | { 9 | def name; 10 | 11 | City(String name) 12 | { 13 | this.name = name; 14 | } 15 | 16 | def getName() { return name; } 17 | } 18 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/City.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class City 8 | { 9 | protected String name; 10 | 11 | public City(String name) 12 | { 13 | this.name = name; 14 | } 15 | 16 | public String getName() { return name; } 17 | } 18 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/screngine/BindingsImpl.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.impl.jproxy.screngine; 3 | 4 | import java.util.HashMap; 5 | import javax.script.Bindings; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class BindingsImpl extends HashMap implements Bindings 12 | { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/gproxy/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | Contains the classes related with Groovy support of RelProxy. 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | Contains the classes related with Java support of RelProxy. 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/hotreload/JProxyExampleAux2.java: -------------------------------------------------------------------------------- 1 | package example.javaex.hotreload; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleAux2 8 | { 9 | public static void log() 10 | { 11 | System.out.println("JProxyExampleAux2: 1 " + JProxyExampleAux2.class.getClassLoader().hashCode()); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/code2/example/javaex/JProxyExampleAux.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleAux 8 | { 9 | public static void log() 10 | { 11 | System.out.println("JProxyExampleAux: 1 " + JProxyExampleAux.class.getClassLoader().hashCode()); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/fixesforunix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT=`dirname $0`/.. 4 | 5 | # set PROJECT env as absolute path 6 | TMP_PWD=`pwd` 7 | cd $PROJECT 8 | PROJECT=`pwd` 9 | cd $TMP_PWD 10 | 11 | chmod +x $PROJECT/cmd_examples/*.sh 12 | 13 | chmod +x $PROJECT/cmd_examples/code/example_java_shell 14 | chmod +x $PROJECT/cmd_examples/code/example_java_shell_complete_class 15 | 16 | chmod +x $PROJECT/bin/jproxysh 17 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/code/example/javaex/JProxyExampleAuxIgnored.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleAuxIgnored 8 | { 9 | public static void log() 10 | { 11 | System.out.println("JProxyExampleAuxIgnored: 2 " + JProxyExampleAuxIgnored.class.getClassLoader().hashCode()); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/nothotreload/JProxyExampleAuxIgnored2.java: -------------------------------------------------------------------------------- 1 | package example.javaex.nothotreload; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleAuxIgnored2 8 | { 9 | public static void log() 10 | { 11 | System.out.println("JProxyExampleAuxIgnored2: 2 " + JProxyExampleAuxIgnored2.class.getClassLoader().hashCode()); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/nothotreload/JProxyExampleAuxIgnored3.java: -------------------------------------------------------------------------------- 1 | package example.javaex.nothotreload; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleAuxIgnored3 8 | { 9 | public static void log() 10 | { 11 | System.out.println("JProxyExampleAuxIgnored3: 1 " + JProxyExampleAuxIgnored3.class.getClassLoader().hashCode()); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/code/example/javaex/JProxyExampleDocumentBase.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class JProxyExampleDocumentBase 8 | { 9 | public JProxyExampleDocumentBase() 10 | { 11 | System.out.println("JProxyExampleDocumentBase 7 " + this.getClass().getClassLoader().hashCode()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /relproxy/conf/conf.properties: -------------------------------------------------------------------------------- 1 | 2 | program.name=RelProxy 3 | 4 | # CHANGE ALSO IN RelProxy.getVersion() 5 | program.version=0.8.8 6 | program.javadoc.prog.version=0.8.8 7 | program.javadoc.doc.version=1.0 8 | 9 | # El proyecto al ser Maven no Ant ${program} no est\u00e1 definido, lo definimos 10 | program = ${basedir} 11 | 12 | program.target=${program}/target 13 | 14 | program.src=${program}/src/main/java 15 | 16 | 17 | -------------------------------------------------------------------------------- /relproxy/test_cmd/test_java_shell_snippet_launcher_complete_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source _shared_test_java_shell_inter_and_snippet_launcher.sh 4 | 5 | jproxysh -c 'public class _jproxyMainClass_ { ' \ 6 | ' public static void main(String[] args) { ' \ 7 | ' System.out.print("This code snippet says: ");' \ 8 | ' System.out.println("Hello World!!");' \ 9 | ' }' \ 10 | '}' 11 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | Contains the root and shared interfaces and classes of RelProxy, shared between all different language based utilities. 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/RelProxy.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy; 2 | 3 | /** 4 | * Is the root of RelProxy 5 | * 6 | * @author Jose Maria Arranz Santamaria 7 | */ 8 | public class RelProxy 9 | { 10 | /** 11 | * Returns the version of this RelProxy library. 12 | * 13 | * @return the version of the library. 14 | */ 15 | public static String getVersion() 16 | { 17 | return "0.8.8"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceScriptRoot.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public abstract class SourceScriptRoot extends SourceUnit 8 | { 9 | public SourceScriptRoot(String className) 10 | { 11 | super(className); 12 | } 13 | 14 | public abstract String getScriptCode(String encoding,boolean[] hasHashBang); 15 | } 16 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/code/example/groovyex/FalseDB.groovy: -------------------------------------------------------------------------------- 1 | package example.groovyex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | class FalseDB 8 | { 9 | def cities 10 | 11 | FalseDB() 12 | { 13 | cities = new LinkedList(); 14 | cities.add(new City("Madrid")); 15 | cities.add(new City("Barcelona")); 16 | cities.add(new City("Bilbao")); 17 | } 18 | 19 | def getCityList() { return cities; /*cities;*/ } 20 | } 21 | -------------------------------------------------------------------------------- /relproxy/bin/jproxysh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -z "$JPROXYSH_CACHE_CLASS_FOLDER" ]; then JPROXYSH_CACHE_CLASS_FOLDER_PARAM=-DcacheClassFolder="$JPROXYSH_CACHE_CLASS_FOLDER" 4 | fi 5 | 6 | if [ ! -z "$JPROXYSH_COMPILATION_OPTIONS" ]; then JPROXYSH_COMPILATION_OPTIONS_PARAM=-DcompilationOptions="$JPROXYSH_COMPILATION_OPTIONS" 7 | fi 8 | 9 | 10 | "$JAVA_HOME/bin/java" $JAVA_OPTS com.innowhere.relproxy.jproxy.JProxyShell "$@" \ 11 | "$JPROXYSH_CACHE_CLASS_FOLDER_PARAM" \ 12 | "$JPROXYSH_COMPILATION_OPTIONS_PARAM" 13 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyCompilerListener.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * Is the interface to monitor the files being compiled. 7 | * 8 | * @see JProxyConfig#setJProxyCompilerListener(JProxyCompilerListener) 9 | * @author Jose Maria Arranz Santamaria 10 | */ 11 | public interface JProxyCompilerListener 12 | { 13 | public void beforeCompile(File file); 14 | public void afterCompile(File file); 15 | } 16 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandError.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class CommandError extends Command 8 | { 9 | public CommandError(JProxyShellProcessor parent) 10 | { 11 | super(parent, "ERROR"); 12 | } 13 | 14 | @Override 15 | public boolean run() 16 | { 17 | return false; 18 | } 19 | 20 | @Override 21 | public void runPostCommand() 22 | { 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/FalseDB.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | import java.util.LinkedList; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public class FalseDB 10 | { 11 | protected LinkedList cities; 12 | 13 | public FalseDB() 14 | { 15 | cities = new LinkedList(); 16 | cities.add(new City("Madrid")); 17 | cities.add(new City("Barcelona")); 18 | cities.add(new City("Bilbao")); 19 | } 20 | 21 | public LinkedList getCityList() { return cities; /*cities;*/ } 22 | } -------------------------------------------------------------------------------- /relproxy/src/test/resources/example_normal_class.java: -------------------------------------------------------------------------------- 1 | 2 | // Test comment 3 | 4 | /* Another test comment 5 | * 6 | */ 7 | 8 | // Add this import to test if a complete class declaration is detected when imports present 9 | //import example.javashellex.JProxyShellExample; 10 | 11 | public class example_normal_class 12 | { 13 | public static void main(String[] args) 14 | { 15 | String msg = args[0] + args[1]; 16 | System.out.println(msg); 17 | 18 | System.out.println("example_normal_class 1 "); 19 | 20 | example.javashellex.JProxyShellExample.exec(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /relproxy/test_cmd/fixesforunix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT=`dirname $0`/.. 4 | 5 | # set PROJECT env as absolute path 6 | TMP_PWD=`pwd` 7 | cd $PROJECT 8 | PROJECT=`pwd` 9 | cd $TMP_PWD 10 | 11 | dos2unix $PROJECT/test_cmd/*.sh 12 | chmod +x $PROJECT/test_cmd/*.sh 13 | 14 | dos2unix $PROJECT/bin/jproxysh 15 | chmod +x $PROJECT/bin/jproxysh 16 | 17 | dos2unix $PROJECT/src/test/resources/example_java_shell 18 | chmod +x $PROJECT/src/test/resources/example_java_shell 19 | 20 | dos2unix $PROJECT/src/test/resources/example_java_shell 21 | chmod +x $PROJECT/src/test/resources/example_java_shell_complete_class 22 | 23 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/GenericProxyConfigBaseImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl; 2 | 3 | import com.innowhere.relproxy.RelProxyOnReloadListener; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public class GenericProxyConfigBaseImpl 10 | { 11 | protected boolean enabled = true; 12 | protected RelProxyOnReloadListener relListener; 13 | 14 | public boolean isEnabled() 15 | { 16 | return enabled; 17 | } 18 | 19 | public RelProxyOnReloadListener getRelProxyOnReloadListener() 20 | { 21 | return relListener; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /relproxy/test_cmd/_shared_test_java_shell_inter_and_snippet_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PROJECT=`dirname $0`/.. 4 | 5 | # set PROJECT env as absolute path 6 | TMP_PWD=`pwd` 7 | cd $PROJECT 8 | PROJECT=`pwd` 9 | # restoring: 10 | cd $TMP_PWD 11 | 12 | if [ -z "$JAVA_HOME" ]; then 13 | echo Missing JAVA_HOME environment variable, exiting... 14 | exit 1 15 | fi 16 | 17 | export PATH=$PATH:$PROJECT/bin 18 | export CLASSPATH=$PROJECT/target/classes 19 | export JAVA_OPTS="-client -Xmx100m" 20 | # Nothing really required in JAVA_OPTS, just to test 21 | 22 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/gproxy/core/GProxyInvocationHandler.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.gproxy.core; 2 | 3 | import com.innowhere.relproxy.impl.GenericProxyInvocationHandler; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public class GProxyInvocationHandler extends GenericProxyInvocationHandler 10 | { 11 | public GProxyInvocationHandler(Object obj,GProxyImpl root) 12 | { 13 | super(root); 14 | this.verObj = new GProxyVersionedObject(obj,this); 15 | } 16 | 17 | public GProxyImpl getGProxyImpl() 18 | { 19 | return (GProxyImpl)root; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/JProxyInvocationHandler.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.impl.jproxy.core; 3 | 4 | import com.innowhere.relproxy.impl.GenericProxyInvocationHandler; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public class JProxyInvocationHandler extends GenericProxyInvocationHandler 11 | { 12 | public JProxyInvocationHandler(Object obj,JProxyImpl root) 13 | { 14 | super(root); 15 | this.verObj = new JProxyVersionedObject(obj,this); 16 | } 17 | 18 | public JProxyImpl getJProxyImpl() 19 | { 20 | return (JProxyImpl)root; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /relproxy/src/test/resources/example_java_shell_complete_class: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env jproxysh 2 | 3 | // Test comment 4 | 5 | /* Another test comment 6 | * 7 | */ 8 | 9 | // Add this import to test if a complete class declaration is detected when imports present 10 | //import example.javashellex.JProxyShellExample; 11 | 12 | public class example_java_shell_complete_class 13 | { 14 | public static void main(String[] args) 15 | { 16 | String msg = args[0] + args[1]; 17 | System.out.println(msg); 18 | 19 | System.out.println("example_java_shell_complete_class 1 "); 20 | 21 | example.javashellex.JProxyShellExample.exec(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /relproxy/test_cmd/_shared_test_java_shell_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | PROJECT=`dirname $0`/.. 4 | 5 | # set PROJECT env as absolute path 6 | TMP_PWD=`pwd` 7 | cd $PROJECT 8 | PROJECT=`pwd` 9 | cd $TMP_PWD 10 | 11 | 12 | if [ -z "$JAVA_HOME" ]; then 13 | echo Missing JAVA_HOME environment variable, exiting... 14 | exit 1 15 | fi 16 | 17 | export PATH=$PATH:$PROJECT/bin 18 | export CLASSPATH=$PROJECT/target/classes 19 | export JAVA_OPTS="-client -Xmx100m" 20 | # Nothing really required in JAVA_OPTS, just to test 21 | 22 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 23 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 24 | 25 | 26 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_interactive_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | 14 | if [ -z "$JAVA_HOME" ]; then 15 | echo Missing JAVA_HOME environment variable, exiting... 16 | exit 1 17 | fi 18 | 19 | export PATH=$PATH:$PROJECT/bin 20 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 21 | export JAVA_OPTS="-client -Xmx100m" 22 | # Nothing really required in JAVA_OPTS, just to test 23 | 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | jproxysh 27 | 28 | 29 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/pages/groovyex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | GProxy Example (Groovy) 5 | 6 | 7 |

GProxy Example (Groovy)

8 | 9 |
10 |
11 | Say something to GProxy:
12 | 13 |
14 | 15 |
16 |
You said:
17 |
18 | 19 |

20 | RETURN 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/Keyboard.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public abstract class Keyboard 10 | { 11 | public abstract void type(CharSequence characters); 12 | 13 | public static Keyboard create(Charset cs) 14 | { 15 | return KeyboardUsingClipboard.create(cs); 16 | //return KeyboardNotUsingClipboard.create(cs); 17 | } 18 | 19 | public static void test(String arg) 20 | { 21 | Charset charset = Charset.defaultCharset(); 22 | Keyboard kbd = create(charset); 23 | kbd.type(arg); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /relproxy/src/test/resources/example/javashellex/JProxyShellExample.java: -------------------------------------------------------------------------------- 1 | package example.javashellex; 2 | 3 | import javax.script.ScriptEngine; 4 | import com.innowhere.relproxy.jproxy.JProxyScriptEngine; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public class JProxyShellExample 11 | { 12 | public static void exec() 13 | { 14 | System.out.println("JProxyShellExample exec() 1 "); 15 | } 16 | 17 | public static void exec(ScriptEngine engine) 18 | { 19 | JProxyScriptEngine jengine = ((JProxyScriptEngine)engine); // Just to show that ScriptEngine is a JProxyScriptEngine object 20 | System.out.println("JProxyShellExample exec(ScriptEngine) 1 "); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | $PROJECT/cmd_examples/code/example_java_shell "HELLO " "WORLD!" 27 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyShell.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.shell.JProxyShellImpl; 4 | 5 | /** 6 | * Is the main class to execute shell scripting based on Java. 7 | * 8 | *

You are not going to use directly this class, use instead jproxysh command line.

9 | * 10 | * @author Jose Maria Arranz Santamaria 11 | */ 12 | public class JProxyShell 13 | { 14 | /** 15 | * The main method. 16 | * 17 | * @param args arguments with the necessary data to initialize and executing the provided script. 18 | */ 19 | public static void main(String[] args) 20 | { 21 | JProxyShellImpl.main(args); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_snippet_launcher.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 24 | 25 | jproxysh -c 'System.out.print("This code snippet says: ");' \ 26 | 'System.out.println("Hello World!!");' 27 | 28 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyDiagnosticsListener.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import javax.tools.DiagnosticCollector; 4 | import javax.tools.JavaFileObject; 5 | 6 | /** 7 | * Is the interface to implement diagnostic listeners to capture compilation errors and warnings. 8 | * 9 | * @see JProxyConfig#setJProxyDiagnosticsListener(JProxyDiagnosticsListener) 10 | * @author Jose Maria Arranz Santamaria 11 | */ 12 | public interface JProxyDiagnosticsListener 13 | { 14 | /** 15 | * This method is called when compilation Java code has generated diagnostics. 16 | * 17 | * @param diagnostics the list of diagnostics. 18 | */ 19 | public void onDiagnostics(DiagnosticCollector diagnostics); 20 | } 21 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/cldesc/ClassDescriptorInner.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class ClassDescriptorInner extends ClassDescriptor 8 | { 9 | protected final ClassDescriptorSourceUnit parent; 10 | 11 | public ClassDescriptorInner(String className,ClassDescriptorSourceUnit parent) 12 | { 13 | super(className); 14 | this.parent = parent; 15 | } 16 | 17 | @Override 18 | public boolean isInnerClass() 19 | { 20 | return true; 21 | } 22 | 23 | public ClassDescriptorSourceUnit getClassDescriptorSourceUnit() 24 | { 25 | return parent; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_launcher_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | jproxysh $PROJECT/cmd_examples/code/example_java_shell "HELLO " "WORLD!" 27 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/pages/javaex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | JProxy Example (Java) 5 | 6 | 7 |

JProxy Example (Java)

8 | 9 |
Note: in NetBeans after every hot reloadable source change, execute Ant sync.xml and reload
10 |
11 |
12 | Say something to JProxy:
13 | 14 |
15 | 16 |
17 |
You said:
18 |
19 | 20 |

21 | RETURN 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_launcher_complete_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | $PROJECT/cmd_examples/code/example_java_shell_complete_class "HELLO " "WORLD!" 27 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_launcher_normal_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | jproxysh $PROJECT/cmd_examples/code/example_normal_class.java "HELLO " "WORLD!" 27 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyScriptEngineFactory.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.screngine.JProxyScriptEngineFactoryImpl; 4 | import javax.script.ScriptEngineFactory; 5 | 6 | /** 7 | * Is the root class of JSR-223 Java Scripting API support. 8 | * 9 | * @author Jose Maria Arranz Santamaria 10 | */ 11 | public abstract class JProxyScriptEngineFactory implements ScriptEngineFactory 12 | { 13 | /** 14 | * Factory method to create a JProxyScriptEngineFactory implementing ScriptEngineFactory. 15 | * 16 | * @return the new factory. 17 | */ 18 | public static JProxyScriptEngineFactory create() 19 | { 20 | return JProxyScriptEngineFactoryImpl.create(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_launcher_complete_class_2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_CACHE_CLASS_FOLDER="$PROJECT/tmp/java_shell_test_classes" 24 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 25 | 26 | jproxysh $PROJECT/cmd_examples/code/example_java_shell_complete_class "HELLO " "WORLD!" 27 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceFileJavaNormal.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public class SourceFileJavaNormal extends SourceUnit 10 | { 11 | protected final FileExt sourceFile; 12 | 13 | public SourceFileJavaNormal(FileExt sourceFile,FileExt rootFolderOfSources) 14 | { 15 | super(buildClassNameFromFile(sourceFile,rootFolderOfSources)); 16 | this.sourceFile = sourceFile; 17 | } 18 | 19 | @Override 20 | public long lastModified() 21 | { 22 | return sourceFile.getFile().lastModified(); 23 | } 24 | 25 | public FileExt getFileExt() 26 | { 27 | return sourceFile; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/JProxyCompilationException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp; 3 | 4 | import com.innowhere.relproxy.RelProxyException; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceUnit; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class JProxyCompilationException extends RelProxyException 12 | { 13 | protected ClassDescriptorSourceUnit sourceUnit; 14 | 15 | public JProxyCompilationException(ClassDescriptorSourceUnit sourceUnit) 16 | { 17 | super("Compilation error"); 18 | this.sourceUnit = sourceUnit; 19 | } 20 | 21 | public ClassDescriptorSourceUnit getClassDescriptorSourceUnit() 22 | { 23 | return sourceUnit; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceScriptRootFileJavaExt.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class SourceScriptRootFileJavaExt extends SourceScriptRootFile 12 | { 13 | public SourceScriptRootFileJavaExt(FileExt sourceFile,FolderSourceList folderSourceList) 14 | { 15 | super(sourceFile,folderSourceList); 16 | } 17 | 18 | @Override 19 | public String getScriptCode(String encoding,boolean[] hasHashBang) 20 | { 21 | hasHashBang[0] = false; 22 | return JProxyUtil.readTextFile(sourceFile.getFile(),encoding); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/code/example/groovyex/GroovyExampleLoadListener.groovy: -------------------------------------------------------------------------------- 1 | 2 | package example.groovyex; 3 | 4 | import org.itsnat.core.event.ItsNatServletRequestListener; 5 | import org.itsnat.core.ItsNatServletRequest; 6 | import org.itsnat.core.ItsNatServletResponse; 7 | import example.groovyex.FalseDB; 8 | 9 | class GroovyExampleLoadListener implements ItsNatServletRequestListener 10 | { 11 | def db 12 | 13 | GroovyExampleLoadListener() 14 | { 15 | } 16 | 17 | GroovyExampleLoadListener(FalseDB db) // Explicit type tells Groovy to reload FalseDB class when changed 18 | { 19 | this.db = db; 20 | } 21 | 22 | void processRequest(ItsNatServletRequest request, ItsNatServletResponse response) 23 | { 24 | println("GroovyExampleLoadListener 4 "); 25 | 26 | new example.groovyex.GroovyExampleDocument(request.getItsNatDocument(),db); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/jsp/test_jproxy_stop.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="com.innowhere.relproxy.jproxy.JProxy"%> 2 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Test JProxy class reloader STOP 8 | 9 | 10 |

Test JProxy class reloader STOP

11 | 12 | <% 13 | boolean res = JProxy.stop(); 14 | if (res) 15 | { 16 | %> 17 |

Source change detection is disabled!

18 | 19 | <% } 20 | else 21 | { 22 | %> 23 |

Source change detection stop action is failed, maybe is already stopped!

24 | 25 | <% 26 | } 27 | %> 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/jsp/test_jproxy_start.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="com.innowhere.relproxy.jproxy.JProxy"%> 2 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Test JProxy class reloader RE-START 8 | 9 | 10 |

Test JProxy class reloader RE-START

11 | 12 | <% 13 | boolean res = JProxy.start(); 14 | if (res) 15 | { 16 | %> 17 |

Source change detection was re-started!

18 | 19 | <% } 20 | else 21 | { 22 | %> 23 |

Source change detection start action is failed, maybe is already running!

24 | 25 | <% 26 | } 27 | %> 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /relproxy/src/main/cmd_examples/ex_java_shell_snippet_launcher_complete_class.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | RELPROXY_JAR=relproxy-0.8.8.jar 4 | 5 | PROJECT=`dirname $0`/.. 6 | 7 | # set PROJECT env as absolute path 8 | TMP_PWD=`pwd` 9 | cd $PROJECT 10 | PROJECT=`pwd` 11 | cd $TMP_PWD 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo Missing JAVA_HOME environment variable, exiting... 15 | exit 1 16 | fi 17 | 18 | export PATH=$PATH:$PROJECT/bin 19 | export CLASSPATH=$PROJECT/lib/$RELPROXY_JAR 20 | export JAVA_OPTS="-client -Xmx100m" 21 | # Nothing really required in JAVA_OPTS, just to test 22 | 23 | export JPROXYSH_COMPILATION_OPTIONS="-source 1.6 -target 1.6" 24 | 25 | jproxysh -c 'public class _jproxyMainClass_ { ' \ 26 | ' public static void main(String[] args) { ' \ 27 | ' System.out.print("This code snippet says: ");' \ 28 | ' System.out.println("Hello World!!");' \ 29 | ' }' \ 30 | '}' 31 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputSourceInMemory.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | /** 4 | * http://www.javablogging.com/dynamic-in-memory-compilation/ 5 | * 6 | * @author jmarranz 7 | */ 8 | public class JavaFileObjectInputSourceInMemory extends JavaFileObjectInputSourceBase 9 | { 10 | protected String source; 11 | protected long timestamp; 12 | 13 | public JavaFileObjectInputSourceInMemory(String name,String source,String encoding,long timestamp) 14 | { 15 | super(name,encoding); 16 | this.source = source; 17 | this.timestamp = timestamp; 18 | } 19 | 20 | @Override 21 | protected String getSource() 22 | { 23 | return source; 24 | } 25 | 26 | @Override 27 | public long getLastModified() 28 | { 29 | return timestamp; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyInputSourceFileExcludedListener.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * This interface is provided to developers to implement excluding rules to filter source files not to be part of the hot reloading system in spite of included in input paths 7 | * 8 | * @see JProxyConfig#setJProxyInputSourceFileExcludedListener(JProxyInputSourceFileExcludedListener) 9 | * @author Jose Maria Arranz Santamaria 10 | */ 11 | public interface JProxyInputSourceFileExcludedListener 12 | { 13 | /** 14 | * This method is called per file when going to be managed by the hot reloading system. 15 | * 16 | * @param file the file to be managed. 17 | * @param rootFolderOfSources the folder root of sources where this file is located. 18 | * @return true whether the file must be ignored. 19 | */ 20 | public boolean isExcluded(File file,File rootFolderOfSources); 21 | } 22 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/FileExt.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import java.io.File; 5 | import java.io.IOException; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class FileExt 12 | { 13 | protected final File file; 14 | protected final String cannonicalPath; // El obtener el cannonicalPath exige acceder al sistema de archivos, por eso nos inventamos esta clase, para evitar sucesivas llamadas a File.getCanonicalPath() 15 | 16 | public FileExt(File file) 17 | { 18 | this.file = file; 19 | try { this.cannonicalPath = file.getCanonicalPath(); } 20 | catch (IOException ex) { throw new RelProxyException(ex); } 21 | } 22 | 23 | public File getFile() 24 | { 25 | return file; 26 | } 27 | 28 | public String getCanonicalPath() 29 | { 30 | return cannonicalPath; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/util/JProxyTestUtil.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.jproxy.util; 3 | 4 | import java.io.File; 5 | import java.net.URL; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class JProxyTestUtil 12 | { 13 | public static final String RESOURCES_FOLDER = "src/test/resources"; 14 | public static final String CACHE_CLASS_FOLDER = "tmp/java_shell_test_classes"; 15 | 16 | public static File getProjectFolder() 17 | { 18 | String className = JProxyTestUtil.class.getName(); // com.innowhere.relproxy.jproxy.util.JProxyTestUtil 19 | URL urlClass = JProxyTestUtil.class.getClassLoader().getResource(className.replace('.','/') + ".class"); 20 | File fileClass = new File(urlClass.getPath()); 21 | File projectFolder = fileClass.getParentFile(); 22 | for(int i = 0; i < 7; i++) 23 | projectFolder = projectFolder.getParentFile(); 24 | return projectFolder; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/cldesc/ClassDescriptorSourceFileJava.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.JProxyEngine; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceFileJavaNormal; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class ClassDescriptorSourceFileJava extends ClassDescriptorSourceUnit 12 | { 13 | public ClassDescriptorSourceFileJava(JProxyEngine engine,String className, SourceFileJavaNormal sourceFile, long timestamp) 14 | { 15 | super(engine,className, sourceFile, timestamp); 16 | } 17 | 18 | public SourceFileJavaNormal getSourceFileJavaNormal() 19 | { 20 | return (SourceFileJavaNormal)sourceUnit; 21 | } 22 | 23 | public FileExt getSourceFile() 24 | { 25 | return getSourceFileJavaNormal().getFileExt(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputSourceInFile.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 4 | import java.io.File; 5 | 6 | /** 7 | * http://www.javablogging.com/dynamic-in-memory-compilation/ 8 | * 9 | * @author jmarranz 10 | */ 11 | public class JavaFileObjectInputSourceInFile extends JavaFileObjectInputSourceBase 12 | { 13 | protected File file; 14 | protected String source; 15 | 16 | public JavaFileObjectInputSourceInFile(String name,File file,String encoding) 17 | { 18 | super(name,encoding); 19 | this.file = file; 20 | } 21 | 22 | @Override 23 | protected String getSource() 24 | { 25 | if (source != null) 26 | return source; 27 | this.source = JProxyUtil.readTextFile(file, encoding); 28 | return source; 29 | } 30 | 31 | @Override 32 | public long getLastModified() 33 | { 34 | return file.lastModified(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/gproxy/core/GProxyImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.gproxy.core; 2 | 3 | import com.innowhere.relproxy.impl.gproxy.GProxyConfigImpl; 4 | import com.innowhere.relproxy.gproxy.GProxyGroovyScriptEngine; 5 | import com.innowhere.relproxy.impl.GenericProxyImpl; 6 | import com.innowhere.relproxy.impl.GenericProxyInvocationHandler; 7 | 8 | 9 | /** 10 | * 11 | * @author jmarranz 12 | */ 13 | public abstract class GProxyImpl extends GenericProxyImpl 14 | { 15 | public static GProxyImpl SINGLETON; 16 | protected GProxyGroovyScriptEngine engine; 17 | 18 | public void init(GProxyConfigImpl config) 19 | { 20 | super.init(config); 21 | this.engine = config.getGProxyGroovyScriptEngine(); 22 | } 23 | 24 | public GProxyGroovyScriptEngine getGProxyGroovyScriptEngine() 25 | { 26 | return engine; 27 | } 28 | 29 | @Override 30 | public GenericProxyInvocationHandler createGenericProxyInvocationHandler(Object obj) 31 | { 32 | return new GProxyInvocationHandler(obj,this); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputClassInJar.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.URI; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class JavaFileObjectInputClassInJar extends JavaFileObjectInputClassInFileSystem 12 | { 13 | protected long timestamp; 14 | 15 | public JavaFileObjectInputClassInJar(String binaryName, URI uri,long timestamp) 16 | { 17 | super(binaryName,uri,uri.getSchemeSpecificPart()); 18 | this.timestamp = timestamp; 19 | } 20 | 21 | @Override 22 | public InputStream openInputStream() throws IOException 23 | { 24 | return uri.toURL().openStream(); // easy way to handle any URI! 25 | } 26 | 27 | @Override 28 | public long getLastModified() 29 | { 30 | return timestamp; 31 | } 32 | 33 | @Override 34 | public String toString() 35 | { 36 | return "JavaFileObjectInputClassInJar{uri=" + uri + '}'; 37 | } 38 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceUnit.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public abstract class SourceUnit 11 | { 12 | protected final String className; 13 | 14 | public SourceUnit(String className) 15 | { 16 | this.className = className; 17 | } 18 | 19 | public abstract long lastModified(); 20 | 21 | protected static String buildClassNameFromFile(FileExt sourceFile,FolderSourceList sourceList) 22 | { 23 | return sourceList.buildClassNameFromFile(sourceFile); 24 | } 25 | 26 | protected static String buildClassNameFromFile(FileExt sourceFile,FileExt rootFolderOfSources) 27 | { 28 | return FolderSourceList.buildClassNameFromFile(sourceFile,rootFolderOfSources); 29 | } 30 | 31 | public String getClassName() 32 | { 33 | return className; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/code/example/javaex/JProxyExampleLoadListener.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | import org.itsnat.core.event.ItsNatServletRequestListener; 8 | import org.itsnat.core.ItsNatServletRequest; 9 | import org.itsnat.core.ItsNatServletResponse; 10 | import org.itsnat.core.html.ItsNatHTMLDocument; 11 | 12 | public class JProxyExampleLoadListener implements ItsNatServletRequestListener 13 | { 14 | protected final FalseDB db; 15 | protected static Integer testStatic = 10; 16 | protected static final Integer testStaticFinal = 11; 17 | 18 | public JProxyExampleLoadListener() 19 | { 20 | this(null); 21 | } 22 | 23 | public JProxyExampleLoadListener(FalseDB db) 24 | { 25 | this.db = db; 26 | } 27 | 28 | 29 | @Override 30 | public void processRequest(ItsNatServletRequest request, ItsNatServletResponse response) 31 | { 32 | System.out.println("JProxyExampleLoadListener 1 " + this.getClass().getClassLoader().hashCode()); 33 | new example.javaex.JProxyExampleDocument(request,(ItsNatHTMLDocument)request.getItsNatDocument(),db); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/gproxy/GProxyConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.gproxy; 2 | 3 | import com.innowhere.relproxy.RelProxyOnReloadListener; 4 | import com.innowhere.relproxy.gproxy.GProxyConfig; 5 | import com.innowhere.relproxy.gproxy.GProxyGroovyScriptEngine; 6 | import com.innowhere.relproxy.impl.GenericProxyConfigBaseImpl; 7 | 8 | /** 9 | * 10 | * @author jmarranz 11 | */ 12 | public class GProxyConfigImpl extends GenericProxyConfigBaseImpl implements GProxyConfig 13 | { 14 | protected GProxyGroovyScriptEngine engine; 15 | 16 | public GProxyConfig setEnabled(boolean enabled) 17 | { 18 | this.enabled = enabled; 19 | return this; 20 | } 21 | 22 | public GProxyConfig setRelProxyOnReloadListener(RelProxyOnReloadListener relListener) 23 | { 24 | this.relListener = relListener; 25 | return this; 26 | } 27 | 28 | public GProxyConfig setGProxyGroovyScriptEngine(GProxyGroovyScriptEngine engine) 29 | { 30 | this.engine = engine; 31 | return this; 32 | } 33 | 34 | public GProxyGroovyScriptEngine getGProxyGroovyScriptEngine() 35 | { 36 | return engine; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/code/example/groovyex/GroovyExampleDocument.groovy: -------------------------------------------------------------------------------- 1 | 2 | package example.groovyex; 3 | 4 | import org.w3c.dom.events.Event 5 | import org.w3c.dom.events.EventListener 6 | 7 | class GroovyExampleDocument 8 | { 9 | def itsNatDoc // ItsNatHTMLDocument 10 | def textInput // ItsNatHTMLInputText 11 | def resultsElem // Element 12 | 13 | GroovyExampleDocument(itsNatDoc,db) 14 | { 15 | this.itsNatDoc = itsNatDoc 16 | 17 | if (db.getCityList().size() != 3) 18 | throw new RuntimeException("Unexpected"); 19 | 20 | def doc = itsNatDoc.getHTMLDocument() 21 | 22 | def compMgr = itsNatDoc.getItsNatComponentManager() 23 | this.textInput = compMgr.createItsNatComponentById("inputId") 24 | 25 | def buttonElem = doc.getElementById("buttonId") 26 | buttonElem.addEventListener("click", 27 | { Event evt -> def text = textInput.getText(); resultsElem.setTextContent(text); } as EventListener, false) 28 | 29 | def closure = { println("GroovyExampleDocument closure 2 ") } 30 | closure(); 31 | 32 | this.resultsElem = doc.getElementById("resultsId") 33 | 34 | println("GroovyExampleDocument 2 ") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/JProxyVersionedObject.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core; 2 | 3 | import com.innowhere.relproxy.impl.GenericProxyVersionedObject; 4 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.JProxyEngine; 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class JProxyVersionedObject extends GenericProxyVersionedObject 12 | { 13 | protected String className; 14 | 15 | public JProxyVersionedObject(Object obj,JProxyInvocationHandler parent) 16 | { 17 | super(obj,parent); 18 | this.className = obj.getClass().getName(); 19 | } 20 | 21 | public JProxyInvocationHandler getJProxyInvocationHandler() 22 | { 23 | return (JProxyInvocationHandler)parent; 24 | } 25 | 26 | @Override 27 | protected Class reloadClass() 28 | { 29 | JProxyEngine engine = getJProxyInvocationHandler().getJProxyImpl().getJProxyEngine(); 30 | engine.reloadWhenChanged(); 31 | return (Class)engine.findClass(className); 32 | } 33 | 34 | @Override 35 | protected boolean ignoreField(Field field) 36 | { 37 | return false; // Todos cuentan (útil en Groovy no en Java) 38 | } 39 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/gproxy/GProxyDefaultImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.gproxy; 2 | 3 | import com.innowhere.relproxy.gproxy.GProxyConfig; 4 | import com.innowhere.relproxy.impl.gproxy.core.GProxyImpl; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public class GProxyDefaultImpl extends GProxyImpl 11 | { 12 | public static GProxyConfig createGProxyConfig() 13 | { 14 | return new GProxyConfigImpl(); 15 | } 16 | 17 | public static void initStatic(GProxyConfigImpl config) 18 | { 19 | if (!config.isEnabled()) return; 20 | 21 | checkSingletonNull(SINGLETON); 22 | SINGLETON = new GProxyDefaultImpl(); 23 | SINGLETON.init(config); 24 | } 25 | 26 | public static T createStatic(T obj,Class clasz) 27 | { 28 | if (SINGLETON == null) 29 | return obj; // No se ha llamado al init o enabled = false 30 | 31 | return SINGLETON.create(obj, clasz); 32 | } 33 | 34 | public static Object createStatic(Object obj,Class[] classes) 35 | { 36 | if (SINGLETON == null) 37 | return obj; // No se ha llamado al init o enabled = false 38 | 39 | return SINGLETON.create(obj, classes); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | RelProxy Examples 8 | 9 | 10 |

RelProxy Examples

11 | 12 |

This project is mainly created to help development and testing of RelProxy, it binds directly RelProxy source code instead the jar

13 | 14 |

RelProxy provides a simple approach for hot class reload for Java and Groovy

15 | 16 |

Source code of RelProxy and these examples are HERE

17 | 18 | 21 | 22 | 25 | 26 | 29 | 30 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/build.gradle: -------------------------------------------------------------------------------- 1 | import java.util.jar.Attributes.Name; 2 | 3 | apply plugin: 'java' 4 | apply plugin: 'eclipse' 5 | apply plugin: 'war' 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | providedCompile 'javax.servlet:servlet-api:2.5' 13 | providedCompile 'javax.servlet.jsp:jsp-api:2.1' 14 | 15 | compile files('/src/main/webapp/WEB-INF/lib/ItsNat_1.3.1.jar') 16 | compile 'org.apache.xmlgraphics:batik-dom:1.7@jar' 17 | compile 'org.apache.xmlgraphics:batik-xml:1.7@jar' 18 | compile 'org.apache.xmlgraphics:batik-util:1.7@jar' 19 | compile 'net.sourceforge.nekohtml:nekohtml:1.9.12@jar' 20 | compile 'xalan:serializer:2.7.1@jar' 21 | compile 'org.codehaus.groovy:groovy-all:2.1.6@jar' 22 | 23 | runtime files('/src/main/webapp/WEB-INF/lib/ItsNat-1.3.1.jar') 24 | runtime 'org.apache.xmlgraphics:batik-dom:1.7' 25 | runtime 'org.apache.xmlgraphics:batik-xml:1.7' 26 | runtime 'org.apache.xmlgraphics:batik-util:1.7' 27 | runtime 'net.sourceforge.nekohtml:nekohtml:1.9.12' 28 | runtime 'xalan:serializer:2.7.1' 29 | runtime 'org.codehaus.groovy:groovy-all:2.1.6' 30 | } 31 | 32 | sourceSets.main.java.srcDirs 'src/main/webapp/WEB-INF/javaex/code' 33 | sourceSets.main.java.srcDirs 'src/main/webapp/WEB-INF/groovyex/code' 34 | 35 | task explodedWar(type: Copy) { 36 | into "$buildDir/web" 37 | with war 38 | } 39 | 40 | 41 | war.dependsOn explodedWar 42 | 43 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputClassInFile.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo.JavaFileObjectInputClassInFileSystem; 4 | import java.io.BufferedInputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.net.URI; 10 | 11 | /** 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JavaFileObjectInputClassInFile extends JavaFileObjectInputClassInFileSystem 16 | { 17 | protected File file; 18 | 19 | public JavaFileObjectInputClassInFile(File file,String binaryName, URI uri) 20 | { 21 | super(binaryName,uri,uri.getPath()); 22 | this.file = file; 23 | } 24 | 25 | @Override 26 | public InputStream openInputStream() throws IOException 27 | { 28 | // Podríamos hacer uri.toURL().openStream() pero si tenemos el File es para algo 29 | return new BufferedInputStream(new FileInputStream(file),10 * 1024); 30 | } 31 | 32 | @Override 33 | public long getLastModified() 34 | { 35 | return file.lastModified(); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "JavaFileObjectInputClassInFile{uri=" + uri + '}'; 41 | } 42 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceScriptRootFileOtherExt.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class SourceScriptRootFileOtherExt extends SourceScriptRootFile 12 | { 13 | public SourceScriptRootFileOtherExt(FileExt sourceFile,FolderSourceList folderSourceList) 14 | { 15 | super(sourceFile,folderSourceList); 16 | } 17 | 18 | @Override 19 | public String getScriptCode(String encoding,boolean[] hasHashBang) 20 | { 21 | String codeBody = JProxyUtil.readTextFile(sourceFile.getFile(),encoding); 22 | // Eliminamos la primera línea #! (debe estar en la primera línea y sin espacios antes) 23 | if (codeBody.startsWith("#!")) 24 | { 25 | hasHashBang[0] = true; 26 | int pos = codeBody.indexOf('\n'); 27 | if (pos != -1) // Rarísimo que sólo esté el hash bang (script vacío) 28 | { 29 | codeBody = codeBody.substring(pos + 1); 30 | } 31 | } 32 | else hasHashBang[0] = false; 33 | return codeBody; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/RelProxyException.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy; 2 | 3 | /** 4 | * Internal checked exceptions thrown by RelProxy and library specific errors are wrapped into this exception class. 5 | * 6 | * @author Jose Maria Arranz Santamaria 7 | */ 8 | public class RelProxyException extends RuntimeException 9 | { 10 | /** 11 | * Constructs a new exception with the specified message and cause. 12 | * 13 | *

Parameters are passed to the super constructor.

14 | * 15 | * @param message the detail message 16 | * @param cause the cause 17 | */ 18 | public RelProxyException(String message, Throwable cause) 19 | { 20 | super(message, cause); 21 | } 22 | 23 | /** 24 | * Constructs a new exception with the specified message. 25 | * 26 | *

Parameter is passed to the super constructor.

27 | * 28 | * @param message the detail message 29 | */ 30 | public RelProxyException(String message) 31 | { 32 | super(message); 33 | } 34 | 35 | /** 36 | * Constructs a new exception with the specified cause. 37 | * 38 | *

Parameter is passed to the super constructor.

39 | * 40 | * @param cause the cause 41 | */ 42 | public RelProxyException(Throwable cause) 43 | { 44 | super(cause); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceScriptRootFile.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | import com.innowhere.relproxy.impl.FileExt; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public abstract class SourceScriptRootFile extends SourceScriptRoot 12 | { 13 | protected FileExt sourceFile; 14 | 15 | public SourceScriptRootFile(FileExt sourceFile,FolderSourceList folderSourceList) 16 | { 17 | super(buildClassNameFromFile(sourceFile,folderSourceList)); 18 | this.sourceFile = sourceFile; 19 | } 20 | 21 | public static SourceScriptRootFile createSourceScriptRootFile(FileExt sourceFile,FolderSourceList folderSourceList) 22 | { 23 | String ext = JProxyUtil.getFileExtension(sourceFile.getFile()); // Si no tiene extensión devuelve "" 24 | if ("java".equals(ext)) 25 | return new SourceScriptRootFileJavaExt(sourceFile,folderSourceList); 26 | else 27 | return new SourceScriptRootFileOtherExt(sourceFile,folderSourceList); // Caso de archivo script inicial sin extensión .java (puede ser sin extensión) 28 | } 29 | 30 | @Override 31 | public long lastModified() 32 | { 33 | return sourceFile.getFile().lastModified(); 34 | } 35 | 36 | public FileExt getFileExt() 37 | { 38 | return sourceFile; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/gproxy/GProxyGroovyScriptEngine.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.gproxy; 2 | 3 | /** 4 | * Interface to implement the object implementing the GroovyScriptEngine wrapper used to reload Groovy classes. 5 | * 6 | *

The following is a very simple example of the required implementation, groovyEngine is the groovy.util.GroovyScriptEngine 7 | * object:

8 | 9 | def gproxyGroovyEngine = { 10 | String scriptName -> return (java.lang.Class)groovyEngine.loadScriptByName(scriptName) 11 | } as GProxyGroovyScriptEngine; 12 | 13 | * 14 | * 15 | * @see GProxyConfig#setGProxyGroovyScriptEngine(GProxyGroovyScriptEngine) 16 | * @author Jose Maria Arranz Santamaria 17 | */ 18 | public interface GProxyGroovyScriptEngine 19 | { 20 | /** 21 | * The class implementing this method must call the method groovy.util.GroovyScriptEngine.loadScriptByName(String scriptName) passing 22 | * the scriptName. 23 | * 24 | *

This method is called by GProxy when it needs to get the Class associated to the specified Groovy script/class to check if this class 25 | * has changed because Groovy has reloaded the class when a source code has been detected. 26 | * 27 | * @param scriptName the name of the Groovy script/class. 28 | * @return the class associated to the specified Groovy script. 29 | */ 30 | public Class loadScriptByName(String scriptName); 31 | } 32 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyJavaShellInteractiveTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.innowhere.relproxy.jproxy; 8 | 9 | import org.junit.After; 10 | import org.junit.AfterClass; 11 | import org.junit.Before; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * 18 | * @author jmarranz 19 | */ 20 | public class JProxyJavaShellInteractiveTest 21 | { 22 | public JProxyJavaShellInteractiveTest() 23 | { 24 | } 25 | 26 | @BeforeClass 27 | public static void setUpClass() 28 | { 29 | } 30 | 31 | @AfterClass 32 | public static void tearDownClass() 33 | { 34 | } 35 | 36 | @Before 37 | public void setUp() 38 | { 39 | 40 | } 41 | 42 | @After 43 | public void tearDown() 44 | { 45 | 46 | } 47 | 48 | @Test 49 | public void test_java_shell_interactive() 50 | { 51 | String compilationOptions = "-source 1.6 -target 1.6"; 52 | 53 | String[] args = new String[] 54 | { 55 | "", // El args[0] esperado 56 | "-DcompilationOptions=" + compilationOptions, 57 | "-Dtest=true" 58 | }; 59 | 60 | JProxyShell.main(args); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/RelProxyOnReloadListener.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * Is the interface needed to register a class reload listener. 7 | * 8 | *

An object implementing this interface can optionally be registered on RelProxy to listen when the method of a proxy object has been called 9 | * and the class of the original object associated has been reloaded (and a new "original" object based on the new class was created to replace it). 10 | *

11 | * 12 | * 13 | * @see com.innowhere.relproxy.jproxy.JProxyConfig#setRelProxyOnReloadListener(com.innowhere.relproxy.RelProxyOnReloadListener) 14 | * @see com.innowhere.relproxy.gproxy.GProxyConfig#setRelProxyOnReloadListener(com.innowhere.relproxy.RelProxyOnReloadListener) 15 | * @author Jose Maria Arranz Santamaria 16 | */ 17 | public interface RelProxyOnReloadListener 18 | { 19 | /** 20 | * Called when some source code change has happened and a new class has been compiled and reloaded. 21 | * 22 | * @param objOld the old object before class reload. 23 | * @param objNew the new object based on the new class loaded by the new class loader. 24 | * @param proxy the proxy object created by {@link java.lang.reflect.Proxy} being used. 25 | * @param method the method being called through the proxy object. 26 | * @param args the parameters being used in the method call. 27 | */ 28 | public void onReload(Object objOld,Object objNew,Object proxy, Method method, Object[] args); 29 | } 30 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/WindowUnicodeKeyboard.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import static java.awt.event.KeyEvent.VK_ALT; 4 | import java.nio.charset.Charset; 5 | 6 | /** 7 | * http://stackoverflow.com/questions/1248510/convert-string-to-keyevents 8 | * 9 | * @author jmarranz 10 | */ 11 | public class WindowUnicodeKeyboard extends KeyboardNotUsingClipboard 12 | { 13 | public WindowUnicodeKeyboard(Charset cs) 14 | { 15 | super(cs); 16 | } 17 | 18 | @Override 19 | public boolean isUseCodePoint() 20 | { 21 | return false; 22 | } 23 | 24 | @Override 25 | public boolean type(char character) 26 | { 27 | if (super.type(character)) 28 | return true; 29 | 30 | // En Windows usar mintty porque usando la consola de MSYS por sí misma, que es realmente la de Windows, hay problemas con el set de caracteres, pues sería Cp1252 para Java pero Cp850 para la consola y salen mal por tanto los caracteres no ASCII 31 | 32 | 33 | String unicodeDigits = getUnicodeDigits(character,10); // En DECIMAL 34 | 35 | robot.keyPress(VK_ALT); 36 | try 37 | { 38 | for (int i = 0; i < unicodeDigits.length(); i++) { 39 | typeNumPad(Integer.parseInt(unicodeDigits.substring(i, i + 1))); 40 | } 41 | } 42 | finally 43 | { 44 | robot.keyRelease(VK_ALT); 45 | } 46 | 47 | return true; 48 | } 49 | 50 | 51 | } -------------------------------------------------------------------------------- /relproxy_test_itsnat/sync.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/gproxy/core/GProxyVersionedObject.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.gproxy.core; 2 | 3 | import com.innowhere.relproxy.gproxy.GProxyGroovyScriptEngine; 4 | import com.innowhere.relproxy.impl.GenericProxyVersionedObject; 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class GProxyVersionedObject extends GenericProxyVersionedObject 12 | { 13 | protected String path; 14 | 15 | public GProxyVersionedObject(Object obj,GProxyInvocationHandler parent) 16 | { 17 | super(obj,parent); 18 | this.path = obj.getClass().getName().replace('.','/'); 19 | } 20 | 21 | 22 | public GProxyInvocationHandler getGProxyInvocationHandler() 23 | { 24 | return (GProxyInvocationHandler)parent; 25 | } 26 | 27 | @Override 28 | protected Class reloadClass() 29 | { 30 | GProxyGroovyScriptEngine engine = getGProxyInvocationHandler().getGProxyImpl().getGProxyGroovyScriptEngine(); 31 | 32 | try 33 | { 34 | return engine.loadScriptByName(path + ".groovy"); //Ej: example/groovyex/GroovyExampleLoadListener.groovy 35 | } 36 | catch(Exception ex) 37 | { 38 | ex.printStackTrace(System.err); 39 | return null; 40 | } 41 | } 42 | 43 | @Override 44 | protected boolean ignoreField(Field field) 45 | { 46 | return field.getName().startsWith("__timeStamp__"); // Este atributo cambia de nombre en cada reload, no lo consideramos 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/JProxyShellClassLoader.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptor; 5 | import java.io.File; 6 | import java.net.MalformedURLException; 7 | import java.net.URL; 8 | import java.net.URLClassLoader; 9 | 10 | /** 11 | * 12 | * @author jmarranz 13 | */ 14 | public class JProxyShellClassLoader extends URLClassLoader 15 | { 16 | public JProxyShellClassLoader(ClassLoader parent,File classFolder) 17 | { 18 | super(toURLArray(classFolder),parent); 19 | } 20 | 21 | private static URL[] toURLArray(File file) 22 | { 23 | try { return new URL[]{file.toURI().toURL()}; } 24 | catch (MalformedURLException ex) { throw new RelProxyException(ex); } 25 | } 26 | 27 | @Override 28 | protected Class findClass(String name) throws ClassNotFoundException 29 | { 30 | return super.findClass(name); 31 | } 32 | 33 | @Override 34 | protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException 35 | { 36 | return super.loadClass(name, resolve); 37 | } 38 | 39 | public synchronized Class defineClass(ClassDescriptor classDesc) 40 | { 41 | String className = classDesc.getClassName(); 42 | byte[] classBytes = classDesc.getClassBytes(); 43 | Class clasz = defineClass(className,classBytes, 0, classBytes.length); 44 | classDesc.setLastLoadedClass(clasz); 45 | return clasz; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/MacOSXUnicodeKeyboard.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import static java.awt.Event.ALT_MASK; 4 | import java.nio.charset.Charset; 5 | 6 | /** 7 | * 8 | * https://discussions.apple.com/thread/1899290 9 | * http://superuser.com/questions/13086/how-do-you-type-unicode-characters-using-hexadecimal-codes (buscar OS X) 10 | * http://controlyourmac.com/2012/05/understanding-mac-keyboard.html 11 | * 12 | * @author jmarranz 13 | */ 14 | public class MacOSXUnicodeKeyboard extends KeyboardNotUsingClipboard 15 | { 16 | public MacOSXUnicodeKeyboard(Charset cs) 17 | { 18 | super(cs); 19 | } 20 | 21 | @Override 22 | public boolean isUseCodePoint() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | public boolean type(char character) 29 | { 30 | if (super.type(character)) 31 | return true; 32 | 33 | String unicodeDigits = getUnicodeDigits(character,16); // En hexadecimal 34 | 35 | robot.keyPress(ALT_MASK); // "Since the ALT_MASK modifier is the Option key in OS X" https://developer.apple.com/library/mac/documentation/java/conceptual/java14development/07-NativePlatformIntegration/NativePlatformIntegration.html 36 | 37 | try 38 | { 39 | for (int i = 0; i < unicodeDigits.length(); i++) { 40 | type(unicodeDigits.charAt(i)); 41 | } 42 | } 43 | finally 44 | { 45 | robot.keyRelease(ALT_MASK); 46 | } 47 | 48 | return true; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputClassInMemory.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.OutputStream; 7 | import java.net.URI; 8 | import javax.tools.SimpleJavaFileObject; 9 | 10 | /** 11 | * http://www.javablogging.com/dynamic-in-memory-compilation/ 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JavaFileObjectInputClassInMemory extends SimpleJavaFileObject implements JProxyJavaFileObjectInput 16 | { 17 | protected String binaryName; 18 | protected byte[] byteCode; 19 | protected long timestamp; 20 | 21 | public JavaFileObjectInputClassInMemory(String name,byte[] byteCode,long timestamp) 22 | { 23 | super(URI.create("string:///" + name.replace('.', '/') + Kind.CLASS.extension), Kind.CLASS); 24 | 25 | this.binaryName = name; 26 | this.byteCode = byteCode; 27 | this.timestamp = timestamp; 28 | } 29 | 30 | public byte[] getBytes() 31 | { 32 | return byteCode; 33 | } 34 | 35 | @Override 36 | public long getLastModified() 37 | { 38 | return timestamp; 39 | } 40 | 41 | @Override 42 | public InputStream openInputStream() throws IOException 43 | { 44 | return new ByteArrayInputStream(getBytes()); 45 | } 46 | 47 | @Override 48 | public OutputStream openOutputStream() throws IOException 49 | { 50 | throw new UnsupportedOperationException(); 51 | } 52 | 53 | @Override 54 | public String getBinaryName() 55 | { 56 | return binaryName; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | relproxy_test_itsnat 4 | 5 | ItsNatGroovyServlet 6 | example.groovyex.ItsNatGroovyServlet 7 | 8 | scriptRootPath 9 | groovyex/code 10 | 11 | 12 | initScript 13 | example/groovyex/groovy_servlet_init.groovy 14 | 15 | 16 | 17 | ItsNatGroovyServlet 18 | /groovyex 19 | 20 | 21 | ItsNatJProxyServlet 22 | example.javaex.JProxyExampleServlet 23 | 24 | 25 | ItsNatJProxyServlet 26 | /javaex 27 | 28 | 29 | 30 | 30 31 | 32 | 33 | 34 | index.html 35 | 36 | 37 | 38 | 39 | example.javaex.JProxyServletContextListener 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/nb-configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | 1.5 17 | Tomcat 18 | all 19 | js/libs 20 | false 21 | true 22 | 23 | 24 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyCodeSnippetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.innowhere.relproxy.jproxy; 8 | 9 | import org.junit.After; 10 | import org.junit.AfterClass; 11 | import org.junit.Before; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * 18 | * @author jmarranz 19 | */ 20 | public class JProxyCodeSnippetTest 21 | { 22 | public static boolean RESULT; 23 | 24 | public JProxyCodeSnippetTest() 25 | { 26 | } 27 | 28 | @BeforeClass 29 | public static void setUpClass() 30 | { 31 | } 32 | 33 | @AfterClass 34 | public static void tearDownClass() 35 | { 36 | } 37 | 38 | @Before 39 | public void setUp() 40 | { 41 | RESULT = false; 42 | } 43 | 44 | @After 45 | public void tearDown() 46 | { 47 | RESULT = false; 48 | } 49 | 50 | @Test 51 | public void test_code_snippet() 52 | { 53 | String compilationOptions = "-source 1.6 -target 1.6"; 54 | 55 | String[] args = new String[] 56 | { 57 | "-c", 58 | "System.out.print(\"This code snippet says: \");", 59 | "System.out.println(\"Hello World!!\");", 60 | JProxyCodeSnippetTest.class.getName() + ".RESULT = true;", 61 | "-DcompilationOptions=" + compilationOptions 62 | }; 63 | 64 | JProxyShell.main(args); 65 | 66 | assertTrue(RESULT); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandSave.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 4 | import java.io.File; 5 | import java.util.List; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class CommandSave extends Command 12 | { 13 | public static final String NAME = "save"; 14 | protected String path; 15 | 16 | public CommandSave(JProxyShellProcessor parent,String url) 17 | { 18 | super(parent,NAME); 19 | this.path = url; 20 | } 21 | 22 | public static CommandSave createCommandSave(JProxyShellProcessor parent,String cmd) 23 | { 24 | String url = getParameter(NAME,cmd); 25 | if (url == null) 26 | { 27 | System.out.println("Command error: parameter is required"); 28 | return null; 29 | } 30 | 31 | return new CommandSave(parent,url); 32 | } 33 | 34 | @Override 35 | public boolean run() 36 | { 37 | try 38 | { 39 | List codeBuffer = parent.getCodeBuffer(); 40 | StringBuilder code = new StringBuilder(); 41 | for(String line : codeBuffer) 42 | { 43 | code.append(line); 44 | code.append("\n"); 45 | } 46 | byte[] content = code.toString().getBytes(parent.getEncoding()); // Como no conocemos encoding... 47 | JProxyUtil.saveFile(new File(path),content); 48 | return true; 49 | } 50 | catch (Exception ex) 51 | { 52 | ex.printStackTrace(); 53 | return false; 54 | } 55 | } 56 | 57 | @Override 58 | public void runPostCommand() 59 | { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/javaex/JProxyExampleServlet.java: -------------------------------------------------------------------------------- 1 | 2 | package example.javaex; 3 | 4 | import com.innowhere.relproxy.jproxy.JProxy; 5 | import javax.servlet.ServletConfig; 6 | import javax.servlet.ServletContext; 7 | import javax.servlet.ServletException; 8 | import org.itsnat.core.event.ItsNatServletRequestListener; 9 | import org.itsnat.core.http.HttpServletWrapper; 10 | import org.itsnat.core.tmpl.ItsNatDocumentTemplate; 11 | 12 | 13 | /** 14 | * 15 | * @author jmarranz 16 | */ 17 | public class JProxyExampleServlet extends HttpServletWrapper 18 | { 19 | public JProxyExampleServlet() 20 | { 21 | } 22 | 23 | @Override 24 | public void init(ServletConfig config) throws ServletException 25 | { 26 | super.init(config); 27 | 28 | ServletContext context = config.getServletContext(); 29 | 30 | String pathPrefix = context.getRealPath("/") + "/WEB-INF/javaex/pages/"; 31 | 32 | final FalseDB db = new FalseDB(); 33 | 34 | ItsNatDocumentTemplate docTemplate; 35 | docTemplate = itsNatServlet.registerItsNatDocumentTemplate("javaex","text/html", pathPrefix + "javaex.html"); 36 | ItsNatServletRequestListener listener = JProxy.create(new example.javaex.JProxyExampleLoadListener(db), ItsNatServletRequestListener.class); 37 | docTemplate.addItsNatServletRequestListener(listener); 38 | 39 | ItsNatServletRequestListener original = new example.javaex.JProxyExampleLoadListener(db); 40 | ItsNatServletRequestListener proxy = JProxy.create(original, ItsNatServletRequestListener.class); 41 | ItsNatServletRequestListener proxy2 = JProxy.create(original, ItsNatServletRequestListener.class); 42 | System.out.println("EQUALS TEST (true if not reloaded): " + (proxy.equals(proxy2))); 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectOutputClass.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | import java.net.URI; 8 | import javax.tools.SimpleJavaFileObject; 9 | 10 | /** 11 | * http://www.javablogging.com/dynamic-in-memory-compilation/ 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JavaFileObjectOutputClass extends SimpleJavaFileObject { 16 | 17 | /** 18 | * Byte code created by the compiler will be stored in this 19 | * ByteArrayOutputStream so that we can later get the 20 | * byte array out of it 21 | * and put it in the memory as an instance of our class. 22 | */ 23 | protected final ByteArrayOutputStream bos = new ByteArrayOutputStream(); 24 | protected String binaryName; 25 | 26 | /** 27 | * Registers the compiled class object under URI 28 | * containing the class full name 29 | * 30 | * @param name 31 | * Full name of the compiled class 32 | * @param kind 33 | * Kind of the data. It will be CLASS in our case 34 | */ 35 | public JavaFileObjectOutputClass(String name, Kind kind) 36 | { 37 | super(URI.create("string:///" + name.replace('.', '/') + kind.extension), kind); 38 | 39 | if (!Kind.CLASS.equals(kind)) throw new RelProxyException("Unexpected"); 40 | this.binaryName = name; 41 | } 42 | 43 | public String binaryName() 44 | { 45 | return binaryName; 46 | } 47 | 48 | public byte[] getBytes() 49 | { 50 | return bos.toByteArray(); 51 | } 52 | 53 | @Override 54 | public OutputStream openOutputStream() throws IOException 55 | { 56 | return bos; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyJavaShellTest.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import com.innowhere.relproxy.jproxy.util.JProxyTestUtil; 4 | import java.io.File; 5 | import org.junit.After; 6 | import org.junit.AfterClass; 7 | import org.junit.Before; 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | /** 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JProxyJavaShellTest 16 | { 17 | 18 | 19 | 20 | public JProxyJavaShellTest() 21 | { 22 | } 23 | 24 | @BeforeClass 25 | public static void setUpClass() 26 | { 27 | } 28 | 29 | @AfterClass 30 | public static void tearDownClass() 31 | { 32 | } 33 | 34 | @Before 35 | public void setUp() 36 | { 37 | 38 | } 39 | 40 | @After 41 | public void tearDown() 42 | { 43 | 44 | } 45 | 46 | 47 | @Test 48 | public void test_java_shell() 49 | { 50 | File projectFolder = JProxyTestUtil.getProjectFolder(); 51 | File inputFolderFile = new File(projectFolder,JProxyTestUtil.RESOURCES_FOLDER); 52 | File cacheClassFolderFile = new File(projectFolder,JProxyTestUtil.CACHE_CLASS_FOLDER); 53 | 54 | String inputPath = inputFolderFile.getAbsolutePath(); 55 | String cacheClassFolder = cacheClassFolderFile.getAbsolutePath(); 56 | String compilationOptions = "-source 1.6 -target 1.6"; 57 | 58 | 59 | String[] args = new String[] 60 | { 61 | inputPath + "/example_java_shell", 62 | "HELLO ", 63 | "WORLD!", 64 | "-DcacheClassFolder=" + cacheClassFolder, 65 | "-DcompilationOptions=" + compilationOptions 66 | }; 67 | 68 | JProxyShell.main(args); 69 | } 70 | 71 | 72 | } 73 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyJavaShellNormalClassTest.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import com.innowhere.relproxy.jproxy.util.JProxyTestUtil; 4 | import java.io.File; 5 | import org.junit.After; 6 | import org.junit.AfterClass; 7 | import org.junit.Before; 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | /** 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JProxyJavaShellNormalClassTest 16 | { 17 | public JProxyJavaShellNormalClassTest() 18 | { 19 | } 20 | 21 | @BeforeClass 22 | public static void setUpClass() 23 | { 24 | } 25 | 26 | @AfterClass 27 | public static void tearDownClass() 28 | { 29 | } 30 | 31 | @Before 32 | public void setUp() 33 | { 34 | 35 | } 36 | 37 | @After 38 | public void tearDown() 39 | { 40 | 41 | } 42 | 43 | 44 | @Test 45 | public void test_java_shell() 46 | { 47 | File projectFolder = JProxyTestUtil.getProjectFolder(); 48 | File inputFolderFile = new File(projectFolder,JProxyTestUtil.RESOURCES_FOLDER); 49 | File cacheClassFolderFile = new File(projectFolder,JProxyTestUtil.CACHE_CLASS_FOLDER); 50 | 51 | String inputPath = inputFolderFile.getAbsolutePath(); 52 | String cacheClassFolder = cacheClassFolderFile.getAbsolutePath(); 53 | String compilationOptions = "-source 1.6 -target 1.6"; 54 | 55 | String[] args = new String[] 56 | { 57 | inputPath + "/example_normal_class.java", 58 | "HELLO ", 59 | "WORLD!", 60 | "-DcacheClassFolder=" + cacheClassFolder, 61 | "-DcompilationOptions=" + compilationOptions 62 | }; 63 | 64 | JProxyShell.main(args); 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/gproxy/GProxyConfig.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.gproxy; 3 | 4 | import com.innowhere.relproxy.RelProxyOnReloadListener; 5 | 6 | /** 7 | * Interface implemented by the configuration object needed to initialize GProxy. 8 | * 9 | * 10 | * @see GProxy#init(GProxyConfig) 11 | * @author Jose Maria Arranz Santamaria 12 | */ 13 | public interface GProxyConfig 14 | { 15 | /** 16 | * Sets whether automatic detection of source code changes is enabled. 17 | * 18 | *

If set to false other configuration parameters are ignored, there is no automatic source code change detection/reload and original objects are returned 19 | * instead of proxies, performance penalty is zero. Setting to false is recommended in production whether source code change detection/reload is not required.

20 | * 21 | * @param enabled whether automatic source code change detection and reload is enabled. By default is true. 22 | * @return this object for flow API use. 23 | */ 24 | public GProxyConfig setEnabled(boolean enabled); 25 | 26 | /** 27 | * Sets the class reload listener. 28 | * 29 | * @param relListener the class reload listener. By default is null. 30 | * @return this object for flow API use. 31 | */ 32 | public GProxyConfig setRelProxyOnReloadListener(RelProxyOnReloadListener relListener); 33 | 34 | /** 35 | * Sets the object implementing the GroovyScriptEngine wrapper used to reload Groovy classes. 36 | * 37 | *

This parameter is required otherwise there is no bridge between RelProxy and Groovy because there is no explicit Groovy dependency in RelProxy. 38 | * 39 | * @param engine the GroovyScriptEngine wrapper. 40 | * @return this object for flow API use. 41 | */ 42 | public GProxyConfig setGProxyGroovyScriptEngine(GProxyGroovyScriptEngine engine); 43 | } 44 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/LinuxUnicodeKeyboard.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import static java.awt.event.KeyEvent.VK_CONTROL; 4 | import static java.awt.event.KeyEvent.VK_SHIFT; 5 | import static java.awt.event.KeyEvent.VK_U; 6 | import java.nio.charset.Charset; 7 | 8 | /** 9 | * 10 | * http://superuser.com/questions/59418/how-to-type-special-characters-in-linux 11 | * 12 | * @author jmarranz 13 | */ 14 | public class LinuxUnicodeKeyboard extends KeyboardNotUsingClipboard 15 | { 16 | public LinuxUnicodeKeyboard(Charset cs) 17 | { 18 | super(cs); 19 | } 20 | 21 | @Override 22 | public boolean isUseCodePoint() 23 | { 24 | return true; 25 | } 26 | 27 | @Override 28 | public boolean type(char character) 29 | { 30 | if (super.type(character)) 31 | return true; 32 | 33 | String unicodeDigits = getUnicodeDigits(character,16); // En hexadecimal 34 | 35 | robot.keyPress(VK_CONTROL); 36 | robot.keyPress(VK_SHIFT); 37 | 38 | doType(VK_U); // 'u' indica que después viene un valor unicode hexadecimal 39 | 40 | // Pero dejamos pulsadas CTRL y SHIFT mientras 41 | // Ejemplo: 266A es una nota de solfeo 42 | try 43 | { 44 | for (int i = 0; i < unicodeDigits.length(); i++) 45 | { 46 | char c = unicodeDigits.charAt(i); 47 | if (Character.isDigit(c)) 48 | typeNumPad(Integer.parseInt(unicodeDigits.substring(i, i + 1))); 49 | else 50 | type(c); 51 | } 52 | } 53 | finally 54 | { 55 | robot.keyRelease(VK_CONTROL); 56 | robot.keyRelease(VK_SHIFT); 57 | } 58 | 59 | return true; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/srcunit/SourceScriptRootInMemory.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public class SourceScriptRootInMemory extends SourceScriptRoot 8 | { 9 | public static final String DEFAULT_CLASS_NAME = "_jproxyMainClass_"; // OJO NO CAMBIAR, está ya documentada 10 | 11 | protected String code; 12 | protected long timestamp; 13 | 14 | private SourceScriptRootInMemory(String className,String code) 15 | { 16 | super(className); 17 | setScriptCode(code,System.currentTimeMillis()); 18 | } 19 | 20 | public static SourceScriptRootInMemory createSourceScriptInMemory(String code) 21 | { 22 | return new SourceScriptRootInMemory(DEFAULT_CLASS_NAME,code); 23 | } 24 | 25 | @Override 26 | public long lastModified() 27 | { 28 | return timestamp; // Siempre ha sido modificado 29 | } 30 | 31 | @Override 32 | public String getScriptCode(String encoding,boolean[] hasHashBang) 33 | { 34 | hasHashBang[0] = false; 35 | return code; 36 | } 37 | 38 | public boolean isEmptyCode() 39 | { 40 | // Si code es "" la clase especial se genera pero no hace nada simplemente devuelve un null. 41 | // Este es el caso en el que utilizamos RelProxy embebido en un framework utilizando la API ScriptEngine pero únicamente porque se usa una API basada 42 | // en interfaces, pero tiene el inconveniente de generarse un SourceScriptRootInMemory inútil que no hace nada 43 | return code.isEmpty(); 44 | } 45 | 46 | public String getScriptCode() 47 | { 48 | return code; 49 | } 50 | 51 | public final void setScriptCode(String code,long timestamp) 52 | { 53 | this.code = code; 54 | this.timestamp = timestamp; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyJavaShellCompleteClassTest.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import com.innowhere.relproxy.jproxy.util.JProxyTestUtil; 4 | import java.io.File; 5 | import org.junit.After; 6 | import org.junit.AfterClass; 7 | import org.junit.Before; 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | 11 | /** 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JProxyJavaShellCompleteClassTest 16 | { 17 | 18 | 19 | 20 | public JProxyJavaShellCompleteClassTest() 21 | { 22 | } 23 | 24 | @BeforeClass 25 | public static void setUpClass() 26 | { 27 | } 28 | 29 | @AfterClass 30 | public static void tearDownClass() 31 | { 32 | } 33 | 34 | @Before 35 | public void setUp() 36 | { 37 | 38 | } 39 | 40 | @After 41 | public void tearDown() 42 | { 43 | 44 | } 45 | 46 | 47 | @Test 48 | public void test_java_shell() 49 | { 50 | File projectFolder = JProxyTestUtil.getProjectFolder(); 51 | File inputFolderFile = new File(projectFolder,JProxyTestUtil.RESOURCES_FOLDER); 52 | File cacheClassFolderFile = new File(projectFolder,JProxyTestUtil.CACHE_CLASS_FOLDER); 53 | 54 | String inputPath = inputFolderFile.getAbsolutePath(); 55 | String cacheClassFolder = cacheClassFolderFile.getAbsolutePath(); 56 | String compilationOptions = "-source 1.6 -target 1.6"; 57 | 58 | String[] args = new String[] 59 | { 60 | inputPath + "/example_java_shell_complete_class", 61 | "HELLO ", 62 | "WORLD!", 63 | "-DcacheClassFolder=" + cacheClassFolder, 64 | "-DcompilationOptions=" + compilationOptions, 65 | }; 66 | 67 | JProxyShell.main(args); 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/GenericProxyImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.RelProxyOnReloadListener; 5 | import java.lang.reflect.InvocationHandler; 6 | import java.lang.reflect.Proxy; 7 | 8 | /** 9 | * 10 | * @author jmarranz 11 | */ 12 | public abstract class GenericProxyImpl 13 | { 14 | protected RelProxyOnReloadListener reloadListener; 15 | 16 | public GenericProxyImpl() 17 | { 18 | } 19 | 20 | public static void checkSingletonNull(GenericProxyImpl singleton) 21 | { 22 | if (singleton != null) 23 | throw new RelProxyException("Already initialized"); 24 | } 25 | 26 | protected static void checkSingletonExists(GenericProxyImpl singleton) 27 | { 28 | if (singleton == null) 29 | throw new RelProxyException("Execute first the init method"); 30 | } 31 | 32 | protected void init(GenericProxyConfigBaseImpl config) 33 | { 34 | this.reloadListener = config.getRelProxyOnReloadListener(); 35 | } 36 | 37 | public RelProxyOnReloadListener getRelProxyOnReloadListener() 38 | { 39 | return reloadListener; 40 | } 41 | 42 | public T create(T obj,Class clasz) 43 | { 44 | if (obj == null) return null; 45 | 46 | return (T)create(obj,new Class[] { clasz }); 47 | } 48 | 49 | public Object create(Object obj,Class[] classes) 50 | { 51 | if (obj == null) return null; 52 | 53 | InvocationHandler handler = createGenericProxyInvocationHandler(obj); 54 | 55 | Object proxy = Proxy.newProxyInstance(obj.getClass().getClassLoader(),classes, handler); 56 | return proxy; 57 | } 58 | 59 | 60 | public abstract GenericProxyInvocationHandler createGenericProxyInvocationHandler(Object obj); 61 | } 62 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/groovyex/code/example/groovyex/groovy_servlet_init.groovy: -------------------------------------------------------------------------------- 1 | 2 | package example.groovyex; 3 | 4 | import org.itsnat.core.http.ItsNatHttpServlet; 5 | import org.itsnat.core.tmpl.ItsNatDocumentTemplate; 6 | import org.itsnat.core.event.ItsNatServletRequestListener; 7 | import groovy.util.GroovyScriptEngine; 8 | import java.lang.reflect.Method; 9 | import com.innowhere.relproxy.RelProxyOnReloadListener; 10 | import com.innowhere.relproxy.gproxy.GProxy; 11 | import com.innowhere.relproxy.gproxy.GProxyGroovyScriptEngine; 12 | import com.innowhere.relproxy.gproxy.GProxyConfig; 13 | 14 | 15 | GroovyScriptEngine groovyEngine = servlet.getGroovyScriptEngine(); 16 | 17 | def gproxyGroovyEngine = { 18 | String scriptName -> return (java.lang.Class)groovyEngine.loadScriptByName(scriptName) 19 | } as GProxyGroovyScriptEngine; 20 | 21 | /* This alternative throws a weird error when called loadScriptByName, why? 22 | GProxyGroovyScriptEngine groovyEngine = 23 | { 24 | loadScriptByName : { String scriptName -> return (java.lang.Class)servlet.getGroovyScriptEngine().loadScriptByName(scriptName) } 25 | } as GProxyGroovyScriptEngine; 26 | */ 27 | 28 | def reloadListener = { 29 | Object objOld,Object objNew,Object proxy, Method method, Object[] args -> 30 | println("Reloaded " + objNew + " Calling method: " + method) 31 | } as RelProxyOnReloadListener; 32 | 33 | def gpConfig = GProxy.createGProxyConfig(); 34 | gpConfig.setEnabled(true) 35 | .setRelProxyOnReloadListener(reloadListener) 36 | .setGProxyGroovyScriptEngine(gproxyGroovyEngine); 37 | 38 | GProxy.init(gpConfig); 39 | 40 | 41 | String pathPrefix = context.getRealPath("/") + "/WEB-INF/groovyex/pages/"; 42 | 43 | def docTemplate; 44 | docTemplate = itsNatServlet.registerItsNatDocumentTemplate("groovyex","text/html", pathPrefix + "groovyex.html"); 45 | 46 | def db = new FalseDB(); 47 | 48 | ItsNatServletRequestListener listener = GProxy.create(new example.groovyex.GroovyExampleLoadListener(db), ItsNatServletRequestListener.class); 49 | docTemplate.addItsNatServletRequestListener(listener); 50 | 51 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputSourceBase.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | import java.io.UnsupportedEncodingException; 9 | import java.net.URI; 10 | import javax.tools.SimpleJavaFileObject; 11 | 12 | /** 13 | * http://www.javablogging.com/dynamic-in-memory-compilation/ 14 | * 15 | * @author jmarranz 16 | */ 17 | public abstract class JavaFileObjectInputSourceBase extends SimpleJavaFileObject implements JProxyJavaFileObjectInput 18 | { 19 | protected String binaryName; 20 | protected String encoding; 21 | 22 | public JavaFileObjectInputSourceBase(String name,String encoding) 23 | { 24 | super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension), Kind.SOURCE); // La extensión .java es necesaria aunque sea falsa sino da error 25 | 26 | this.binaryName = name; 27 | this.encoding = encoding; 28 | } 29 | 30 | protected abstract String getSource(); 31 | 32 | 33 | @Override 34 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException 35 | { 36 | return getSource(); 37 | } 38 | 39 | public byte[] getBytes() 40 | { 41 | try 42 | { 43 | return getSource().getBytes(encoding); 44 | } 45 | catch (UnsupportedEncodingException ex) { throw new RelProxyException(ex); } 46 | } 47 | 48 | @Override 49 | public InputStream openInputStream() throws IOException 50 | { 51 | return new ByteArrayInputStream(getBytes()); 52 | } 53 | 54 | @Override 55 | public OutputStream openOutputStream() throws IOException 56 | { 57 | throw new UnsupportedOperationException(); 58 | } 59 | 60 | public String getBinaryName() 61 | { 62 | return binaryName; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/KeyboardUsingClipboard.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | 4 | import com.innowhere.relproxy.RelProxyException; 5 | import java.awt.AWTException; 6 | import java.awt.Robot; 7 | import java.awt.Toolkit; 8 | import java.awt.datatransfer.Clipboard; 9 | import java.awt.datatransfer.ClipboardOwner; 10 | import java.awt.datatransfer.StringSelection; 11 | import java.awt.datatransfer.Transferable; 12 | import java.awt.event.KeyEvent; 13 | import java.nio.charset.Charset; 14 | 15 | /** 16 | * http://stackoverflow.com/questions/1248510/convert-string-to-keyevents 17 | * http://en.wikipedia.org/wiki/Unicode_input#Hexadecimal_code_input 18 | * http://stackoverflow.com/questions/9814701/accent-with-robot-keypress 19 | * 20 | * @author jmarranz 21 | */ 22 | public class KeyboardUsingClipboard extends Keyboard implements ClipboardOwner 23 | { 24 | protected final Robot robot; 25 | protected Charset cs; 26 | 27 | 28 | public KeyboardUsingClipboard(Charset cs) 29 | { 30 | this.cs = cs; 31 | try 32 | { 33 | this.robot = new Robot(); 34 | } 35 | catch (AWTException ex) 36 | { 37 | throw new RelProxyException(ex); 38 | } 39 | } 40 | 41 | public static KeyboardUsingClipboard create(Charset cs) 42 | { 43 | return new KeyboardUsingClipboard(cs); 44 | } 45 | 46 | 47 | @Override 48 | public void type(CharSequence characters) 49 | { 50 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 51 | StringSelection stringSelection = new StringSelection( characters.toString() ); 52 | clipboard.setContents(stringSelection, this); 53 | 54 | robot.keyPress(KeyEvent.VK_CONTROL); 55 | robot.keyPress(KeyEvent.VK_V); 56 | robot.keyRelease(KeyEvent.VK_V); 57 | robot.keyRelease(KeyEvent.VK_CONTROL); 58 | } 59 | 60 | @Override 61 | public void lostOwnership(Clipboard clipboard, Transferable contents) 62 | { 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /relproxy/src/test/java/com/innowhere/relproxy/jproxy/JProxyCodeSnippetCompleteClassTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package com.innowhere.relproxy.jproxy; 8 | 9 | import org.junit.After; 10 | import org.junit.AfterClass; 11 | import org.junit.Before; 12 | import org.junit.BeforeClass; 13 | import org.junit.Test; 14 | import static org.junit.Assert.*; 15 | 16 | /** 17 | * 18 | * @author jmarranz 19 | */ 20 | public class JProxyCodeSnippetCompleteClassTest 21 | { 22 | public static boolean RESULT; 23 | 24 | public JProxyCodeSnippetCompleteClassTest() 25 | { 26 | } 27 | 28 | @BeforeClass 29 | public static void setUpClass() 30 | { 31 | } 32 | 33 | @AfterClass 34 | public static void tearDownClass() 35 | { 36 | } 37 | 38 | @Before 39 | public void setUp() 40 | { 41 | RESULT = false; 42 | } 43 | 44 | @After 45 | public void tearDown() 46 | { 47 | RESULT = false; 48 | } 49 | 50 | @Test 51 | public void test_code_snippet_complete_class() 52 | { 53 | String compilationOptions = "-source 1.6 -target 1.6"; 54 | 55 | String[] args = new String[] 56 | { 57 | "-c", 58 | "public class _jproxyMainClass_ { ", 59 | " public static void main(String[] args) { ", 60 | " System.out.print(\"This code snippet says: \");", 61 | " System.out.println(\"Hello World!!\");", 62 | JProxyCodeSnippetCompleteClassTest.class.getName() + ".RESULT = true;", 63 | " }", 64 | "}", 65 | "-DcompilationOptions=" + compilationOptions 66 | }; 67 | 68 | JProxyShell.main(args); 69 | 70 | assertTrue(RESULT); 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandDelete.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | 4 | /** 5 | * 6 | * @author jmarranz 7 | */ 8 | public class CommandDelete extends CommandCodeChangerBase 9 | { 10 | public static final String NAME = "delete"; 11 | 12 | public CommandDelete(JProxyShellProcessor parent,int line) 13 | { 14 | super(parent,NAME,line); 15 | } 16 | 17 | public static CommandDelete createCommandDelete(JProxyShellProcessor parent,String cmd) 18 | { 19 | int line = getLineFromParam(parent,NAME,cmd); 20 | if (line < 0) 21 | { 22 | switch(line) 23 | { 24 | case ERROR_LAST_REQUIRED: 25 | System.out.println("Command error: parameter \"last\" or a line number is required"); 26 | break; 27 | case ERROR_NO_LAST_LINE: 28 | System.out.println("Command error: no new or edited line code has been introduced"); 29 | break; 30 | case ERROR_NOT_A_NUMBER: 31 | System.out.println("Command error: line value is not a number"); 32 | break; 33 | case ERROR_VALUE_NOT_0_OR_NEGATIVE: 34 | System.out.println("Command error: line value cannot be 0 or negative"); 35 | break; 36 | case ERROR_LINE_1_NOT_VALID: 37 | System.out.println("Command error: line 1 is ever empty and cannot be deleted"); 38 | break; 39 | case ERROR_OUT_OF_RANGE: 40 | System.out.println("Command error: line number out of range"); 41 | break; 42 | default: 43 | // Para que se calle el FindBugs 44 | } 45 | return null; 46 | } 47 | 48 | return new CommandDelete(parent,line); 49 | } 50 | 51 | @Override 52 | public void runPostCommand() 53 | { 54 | parent.removeCodeBuffer(line); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandInsert.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | 4 | /** 5 | * 6 | * @author jmarranz 7 | */ 8 | public class CommandInsert extends CommandCodeChangerBase 9 | { 10 | public static final String NAME = "insert"; 11 | 12 | public CommandInsert(JProxyShellProcessor parent,int line) 13 | { 14 | super(parent,NAME,line); 15 | } 16 | 17 | public static CommandInsert createCommandInsert(JProxyShellProcessor parent,String cmd) 18 | { 19 | int line = getLineFromParam(parent,NAME,cmd); 20 | if (line < 0) 21 | { 22 | switch(line) 23 | { 24 | case ERROR_LAST_REQUIRED: 25 | System.out.println("Command error: parameter \"last\" or a line number is required"); 26 | break; 27 | case ERROR_NO_LAST_LINE: 28 | System.out.println("Command error: no new or edited line code has been introduced"); 29 | break; 30 | case ERROR_NOT_A_NUMBER: 31 | System.out.println("Command error: line value is not a number"); 32 | break; 33 | case ERROR_VALUE_NOT_0_OR_NEGATIVE: 34 | System.out.println("Command error: line value cannot be 0 or negative"); 35 | break; 36 | case ERROR_LINE_1_NOT_VALID: 37 | System.out.println("Command error: line 1 is ever empty and no code can be inserted before"); 38 | break; 39 | case ERROR_OUT_OF_RANGE: 40 | System.out.println("Command error: line number out of range"); 41 | break; 42 | default: 43 | // Para que se calle el FindBugs 44 | } 45 | return null; 46 | } 47 | 48 | return new CommandInsert(parent,line); 49 | } 50 | 51 | @Override 52 | public void runPostCommand() 53 | { 54 | parent.insertCodeBuffer(line,""); 55 | parent.setLineEditing(line); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandEdit.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | 4 | /** 5 | * 6 | * @author jmarranz 7 | */ 8 | public class CommandEdit extends CommandCodeChangerBase 9 | { 10 | public static final String NAME = "edit"; 11 | protected String codeLine; 12 | 13 | public CommandEdit(JProxyShellProcessor parent,int line,String codeLine) 14 | { 15 | super(parent,NAME,line); 16 | this.codeLine = codeLine; 17 | } 18 | 19 | public static CommandEdit createCommandEdit(JProxyShellProcessor parent,String cmd) 20 | { 21 | int line = getLineFromParam(parent,NAME,cmd); 22 | if (line < 0) 23 | { 24 | switch(line) 25 | { 26 | case ERROR_LAST_REQUIRED: 27 | System.out.println("Command error: parameter \"last\" or a line number is required"); 28 | break; 29 | case ERROR_NO_LAST_LINE: 30 | System.out.println("Command error: no new or edited line code has been introduced"); 31 | break; 32 | case ERROR_NOT_A_NUMBER: 33 | System.out.println("Command error: line value is not a number"); 34 | break; 35 | case ERROR_VALUE_NOT_0_OR_NEGATIVE: 36 | System.out.println("Command error: line value cannot be 0 or negative"); 37 | break; 38 | case ERROR_LINE_1_NOT_VALID: 39 | System.out.println("Command error: line 1 is ever empty and cannot be edited"); 40 | break; 41 | case ERROR_OUT_OF_RANGE: 42 | System.out.println("Command error: line number out of range"); 43 | break; 44 | default: 45 | // Para que se calle el FindBugs 46 | } 47 | return null; 48 | } 49 | 50 | String codeLine = parent.getCodeBuffer().get(line); 51 | return new CommandEdit(parent,line,codeLine); 52 | } 53 | 54 | @Override 55 | public void runPostCommand() 56 | { 57 | parent.getKeyboard().type(codeLine); 58 | parent.setLineEditing(line); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/JProxyDefaultImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.core.JProxyImpl; 4 | import com.innowhere.relproxy.jproxy.JProxyConfig; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public class JProxyDefaultImpl extends JProxyImpl 11 | { 12 | public JProxyDefaultImpl() 13 | { 14 | } 15 | 16 | @Override 17 | public Class getMainParamClass() 18 | { 19 | return null; 20 | } 21 | 22 | public static JProxyConfig createJProxyConfig() 23 | { 24 | return new JProxyConfigImpl(); 25 | } 26 | 27 | public static void initStatic(JProxyConfigImpl config) 28 | { 29 | if (!config.isEnabled()) return; 30 | 31 | checkSingletonNull(SINGLETON); 32 | SINGLETON = new JProxyDefaultImpl(); 33 | SINGLETON.init(config); 34 | } 35 | 36 | 37 | public static T createStatic(T obj,Class clasz) 38 | { 39 | if (SINGLETON == null) 40 | return obj; // No se ha llamado al init o enabled = false 41 | 42 | return SINGLETON.create(obj, clasz); 43 | } 44 | 45 | public static Object createStatic(Object obj,Class[] classes) 46 | { 47 | if (SINGLETON == null) 48 | return obj; // No se ha llamado al init o enabled = false 49 | 50 | return SINGLETON.create(obj, classes); 51 | } 52 | 53 | 54 | public static boolean isEnabledStatic() 55 | { 56 | if (SINGLETON == null) 57 | return false; 58 | 59 | return SINGLETON.isEnabled(); 60 | } 61 | 62 | 63 | public static boolean isRunningStatic() 64 | { 65 | if (SINGLETON == null) 66 | return false; 67 | 68 | return SINGLETON.isRunning(); 69 | } 70 | 71 | public static boolean stopStatic() 72 | { 73 | if (SINGLETON == null) 74 | return false; 75 | 76 | return SINGLETON.stop(); 77 | } 78 | 79 | public static boolean startStatic() 80 | { 81 | if (SINGLETON == null) 82 | return false; 83 | 84 | return SINGLETON.start(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandCodeChangerBase.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | 4 | /** 5 | * 6 | * @author jmarranz 7 | */ 8 | public abstract class CommandCodeChangerBase extends Command 9 | { 10 | public static final int ERROR_LAST_REQUIRED = -1; 11 | public static final int ERROR_NO_LAST_LINE = -2; 12 | public static final int ERROR_NOT_A_NUMBER = -3; 13 | public static final int ERROR_VALUE_NOT_0_OR_NEGATIVE = -4; 14 | public static final int ERROR_LINE_1_NOT_VALID = -5; 15 | public static final int ERROR_OUT_OF_RANGE = -6; 16 | 17 | 18 | protected int line; 19 | 20 | public CommandCodeChangerBase(JProxyShellProcessor parent,String name,int line) 21 | { 22 | super(parent,name); 23 | this.line = line; 24 | } 25 | 26 | public static int getLineFromParam(JProxyShellProcessor parent,String name,String cmd) 27 | { 28 | String param = getParameter(name,cmd); 29 | if (param == null) 30 | { 31 | return ERROR_LAST_REQUIRED; 32 | } 33 | 34 | int line; 35 | if (param.equals("last")) 36 | { 37 | int lastLine = parent.getLastLine(); 38 | if (lastLine == -1) 39 | { 40 | return ERROR_NO_LAST_LINE; 41 | } 42 | line = lastLine; 43 | } 44 | else 45 | { 46 | try 47 | { 48 | line = Integer.parseInt(param); 49 | } 50 | catch(NumberFormatException ex) 51 | { 52 | return ERROR_NOT_A_NUMBER; 53 | } 54 | // Ojo es el valor dado por el usuario (empezando en 1 y con línea vacía) 55 | if (line <= 0) 56 | { 57 | return ERROR_VALUE_NOT_0_OR_NEGATIVE; 58 | } 59 | else if (line == 1) 60 | { 61 | return ERROR_LINE_1_NOT_VALID; 62 | } 63 | line -= JProxyShellProcessor.LINE_OFFSET; 64 | 65 | if (line >= parent.getCodeBuffer().size()) 66 | { 67 | return ERROR_OUT_OF_RANGE; 68 | } 69 | } 70 | return line; 71 | } 72 | 73 | 74 | @Override 75 | public boolean run() 76 | { 77 | return true; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandLoad.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 4 | import java.io.File; 5 | import java.net.URI; 6 | import java.net.URL; 7 | import java.util.LinkedList; 8 | import java.util.Scanner; 9 | 10 | /** 11 | * 12 | * @author jmarranz 13 | */ 14 | public class CommandLoad extends Command 15 | { 16 | public static final String NAME = "load"; 17 | protected String url; 18 | 19 | public CommandLoad(JProxyShellProcessor parent,String url) 20 | { 21 | super(parent,NAME); 22 | this.url = url; 23 | } 24 | 25 | public static CommandLoad createCommandLoad(JProxyShellProcessor parent,String cmd) 26 | { 27 | String url = getParameter(NAME,cmd); 28 | if (url == null) 29 | { 30 | System.out.println("Command error: parameter is required"); 31 | return null; 32 | } 33 | 34 | return new CommandLoad(parent,url); 35 | } 36 | 37 | @Override 38 | public boolean run() 39 | { 40 | try 41 | { 42 | byte[] content; 43 | URI uri = new URI(url); 44 | if (uri.getScheme() == null) // Archivo 45 | { 46 | File file = new File(url); 47 | content = JProxyUtil.readFile(file); 48 | } 49 | else // URL (incluyendo file:///...) 50 | { 51 | URL urlObj = new URL(url); 52 | content = JProxyUtil.readURL(urlObj); // Como no conocemos encoding... 53 | } 54 | 55 | String code = new String(content,parent.getEncoding()); // Como no conocemos encoding... 56 | LinkedList lines = new LinkedList(); 57 | Scanner scanner = new Scanner(code); 58 | while (scanner.hasNextLine()) 59 | { 60 | String line = scanner.nextLine(); 61 | lines.add(line); 62 | } 63 | 64 | parent.setCodeBuffer(lines); 65 | return true; 66 | } 67 | catch (Exception ex) 68 | { 69 | ex.printStackTrace(); 70 | return false; 71 | } 72 | } 73 | 74 | @Override 75 | public void runPostCommand() 76 | { 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/JProxyShellCodeSnippetImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceScript; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 7 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 8 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRootInMemory; 9 | import java.util.LinkedList; 10 | 11 | /** 12 | * 13 | * @author jmarranz 14 | */ 15 | public class JProxyShellCodeSnippetImpl extends JProxyShellImpl 16 | { 17 | public void init(String[] args) 18 | { 19 | super.init(args, null); 20 | } 21 | 22 | @Override 23 | protected void executeFirstTime(ClassDescriptorSourceScript scriptFileDesc,LinkedList argsToScript,JProxyShellClassLoader classLoader) 24 | { 25 | try 26 | { 27 | scriptFileDesc.callMainMethod(argsToScript); 28 | } 29 | catch(Throwable ex) 30 | { 31 | ex.printStackTrace(System.out); 32 | } 33 | } 34 | 35 | @Override 36 | protected void processConfigParams(String[] args,LinkedList argsToScript,JProxyConfigImpl config) 37 | { 38 | super.processConfigParams(args, argsToScript, config); 39 | 40 | String classFolder = config.getClassFolder(); 41 | if (classFolder != null && !classFolder.trim().isEmpty()) throw new RelProxyException("cacheClassFolder is useless to execute a code snippet"); 42 | } 43 | 44 | @Override 45 | protected SourceScriptRoot createSourceScriptRoot(String[] args,LinkedList argsToScript,FolderSourceList folderSourceList) 46 | { 47 | // En argsToScript no está el args[0] ni falta que hace porque es el flag "-c" 48 | StringBuilder code = new StringBuilder(); 49 | for(String chunk : argsToScript) 50 | code.append(chunk); 51 | return SourceScriptRootInMemory.createSourceScriptInMemory(code.toString()); 52 | } 53 | 54 | @Override 55 | protected JProxyShellClassLoader getJProxyShellClassLoader(JProxyConfigImpl config) 56 | { 57 | // No hay classFolder => no hay necesidad de nuevo ClassLoader 58 | return null; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/GenericProxyInvocationHandler.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl; 2 | 3 | import com.innowhere.relproxy.RelProxyOnReloadListener; 4 | import java.lang.reflect.InvocationHandler; 5 | import java.lang.reflect.Method; 6 | import java.lang.reflect.Proxy; 7 | 8 | /** 9 | * 10 | * @author jmarranz 11 | */ 12 | public abstract class GenericProxyInvocationHandler implements InvocationHandler 13 | { 14 | protected GenericProxyImpl root; 15 | protected GenericProxyVersionedObject verObj; 16 | 17 | public GenericProxyInvocationHandler(GenericProxyImpl root) 18 | { 19 | this.root = root; 20 | } 21 | 22 | private Object getCurrent() 23 | { 24 | return verObj.getCurrent(); 25 | } 26 | 27 | private Object getNewVersion() throws Throwable 28 | { 29 | return verObj.getNewVersion(); 30 | } 31 | 32 | @Override 33 | public synchronized Object invoke(Object proxy, Method method, Object[] args) throws Throwable 34 | { 35 | Object oldObj = getCurrent(); 36 | Object obj = getNewVersion(); 37 | 38 | RelProxyOnReloadListener reloadListener = root.getRelProxyOnReloadListener(); 39 | if (oldObj != obj && reloadListener != null) 40 | reloadListener.onReload(oldObj,obj,proxy,method,args); 41 | 42 | if (args != null && args.length == 1) 43 | { 44 | // Conseguimos que en proxy1.equals(proxy2) se usen los objetos asociados no los propios proxies, para ello obtenemos el objeto asociado al parámetro 45 | // No hace falta que equals forme parte de la interface, pero está ahí implícitamente 46 | // hashCode() como no tiene params es llamado sin problema de conversiones 47 | Object param = args[0]; 48 | if (param instanceof Proxy && // Si es una clase generada com.sun.proxy.$ProxyN (N=1,2...) es también derivada de Proxy 49 | method.getName().equals("equals") && 50 | method.getReturnType().equals(boolean.class)) 51 | { 52 | Class[] paramTypes = method.getParameterTypes(); 53 | if (paramTypes.length == 1 && paramTypes[0].equals(Object.class)) 54 | { 55 | InvocationHandler paramInvHandler = Proxy.getInvocationHandler(param); 56 | if (paramInvHandler instanceof GenericProxyInvocationHandler) 57 | { 58 | args[0] = ((GenericProxyInvocationHandler)paramInvHandler).getCurrent(); // reemplazamos el Proxy por el objeto asociado 59 | } 60 | } 61 | } 62 | } 63 | 64 | return method.invoke(obj, args); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/jfo/JavaFileObjectInputClassInFileSystem.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.jfo; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.io.Reader; 6 | import java.io.Writer; 7 | import java.net.URI; 8 | import javax.lang.model.element.Modifier; 9 | import javax.lang.model.element.NestingKind; 10 | import javax.tools.JavaFileObject; 11 | 12 | /** 13 | * 14 | * @author jmarranz 15 | */ 16 | public abstract class JavaFileObjectInputClassInFileSystem implements JavaFileObject,JProxyJavaFileObjectInput 17 | { 18 | protected final String binaryName; 19 | protected final URI uri; 20 | protected final String name; 21 | 22 | public JavaFileObjectInputClassInFileSystem(String binaryName, URI uri,String name) 23 | { 24 | this.uri = uri; 25 | this.binaryName = binaryName; 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | public URI toUri() { 31 | return uri; 32 | } 33 | 34 | @Override 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | @Override 40 | public String getBinaryName() { 41 | return binaryName; 42 | } 43 | 44 | @Override 45 | public OutputStream openOutputStream() throws IOException { 46 | throw new UnsupportedOperationException(); 47 | } 48 | 49 | @Override 50 | public Reader openReader(boolean ignoreEncodingErrors) throws IOException { 51 | throw new UnsupportedOperationException(); 52 | } 53 | 54 | @Override 55 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { 56 | throw new UnsupportedOperationException(); 57 | } 58 | 59 | @Override 60 | public Writer openWriter() throws IOException { 61 | throw new UnsupportedOperationException(); 62 | } 63 | 64 | @Override 65 | public boolean delete() { 66 | throw new UnsupportedOperationException(); 67 | } 68 | 69 | @Override 70 | public Kind getKind() { 71 | return Kind.CLASS; 72 | } 73 | 74 | @Override // copied from SimpleJavaFileManager 75 | public boolean isNameCompatible(String simpleName, Kind kind) { 76 | String baseName = simpleName + kind.extension; 77 | return kind.equals(getKind()) 78 | && (baseName.equals(getName()) 79 | || getName().endsWith("/" + baseName)); 80 | } 81 | 82 | @Override 83 | public NestingKind getNestingKind() { 84 | throw new UnsupportedOperationException(); 85 | } 86 | 87 | @Override 88 | public Modifier getAccessLevel() { 89 | throw new UnsupportedOperationException(); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/comp/JProxyCompilerContext.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.jproxy.JProxyDiagnosticsListener; 5 | import java.io.IOException; 6 | import java.util.List; 7 | import javax.tools.Diagnostic; 8 | import javax.tools.DiagnosticCollector; 9 | import javax.tools.JavaFileObject; 10 | import javax.tools.StandardJavaFileManager; 11 | 12 | /** 13 | * 14 | * @author jmarranz 15 | */ 16 | public class JProxyCompilerContext 17 | { 18 | protected StandardJavaFileManager standardFileManager; 19 | protected DiagnosticCollector diagnostics; 20 | protected JProxyDiagnosticsListener diagnosticsListener; 21 | 22 | public JProxyCompilerContext(StandardJavaFileManager standardFileManager,DiagnosticCollector diagnostics,JProxyDiagnosticsListener diagnosticsListener) 23 | { 24 | this.standardFileManager = standardFileManager; 25 | this.diagnostics = diagnostics; 26 | this.diagnosticsListener = diagnosticsListener; 27 | } 28 | 29 | public StandardJavaFileManager getStandardFileManager() 30 | { 31 | return standardFileManager; 32 | } 33 | 34 | public DiagnosticCollector getDiagnosticCollector() 35 | { 36 | return diagnostics; 37 | } 38 | 39 | public void close() 40 | { 41 | try { this.standardFileManager.close(); } 42 | catch (IOException ex) { throw new RelProxyException(ex); } 43 | 44 | List> diagList = diagnostics.getDiagnostics(); 45 | if (!diagList.isEmpty()) 46 | { 47 | if (diagnosticsListener != null) 48 | { 49 | diagnosticsListener.onDiagnostics(diagnostics); 50 | } 51 | else 52 | { 53 | int i = 1; 54 | for (Diagnostic diagnostic : diagList) 55 | { 56 | System.err.println("Diagnostic " + i); 57 | System.err.println(" code: " + diagnostic.getCode()); 58 | System.err.println(" kind: " + diagnostic.getKind()); 59 | System.err.println(" line number: " + diagnostic.getLineNumber()); 60 | System.err.println(" column number: " + diagnostic.getColumnNumber()); 61 | System.err.println(" start position: " + diagnostic.getStartPosition()); 62 | System.err.println(" position: " + diagnostic.getPosition()); 63 | System.err.println(" end position: " + diagnostic.getEndPosition()); 64 | System.err.println(" source: " + diagnostic.getSource()); 65 | System.err.println(" message: " + diagnostic.getMessage(null)); 66 | i++; 67 | } 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxyScriptEngine.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.jproxy; 2 | 3 | import javax.script.ScriptEngine; 4 | 5 | /** 6 | * Interface implemented by RelProxy to provide javax.script.ScriptEngine objects supporting Java as a scripting language. 7 | * 8 | *

The method {@link JProxyScriptEngineFactory#getScriptEngine()} returns an implementation of this interface.

9 | * 10 | * @author Jose Maria Arranz Santamaria 11 | */ 12 | public interface JProxyScriptEngine extends ScriptEngine 13 | { 14 | /** 15 | * Initializes this JProxyScriptEngine instance with the provided configuration object. 16 | * 17 | * @param config the configuration object. 18 | */ 19 | public void init(JProxyConfig config); 20 | 21 | /** 22 | * This method is the same as {@link JProxy#create(java.lang.Object, java.lang.Class)} but applied to this JProxyScriptEngine 23 | * 24 | * @param the interface implemented by the original object and proxy object returned. 25 | * @param obj the original object to proxy. 26 | * @param clasz the class of the interface implemented by the original object and proxy object returned. 27 | * @return the java.lang.reflect.Proxy object associated or the original object when is disabled. 28 | */ 29 | public T create(T obj,Class clasz); 30 | 31 | /** 32 | * This method is the same as {@link JProxy#create(java.lang.Object, java.lang.Class[])} but applied to this JProxyScriptEngine 33 | * 34 | * @param obj the original object to proxy. 35 | * @param classes the classes of the interfaces implemented by the original object and proxy object returned. 36 | * @return the java.lang.reflect.Proxy object associated or the original object when is disabled. 37 | */ 38 | public Object create(Object obj,Class[] classes); 39 | 40 | /** 41 | * This method is the same as {@link JProxy#isEnabled()} but applied to this JProxyScriptEngine 42 | * 43 | * @return true if enabled. 44 | */ 45 | public boolean isEnabled(); 46 | 47 | /** 48 | * This method is the same as {@link JProxy#isRunning()} but applied to this JProxyScriptEngine 49 | * 50 | * @return true if running. 51 | */ 52 | public boolean isRunning(); 53 | 54 | /** 55 | * This method is the same as {@link JProxy#stop()} but applied to this JProxyScriptEngine 56 | * 57 | * @return true if source change detection has been stopped, false if it is already stopped or this JProxyScriptEngine is not enabled or initialized. 58 | * @see #stop() 59 | */ 60 | public boolean stop(); 61 | 62 | /** 63 | * This method is the same as {@link JProxy#start()} but applied to this JProxyScriptEngine 64 | * 65 | * @return true if source change detection has been started again, false if it is already started or cannot start because this JProxyScriptEngine is not enabled or initialized or scan period is not positive. 66 | * @see #start() 67 | */ 68 | public boolean start(); 69 | } 70 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/FolderSourceList.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.FileExt; 5 | import java.io.File; 6 | 7 | /** 8 | * 9 | * @author jmarranz 10 | */ 11 | public class FolderSourceList 12 | { 13 | protected FileExt[] sourceList; 14 | 15 | public FolderSourceList(String[] sourcePathList,boolean expectedDirectory) 16 | { 17 | if (sourcePathList != null) // En el caso de shell interactivo es null 18 | { 19 | // El convertir siempre a File los paths es para normalizar paths 20 | this.sourceList = new FileExt[sourcePathList.length]; 21 | for(int i = 0; i < sourcePathList.length; i++) 22 | { 23 | File folder = new File(sourcePathList[i]); 24 | if (!folder.exists()) 25 | throw new RelProxyException("Source folder does not exist: " + folder.getAbsolutePath()); 26 | boolean isDirectory = folder.isDirectory(); 27 | if (expectedDirectory) 28 | { 29 | if (!isDirectory) 30 | throw new RelProxyException("Source folder is not a directory: " + folder.getAbsolutePath()); 31 | } 32 | else 33 | { 34 | if (isDirectory) 35 | throw new RelProxyException("Expected a file not a directory: " + folder.getAbsolutePath()); 36 | } 37 | sourceList[i] = new FileExt(folder); 38 | } 39 | } 40 | } 41 | 42 | public FileExt[] getArray() 43 | { 44 | return sourceList; 45 | } 46 | 47 | public String buildClassNameFromFile(FileExt sourceFile) 48 | { 49 | for(FileExt rootFolderOfSources : sourceList) 50 | { 51 | String className = buildClassNameFromFile(sourceFile,rootFolderOfSources); 52 | if (className != null) 53 | return className; 54 | } 55 | throw new RelProxyException("File not found in source folders: " + sourceFile.getFile().getAbsolutePath()); 56 | } 57 | 58 | public static String buildClassNameFromFile(FileExt sourceFile,FileExt rootFolderOfSources) 59 | { 60 | String path = sourceFile.getCanonicalPath(); 61 | 62 | String rootFolderOfSourcesAbsPath = rootFolderOfSources.getCanonicalPath(); 63 | int pos = path.indexOf(rootFolderOfSourcesAbsPath); 64 | if (pos == 0) // Está en este source folder 65 | { 66 | path = path.substring(rootFolderOfSourcesAbsPath.length() + 1); // Sumamos +1 para quitar también el / separador del pathInput y el path relativo de la clase 67 | // Puede no tener extensión (script) o bien ser .java o bien ser una inventada (ej .jsh), la quitamos si existe 68 | pos = path.lastIndexOf('.'); 69 | if (pos != -1) 70 | path = path.substring(0, pos); 71 | path = path.replace(File.separatorChar, '.'); // getAbsolutePath() normaliza con el caracter de la plataforma 72 | return path; 73 | } 74 | return null; 75 | } 76 | 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/JProxyShellInteractiveImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceScript; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 7 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 8 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRootInMemory; 9 | import com.innowhere.relproxy.impl.jproxy.shell.inter.JProxyShellProcessor; 10 | import java.util.LinkedList; 11 | 12 | /** 13 | * Alguna inspiración: http://groovy.codehaus.org/Groovy+Shell 14 | * 15 | * @author jmarranz 16 | */ 17 | public class JProxyShellInteractiveImpl extends JProxyShellImpl 18 | { 19 | protected boolean test = false; 20 | protected JProxyShellProcessor processor = new JProxyShellProcessor(this); 21 | protected ClassDescriptorSourceScript classDescSourceScript; 22 | 23 | public void init(String[] args) 24 | { 25 | this.classDescSourceScript = super.init(args, null); 26 | 27 | if (test) 28 | { 29 | processor.test(); 30 | return; 31 | } 32 | 33 | processor.loop(); 34 | } 35 | 36 | public ClassDescriptorSourceScript getClassDescriptorSourceScript() 37 | { 38 | return classDescSourceScript; 39 | } 40 | 41 | public SourceScriptRootInMemory getSourceScriptInMemory() 42 | { 43 | return (SourceScriptRootInMemory)classDescSourceScript.getSourceScript(); 44 | } 45 | 46 | @Override 47 | public ClassDescriptorSourceScript init(JProxyConfigImpl config,SourceScriptRoot scriptFile,ClassLoader classLoader) 48 | { 49 | ClassDescriptorSourceScript script = super.init(config,scriptFile, classLoader); 50 | 51 | this.test = config.isTest(); 52 | 53 | return script; 54 | } 55 | 56 | @Override 57 | protected void executeFirstTime(ClassDescriptorSourceScript scriptFileDesc,LinkedList argsToScript,JProxyShellClassLoader classLoader) 58 | { 59 | // La primera vez el script es vacío, no hay nada que ejecutar 60 | } 61 | 62 | @Override 63 | protected void processConfigParams(String[] args,LinkedList argsToScript,JProxyConfigImpl config) 64 | { 65 | super.processConfigParams(args, argsToScript, config); 66 | 67 | String classFolder = config.getClassFolder(); 68 | if (classFolder != null && !classFolder.trim().isEmpty()) throw new RelProxyException("cacheClassFolder is useless to execute in interactive mode"); 69 | } 70 | 71 | @Override 72 | protected SourceScriptRoot createSourceScriptRoot(String[] args,LinkedList argsToScript,FolderSourceList folderSourceList) 73 | { 74 | return SourceScriptRootInMemory.createSourceScriptInMemory(""); // La primera vez no hace nada, sirve para "calentar" la app 75 | } 76 | 77 | @Override 78 | protected JProxyShellClassLoader getJProxyShellClassLoader(JProxyConfigImpl config) 79 | { 80 | // No hay classFolder => no hay necesidad de nuevo ClassLoader 81 | return null; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/gproxy/GProxy.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.gproxy; 3 | 4 | import com.innowhere.relproxy.impl.gproxy.GProxyConfigImpl; 5 | import com.innowhere.relproxy.impl.gproxy.GProxyDefaultImpl; 6 | 7 | /** 8 | * Is the class to create Java proxy objects based on Groovy objects and keep track of Groovy source code changes reloading Groovy classes when detected. 9 | * 10 | * @author Jose Maria Arranz Santamaria 11 | */ 12 | public class GProxy 13 | { 14 | /** 15 | * Creates a {@link GProxyConfig} object to be used to configure GProxy. 16 | * 17 | * @return a new configuration object. 18 | * @see #init(GProxyConfig) 19 | */ 20 | public static GProxyConfig createGProxyConfig() 21 | { 22 | return GProxyDefaultImpl.createGProxyConfig(); 23 | } 24 | 25 | /** 26 | * Initializes GProxy with the provided configuration object. 27 | * 28 | * @param config 29 | */ 30 | public static void init(GProxyConfig config) 31 | { 32 | GProxyDefaultImpl.initStatic((GProxyConfigImpl)config); 33 | } 34 | 35 | /** 36 | * Creates a proxy object using java.lang.reflect.Proxy based on the provided Groovy object and the class of the implemented Java interface. 37 | * 38 | *

This method is a simplification for a single interface (the most common case) of {@link #create(Object,Class[])} .

39 | * 40 | * @param the interface implemented by the original object and proxy object returned. 41 | * @param obj the original object to proxy. 42 | * @param clasz the class of the interface implemented by the original object and proxy object returned. 43 | * @return the java.lang.reflect.Proxy object associated or the original object when GProxy is disabled. 44 | */ 45 | public static T create(T obj,Class clasz) 46 | { 47 | return GProxyDefaultImpl.createStatic(obj, clasz); 48 | } 49 | 50 | /** 51 | * Creates a proxy object using java.lang.reflect.Proxy based on the provided Groovy object and the classes of the implemented Java interfaces. 52 | * 53 | *

If GProxy has been configured and is enabled this method returns a java.lang.reflect.Proxy object implementing instead of 54 | * the original object provided. Methods called in proxy object are received by GProxy and forwarded to the original object, if source code 55 | * managed by GProxy has been changed, the class of the original object is reloaded based on the new source and the original object 56 | * is recreated with the new class and fields are re-set in the new object, then the method is called on the new original object.

57 | * 58 | *

If GProxy is disabled returns the original object provided with no performance penalty.

59 | * 60 | * @param obj the original object to proxy. 61 | * @param classes the classes of the interfaces implemented by the original object and proxy object returned. 62 | * @return the java.lang.reflect.Proxy object associated or the original object when GProxy is disabled. 63 | */ 64 | public static Object create(Object obj,Class[] classes) 65 | { 66 | return GProxyDefaultImpl.createStatic(obj, classes); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/JProxyShellScriptFileImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.FileExt; 5 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 6 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 7 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceScript; 8 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 9 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 10 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRootFile; 11 | import java.io.File; 12 | import java.util.LinkedList; 13 | 14 | /** 15 | * 16 | * @author jmarranz 17 | */ 18 | public class JProxyShellScriptFileImpl extends JProxyShellImpl 19 | { 20 | protected FileExt scriptFile; 21 | 22 | public void init(String[] args) 23 | { 24 | File scriptFile = new File(args[0]); 25 | if (!scriptFile.exists()) 26 | throw new RelProxyException("File " + args[0] + " does not exist"); 27 | 28 | this.scriptFile = new FileExt(scriptFile); 29 | 30 | File parentDir = JProxyUtil.getParentDir(scriptFile); 31 | String inputPath = parentDir.getAbsolutePath(); 32 | super.init(args, inputPath); 33 | } 34 | 35 | @Override 36 | protected void executeFirstTime(ClassDescriptorSourceScript scriptFileDesc,LinkedList argsToScript,JProxyShellClassLoader classLoader) 37 | { 38 | fixLastLoadedClass(scriptFileDesc,classLoader); 39 | 40 | try 41 | { 42 | scriptFileDesc.callMainMethod(argsToScript); 43 | } 44 | catch(Throwable ex) 45 | { 46 | ex.printStackTrace(System.out); 47 | } 48 | } 49 | 50 | @Override 51 | protected SourceScriptRoot createSourceScriptRoot(String[] args,LinkedList argsToScript,FolderSourceList folderSourceList) 52 | { 53 | return SourceScriptRootFile.createSourceScriptRootFile(scriptFile,folderSourceList); 54 | } 55 | 56 | @Override 57 | protected JProxyShellClassLoader getJProxyShellClassLoader(JProxyConfigImpl config) 58 | { 59 | String classFolder = config.getClassFolder(); 60 | if (classFolder != null) 61 | return new JProxyShellClassLoader(getDefaultClassLoader(),new File(classFolder)); 62 | else 63 | return null; 64 | } 65 | 66 | protected void fixLastLoadedClass(ClassDescriptorSourceScript scriptFileDesc,JProxyShellClassLoader classLoader) 67 | { 68 | Class scriptClass = scriptFileDesc.getLastLoadedClass(); 69 | if (scriptClass != null) return; 70 | 71 | // Esto es esperable cuando especificamos un classFolder en donde está ya compilado el script lanzador y es más actual que el fuente 72 | // no ha habido necesidad de crear un class loader "reloader" ni de recargar todos los archivos fuente con él 73 | if (classLoader == null) throw new RelProxyException("INTERNAL ERROR"); 74 | if (scriptFileDesc.getClassBytes() == null) throw new RelProxyException("INTERNAL ERROR"); 75 | scriptClass = classLoader.defineClass(scriptFileDesc); 76 | scriptFileDesc.setLastLoadedClass(scriptClass); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/JProxyImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core; 2 | 3 | import com.innowhere.relproxy.impl.GenericProxyImpl; 4 | import com.innowhere.relproxy.impl.GenericProxyInvocationHandler; 5 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceScript; 7 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 8 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.JProxyEngine; 9 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 10 | import com.innowhere.relproxy.jproxy.JProxyCompilerListener; 11 | import com.innowhere.relproxy.jproxy.JProxyDiagnosticsListener; 12 | import com.innowhere.relproxy.jproxy.JProxyInputSourceFileExcludedListener; 13 | 14 | /** 15 | * 16 | * @author jmarranz 17 | */ 18 | public abstract class JProxyImpl extends GenericProxyImpl 19 | { 20 | public static JProxyImpl SINGLETON; 21 | protected JProxyEngine engine; 22 | 23 | 24 | protected JProxyImpl() 25 | { 26 | } 27 | 28 | public static ClassLoader getDefaultClassLoader() 29 | { 30 | return Thread.currentThread().getContextClassLoader(); 31 | } 32 | 33 | public ClassDescriptorSourceScript init(JProxyConfigImpl config) 34 | { 35 | return init(config,null,null); 36 | } 37 | 38 | public ClassDescriptorSourceScript init(JProxyConfigImpl config,SourceScriptRoot scriptFile,ClassLoader classLoader) 39 | { 40 | super.init(config); 41 | 42 | FolderSourceList folderSourceList = config.getFolderSourceList(); 43 | FolderSourceList requiredExtraJarPaths = config.getRequiredExtraJarPaths(); 44 | JProxyInputSourceFileExcludedListener excludedListener = config.getJProxyInputSourceFileExcludedListener(); 45 | JProxyCompilerListener compilerListener = config.getJProxyCompilerListener(); 46 | String classFolder = config.getClassFolder(); 47 | long scanPeriod = config.getScanPeriod(); 48 | Iterable compilationOptions = config.getCompilationOptions(); 49 | JProxyDiagnosticsListener diagnosticsListener = config.getJProxyDiagnosticsListener(); 50 | boolean enabled = config.isEnabled(); 51 | 52 | classLoader = classLoader != null ? classLoader : getDefaultClassLoader(); 53 | this.engine = new JProxyEngine(this,enabled,scriptFile,classLoader,folderSourceList,requiredExtraJarPaths,classFolder,scanPeriod,excludedListener,compilerListener,compilationOptions,diagnosticsListener); 54 | 55 | return engine.init(); 56 | } 57 | 58 | public JProxyEngine getJProxyEngine() 59 | { 60 | return engine; 61 | } 62 | 63 | public boolean isEnabled() 64 | { 65 | return engine.isEnabled(); 66 | } 67 | 68 | public boolean isRunning() 69 | { 70 | return engine.isRunning(); 71 | } 72 | 73 | public boolean stop() 74 | { 75 | return engine.stop(); 76 | } 77 | 78 | public boolean start() 79 | { 80 | return engine.start(); 81 | } 82 | 83 | @Override 84 | public GenericProxyInvocationHandler createGenericProxyInvocationHandler(Object obj) 85 | { 86 | return new JProxyInvocationHandler(obj,this); 87 | } 88 | 89 | public abstract Class getMainParamClass(); 90 | } 91 | -------------------------------------------------------------------------------- /relproxy/CHANGES.txt: -------------------------------------------------------------------------------- 1 | 2 | RELEASE CHANGES 3 | 4 | * 0.8.8 5 | 6 | - Support of static final fields in reloadable proxies. 7 | 8 | * 0.8.7 9 | 10 | - Some improvement needed when embedding RelProxy Java using the scripting API (avoiding one unnecessary first class reload). 11 | - Added chapter to Manual: "Embedding RelProxy Java in your Java framework to provide hot reload". 12 | - Added new example in RelProxy Examples repository named relproxy_builtin_ex on how to embed RelProxy. 13 | 14 | * 0.8.6 15 | 16 | - Support of class reloading in inner classes including anonymous inner classes. Chapter "JProxy or how to be able..." updated accordingly. This feature 17 | is used by ItsNat 1.4, this release uses RelProxy internally for user class reloading (mainly listeners). 18 | 19 | * 0.8.5 20 | 21 | - Improved performance reducing blocking code when checking source code changes and no change is detected. 22 | 23 | * 0.8.4 24 | 25 | - Added the method JProxyConfig.setRequiredExtraJarPaths(String[] inputJarPaths) to workaround a problem with Liferay 6.2. 26 | - Added JProxy.create(Object,Class[]), GProxy.create(Object,Class[]),JProxyScriptEngine.create(Object,Class[]) for classes implementing multiple interfaces 27 | - The call proxy.equals(proxy2) returns true if both proxies have associated the same original object and there is no reload. 28 | - Added to Manual "Solving jar manifest configuration problems in JProxy" and "Identity of returned proxies" 29 | 30 | * 0.8.3 31 | 32 | - First release published on bintray.com/JCenter and Maven Central. In Maven just add to your POM: 33 | 34 | 35 | com.innowhere 36 | relproxy 37 | 0.8.3 38 | 39 | 40 | * 0.8.2 41 | 42 | - Optimization: method JProxyInputSourceFileExcludedListener.isExcluded(File file,File) is called being parameter file also a directory, if the directory is fully 43 | excluded, RelProxy doesn't call isExcluded for files into the folder. Useful for big source code bases and used RelProxy for normal source code folders. 44 | - Reload reloadable classes using a new ClassLoader is done only when a exposed method of a singleton registered on JProxy is called. 45 | - Added JProxy.isEnabled() 46 | - API for configuration of JProxyScriptEngineFactory and JProxyScriptEngine has changed. 47 | - JProxyScriptEngine has now the same methods (and same behavior) as JProxy. 48 | - Removed JPROXYSH_SCAN_PERIOD, has no sense in shell scripting. 49 | - Bug fix in case of paths with spaces in JProxy. 50 | - Bug fix in case of ".." in paths in JProxy. 51 | - Manual has been very improved documenting new features and new chapters. 52 | - A lot of examples of using RelProxy with popular Java web frameworks. 53 | 54 | * 0.8.1 55 | 56 | - Fixed a problem with class localization and loading of javax.* classes not included in Java core (ex javax.servlet classes) 57 | - Support of multiple input folder roots for sources: JProxyConfig.setInputPaths(String[] inputPaths) 58 | - Added listener JProxyConfig.setRelProxyOnReloadListener(RelProxyOnReloadListener) to expecify excluded files 59 | - Added listener JProxyConfig.setJProxyCompilerListener(JProxyCompilerListener) to monitor when files are compiled 60 | - Added JProxyConfig.isRunning() to detect whether JProxy is configured and running 61 | - Added new chapters to manual: 62 | "Setting up a web project based on a Maven POM in NetBeans to use JProxy or GProxy" 63 | "How JProxy can help you only in development time (GWT example)" 64 | 65 | * 0.8 First release 66 | 67 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/cldesc/ClassDescriptorSourceFileRegistry.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | import java.util.LinkedList; 6 | import java.util.Map; 7 | 8 | /** 9 | * 10 | * @author jmarranz 11 | */ 12 | public class ClassDescriptorSourceFileRegistry 13 | { 14 | protected final Map sourceUnitMapByClassName; 15 | 16 | public ClassDescriptorSourceFileRegistry() 17 | { 18 | this.sourceUnitMapByClassName = new HashMap(); 19 | } 20 | 21 | public ClassDescriptorSourceFileRegistry(ClassDescriptorSourceFileRegistry origin) 22 | { 23 | this.sourceUnitMapByClassName = new HashMap( origin.sourceUnitMapByClassName ); 24 | } 25 | 26 | public boolean isEmpty() 27 | { 28 | return sourceUnitMapByClassName.isEmpty(); 29 | } 30 | 31 | public Collection getClassDescriptorSourceFileColl() 32 | { 33 | return sourceUnitMapByClassName.values(); 34 | } 35 | 36 | public ClassDescriptorSourceUnit getClassDescriptorSourceUnit(String className) 37 | { 38 | return sourceUnitMapByClassName.get(className); 39 | } 40 | 41 | public ClassDescriptorSourceUnit removeClassDescriptorSourceUnit(String className) 42 | { 43 | return sourceUnitMapByClassName.remove(className); 44 | } 45 | 46 | public void addClassDescriptorSourceUnit(ClassDescriptorSourceUnit sourceFile) 47 | { 48 | sourceUnitMapByClassName.put(sourceFile.getClassName(), sourceFile); 49 | } 50 | 51 | public void setAllClassDescriptorSourceFilesPendingToRemove(boolean pending) 52 | { 53 | for(Map.Entry entries : sourceUnitMapByClassName.entrySet()) 54 | entries.getValue().setPendingToRemove(pending); 55 | } 56 | 57 | public LinkedList getAllClassDescriptorSourceFilesPendingToRemove(LinkedList deletedSourceFiles) 58 | { 59 | for(Map.Entry entries : sourceUnitMapByClassName.entrySet()) 60 | { 61 | ClassDescriptorSourceUnit classDesc = entries.getValue(); 62 | boolean pending = classDesc.isPendingToRemove(); 63 | if (pending) 64 | deletedSourceFiles.add(classDesc); 65 | } 66 | return deletedSourceFiles; 67 | } 68 | 69 | public ClassDescriptor getClassDescriptor(String className) 70 | { 71 | // Puede ser el de una innerclass 72 | // Las innerclasses no están como tales en sourceFileMap pues sólo está la clase contenedora pero también la consideramos hotloadable 73 | String parentClassName; 74 | int pos = className.lastIndexOf('$'); 75 | boolean inner; 76 | if (pos != -1) 77 | { 78 | parentClassName = className.substring(0, pos); 79 | inner = true; 80 | } 81 | else 82 | { 83 | parentClassName = className; 84 | inner = false; 85 | } 86 | ClassDescriptorSourceUnit sourceDesc = sourceUnitMapByClassName.get(parentClassName); 87 | if (sourceDesc == null) 88 | return null; 89 | if (!inner) return sourceDesc; 90 | return sourceDesc.getInnerClassDescriptor(className,true); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/Command.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 2 | 3 | /** 4 | * 5 | * @author jmarranz 6 | */ 7 | public abstract class Command 8 | { 9 | protected JProxyShellProcessor parent; 10 | protected String name; 11 | 12 | public Command(JProxyShellProcessor parent,String name) 13 | { 14 | this.parent = parent; 15 | this.name = name; 16 | } 17 | 18 | public static Command createCommand(JProxyShellProcessor parent,String cmd) 19 | { 20 | cmd = cmd.trim(); 21 | if (cmd.equals("clear")) 22 | { 23 | return new CommandOther(parent,cmd); 24 | } 25 | else if (cmd.startsWith("delete")) 26 | { 27 | CommandDelete command = CommandDelete.createCommandDelete(parent,cmd); 28 | if (command != null) 29 | return command; 30 | else 31 | return new CommandError(parent); 32 | } 33 | else if (cmd.equals("display")) 34 | { 35 | return new CommandOther(parent,cmd); 36 | } 37 | else if (cmd.startsWith("edit")) 38 | { 39 | CommandEdit command = CommandEdit.createCommandEdit(parent,cmd); 40 | if (command != null) 41 | return command; 42 | else 43 | return new CommandError(parent); 44 | } 45 | else if (cmd.equals("exec")) 46 | { 47 | return new CommandOther(parent,cmd); 48 | } 49 | else if (cmd.equals("exit")) 50 | { 51 | return new CommandOther(parent,cmd); 52 | } 53 | else if (cmd.equals("help")) 54 | { 55 | return new CommandOther(parent,cmd); 56 | } 57 | else if (cmd.startsWith("insert")) 58 | { 59 | CommandInsert command = CommandInsert.createCommandInsert(parent,cmd); 60 | if (command != null) 61 | return command; 62 | else 63 | return new CommandError(parent); 64 | } 65 | else if (cmd.startsWith("load")) 66 | { 67 | CommandLoad command = CommandLoad.createCommandLoad(parent,cmd); 68 | if (command != null) 69 | return command; 70 | else 71 | return new CommandError(parent); 72 | } 73 | else if (cmd.equals("quit")) 74 | { 75 | return new CommandOther(parent,cmd); 76 | } 77 | else if (cmd.startsWith("save")) 78 | { 79 | CommandSave command = CommandSave.createCommandSave(parent,cmd); 80 | if (command != null) 81 | return command; 82 | else 83 | return new CommandError(parent); 84 | } 85 | 86 | return null; // No es un comando 87 | } 88 | 89 | protected static String getParameter(String cmdName,String cmd) 90 | { 91 | int pos = cmd.indexOf(cmdName + " "); 92 | if (pos != 0) 93 | return null; 94 | pos = cmd.indexOf(' '); 95 | String param = cmd.substring(pos + 1); 96 | param = param.trim(); 97 | return param; 98 | } 99 | 100 | public abstract boolean run(); 101 | 102 | public abstract void runPostCommand(); 103 | } 104 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/webapp/WEB-INF/javaex/code/example/javaex/JProxyExampleDocument.java: -------------------------------------------------------------------------------- 1 | package example.javaex; 2 | 3 | import com.innowhere.relproxy.jproxy.JProxy; 4 | import example.javaex.hotreload.JProxyExampleAux2; 5 | import example.javaex.nothotreload.JProxyExampleAuxIgnored2; 6 | import example.javaex.nothotreload.JProxyExampleAuxIgnored3; 7 | import org.itsnat.comp.ItsNatComponentManager; 8 | import org.itsnat.comp.text.ItsNatHTMLInputText; 9 | import org.itsnat.core.ItsNatServletRequest; 10 | import org.itsnat.core.event.ItsNatServletRequestListener; 11 | import org.itsnat.core.html.ItsNatHTMLDocument; 12 | import org.w3c.dom.Element; 13 | import org.w3c.dom.events.Event; 14 | import org.w3c.dom.events.EventListener; 15 | import org.w3c.dom.events.EventTarget; 16 | import org.w3c.dom.html.HTMLDocument; 17 | 18 | public class JProxyExampleDocument extends JProxyExampleDocumentBase 19 | { 20 | protected ItsNatHTMLDocument itsNatDoc; // ItsNatHTMLDocument 21 | protected ItsNatHTMLInputText textInput; // ItsNatHTMLInputText 22 | protected Element resultsElem; // Element 23 | 24 | public static class AuxMember 25 | { 26 | public static void log() 27 | { 28 | System.out.println(AuxMember.class.getName() + ": 1 " + AuxMember.class.getClassLoader().hashCode()); 29 | } 30 | } 31 | 32 | public JProxyExampleDocument() // Requerido por el listener ejemplo anonymous inner class del "dlbclick" 33 | { 34 | } 35 | 36 | public JProxyExampleDocument(ItsNatServletRequest request,ItsNatHTMLDocument itsNatDoc,FalseDB db) 37 | { 38 | class AuxMemberInMethod 39 | { 40 | public void log() 41 | { 42 | System.out.println("JProxyExampleDocument.AuxMemberInMethod: 1 " + AuxMemberInMethod.class.getClassLoader().hashCode()); 43 | } 44 | } 45 | 46 | this.itsNatDoc = itsNatDoc; 47 | 48 | if (db.getCityList().size() != 3) 49 | throw new RuntimeException("Unexpected"); 50 | 51 | HTMLDocument doc = itsNatDoc.getHTMLDocument(); 52 | 53 | ItsNatComponentManager compMgr = itsNatDoc.getItsNatComponentManager(); 54 | this.textInput = (ItsNatHTMLInputText)compMgr.createItsNatComponentById("inputId"); 55 | 56 | EventListener listener = new EventListener() 57 | { 58 | { 59 | System.out.println("JProxyExampleDocument Anonymous Inner 1 " + this.getClass().getClassLoader().hashCode()); 60 | } 61 | 62 | @Override 63 | public void handleEvent(Event evt) 64 | { 65 | String text = textInput.getText(); 66 | String comment = " YES I SAID THIS (" + evt.getType() + ")"; 67 | resultsElem.setTextContent(text + comment); 68 | } 69 | }; 70 | 71 | Element buttonElem = doc.getElementById("buttonId"); 72 | ((EventTarget)buttonElem).addEventListener("click",listener,false); 73 | 74 | ((EventTarget)buttonElem).addEventListener("dblclick", JProxy.create(listener, EventListener.class) ,false); 75 | 76 | this.resultsElem = doc.getElementById("resultsId"); 77 | 78 | System.out.println("JProxyExampleDocument 1 " + this.getClass().getClassLoader().hashCode()); 79 | new AuxMemberInMethod().log(); 80 | AuxMember.log(); 81 | JProxyExampleAux.log(); 82 | JProxyExampleAux2.log(); 83 | JProxyExampleAuxIgnored.log(); 84 | JProxyExampleAuxIgnored2.log(); 85 | JProxyExampleAuxIgnored3.log(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/screngine/JProxyScriptEngineImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.screngine; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.GenericProxyImpl; 5 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 6 | import com.innowhere.relproxy.impl.jproxy.JProxyUtil; 7 | import com.innowhere.relproxy.jproxy.JProxyConfig; 8 | import com.innowhere.relproxy.jproxy.JProxyScriptEngine; 9 | import java.io.Reader; 10 | import javax.script.AbstractScriptEngine; 11 | import javax.script.Bindings; 12 | import javax.script.ScriptContext; 13 | import javax.script.ScriptEngineFactory; 14 | import javax.script.ScriptException; 15 | 16 | /** 17 | * Methods of this class are similar to JProxyDefaultImpl 18 | * 19 | * @author jmarranz 20 | */ 21 | public class JProxyScriptEngineImpl extends AbstractScriptEngine implements JProxyScriptEngine 22 | { 23 | protected JProxyScriptEngineDelegateImpl jproxy; 24 | protected JProxyScriptEngineFactoryImpl factory; 25 | 26 | public JProxyScriptEngineImpl(JProxyScriptEngineFactoryImpl factory) 27 | { 28 | this.factory = factory; 29 | } 30 | 31 | @Override 32 | public void init(JProxyConfig config) 33 | { 34 | JProxyConfigImpl configImpl = (JProxyConfigImpl)config; 35 | if (!configImpl.isEnabled()) return; // jproxy quedará null 36 | 37 | GenericProxyImpl.checkSingletonNull(jproxy); 38 | this.jproxy = new JProxyScriptEngineDelegateImpl(this); 39 | jproxy.init(configImpl); 40 | } 41 | 42 | 43 | @Override 44 | public Object eval(String script, ScriptContext context) throws ScriptException 45 | { 46 | if (jproxy == null) 47 | throw new RelProxyException("Engine is disabled"); 48 | 49 | return jproxy.execute(script,context); 50 | } 51 | 52 | @Override 53 | public Object eval(Reader reader, ScriptContext context) throws ScriptException 54 | { 55 | String script = JProxyUtil.readTextFile(reader); 56 | return eval(script,context); 57 | } 58 | 59 | @Override 60 | public Bindings createBindings() 61 | { 62 | return new BindingsImpl(); 63 | } 64 | 65 | @Override 66 | public ScriptEngineFactory getFactory() 67 | { 68 | return factory; 69 | } 70 | 71 | @Override 72 | public T create(T obj,Class clasz) 73 | { 74 | if (jproxy == null) 75 | return obj; // No se ha llamado al init o enabled = false 76 | return jproxy.create(obj, clasz); 77 | } 78 | 79 | @Override 80 | public Object create(Object obj,Class[] classes) 81 | { 82 | if (jproxy == null) 83 | return obj; // No se ha llamado al init o enabled = false 84 | return jproxy.create(obj, classes); 85 | } 86 | 87 | @Override 88 | public boolean isEnabled() 89 | { 90 | if (jproxy == null) 91 | return false; 92 | 93 | return jproxy.isEnabled(); 94 | } 95 | 96 | @Override 97 | public boolean isRunning() 98 | { 99 | if (jproxy == null) 100 | return false; 101 | 102 | return jproxy.isRunning(); 103 | } 104 | 105 | @Override 106 | public boolean start() 107 | { 108 | if (jproxy == null) 109 | return false; 110 | 111 | return jproxy.start(); 112 | } 113 | 114 | @Override 115 | public boolean stop() 116 | { 117 | if (jproxy == null) 118 | return false; 119 | 120 | return jproxy.stop(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/shell/inter/CommandOther.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.impl.jproxy.shell.inter; 3 | 4 | import com.innowhere.relproxy.RelProxyException; 5 | 6 | /** 7 | * 8 | * @author jmarranz 9 | */ 10 | public class CommandOther extends Command 11 | { 12 | public CommandOther(JProxyShellProcessor parent,String name) 13 | { 14 | super(parent,name); 15 | } 16 | 17 | @Override 18 | public boolean run() 19 | { 20 | if (name.equals("clear")) 21 | { 22 | commandClear(); 23 | } 24 | else if (name.equals("display")) 25 | { 26 | commandDisplay(); 27 | } 28 | else if (name.equals("exec")) 29 | { 30 | commandExec(); 31 | } 32 | else if (name.equals("exit")) 33 | { 34 | commandExit(); 35 | } 36 | else if (name.equals("help")) 37 | { 38 | commandHelp(); 39 | } 40 | else if (name.equals("quit")) 41 | { 42 | commandExit(); 43 | } 44 | else throw new RelProxyException("Internal Error"); 45 | 46 | return true; 47 | } 48 | 49 | @Override 50 | public void runPostCommand() 51 | { 52 | } 53 | 54 | private void commandClear() 55 | { 56 | parent.clearCodeBuffer(); 57 | } 58 | 59 | private void commandExit() 60 | { 61 | System.exit(0); 62 | } 63 | 64 | private void commandDisplay() 65 | { 66 | System.out.println("001>"); // La primera línea es siempre vacía porque en ella es donde ponemos el "public class /_jproxyShellInMemoryClass_ { " que el usuario ignora, así al dar error el número de línea será correcto respecto al "display" 67 | 68 | int i = 2; 69 | for(String line : parent.getCodeBuffer()) 70 | { 71 | for(int j = 0; j < 3 - String.valueOf(i).length(); j++) System.out.print("0"); 72 | System.out.print(i + ">"); 73 | System.out.print(line); 74 | System.out.println(); 75 | i++; 76 | } 77 | } 78 | 79 | private void commandExec() 80 | { 81 | parent.executeCodeBuffer(); 82 | } 83 | 84 | private void commandHelp() 85 | { 86 | System.out.println("Everything you write in the prompt is added to a code buffer, code buffer is compiled on the fly and executed by exec command, unless a command is detected"); 87 | System.out.println(""); 88 | System.out.println("Available commands:"); 89 | System.out.println(" clear"); 90 | System.out.println(" Clears the buffer"); 91 | System.out.println(" display"); 92 | System.out.println(" Shows the buffer content"); 93 | System.out.println(" edit last | "); 94 | System.out.println(" Edits the last introduced line code or the specified line number"); 95 | System.out.println(" exec"); 96 | System.out.println(" Compile and execute the buffer content"); 97 | System.out.println(" exit"); 98 | System.out.println(" Exits shell"); 99 | System.out.println(" help"); 100 | System.out.println(" This command"); 101 | System.out.println(" insert last | "); 102 | System.out.println(" Insert the next line of code before the last introduced line or the specified line number"); 103 | System.out.println(" load | "); 104 | System.out.println(" Load a file or URL into the buffer"); 105 | System.out.println(" quit"); 106 | System.out.println(" Same as exit"); 107 | System.out.println(" save "); 108 | System.out.println(" Save the current buffer to a file"); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /relproxy_test_itsnat/src/main/java/example/groovyex/ItsNatGroovyServlet.java: -------------------------------------------------------------------------------- 1 | 2 | package example.groovyex; 3 | 4 | import groovy.lang.Binding; 5 | import groovy.lang.Closure; 6 | import groovy.servlet.ServletCategory; 7 | import groovy.util.GroovyScriptEngine; 8 | import groovy.util.ResourceException; 9 | import groovy.util.ScriptException; 10 | import java.io.File; 11 | import java.io.IOException; 12 | import javax.servlet.ServletConfig; 13 | import javax.servlet.ServletException; 14 | import org.codehaus.groovy.runtime.GroovyCategorySupport; 15 | import org.itsnat.core.http.HttpServletWrapper; 16 | 17 | 18 | /** 19 | * Inspired on: 20 | * https://github.com/groovy/groovy-core/blob/master/subprojects/groovy-servlet/src/main/java/groovy/servlet/GroovyServlet.java 21 | * 22 | * @author jmarranz 23 | */ 24 | public class ItsNatGroovyServlet extends HttpServletWrapper 25 | { 26 | protected GroovyScriptEngine gse; 27 | 28 | public ItsNatGroovyServlet() 29 | { 30 | } 31 | 32 | public GroovyScriptEngine getGroovyScriptEngine() 33 | { 34 | return gse; 35 | } 36 | 37 | public String getScriptRootPath(ServletConfig config) throws ServletException 38 | { 39 | String scriptRootPath = config.getInitParameter("scriptRootPath"); 40 | if (scriptRootPath == null) throw new ServletException("Missing servlet init param scriptRootPath"); 41 | return getServletContext().getRealPath("/") + "/WEB-INF/" + scriptRootPath + "/"; 42 | } 43 | 44 | public String getInitScript(ServletConfig config) throws ServletException 45 | { 46 | String initScript = config.getInitParameter("initScript"); 47 | if (initScript == null) throw new ServletException("Missing servlet init param initScript"); 48 | return initScript; 49 | } 50 | 51 | @Override 52 | public void init(ServletConfig config) throws ServletException 53 | { 54 | super.init(config); 55 | 56 | // Set up the scripting engine 57 | 58 | String pathPrefix = getScriptRootPath(config); 59 | 60 | try 61 | { 62 | this.gse = new GroovyScriptEngine(new String[]{pathPrefix}); 63 | } 64 | catch(IOException ex) { throw new RuntimeException(ex); } 65 | 66 | //gse.getConfig().setMinimumRecompilationInterval(0); 67 | 68 | //System.out.println("MinimumRecompilationInterval " + gse.getConfig().getMinimumRecompilationInterval()); 69 | 70 | getServletContext().log("Groovy servlet initialized on " + gse + "."); 71 | 72 | String initScript = getInitScript(config); 73 | 74 | File initFile = new File(pathPrefix + initScript); 75 | if (!initFile.exists()) 76 | throw new ServletException(initFile.getAbsolutePath() + " does not exist"); 77 | 78 | final Binding binding = new Binding(); 79 | binding.setVariable("itsNatServlet", itsNatServlet); 80 | binding.setVariable("servlet", this); 81 | binding.setVariable("config", config); 82 | binding.setVariable("context", getServletContext()); 83 | binding.setVariable("application", getServletContext()); 84 | 85 | com.innowhere.relproxy.gproxy.GProxyGroovyScriptEngine.class.getName(); 86 | com.innowhere.relproxy.gproxy.GProxyConfig.class.getName(); 87 | com.innowhere.relproxy.gproxy.GProxy.class.getName(); 88 | 89 | execGroovyScript(initScript,binding); 90 | } 91 | 92 | protected void execGroovyScript(final String filePath,final Binding binding) 93 | { 94 | Closure closure = new Closure(gse) 95 | { 96 | @Override 97 | public Object call() { 98 | try { 99 | return ((GroovyScriptEngine)getDelegate()).run(filePath, binding); 100 | } 101 | catch (ResourceException e) { throw new RuntimeException(e); } 102 | catch (ScriptException e) { throw new RuntimeException(e); } 103 | } 104 | }; 105 | GroovyCategorySupport.use(ServletCategory.class, closure); 106 | } 107 | 108 | } 109 | 110 | 111 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/cldesc/ClassDescriptor.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author jmarranz 8 | */ 9 | public abstract class ClassDescriptor 10 | { 11 | protected final String className; // El nombre basado en puntos pero usando $ en el caso de innerclasses 12 | protected final String simpleClassName; // className sin el package 13 | protected final String packageName; // El package pero acabado en un "." o bien "" si no hay package, el motivo de acabar en un punto es simplemente para poder concatenar ciegamente el package y el simpleClassName 14 | protected byte[] classBytes; 15 | protected Class clasz; 16 | 17 | public ClassDescriptor(String className) 18 | { 19 | this.className = className; 20 | int pos = className.lastIndexOf('.'); 21 | this.simpleClassName = (pos != -1) ? className.substring(pos + 1) : className; 22 | this.packageName = (pos != -1) ? className.substring(0,pos + 1) : ""; // SE INCLUYE EL . en el caso de existir package 23 | } 24 | 25 | public abstract boolean isInnerClass(); 26 | 27 | public String getClassName() 28 | { 29 | return className; 30 | } 31 | 32 | public String getSimpleClassName() 33 | { 34 | return simpleClassName; 35 | } 36 | 37 | public String getPackageName() 38 | { 39 | return packageName; 40 | } 41 | 42 | public byte[] getClassBytes() 43 | { 44 | return classBytes; 45 | } 46 | 47 | public void setClassBytes(byte[] classBytes) 48 | { 49 | this.classBytes = classBytes; 50 | } 51 | 52 | public Class getLastLoadedClass() 53 | { 54 | return clasz; 55 | } 56 | 57 | public void setLastLoadedClass(Class clasz) 58 | { 59 | this.clasz = clasz; 60 | } 61 | 62 | public void resetLastLoadedClass() 63 | { 64 | setLastLoadedClass(null); 65 | } 66 | 67 | /* 68 | public String getClassFileNameFromClassName() 69 | { 70 | return getClassFileNameFromClassName(className); 71 | } 72 | */ 73 | 74 | public static String getClassFileNameFromClassName(String className) 75 | { 76 | // Es válido también para las innerclasses (ej Nombre$Otro => Nombre$Otro.class, Nombre$1 => Nombre$1.class, Nombre$1Nombre => Nombre$1Nombre.class 77 | int pos = className.lastIndexOf("."); 78 | if(pos != -1) className = className.substring(pos + 1); 79 | return className + ".class"; 80 | } 81 | 82 | public static String getRelativeClassFilePathFromClassName(String className) 83 | { 84 | return className.replace('.','/') + ".class"; // alternativa: className.replaceAll("\\.", "/") + ".class" 85 | } 86 | 87 | public static String getRelativePackagePathFromClassName(String className) 88 | { 89 | String packageName = className.replace('.','/'); 90 | int pos = packageName.lastIndexOf('/'); 91 | if (pos == -1) return packageName; 92 | return packageName.substring(0,pos); 93 | } 94 | 95 | public static File getAbsoluteClassFilePathFromClassNameAndClassPath(String className,String classPath) 96 | { 97 | String relativePath = getRelativeClassFilePathFromClassName(className); 98 | classPath = classPath.trim(); 99 | if (!classPath.endsWith("/") && !classPath.endsWith("\\")) classPath += File.separatorChar; 100 | return new File(classPath + relativePath); 101 | } 102 | 103 | public static String getClassNameFromRelativeClassFilePath(String path) 104 | { 105 | // Ej. org/w3c/dom/Element.class => org.w3c.dom.Element 106 | String binaryName = path.replaceAll("/", "."); 107 | return binaryName.replaceAll(".class$", ""); // El $ indica "el .class del final" 108 | } 109 | 110 | public static String getClassNameFromPackageAndClassFileName(String packageName,String fileName) 111 | { 112 | String className = packageName + "." + fileName; 113 | return className.replaceAll(".class$", ""); // El $ indica "el .class del final" 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/screngine/JProxyScriptEngineDelegateImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.screngine; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 5 | import com.innowhere.relproxy.impl.jproxy.core.JProxyImpl; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc.ClassDescriptorSourceScript; 7 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.JProxyEngine; 8 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 9 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRootInMemory; 10 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.comp.JProxyCompilationException; 11 | import com.innowhere.relproxy.impl.jproxy.shell.JProxyShellClassLoader; 12 | import java.io.File; 13 | import javax.script.ScriptContext; 14 | import javax.script.ScriptException; 15 | 16 | /** 17 | * 18 | * @author jmarranz 19 | */ 20 | public class JProxyScriptEngineDelegateImpl extends JProxyImpl 21 | { 22 | protected JProxyScriptEngineImpl parent; 23 | protected ClassDescriptorSourceScript classDescSourceScript; 24 | protected long codeBufferModTimestamp = 0; 25 | protected long lastCodeCompiledTimestamp = 0; 26 | 27 | public JProxyScriptEngineDelegateImpl(JProxyScriptEngineImpl parent) 28 | { 29 | this.parent = parent; 30 | } 31 | 32 | @Override 33 | public ClassDescriptorSourceScript init(JProxyConfigImpl config) 34 | { 35 | SourceScriptRoot sourceFileScript = SourceScriptRootInMemory.createSourceScriptInMemory(""); 36 | 37 | JProxyShellClassLoader classLoader = null; 38 | String classFolder = config.getClassFolder(); 39 | if (classFolder != null) 40 | classLoader = new JProxyShellClassLoader(getDefaultClassLoader(),new File(classFolder)); 41 | 42 | this.classDescSourceScript = init(config,sourceFileScript,classLoader); 43 | return classDescSourceScript; 44 | } 45 | 46 | @Override 47 | public Class getMainParamClass() 48 | { 49 | return ScriptContext.class; 50 | } 51 | 52 | private SourceScriptRootInMemory getSourceScriptInMemory() 53 | { 54 | return (SourceScriptRootInMemory)classDescSourceScript.getSourceScript(); 55 | } 56 | 57 | public Object execute(String code,ScriptContext context) throws ScriptException 58 | { 59 | Class scriptClass; 60 | JProxyEngine jproxyEngine = getJProxyEngine(); 61 | Object monitor = jproxyEngine.getMonitor(); 62 | synchronized(monitor) 63 | { 64 | if (!getSourceScriptInMemory().getScriptCode().equals(code)) 65 | { 66 | this.codeBufferModTimestamp = System.currentTimeMillis(); 67 | 68 | getSourceScriptInMemory().setScriptCode(code,codeBufferModTimestamp); 69 | // Recuerda que cada vez que se obtiene el timestamp se llama a System.currentTimeMillis(), es imposible que el usuario haga algo en menos de 1ms 70 | 71 | ClassDescriptorSourceScript classDescSourceScript2 = null; 72 | try 73 | { 74 | classDescSourceScript2 = jproxyEngine.detectChangesInSourcesAndReload(); 75 | } 76 | catch(JProxyCompilationException ex) 77 | { 78 | throw new ScriptException(ex); 79 | } 80 | 81 | if (classDescSourceScript2 != classDescSourceScript) 82 | throw new RelProxyException("Internal Error"); 83 | 84 | this.lastCodeCompiledTimestamp = System.currentTimeMillis(); 85 | if (lastCodeCompiledTimestamp == codeBufferModTimestamp) // Demasiado rápido compilando 86 | { 87 | // Aseguramos que el siguiente código se ejecuta si o si con un codeBufferModTimestamp mayor que el timestamp de la compilación 88 | try { Thread.sleep(1); } catch (InterruptedException ex) { throw new RelProxyException(ex); } 89 | } 90 | } 91 | 92 | scriptClass = classDescSourceScript.getLastLoadedClass(); 93 | } 94 | 95 | try 96 | { 97 | return ClassDescriptorSourceScript.callMainMethod(scriptClass,parent,context); 98 | } 99 | catch(Throwable ex) 100 | { 101 | Exception ex2 = (ex instanceof Exception) ? (Exception)ex : new RelProxyException(ex); 102 | throw new ScriptException(ex2); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/core/clsmgr/cldesc/ClassDescriptorSourceUnit.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy.core.clsmgr.cldesc; 2 | 3 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.JProxyEngine; 4 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceFileJavaNormal; 5 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceScriptRoot; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.srcunit.SourceUnit; 7 | import java.util.LinkedList; 8 | 9 | /** 10 | * 11 | * @author jmarranz 12 | */ 13 | public abstract class ClassDescriptorSourceUnit extends ClassDescriptor 14 | { 15 | protected final JProxyEngine engine; 16 | protected volatile long timestamp; 17 | protected final SourceUnit sourceUnit; 18 | protected LinkedList innerClasses; 19 | protected boolean pendingToRemove = false; // Se usa como monohilo, no hay problemas de sincronización 20 | 21 | public ClassDescriptorSourceUnit(JProxyEngine engine,String className,SourceUnit sourceFile, long timestamp) 22 | { 23 | super(className); 24 | this.engine = engine; 25 | this.sourceUnit = sourceFile; 26 | this.timestamp = timestamp; 27 | } 28 | 29 | public static ClassDescriptorSourceUnit create(boolean script,JProxyEngine engine,String className,SourceUnit sourceFile, long timestamp) 30 | { 31 | if (sourceFile instanceof SourceScriptRoot) 32 | return new ClassDescriptorSourceScript(engine,className,(SourceScriptRoot)sourceFile,timestamp); 33 | else if (sourceFile instanceof SourceFileJavaNormal) 34 | return new ClassDescriptorSourceFileJava(engine,className,(SourceFileJavaNormal)sourceFile,timestamp); 35 | else 36 | return null; // WTF!! 37 | } 38 | 39 | public SourceUnit getSourceUnit() 40 | { 41 | return sourceUnit; 42 | } 43 | 44 | public String getEncoding() 45 | { 46 | return engine.getSourceEncoding(); 47 | } 48 | 49 | @Override 50 | public boolean isInnerClass() 51 | { 52 | return false; 53 | } 54 | 55 | public long getTimestamp() 56 | { 57 | return timestamp; 58 | } 59 | 60 | public void updateTimestamp(long timestamp) 61 | { 62 | this.timestamp = timestamp; 63 | } 64 | 65 | public boolean isPendingToRemove() 66 | { 67 | return pendingToRemove; 68 | } 69 | 70 | public void setPendingToRemove(boolean pendingToRemove) 71 | { 72 | this.pendingToRemove = pendingToRemove; 73 | } 74 | 75 | 76 | public void cleanOnSourceCodeChanged() 77 | { 78 | // Como ha cambiado la clase, reseteamos las dependencias 79 | setClassBytes(null); 80 | setLastLoadedClass(null); 81 | clearInnerClassDescriptors(); // El código fuente nuevo puede haber cambiado totalmente las innerclasses antiguas (añadido, eliminado) 82 | } 83 | 84 | public boolean isInnerClass(String className) 85 | { 86 | int pos = className.lastIndexOf('$'); 87 | if (pos == -1) 88 | return false; // No es innerclass 89 | String baseClassName = className.substring(0, pos); 90 | return this.className.equals(baseClassName); // Si es false es que es una innerclass pero de otra clase 91 | } 92 | 93 | public LinkedList getInnerClassDescriptors() 94 | { 95 | return innerClasses; 96 | } 97 | 98 | public void clearInnerClassDescriptors() 99 | { 100 | if (innerClasses != null) 101 | innerClasses.clear(); 102 | } 103 | 104 | public ClassDescriptorInner getInnerClassDescriptor(String className,boolean addWhenMissing) 105 | { 106 | if (innerClasses != null) 107 | { 108 | for(ClassDescriptorInner classDesc : innerClasses) 109 | { 110 | if (classDesc.getClassName().equals(className)) 111 | return classDesc; 112 | } 113 | } 114 | 115 | if (!addWhenMissing) return null; 116 | 117 | return addInnerClassDescriptor(className); 118 | } 119 | 120 | public ClassDescriptorInner addInnerClassDescriptor(String className) 121 | { 122 | if (!isInnerClass(className)) 123 | return null; 124 | 125 | if (innerClasses == null) 126 | innerClasses = new LinkedList(); 127 | 128 | ClassDescriptorInner classDesc = new ClassDescriptorInner(className,this); 129 | innerClasses.add(classDesc); 130 | return classDesc; 131 | } 132 | 133 | @Override 134 | public void resetLastLoadedClass() 135 | { 136 | super.resetLastLoadedClass(); 137 | 138 | LinkedList innerClassDescList = getInnerClassDescriptors(); 139 | if (innerClassDescList != null) 140 | { 141 | for(ClassDescriptorInner innerClassDesc : innerClassDescList) 142 | innerClassDesc.resetLastLoadedClass(); 143 | } 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/impl/jproxy/JProxyConfigImpl.java: -------------------------------------------------------------------------------- 1 | package com.innowhere.relproxy.impl.jproxy; 2 | 3 | import com.innowhere.relproxy.RelProxyException; 4 | import com.innowhere.relproxy.RelProxyOnReloadListener; 5 | import com.innowhere.relproxy.impl.GenericProxyConfigBaseImpl; 6 | import com.innowhere.relproxy.impl.jproxy.core.clsmgr.FolderSourceList; 7 | import com.innowhere.relproxy.jproxy.JProxyCompilerListener; 8 | import com.innowhere.relproxy.jproxy.JProxyConfig; 9 | import com.innowhere.relproxy.jproxy.JProxyDiagnosticsListener; 10 | import com.innowhere.relproxy.jproxy.JProxyInputSourceFileExcludedListener; 11 | import java.io.File; 12 | 13 | /** 14 | * 15 | * @author jmarranz 16 | */ 17 | public class JProxyConfigImpl extends GenericProxyConfigBaseImpl implements JProxyConfig 18 | { 19 | protected File folderSources; 20 | protected FolderSourceList folderSourceList; 21 | protected FolderSourceList requiredExtraJarPaths; 22 | protected JProxyInputSourceFileExcludedListener excludedListener; 23 | protected JProxyCompilerListener compilerListener; 24 | protected String classFolder; 25 | protected long scanPeriod = -1; 26 | protected Iterable compilationOptions; 27 | protected JProxyDiagnosticsListener diagnosticsListener; 28 | protected boolean test = false; 29 | 30 | @Override 31 | public JProxyConfig setEnabled(boolean enabled) 32 | { 33 | this.enabled = enabled; 34 | return this; 35 | } 36 | 37 | @Override 38 | public JProxyConfig setRelProxyOnReloadListener(RelProxyOnReloadListener relListener) 39 | { 40 | this.relListener = relListener; 41 | return this; 42 | } 43 | 44 | @Override 45 | public JProxyConfig setInputPath(String inputPath) 46 | { 47 | setInputPaths(inputPath != null ? new String[]{inputPath} : null); // inputPath es null en el caso de shell interactive 48 | return this; 49 | } 50 | 51 | @Override 52 | public JProxyConfig setInputPaths(String[] inputPaths) 53 | { 54 | this.folderSourceList = new FolderSourceList(inputPaths,true); // inputPaths es null en el caso de shell interactive 55 | return this; 56 | } 57 | 58 | @Override 59 | public JProxyConfig setRequiredExtraJarPaths(String[] inputJarPaths) 60 | { 61 | this.requiredExtraJarPaths = new FolderSourceList(inputJarPaths,false); // inputPaths es null en el caso de shell interactive 62 | return this; 63 | } 64 | 65 | @Override 66 | public JProxyConfig setJProxyInputSourceFileExcludedListener(JProxyInputSourceFileExcludedListener excludedListener) 67 | { 68 | this.excludedListener = excludedListener; 69 | return this; 70 | } 71 | 72 | @Override 73 | public JProxyConfig setJProxyCompilerListener(JProxyCompilerListener compilerListener) 74 | { 75 | this.compilerListener = compilerListener; 76 | return this; 77 | } 78 | 79 | @Override 80 | public JProxyConfig setClassFolder(String classFolder) 81 | { 82 | this.classFolder = classFolder; 83 | return this; 84 | } 85 | 86 | @Override 87 | public JProxyConfig setScanPeriod(long scanPeriod) 88 | { 89 | if (scanPeriod == 0) throw new RelProxyException("scanPeriod cannot be zero"); 90 | this.scanPeriod = scanPeriod; 91 | return this; 92 | } 93 | 94 | @Override 95 | public JProxyConfig setCompilationOptions(Iterable compilationOptions) 96 | { 97 | this.compilationOptions = compilationOptions; 98 | return this; 99 | } 100 | 101 | @Override 102 | public JProxyConfig setJProxyDiagnosticsListener(JProxyDiagnosticsListener diagnosticsListener) 103 | { 104 | this.diagnosticsListener = diagnosticsListener; 105 | return this; 106 | } 107 | 108 | public FolderSourceList getFolderSourceList() 109 | { 110 | return folderSourceList; 111 | } 112 | 113 | public FolderSourceList getRequiredExtraJarPaths() 114 | { 115 | return requiredExtraJarPaths; 116 | } 117 | 118 | public JProxyInputSourceFileExcludedListener getJProxyInputSourceFileExcludedListener() 119 | { 120 | return excludedListener; 121 | } 122 | 123 | public JProxyCompilerListener getJProxyCompilerListener() 124 | { 125 | return compilerListener; 126 | } 127 | 128 | public String getClassFolder() 129 | { 130 | return classFolder; 131 | } 132 | 133 | public long getScanPeriod() 134 | { 135 | return scanPeriod; 136 | } 137 | 138 | public Iterable getCompilationOptions() 139 | { 140 | return compilationOptions; 141 | } 142 | 143 | public JProxyDiagnosticsListener getJProxyDiagnosticsListener() 144 | { 145 | return diagnosticsListener; 146 | } 147 | 148 | public boolean isTest() 149 | { 150 | return test; 151 | } 152 | 153 | public void setTest(boolean test) 154 | { 155 | this.test = test; 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /relproxy/src/main/java/com/innowhere/relproxy/jproxy/JProxy.java: -------------------------------------------------------------------------------- 1 | 2 | package com.innowhere.relproxy.jproxy; 3 | 4 | import com.innowhere.relproxy.impl.jproxy.JProxyConfigImpl; 5 | import com.innowhere.relproxy.impl.jproxy.JProxyDefaultImpl; 6 | 7 | /** 8 | * Is the class to create Java proxy objects based on Java objects and keep track of source code changes reloading classes when detected. 9 | * 10 | * @author Jose Maria Arranz Santamaria 11 | */ 12 | public class JProxy 13 | { 14 | /** 15 | * Creates a {@link JProxyConfig} object to be used to configure JProxy and {@link JProxyScriptEngineFactory}. 16 | * 17 | * @return a new configuration object. 18 | * @see #init(JProxyConfig) 19 | */ 20 | public static JProxyConfig createJProxyConfig() 21 | { 22 | return JProxyDefaultImpl.createJProxyConfig(); 23 | } 24 | 25 | /** 26 | * Initializes JProxy with the provided configuration object. 27 | * 28 | * @param config 29 | */ 30 | public static void init(JProxyConfig config) 31 | { 32 | JProxyDefaultImpl.initStatic((JProxyConfigImpl)config); 33 | } 34 | 35 | 36 | 37 | /** 38 | * Creates a proxy object using java.lang.reflect.Proxy based on the provided Java object and the class of the implemented Java interface. 39 | * 40 | *

This method is a simplification for a single interface (the most common case) of {@link #create(Object,Class[])} .

41 | * 42 | * @param the interface implemented by the original object and proxy object returned. 43 | * @param obj the original object to proxy. 44 | * @param clasz the class of the interface implemented by the original object and proxy object returned. 45 | * @return the java.lang.reflect.Proxy object associated or the original object when GProxy is disabled. 46 | */ 47 | public static T create(T obj,Class clasz) 48 | { 49 | return JProxyDefaultImpl.createStatic(obj, clasz); 50 | } 51 | 52 | /** 53 | * Creates a proxy object using java.lang.reflect.Proxy based on the provided Java object and the classes of the implemented Java interfaces. 54 | * 55 | *

If JProxy has been configured and is enabled this method returns a java.lang.reflect.Proxy object implementing instead of 56 | * the original object provided. Methods called in proxy object are received by JProxy and forwarded to the original object, if source code 57 | * managed by JProxy has been changed, the class of the original object is reloaded based on the new source and the original object 58 | * is recreated with the new class and fields are re-set in the new object, then the method is called on the new original object.

59 | * 60 | *

If JProxy is disabled returns the original object provided with no performance penalty.

61 | * 62 | * @param obj the original object to proxy. 63 | * @param classes the classes of the interfaces implemented by the original object and proxy object returned. 64 | * @return the java.lang.reflect.Proxy object associated or the original object when JProxy is disabled. 65 | */ 66 | public static Object create(Object obj,Class[] classes) 67 | { 68 | return JProxyDefaultImpl.createStatic(obj, classes); 69 | } 70 | 71 | /** 72 | * Informs whether JProxy is configured and enabled. 73 | * 74 | * @return true if enabled. 75 | */ 76 | public static boolean isEnabled() 77 | { 78 | return JProxyDefaultImpl.isEnabledStatic(); 79 | } 80 | 81 | /** 82 | * Informs whether JProxy is enabled and started (timed checking for changes). 83 | * 84 | * @return true if running. 85 | */ 86 | public static boolean isRunning() 87 | { 88 | return JProxyDefaultImpl.isRunningStatic(); 89 | } 90 | 91 | /** 92 | * Stops source code periodic change detection. 93 | * 94 | *

Periodicity of change detection is defined by {@link JProxyConfig#setScanPeriod(long)}

95 | * 96 | * @return true if source change detection has been stopped, false if it is already stopped or JProxy is not enabled or initialized. 97 | * @see #stop() 98 | */ 99 | public static boolean stop() 100 | { 101 | return JProxyDefaultImpl.stopStatic(); 102 | } 103 | 104 | /** 105 | * Starts source code periodic change detection. 106 | * 107 | *

Periodicity of change detection is defined by {@link JProxyConfig#setScanPeriod(long)}.

108 | * 109 | *

By default when JProxy is initialized and enabled.

110 | * 111 | * @return true if source change detection has been started again, false if it is already started or cannot start because JProxy is not enabled or initialized or scan period is not positive. 112 | * @see #start() 113 | */ 114 | public static boolean start() 115 | { 116 | return JProxyDefaultImpl.startStatic(); 117 | } 118 | } 119 | --------------------------------------------------------------------------------