From: vasary.daniel Date: Mon, 9 Aug 2021 09:25:48 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=4f4ab8aff45a99932ab5dd0ec7b2bc7c79245847;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32293 --- diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java index 470e617f..b3fe0976 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java @@ -1,5 +1,6 @@ package user.jobengine.server; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -12,9 +13,11 @@ import java.nio.file.Paths; import java.security.CodeSource; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Stream; @@ -63,15 +66,22 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { } } - private GroovyClassLoader createGroovyClassLoader(URLClassLoader stepsClassLoader) throws FileNotFoundException { + private GroovyClassLoader createGroovyClassLoader(URLClassLoader stepsClassLoader, String excludeFileName) + throws FileNotFoundException { String stepsDir = systemConfig.getConfig(DIR_STEPS); + + Set sharedFiles = getJavaFileList(Paths.get(stepsDir, "shared"), excludeFileName); + Set libFiles = getJavaFileList(Paths.get(stepsDir), excludeFileName); + libFiles.addAll(sharedFiles); + GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader) { @Override protected CompilationUnit createCompilationUnit(CompilerConfiguration config, CodeSource source) { CompilationUnit result = new CompilationUnit(config, source, this); - loadStepSources(result, Paths.get(stepsDir, "shared")); - loadStepSources(result, Paths.get(stepsDir)); + libFiles.forEach(f -> result.addSource(f)); + //loadStepSources(result, Paths.get(stepsDir, "shared")); + //loadStepSources(result, Paths.get(stepsDir)); return result; } @@ -84,7 +94,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { public IJobStep createJobStep(String stepUnitName) throws Exception { IJobStep result = null; - boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy"); + boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") + || stepUnitName.toLowerCase().endsWith(".groovy"); logger.info("Looking for {} step classloader requirement", stepUnitName); if (stepsClassLoader == null) @@ -100,7 +111,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { if (isGroovyClass) { logger.info("Creating GroovyClassLoader"); - GroovyClassLoader gcl = createGroovyClassLoader(stepsClassLoader); + GroovyClassLoader gcl = createGroovyClassLoader(stepsClassLoader, stepUnitName); stepClass = (Class) loadClassFromSourceCode(gcl, stepUnitName); } else stepClass = (Class) stepsClassLoader.loadClass(stepUnitName); @@ -258,7 +269,8 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { int newMaxConcurrent = executor.getMaxConcurrent(); if (currentMaxConcurrent != newMaxConcurrent) { stepExecutor.setMaxConcurrent(newMaxConcurrent); - logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, newMaxConcurrent); + logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, + newMaxConcurrent); } } @@ -297,9 +309,28 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { }); } + private Set getJavaFileList(Path path, String excludeFileName) { + Set result = new HashSet<>(); + if (path.toFile().isDirectory()) { + Predicate filter = file -> !Files.isDirectory(file) + && file.getFileName().toString().endsWith(".java"); + try (Stream stream = Files.list(path)) { + stream.filter(filter).forEach(p -> { + if (!excludeFileName.equals(p.getFileName().toString())) + result.add(p.toFile()); + + }); + } catch (Exception e) { + } + + } + return result; + } + private void loadStepSources(CompilationUnit compilationUnit, Path path) { if (path.toFile().isDirectory()) { - Predicate filter = file -> !Files.isDirectory(file) && file.getFileName().toString().endsWith(".java"); + Predicate filter = file -> !Files.isDirectory(file) + && file.getFileName().toString().endsWith(".java"); try (Stream stream = Files.list(path)) { stream.filter(filter).forEach(p -> { compilationUnit.addSource(p.toFile());