コード例 #1
0
  private void rebuildAll(
      ReleaseId newReleaseId,
      ResultsImpl results,
      InternalKieModule newKM,
      List<String> modifiedClasses,
      KieBaseModel kieBaseModel,
      KnowledgeBuilderImpl kbuilder,
      CompositeKnowledgeBuilder ckbuilder) {
    Set<String> modifiedPackages = new HashSet<String>();
    if (!modifiedClasses.isEmpty()) {
      ClassLoader rootClassLoader = kbuilder.getRootClassLoader();
      if (rootClassLoader instanceof ProjectClassLoader) {
        ProjectClassLoader projectClassLoader = (ProjectClassLoader) rootClassLoader;
        projectClassLoader.reinitTypes();
        for (String resourceName : modifiedClasses) {
          String className = convertResourceToClassName(resourceName);
          byte[] bytes = newKM.getBytes(resourceName);
          Class<?> clazz = projectClassLoader.defineClass(className, resourceName, bytes);
          modifiedPackages.add(clazz.getPackage().getName());
        }
        kbuilder.setAllRuntimesDirty(modifiedPackages);
      }
    }

    ckbuilder.build();

    PackageBuilderErrors errors = kbuilder.getErrors();
    if (!errors.isEmpty()) {
      for (KnowledgeBuilderError error : errors.getErrors()) {
        results.addMessage(error);
      }
      log.error(
          "Unable to update KieBase: "
              + kieBaseModel.getName()
              + " to release "
              + newReleaseId
              + "\n"
              + errors.toString());
    }

    if (!modifiedClasses.isEmpty()) {
      kbuilder.rewireClassObjectTypes(modifiedPackages);
    }
  }
コード例 #2
0
  public KnowledgePackageImpl deepCloneIfAlreadyInUse(ClassLoader classLoader) {
    if (inUse.compareAndSet(false, true)) {
      return this;
    }

    if (classLoader instanceof ProjectClassLoader) {
      ClassLoader originalClassLoader =
          ((JavaDialectRuntimeData) dialectRuntimeRegistry.getDialectData("java"))
              .getRootClassLoader();
      if (originalClassLoader instanceof ProjectClassLoader) {
        ((ProjectClassLoader) classLoader).initFrom((ProjectClassLoader) originalClassLoader);
      }
    }

    return ClassUtils.deepClone(this, classLoader);
  }