Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
laminba2003 committed Feb 17, 2021
1 parent a03d78b commit db4ecf1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/main/java/org/gservlet/ContainerManager.java
Expand Up @@ -134,8 +134,7 @@ public void init(String directory, List<ScriptListener> listeners) throws Servle
*
*/
protected void loadScripts(File folder) throws ServletException, ScriptException {
File[] files = folder.listFiles();
for (File file : files) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
register(scriptManager.createObject(file));
} else {
Expand Down Expand Up @@ -314,13 +313,13 @@ public void onModified(FileEvent event) {
*
* Processes a script file
*
* @param script the script file
* @param file the given file
*
*/
protected void process(File script) {
protected void process(File file) {
try {
logger.log(Level.INFO, "processing script {0}", script.getName());
process(scriptManager.createObject(script));
logger.log(Level.INFO, "processing script {0}", file.getName());
process(scriptManager.createObject(file));
} catch (Exception e) {
logger.log(Level.SEVERE, "exception when reloading script", e);
}
Expand Down Expand Up @@ -409,8 +408,7 @@ protected void reloadFilter(AbstractFilter filter) throws ServletException {
*
*/
protected void reloadScripts(File folder) throws ServletException, ScriptException {
File[] files = folder.listFiles();
for (File file : files) {
for (File file : folder.listFiles()) {
if (file.isFile()) {
Object object = scriptManager.createObject(file);
if (isServlet(object) || isFilter(object) || isListener(object)) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/gservlet/ScriptManager.java
Expand Up @@ -98,14 +98,14 @@ public ScriptManager(File folder) throws ScriptException {
*
* Creates an object from a groovy script file
*
* @param script the groovy script file
* @param file the groovy script file
* @return the instantiated object
* @throws ScriptException the ScriptException
*
*/
public Object createObject(File script) throws ScriptException {
public Object createObject(File file) throws ScriptException {
try {
Class<?> clazz = loadClass(script);
Class<?> clazz = loadClass(file);
if (!clazz.isInterface() && Stream.of(clazz.getConstructors()).anyMatch(c -> c.getParameterCount() == 0)) {
Object object = clazz.getConstructor().newInstance();
listeners.forEach(listener -> listener.onCreated(object));
Expand Down

0 comments on commit db4ecf1

Please sign in to comment.