package user.jobengine.server;\r
\r
+import java.io.File;\r
import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.InputStream;\r
import java.security.CodeSource;\r
import java.util.ArrayList;\r
import java.util.Collections;\r
+import java.util.HashSet;\r
import java.util.LinkedHashMap;\r
import java.util.List;\r
import java.util.Map;\r
+import java.util.Set;\r
import java.util.function.Consumer;\r
import java.util.function.Predicate;\r
import java.util.stream.Stream;\r
}\r
}\r
\r
- private GroovyClassLoader createGroovyClassLoader(URLClassLoader stepsClassLoader) throws FileNotFoundException {\r
+ private GroovyClassLoader createGroovyClassLoader(URLClassLoader stepsClassLoader, String excludeFileName)\r
+ throws FileNotFoundException {\r
String stepsDir = systemConfig.getConfig(DIR_STEPS);\r
+\r
+ Set<File> sharedFiles = getJavaFileList(Paths.get(stepsDir, "shared"), excludeFileName);\r
+ Set<File> libFiles = getJavaFileList(Paths.get(stepsDir), excludeFileName);\r
+ libFiles.addAll(sharedFiles);\r
+\r
GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader) {\r
\r
@Override\r
protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) {\r
CompilationUnit result = new CompilationUnit(config, source, this);\r
- loadStepSources(result, Paths.get(stepsDir, "shared"));\r
- loadStepSources(result, Paths.get(stepsDir));\r
+ libFiles.forEach(f -> result.addSource(f));\r
+ //loadStepSources(result, Paths.get(stepsDir, "shared"));\r
+ //loadStepSources(result, Paths.get(stepsDir));\r
return result;\r
}\r
\r
public IJobStep createJobStep(String stepUnitName) throws Exception {\r
IJobStep result = null;\r
\r
- boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy");\r
+ boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java")\r
+ || stepUnitName.toLowerCase().endsWith(".groovy");\r
logger.info("Looking for {} step classloader requirement", stepUnitName);\r
\r
if (stepsClassLoader == null)\r
\r
if (isGroovyClass) {\r
logger.info("Creating GroovyClassLoader");\r
- GroovyClassLoader gcl = createGroovyClassLoader(stepsClassLoader);\r
+ GroovyClassLoader gcl = createGroovyClassLoader(stepsClassLoader, stepUnitName);\r
stepClass = (Class<IJobStep>) loadClassFromSourceCode(gcl, stepUnitName);\r
} else\r
stepClass = (Class<IJobStep>) stepsClassLoader.loadClass(stepUnitName);\r
int newMaxConcurrent = executor.getMaxConcurrent();\r
if (currentMaxConcurrent != newMaxConcurrent) {\r
stepExecutor.setMaxConcurrent(newMaxConcurrent);\r
- logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, newMaxConcurrent);\r
+ logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent,\r
+ newMaxConcurrent);\r
}\r
}\r
\r
});\r
}\r
\r
+ private Set<File> getJavaFileList(Path path, String excludeFileName) {\r
+ Set<File> result = new HashSet<>();\r
+ if (path.toFile().isDirectory()) {\r
+ Predicate<Path> filter = file -> !Files.isDirectory(file)\r
+ && file.getFileName().toString().endsWith(".java");\r
+ try (Stream<Path> stream = Files.list(path)) {\r
+ stream.filter(filter).forEach(p -> {\r
+ if (!excludeFileName.equals(p.getFileName().toString()))\r
+ result.add(p.toFile());\r
+\r
+ });\r
+ } catch (Exception e) {\r
+ }\r
+\r
+ }\r
+ return result;\r
+ }\r
+\r
private void loadStepSources(CompilationUnit compilationUnit, Path path) {\r
if (path.toFile().isDirectory()) {\r
- Predicate<Path> filter = file -> !Files.isDirectory(file) && file.getFileName().toString().endsWith(".java");\r
+ Predicate<Path> filter = file -> !Files.isDirectory(file)\r
+ && file.getFileName().toString().endsWith(".java");\r
try (Stream<Path> stream = Files.list(path)) {\r
stream.filter(filter).forEach(p -> {\r
compilationUnit.addSource(p.toFile());\r