Skip to content

Commit dbe48a6

Browse files
committed
Junit
1 parent a2f5c55 commit dbe48a6

File tree

5 files changed

+110
-139
lines changed

5 files changed

+110
-139
lines changed

src/main/java/com/sillelien/jas/RelProxyException.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
public class RelProxyException extends RuntimeException {
2727
/**
2828
* Constructs a new exception with the specified message and cause.
29-
* <p>
3029
* <p>Parameters are passed to the super constructor.</p>
3130
*
3231
* @param message the detail message
@@ -38,7 +37,6 @@ public RelProxyException(@NotNull String message, @NotNull Throwable cause) {
3837

3938
/**
4039
* Constructs a new exception with the specified message.
41-
* <p>
4240
* <p>Parameter is passed to the super constructor.</p>
4341
*
4442
* @param message the detail message
@@ -49,7 +47,6 @@ public RelProxyException(@NotNull String message) {
4947

5048
/**
5149
* Constructs a new exception with the specified cause.
52-
* <p>
5350
* <p>Parameter is passed to the super constructor.</p>
5451
*
5552
* @param cause the cause

src/main/java/com/sillelien/jas/RelProxyOnReloadListener.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424

2525
/**
2626
* Is the interface needed to register a class reload listener.
27-
* <p>
2827
* <p>An object implementing this interface can optionally be registered on RelProxy to listen when the method of a proxy object has been called
2928
* 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).
3029
* </p>
3130
*
3231
* @author Jose Maria Arranz Santamaria
3332
* @see JProxyConfig#setRelProxyOnReloadListener(RelProxyOnReloadListener)
34-
* @see com.sillelien.dollar.relproxy.gproxy.GProxyConfig#setRelProxyOnReloadListener(RelProxyOnReloadListener)
3533
*/
3634
public interface RelProxyOnReloadListener {
3735
/**

src/main/java/com/sillelien/jas/jproxy/JProxy.java

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,8 @@
2828
* @author Jose Maria Arranz Santamaria
2929
*/
3030
public final class JProxy {
31-
/**
32-
* Creates a {@link JProxyConfig} object to be used to configure <code>JProxy</code> and {@link JProxyScriptEngineFactory}.
33-
*
34-
* @return a new configuration object.
35-
* @see #init(JProxyConfig)
36-
*/
37-
public static JProxyConfig createJProxyConfig() {
38-
return JProxyDefaultImpl.createJProxyConfig();
39-
}
40-
41-
/**
42-
* Initializes <code>JProxy</code> with the provided configuration object.
43-
*
44-
* @param config the configuration
45-
*/
46-
public static void init(@NotNull JProxyConfig config) {
47-
JProxyDefaultImpl.initStatic((JProxyConfigImpl) config);
48-
}
49-
50-
5131
/**
5232
* Creates a proxy object using <code>java.lang.reflect.Proxy</code> based on the provided Java object and the class of the implemented Java interface.
53-
* <p>
5433
* <p>This method is a simplification for a single interface (the most common case) of {@link #create(Object, Class[])} .</p>
5534
*
5635
* @param <T> the interface implemented by the original object and proxy object returned.
@@ -59,18 +38,16 @@ public static void init(@NotNull JProxyConfig config) {
5938
* @return the <code>java.lang.reflect.Proxy</code> object associated or the original object when <code>GProxy</code> is disabled.
6039
*/
6140
@Nullable
62-
public static <T> T create(@NotNull T obj, @NotNull Class<T> clasz) {
41+
public static <T> T create(@NotNull T obj, @NotNull Class<T> clasz) {
6342
return JProxyDefaultImpl.createStatic(obj, clasz);
6443
}
6544

6645
/**
6746
* Creates a proxy object using <code>java.lang.reflect.Proxy</code> based on the provided Java object and the classes of the implemented Java interfaces.
68-
* <p>
6947
* <p>If <code>JProxy</code> has been configured and is enabled this method returns a <code>java.lang.reflect.Proxy</code> object implementing instead of
7048
* the original object provided. Methods called in proxy object are received by <code>JProxy</code> and forwarded to the original object, if source code
7149
* managed by <code>JProxy</code> has been changed, the class of the original object is reloaded based on the new source and the original object
7250
* 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.</p>
73-
* <p>
7451
* <p>If <code>JProxy</code> is disabled returns the original object provided with no performance penalty.</p>
7552
*
7653
* @param obj the original object to proxy.
@@ -82,6 +59,25 @@ public static Object create(@NotNull Object obj, @NotNull Class<?>[] classes) {
8259
return JProxyDefaultImpl.createStatic(obj, classes);
8360
}
8461

62+
/**
63+
* Creates a {@link JProxyConfig} object to be used to configure <code>JProxy</code> and {@link JProxyScriptEngineFactory}.
64+
*
65+
* @return a new configuration object.
66+
* @see #init(JProxyConfig)
67+
*/
68+
public static JProxyConfig createJProxyConfig() {
69+
return JProxyDefaultImpl.createJProxyConfig();
70+
}
71+
72+
/**
73+
* Initializes <code>JProxy</code> with the provided configuration object.
74+
*
75+
* @param config the configuration
76+
*/
77+
public static void init(@NotNull JProxyConfig config) {
78+
JProxyDefaultImpl.initStatic((JProxyConfigImpl) config);
79+
}
80+
8581
/**
8682
* Informs whether <code>JProxy</code> is configured and enabled.
8783
*
@@ -100,23 +96,9 @@ public static boolean isRunning() {
10096
return JProxyDefaultImpl.isRunningStatic();
10197
}
10298

103-
/**
104-
* Stops source code periodic change detection.
105-
* <p>
106-
* <p>Periodicity of change detection is defined by {@link JProxyConfig#setScanPeriod(long)}</p>
107-
*
108-
* @return true if source change detection has been stopped, false if it is already stopped or <code>JProxy</code> is not enabled or initialized.
109-
* @see #stop()
110-
*/
111-
public static boolean stop() {
112-
return JProxyDefaultImpl.stopStatic();
113-
}
114-
11599
/**
116100
* Starts source code periodic change detection.
117-
* <p>
118101
* <p>Periodicity of change detection is defined by {@link JProxyConfig#setScanPeriod(long)}.</p>
119-
* <p>
120102
* <p>By default when <code>JProxy</code> is initialized and enabled.</p>
121103
*
122104
* @return true if source change detection has been started again, false if it is already started or cannot start because <code>JProxy</code> is not enabled or initialized or scan period is not positive.
@@ -125,4 +107,15 @@ public static boolean stop() {
125107
public static boolean start() {
126108
return JProxyDefaultImpl.startStatic();
127109
}
110+
111+
/**
112+
* Stops source code periodic change detection.
113+
* <p>Periodicity of change detection is defined by {@link JProxyConfig#setScanPeriod(long)}</p>
114+
*
115+
* @return true if source change detection has been stopped, false if it is already stopped or <code>JProxy</code> is not enabled or initialized.
116+
* @see #stop()
117+
*/
118+
public static boolean stop() {
119+
return JProxyDefaultImpl.stopStatic();
120+
}
128121
}

src/main/java/com/sillelien/jas/jproxy/JProxyConfig.java

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,30 @@
3131
* @see JProxyScriptEngine#init(JProxyConfig)
3232
*/
3333
public interface JProxyConfig {
34+
/**
35+
* Sets the folder where to save .class files result of recompiling source code changed.
36+
* <p>This setting is optional and the folder must be included in Java classpath because the objective is to avoid recompiling.</p>
37+
* <p>Be careful when executing several Java scripts in the same time and source code has been changed, some file write collisions may happen.</p>
38+
*
39+
* @param classFolder the folder where to save .class files. By default is null (not defined, .class files are not saved).
40+
* @return this object for flow API use.
41+
*/
42+
@NotNull
43+
JProxyConfig setClassFolder(@Nullable String classFolder);
44+
45+
/**
46+
* Sets the compilation options to be provided to the compiler built-in in JDK like <code>JavaCompiler.getTask()</code> method and the same you would provide to javac.
47+
* <p>Example of compilation options:</p>
48+
* <p><code>Iterable&lt;String&gt; compilationOptions = Arrays.asList(new String[]{"-source","1.6","-target","1.6"});</code></p>
49+
*
50+
* @param compilationOptions compilation options passed to the internal compiler. By default is null (default compiler settings).
51+
* @return this object for flow API use.
52+
*/
53+
@NotNull
54+
JProxyConfig setCompilationOptions(@NotNull Iterable<String> compilationOptions);
55+
3456
/**
3557
* Sets whether automatic detection of source code changes is enabled.
36-
* <p>
3758
* <p>If set to false other configuration parameters are ignored, there is no automatic source code change detection/reload and original objects are returned
3859
* instead of proxies, performance penalty is zero. Setting to false is recommended in production whether source code change detection/reload is not required.</p>
3960
*
@@ -43,21 +64,13 @@ public interface JProxyConfig {
4364
@NotNull
4465
JProxyConfig setEnabled(boolean enabled);
4566

46-
/**
47-
* Sets the class reload listener.
48-
*
49-
* @param relListener the class reload listener. By default is null.
50-
* @return this object for flow API use.
51-
*/
5267
@NotNull
53-
JProxyConfig setRelProxyOnReloadListener(@NotNull RelProxyOnReloadListener relListener);
68+
JProxyConfig setImports(@NotNull List<String> imports);
5469

5570
/**
5671
* Defines the folder root to locate source code Java files.
57-
* <p>
5872
* <p>Structure of the source tree must be the same as a JavaSE application, the only difference is shell scripts, shell scripts must be
5973
* located on the top level of the source tree (default package) and file extension is not required .</p>
60-
* <p>
6174
* <p>Setting some input path is required.</p>
6275
*
6376
* @param inputPath the folder root to locate source code Java files.
@@ -69,10 +82,8 @@ public interface JProxyConfig {
6982

7083
/**
7184
* Defines the folder roots to locate source code Java files.
72-
* <p>
7385
* <p>Structure of the source tree must be the same as a JavaSE application, the only difference is shell scripts, shell scripts must be
7486
* located on the top level of the source tree (default package).</p>
75-
* <p>
7687
* <p>Setting some input path is required.</p>
7788
*
7889
* @param inputPaths the folder roots to locate source code Java files.
@@ -83,31 +94,6 @@ public interface JProxyConfig {
8394
@NotNull
8495
JProxyConfig setInputPaths(@NotNull String[] inputPaths);
8596

86-
/**
87-
* Defines the extra required jars providing the absolute paths to them.
88-
* <p>
89-
* <p>In some circunstances RelProxy is not able to find some required classes by the compiler because the jar containing them is not found in spite of existing in classpath,
90-
* the reason may be due some conflictive configuration of <code>META-INF/MANIFEST.MF</code> of the jar. This problem can be fixed modifying accordingly the <code>META-INF/MANIFEST.MF</code>
91-
* file, or alternatively providing the paths to the conflictive jars calling to this method, in this case RelProxy will find the required classes searching on them by using brute force
92-
* avoiding the jar modification (not recommended).
93-
* </p>
94-
*
95-
* @param inputJarPaths the paths of the required extra jars.
96-
* @return this object for flow API use.
97-
* @see #setInputPaths(String[])
98-
*/
99-
@NotNull
100-
JProxyConfig setRequiredExtraJarPaths(@NotNull String[] inputJarPaths);
101-
102-
/**
103-
* Registers the listener implementing excluding rules to filter source files not to be part of the hot reloading system in spite of included in input paths.
104-
*
105-
* @param listener the listener. By default is null.
106-
* @return this object for flow API use.
107-
*/
108-
@NotNull
109-
JProxyConfig setJProxyInputSourceFileExcludedListener(@Nullable JProxyInputSourceFileExcludedListener listener);
110-
11197
/**
11298
* Registers the listener for monitoring files being compiled.
11399
*
@@ -117,49 +103,9 @@ public interface JProxyConfig {
117103
@NotNull
118104
JProxyConfig setJProxyCompilerListener(@NotNull JProxyCompilerListener listener);
119105

120-
121-
/**
122-
* Sets the folder where to save .class files result of recompiling source code changed.
123-
* <p>
124-
* <p>This setting is optional and the folder must be included in Java classpath because the objective is to avoid recompiling.</p>
125-
* <p>
126-
* <p>Be careful when executing several Java scripts in the same time and source code has been changed, some file write collisions may happen.</p>
127-
*
128-
* @param classFolder the folder where to save .class files. By default is null (not defined, .class files are not saved).
129-
* @return this object for flow API use.
130-
*/
131-
@NotNull
132-
JProxyConfig setClassFolder(@Nullable String classFolder);
133-
134-
/**
135-
* Sets the delay between source code change checking.
136-
* <p>
137-
* <p>If this value is set to 0 or negative, no periodic source code change detection is executed and only compilation on the fly happens in load time,
138-
* this is valid for one shot scripts but it has no sense when using proxies.
139-
*
140-
* @param scanPeriod the delay between source code change checking.
141-
* @return this object for flow API use.
142-
*/
143-
@NotNull
144-
JProxyConfig setScanPeriod(long scanPeriod);
145-
146-
/**
147-
* Sets the compilation options to be provided to the compiler built-in in JDK like <code>JavaCompiler.getTask()</code> method and the same you would provide to javac.
148-
* <p>
149-
* <p>Example of compilation options:</p>
150-
* <p><code>Iterable&lt;String&gt; compilationOptions = Arrays.asList(new String[]{"-source","1.6","-target","1.6"});</code></p>
151-
*
152-
* @param compilationOptions compilation options passed to the internal compiler. By default is null (default compiler settings).
153-
* @return this object for flow API use.
154-
*/
155-
@NotNull
156-
JProxyConfig setCompilationOptions(@NotNull Iterable<String> compilationOptions);
157-
158106
/**
159107
* Sets the diagnostic listener to capture compilation errors and warnings thrown by the internal compiler.
160-
* <p>
161108
* <p>The following is an example similar to the default behavior when this listener is not specified:</p>
162-
* <p>
163109
* <pre>
164110
* JProxyDiagnosticsListener diagnosticsListener = new JProxyDiagnosticsListener()
165111
* {
@@ -192,10 +138,49 @@ public interface JProxyConfig {
192138
@NotNull
193139
JProxyConfig setJProxyDiagnosticsListener(@NotNull JProxyDiagnosticsListener diagnosticsListener);
194140

141+
/**
142+
* Registers the listener implementing excluding rules to filter source files not to be part of the hot reloading system in spite of included in input paths.
143+
*
144+
* @param listener the listener. By default is null.
145+
* @return this object for flow API use.
146+
*/
147+
@NotNull
148+
JProxyConfig setJProxyInputSourceFileExcludedListener(@Nullable JProxyInputSourceFileExcludedListener listener);
149+
150+
/**
151+
* Sets the class reload listener.
152+
*
153+
* @param relListener the class reload listener. By default is null.
154+
* @return this object for flow API use.
155+
*/
156+
@NotNull
157+
JProxyConfig setRelProxyOnReloadListener(@NotNull RelProxyOnReloadListener relListener);
195158

159+
/**
160+
* Defines the extra required jars providing the absolute paths to them.
161+
* <p>In some circunstances RelProxy is not able to find some required classes by the compiler because the jar containing them is not found in spite of existing in classpath,
162+
* the reason may be due some conflictive configuration of <code>META-INF/MANIFEST.MF</code> of the jar. This problem can be fixed modifying accordingly the <code>META-INF/MANIFEST.MF</code>
163+
* file, or alternatively providing the paths to the conflictive jars calling to this method, in this case RelProxy will find the required classes searching on them by using brute force
164+
* avoiding the jar modification (not recommended).
165+
* </p>
166+
*
167+
* @param inputJarPaths the paths of the required extra jars.
168+
* @return this object for flow API use.
169+
* @see #setInputPaths(String[])
170+
*/
196171
@NotNull
197-
JProxyConfig setImports(@NotNull List<String> imports);
172+
JProxyConfig setRequiredExtraJarPaths(@NotNull String[] inputJarPaths);
198173

174+
/**
175+
* Sets the delay between source code change checking.
176+
* <p>If this value is set to 0 or negative, no periodic source code change detection is executed and only compilation on the fly happens in load time,
177+
* this is valid for one shot scripts but it has no sense when using proxies.
178+
*
179+
* @param scanPeriod the delay between source code change checking.
180+
* @return this object for flow API use.
181+
*/
182+
@NotNull
183+
JProxyConfig setScanPeriod(long scanPeriod);
199184

200185
@NotNull
201186
JProxyConfig setStaticImports(@NotNull List<String> staticImports);

0 commit comments

Comments
 (0)