test_class.declarator: MOCK_COMPILER = mock(ScriptArchiveCompiler.class)
test_class.modifier: private final static
test_class.original_string: private final static ScriptArchiveCompiler MOCK_COMPILER = mock(ScriptArchiveCompiler.class);
test_class.type: ScriptArchiveCompiler
test_class.var_name: MOCK_COMPILER
test_class.file: nicobar-core/src/test/java/com/netflix/nicobar/core/module/ScriptModuleLoaderTest.java
test_class.identifier: ScriptModuleLoaderTest
test_case.body: @Test
      public void testBadModuleSpec() throws Exception {
          final URL badJarUrl = new URL("file:///somepath/myMadJarName.jar");
          ScriptArchive badScriptArchive = new TestDependecyScriptArchive(new ScriptModuleSpec.Builder("A").build(), 1) {
              @Override
              public URL getRootUrl() {
                  return badJarUrl;
              }
          };
          ScriptModuleListener mockListener = createMockListener();
          ScriptModuleLoader moduleLoader = new ScriptModuleLoader.Builder().addListener(mockListener).build();
          moduleLoader.updateScriptArchives(Collections.singleton(badScriptArchive));
          verify(mockListener).archiveRejected(Mockito.same(badScriptArchive), Mockito.same(ArchiveRejectedReason.ARCHIVE_IO_EXCEPTION), Mockito.any(Exception.class));
          verifyNoMoreInteractions(mockListener);
      }
test_case.class_method_signature: ScriptModuleLoaderTest.testBadModuleSpec()
test_case.full_signature: @Test public void testBadModuleSpec()
test_case.identifier: testBadModuleSpec
test_case.invocations: build createMockListener build addListener updateScriptArchives singleton archiveRejected verify same same any verifyNoMoreInteractions
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testBadModuleSpec()
focal_class.declarator: logger = LoggerFactory.getLogger(ScriptModuleLoader.class)
focal_class.modifier: private final static
focal_class.original_string: private final static Logger logger = LoggerFactory.getLogger(ScriptModuleLoader.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: loadedScriptModules = new ConcurrentHashMap<ModuleId, ScriptModule>()
focal_class.modifier: protected final
focal_class.original_string: protected final Map<ModuleId, ScriptModule> loadedScriptModules = new ConcurrentHashMap<ModuleId, ScriptModule>();
focal_class.type: Map<ModuleId, ScriptModule>
focal_class.var_name: loadedScriptModules
focal_class.declarator: compilerClassLoaders = new ConcurrentHashMap<String, ClassLoader>()
focal_class.modifier: protected final
focal_class.original_string: protected final Map<String, ClassLoader> compilerClassLoaders = new ConcurrentHashMap<String, ClassLoader>();
focal_class.type: Map<String, ClassLoader>
focal_class.var_name: compilerClassLoaders
focal_class.declarator: pluginSpecs
focal_class.modifier: protected final
focal_class.original_string: protected final Set<ScriptCompilerPluginSpec> pluginSpecs;
focal_class.type: Set<ScriptCompilerPluginSpec>
focal_class.var_name: pluginSpecs
focal_class.declarator: appClassLoader
focal_class.modifier: protected final
focal_class.original_string: protected final ClassLoader appClassLoader;
focal_class.type: ClassLoader
focal_class.var_name: appClassLoader
focal_class.declarator: appPackagePaths
focal_class.modifier: protected final
focal_class.original_string: protected final Set<String> appPackagePaths;
focal_class.type: Set<String>
focal_class.var_name: appPackagePaths
focal_class.declarator: compilers = new ArrayList<ScriptArchiveCompiler>()
focal_class.modifier: protected final
focal_class.original_string: protected final List<ScriptArchiveCompiler> compilers = new ArrayList<ScriptArchiveCompiler>();
focal_class.type: List<ScriptArchiveCompiler>
focal_class.var_name: compilers
focal_class.declarator: compilationRootDir
focal_class.modifier: protected final
focal_class.original_string: protected final Path compilationRootDir;
focal_class.type: Path
focal_class.var_name: compilationRootDir
focal_class.declarator: listeners =
          Collections.newSetFromMap(new ConcurrentHashMap<ScriptModuleListener, Boolean>())
focal_class.modifier: protected final
focal_class.original_string: protected final Set<ScriptModuleListener> listeners =
          Collections.newSetFromMap(new ConcurrentHashMap<ScriptModuleListener, Boolean>());
focal_class.type: Set<ScriptModuleListener>
focal_class.var_name: listeners
focal_class.declarator: jbossModuleLoader
focal_class.modifier: protected final
focal_class.original_string: protected final JBossModuleLoader jbossModuleLoader;
focal_class.type: JBossModuleLoader
focal_class.var_name: jbossModuleLoader
focal_class.file: nicobar-core/src/main/java/com/netflix/nicobar/core/module/ScriptModuleLoader.java
focal_class.identifier: ScriptModuleLoader
focal_class.class_method_signature: ScriptModuleLoader.ScriptModuleLoader(final Set<ScriptCompilerPluginSpec> pluginSpecs,
              final ClassLoader appClassLoader,
              final Set<String> appPackagePaths,
              final Set<ScriptModuleListener> listeners,
              final Path compilationRootDir)
focal_class.full_signature: protected  ScriptModuleLoader(final Set<ScriptCompilerPluginSpec> pluginSpecs,
              final ClassLoader appClassLoader,
              final Set<String> appPackagePaths,
              final Set<ScriptModuleListener> listeners,
              final Path compilationRootDir)
focal_class.identifier: ScriptModuleLoader
focal_class.modifiers: protected
focal_class.parameters: (final Set<ScriptCompilerPluginSpec> pluginSpecs,
              final ClassLoader appClassLoader,
              final Set<String> appPackagePaths,
              final Set<ScriptModuleListener> listeners,
              final Path compilationRootDir)
focal_class.signature:  ScriptModuleLoader(final Set<ScriptCompilerPluginSpec> pluginSpecs,
              final ClassLoader appClassLoader,
              final Set<String> appPackagePaths,
              final Set<ScriptModuleListener> listeners,
              final Path compilationRootDir)
focal_class.class_method_signature: ScriptModuleLoader.updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)
focal_class.full_signature: public synchronized void updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)
focal_class.identifier: updateScriptArchives
focal_class.modifiers: public synchronized
focal_class.parameters: (Set<? extends ScriptArchive> candidateArchives)
focal_class.return: void
focal_class.signature: void updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)
focal_class.class_method_signature: ScriptModuleLoader.createModuleSpec(ScriptArchive archive,
              ModuleIdentifier moduleId,
              Map<ModuleId, ModuleIdentifier> moduleIdMap,
              Path moduleCompilationRoot)
focal_class.full_signature: protected ModuleSpec createModuleSpec(ScriptArchive archive,
              ModuleIdentifier moduleId,
              Map<ModuleId, ModuleIdentifier> moduleIdMap,
              Path moduleCompilationRoot)
focal_class.identifier: createModuleSpec
focal_class.modifiers: protected
focal_class.parameters: (ScriptArchive archive,
              ModuleIdentifier moduleId,
              Map<ModuleId, ModuleIdentifier> moduleIdMap,
              Path moduleCompilationRoot)
focal_class.return: ModuleSpec
focal_class.signature: ModuleSpec createModuleSpec(ScriptArchive archive,
              ModuleIdentifier moduleId,
              Map<ModuleId, ModuleIdentifier> moduleIdMap,
              Path moduleCompilationRoot)
focal_class.class_method_signature: ScriptModuleLoader.compileModule(Module module, Path moduleCompilationRoot)
focal_class.full_signature: protected void compileModule(Module module, Path moduleCompilationRoot)
focal_class.identifier: compileModule
focal_class.modifiers: protected
focal_class.parameters: (Module module, Path moduleCompilationRoot)
focal_class.return: void
focal_class.signature: void compileModule(Module module, Path moduleCompilationRoot)
focal_class.class_method_signature: ScriptModuleLoader.addCompilerPlugin(ScriptCompilerPluginSpec pluginSpec)
focal_class.full_signature: public synchronized void addCompilerPlugin(ScriptCompilerPluginSpec pluginSpec)
focal_class.identifier: addCompilerPlugin
focal_class.modifiers: public synchronized
focal_class.parameters: (ScriptCompilerPluginSpec pluginSpec)
focal_class.return: void
focal_class.signature: void addCompilerPlugin(ScriptCompilerPluginSpec pluginSpec)
focal_class.class_method_signature: ScriptModuleLoader.removeScriptModule(ModuleId scriptModuleId)
focal_class.full_signature: public synchronized void removeScriptModule(ModuleId scriptModuleId)
focal_class.identifier: removeScriptModule
focal_class.modifiers: public synchronized
focal_class.parameters: (ModuleId scriptModuleId)
focal_class.return: void
focal_class.signature: void removeScriptModule(ModuleId scriptModuleId)
focal_class.class_method_signature: ScriptModuleLoader.getScriptModule(String scriptModuleId)
focal_class.full_signature: @Nullable public ScriptModule getScriptModule(String scriptModuleId)
focal_class.identifier: getScriptModule
focal_class.modifiers: @Nullable public
focal_class.parameters: (String scriptModuleId)
focal_class.return: ScriptModule
focal_class.signature: ScriptModule getScriptModule(String scriptModuleId)
focal_class.class_method_signature: ScriptModuleLoader.getCompilerPluginClassLoader(String pluginModuleId)
focal_class.full_signature: @Nullable public ClassLoader getCompilerPluginClassLoader(String pluginModuleId)
focal_class.identifier: getCompilerPluginClassLoader
focal_class.modifiers: @Nullable public
focal_class.parameters: (String pluginModuleId)
focal_class.return: ClassLoader
focal_class.signature: ClassLoader getCompilerPluginClassLoader(String pluginModuleId)
focal_class.class_method_signature: ScriptModuleLoader.getScriptModule(ModuleId scriptModuleId)
focal_class.full_signature: @Nullable public ScriptModule getScriptModule(ModuleId scriptModuleId)
focal_class.identifier: getScriptModule
focal_class.modifiers: @Nullable public
focal_class.parameters: (ModuleId scriptModuleId)
focal_class.return: ScriptModule
focal_class.signature: ScriptModule getScriptModule(ModuleId scriptModuleId)
focal_class.class_method_signature: ScriptModuleLoader.getAllScriptModules()
focal_class.full_signature: public Map<ModuleId, ScriptModule> getAllScriptModules()
focal_class.identifier: getAllScriptModules
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: Map<ModuleId, ScriptModule>
focal_class.signature: Map<ModuleId, ScriptModule> getAllScriptModules()
focal_class.class_method_signature: ScriptModuleLoader.addListeners(Set<ScriptModuleListener> listeners)
focal_class.full_signature: public void addListeners(Set<ScriptModuleListener> listeners)
focal_class.identifier: addListeners
focal_class.modifiers: public
focal_class.parameters: (Set<ScriptModuleListener> listeners)
focal_class.return: void
focal_class.signature: void addListeners(Set<ScriptModuleListener> listeners)
focal_class.class_method_signature: ScriptModuleLoader.findCompilers(ScriptArchive archive)
focal_class.full_signature: protected List<ScriptArchiveCompiler> findCompilers(ScriptArchive archive)
focal_class.identifier: findCompilers
focal_class.modifiers: protected
focal_class.parameters: (ScriptArchive archive)
focal_class.return: List<ScriptArchiveCompiler>
focal_class.signature: List<ScriptArchiveCompiler> findCompilers(ScriptArchive archive)
focal_class.class_method_signature: ScriptModuleLoader.notifyModuleUpdate(@Nullable ScriptModule newModule, @Nullable ScriptModule oldModule)
focal_class.full_signature: protected void notifyModuleUpdate(@Nullable ScriptModule newModule, @Nullable ScriptModule oldModule)
focal_class.identifier: notifyModuleUpdate
focal_class.modifiers: protected
focal_class.parameters: (@Nullable ScriptModule newModule, @Nullable ScriptModule oldModule)
focal_class.return: void
focal_class.signature: void notifyModuleUpdate(@Nullable ScriptModule newModule, @Nullable ScriptModule oldModule)
focal_class.class_method_signature: ScriptModuleLoader.notifyArchiveRejected(ScriptArchive scriptArchive, ArchiveRejectedReason reason, @Nullable Throwable cause)
focal_class.full_signature: protected void notifyArchiveRejected(ScriptArchive scriptArchive, ArchiveRejectedReason reason, @Nullable Throwable cause)
focal_class.identifier: notifyArchiveRejected
focal_class.modifiers: protected
focal_class.parameters: (ScriptArchive scriptArchive, ArchiveRejectedReason reason, @Nullable Throwable cause)
focal_class.return: void
focal_class.signature: void notifyArchiveRejected(ScriptArchive scriptArchive, ArchiveRejectedReason reason, @Nullable Throwable cause)
focal_method.body: public synchronized void updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)  {
          Objects.requireNonNull(candidateArchives);
          long updateNumber = System.currentTimeMillis();
  
          // map script module id to archive to be compiled
          Map<ModuleId, ScriptArchive> archivesToCompile = new HashMap<ModuleId, ScriptArchive>(candidateArchives.size()*2);
  
          // create an updated mapping of the scriptModuleId to latest revisionId including the yet-to-be-compiled archives
          Map<ModuleId, ModuleIdentifier> oldRevisionIdMap = jbossModuleLoader.getLatestRevisionIds();
          Map<ModuleId, ModuleIdentifier> updatedRevisionIdMap = new HashMap<ModuleId, ModuleIdentifier>((oldRevisionIdMap.size()+candidateArchives.size())*2);
          updatedRevisionIdMap.putAll(oldRevisionIdMap);
  
          // Map of the scriptModuleId to it's updated set of dependencies
          Map<ModuleId, Set<ModuleId>> archiveDependencies = new HashMap<ModuleId, Set<ModuleId>>();
          for (ScriptArchive scriptArchive : candidateArchives) {
              ModuleId scriptModuleId = scriptArchive.getModuleSpec().getModuleId();
  
              // filter out archives that have a newer module already loaded
              long createTime = scriptArchive.getCreateTime();
              ScriptModule scriptModule = loadedScriptModules.get(scriptModuleId);
              long latestCreateTime = scriptModule != null ? scriptModule.getCreateTime() : 0;
              if (createTime < latestCreateTime) {
                  notifyArchiveRejected(scriptArchive, ArchiveRejectedReason.HIGHER_REVISION_AVAILABLE, null);
                  continue;
              }
  
              // create the new revisionIds that should be used for the linkages when the new modules
              // are defined.
              ModuleIdentifier newRevisionId = JBossModuleUtils.createRevisionId(scriptModuleId, updateNumber);
              updatedRevisionIdMap.put(scriptModuleId, newRevisionId);
  
              archivesToCompile.put(scriptModuleId, scriptArchive);
  
              // create a dependency map of the incoming archives so that we can later build a candidate graph
              archiveDependencies.put(scriptModuleId, scriptArchive.getModuleSpec().getModuleDependencies());
          }
  
          // create a dependency graph with the candidates swapped in in order to figure out the
          // order in which the candidates should be loaded
          DirectedGraph<ModuleId, DefaultEdge> candidateGraph = jbossModuleLoader.getModuleNameGraph();
          GraphUtils.swapVertices(candidateGraph, archiveDependencies);
  
          // iterate over the graph in reverse dependency order
          Set<ModuleId> leaves = GraphUtils.getLeafVertices(candidateGraph);
          while (!leaves.isEmpty()) {
              for (ModuleId scriptModuleId : leaves) {
                  ScriptArchive scriptArchive = archivesToCompile.get(scriptModuleId);
                  if (scriptArchive == null) {
                      continue;
                  }
                  ModuleSpec moduleSpec;
                  ModuleIdentifier candidateRevisionId = updatedRevisionIdMap.get(scriptModuleId);
                  Path modulePath = createModulePath(candidateRevisionId);
                  final Path moduleCompilationRoot = compilationRootDir.resolve(modulePath);
                  FileUtils.deleteQuietly(moduleCompilationRoot.toFile());
                  try {
                      Files.createDirectories(moduleCompilationRoot);
                  } catch (IOException ioe) {
                      notifyArchiveRejected(scriptArchive, ArchiveRejectedReason.ARCHIVE_IO_EXCEPTION, ioe);
                  }
  
                  try {
                     moduleSpec = createModuleSpec(scriptArchive, candidateRevisionId, updatedRevisionIdMap, moduleCompilationRoot);
                  } catch (ModuleLoadException e) {
                      logger.error("Exception loading archive " +
                          scriptArchive.getModuleSpec().getModuleId(), e);
                      notifyArchiveRejected(scriptArchive, ArchiveRejectedReason.ARCHIVE_IO_EXCEPTION, e);
                      continue;
                  }
  
                  // load and compile the module
                  jbossModuleLoader.addModuleSpec(moduleSpec);
                  Module jbossModule = null;
                  try {
                      jbossModule = jbossModuleLoader.loadModule(candidateRevisionId);
                      compileModule(jbossModule, moduleCompilationRoot);
  
                      // Now refresh the resource loaders for this module, and load the set of
                      // compiled classes and populate into the module's local class cache.
                      jbossModuleLoader.rescanModule(jbossModule);
  
                      final Set<String> classesToLoad = new LinkedHashSet<String>();
                      Files.walkFileTree(moduleCompilationRoot, new SimpleFileVisitor<Path>() {
                          public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                              String relativePath = moduleCompilationRoot.relativize(file).toString();
                              if (relativePath.endsWith(".class")) {
                                  String className = relativePath.replaceAll(".class", "").replace("/", ".");
                                  classesToLoad.add(className);
                              }
                              return FileVisitResult.CONTINUE;
                          };
                      });
                      for (String loadClass: classesToLoad) {
                          Class<?> loadedClass = jbossModule.getClassLoader().loadClassLocal(loadClass, true);
                          if (loadedClass == null)
                              throw new ScriptCompilationException("Unable to load compiled class: " + loadClass);
                      }
                  } catch (Exception e) {
                      // rollback
                      logger.error("Exception loading module " + candidateRevisionId, e);
                      if (candidateArchives.contains(scriptArchive)) {
                          // this spec came from a candidate archive. Send reject notification
                          notifyArchiveRejected(scriptArchive, ArchiveRejectedReason.COMPILE_FAILURE, e);
                      }
                      if (jbossModule != null) {
                          jbossModuleLoader.unloadModule(jbossModule);
                      }
                      continue;
                  }
  
                  // commit the change by removing the old module
                  ModuleIdentifier oldRevisionId = oldRevisionIdMap.get(scriptModuleId);
                  if (oldRevisionId != null) {
                      jbossModuleLoader.unloadModule(oldRevisionId);
                  }
  
                  JBossScriptModule scriptModule = new JBossScriptModule(scriptModuleId, jbossModule, scriptArchive);
                  ScriptModule oldModule = loadedScriptModules.put(scriptModuleId, scriptModule);
                  notifyModuleUpdate(scriptModule, oldModule);
  
                  // find dependents and add them to the to be compiled set
                  Set<ModuleId> dependents = GraphUtils.getIncomingVertices(candidateGraph, scriptModuleId);
                  for (ModuleId dependentScriptModuleId : dependents) {
                      if (!archivesToCompile.containsKey(dependentScriptModuleId)) {
                          ScriptModule dependentScriptModule = loadedScriptModules.get(dependentScriptModuleId);
                          if (dependentScriptModule != null) {
                              archivesToCompile.put(dependentScriptModuleId, dependentScriptModule.getSourceArchive());
                              ModuleIdentifier dependentRevisionId = JBossModuleUtils.createRevisionId(dependentScriptModuleId, updateNumber);
                              updatedRevisionIdMap.put(dependentScriptModuleId, dependentRevisionId);
                          }
                      }
                  }
              }
  
              GraphUtils.removeVertices(candidateGraph, leaves);
              leaves = GraphUtils.getLeafVertices(candidateGraph);
          }
      }
focal_method.class_method_signature: ScriptModuleLoader.updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)
focal_method.full_signature: public synchronized void updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)
focal_method.identifier: updateScriptArchives
focal_method.invocations: requireNonNull currentTimeMillis size getLatestRevisionIds size size putAll getModuleId getModuleSpec getCreateTime get getCreateTime notifyArchiveRejected createRevisionId put put put getModuleDependencies getModuleSpec getModuleNameGraph swapVertices getLeafVertices isEmpty get get createModulePath resolve deleteQuietly toFile createDirectories notifyArchiveRejected createModuleSpec error getModuleId getModuleSpec notifyArchiveRejected addModuleSpec loadModule compileModule rescanModule walkFileTree toString relativize endsWith replace replaceAll add loadClassLocal getClassLoader error contains notifyArchiveRejected unloadModule get unloadModule put notifyModuleUpdate getIncomingVertices containsKey get put getSourceArchive createRevisionId put removeVertices getLeafVertices
focal_method.modifiers: public synchronized
focal_method.parameters: (Set<? extends ScriptArchive> candidateArchives)
focal_method.return: void
focal_method.signature: void updateScriptArchives(Set<? extends ScriptArchive> candidateArchives)