コード例 #1
0
  private static InternalKieModule fetchKModule(URL url, String fixedURL) {
    if (url.getPath().endsWith("-spring.xml")) {
      // the entire kmodule creation is happening in the kie-spring module,
      // hence we force a null return
      fetchKModuleFromSpring(url, fixedURL);
      return null;
    }
    KieModuleModel kieProject = KieModuleModelImpl.fromXML(url);

    setDefaultsforEmptyKieModule(kieProject);

    String pomProperties = getPomProperties(fixedURL);
    if (pomProperties == null) {
      log.warn(
          "Cannot find maven pom properties for this project. Using the container's default ReleaseId");
    }

    ReleaseId releaseId =
        pomProperties != null
            ? ReleaseIdImpl.fromPropertiesString(pomProperties)
            : KieServices.Factory.get().getRepository().getDefaultReleaseId();

    String rootPath = fixedURL;
    if (rootPath.lastIndexOf(':') > 0) {
      rootPath = IoUtils.asSystemSpecificPath(rootPath, rootPath.lastIndexOf(':'));
    }

    return createInternalKieModule(url, fixedURL, kieProject, releaseId, rootPath);
  }
コード例 #2
0
  public static String getPomProperties(String urlPathToAdd) {
    String pomProperties = null;
    String rootPath = urlPathToAdd;
    if (rootPath.lastIndexOf(':') > 0) {
      rootPath = IoUtils.asSystemSpecificPath(rootPath, rootPath.lastIndexOf(':'));
    }

    if (urlPathToAdd.endsWith(".jar") || urlPathToAdd.endsWith("/content")) {
      pomProperties = getPomPropertiesFromZipFile(rootPath);
    } else {
      pomProperties = getPomPropertiesFromFileSystem(rootPath);
      if (pomProperties == null) {
        int webInf = rootPath.indexOf("/WEB-INF");
        if (webInf > 0) {
          rootPath = rootPath.substring(0, webInf);
          pomProperties = getPomPropertiesFromFileSystem(rootPath);
        }
      }
      if (pomProperties == null) {
        pomProperties = generatePomPropertiesFromPom(rootPath);
      }
    }

    if (pomProperties == null) {
      log.warn("Unable to load pom.properties from" + urlPathToAdd);
    }
    return pomProperties;
  }
コード例 #3
0
  @Test
  public void testTimerStartDateISO() throws Exception {

    byte[] content =
        IoUtils.readBytesFromInputStream(
            this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
    String processContent = new String(content, "UTF-8");

    DateTime now = new DateTime(System.currentTimeMillis());
    now = now.plus(2000);

    processContent = processContent.replaceFirst("#\\{date\\}", now.toString());
    Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
    resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
    resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
    KieBase kbase = createKnowledgeBaseFromResources(resource);

    ksession = createKnowledgeSession(kbase);
    final List<Long> list = new ArrayList<Long>();
    ksession.addEventListener(
        new DefaultProcessEventListener() {
          public void afterProcessStarted(ProcessStartedEvent event) {
            list.add(event.getProcessInstance().getId());
          }
        });
    assertEquals(0, list.size());
    Thread.sleep(3000);
    assertEquals(1, list.size());
  }
コード例 #4
0
  public static String fixURLFromKProjectPath(URL url) {
    String urlPath = url.toExternalForm();

    // determine resource type (eg: jar, file, bundle)
    String urlType = "file";
    int colonIndex = urlPath.indexOf(":");
    if (colonIndex != -1) {
      urlType = urlPath.substring(0, colonIndex);
    }

    urlPath = url.getPath();

    if ("jar".equals(urlType)) {
      // switch to using getPath() instead of toExternalForm()
      if (urlPath.indexOf('!') > 0) {
        urlPath = urlPath.substring(0, urlPath.indexOf('!'));
      }
    } else if ("vfs".equals(urlType)) {
      urlPath = getPathForVFS(url);
    } else {
      if (url.toString().contains("-spring.xml")) {
        urlPath =
            urlPath.substring(
                0, urlPath.length() - ("/" + KieModuleModelImpl.KMODULE_SPRING_JAR_PATH).length());
      } else {
        urlPath =
            urlPath.substring(
                0, urlPath.length() - ("/" + KieModuleModelImpl.KMODULE_JAR_PATH).length());
      }
    }

    if (urlPath.endsWith(".jar!")) {
      urlPath = urlPath.substring(0, urlPath.length() - 1);
    }

    // remove any remaining protocols, normally only if it was a jar
    int firstSlash = urlPath.indexOf('/');
    colonIndex = firstSlash > 0 ? urlPath.lastIndexOf(":", firstSlash) : urlPath.lastIndexOf(":");
    if (colonIndex >= 0) {
      urlPath = IoUtils.asSystemSpecificPath(urlPath, colonIndex);
    }

    try {
      urlPath = URLDecoder.decode(urlPath, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      throw new IllegalArgumentException("Error decoding URL (" + url + ") using UTF-8", e);
    }

    log.debug("KieModule URL type=" + urlType + " url=" + urlPath);

    return urlPath;
  }