git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorvasary.daniel <TFS\vasary.daniel>
Mon, 9 Aug 2021 09:25:48 +0000 (09:25 +0000)
committervasary.daniel <TFS\vasary.daniel>
Mon, 9 Aug 2021 09:25:48 +0000 (09:25 +0000)
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java

index 470e617f5e2277ab39d23f86aa7e5b4f90cd5d3b..b3fe09767bc8380ab3e195ab7d59ebab3cab9a84 100644 (file)
@@ -1,5 +1,6 @@
 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
@@ -12,9 +13,11 @@ import java.nio.file.Paths;
 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
@@ -63,15 +66,22 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                }\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
@@ -84,7 +94,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        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
@@ -100,7 +111,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
 \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
@@ -258,7 +269,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                                                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
@@ -297,9 +309,28 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                });\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