private KieBuilder createKieBuilder(final KieFileSystem kieFileSystem) {
   PomModel pomModel;
   final KieBuilderImpl kieBuilder = (KieBuilderImpl) kieServices.newKieBuilder(kieFileSystem);
   if ((pomModel = pomModelCache.getEntry(project)) != null) {
     kieBuilder.setPomModel(pomModel);
   }
   return kieBuilder;
 }
Example #2
0
  private static String generatePomPropertiesFromPom(String rootPath) {
    // recurse until we reach root or find a pom.xml
    File file = null;
    for (File folder = new File(rootPath);
        folder.getParent() != null;
        folder = new File(folder.getParent())) {
      file = new File(folder, "pom.xml");
      if (file.exists()) {
        break;
      }
      file = null;
    }

    if (file != null) {
      FileInputStream fis = null;
      try {
        fis = new FileInputStream(file);
        PomModel pomModel = PomModel.Parser.parse(rootPath + "/pom.xml", fis);

        KieBuilderImpl.validatePomModel(pomModel); // throws an exception if invalid

        ReleaseIdImpl gav = (ReleaseIdImpl) pomModel.getReleaseId();

        String str = KieBuilderImpl.generatePomProperties(gav);
        log.info("Recursed up folders,  found and used pom.xml " + file);

        return str;
      } catch (Exception e) {
        log.error(
            "As folder project tried to fall back to pom.xml "
                + file
                + "\nbut failed with exception:\n"
                + e.getMessage());
      } finally {
        if (fis != null) {
          try {
            fis.close();
          } catch (IOException e) {
            log.error("Error when closing InputStream to " + file + "\n" + e.getMessage());
          }
        }
      }
    } else {
      log.warn(
          "As folder project tried to fall back to pom.xml, but could not find one for " + file);
    }
    return null;
  }
Example #3
0
 private static String getPomPropertiesFromFileSystem(String rootPath) {
   Reader reader = null;
   try {
     File file = KieBuilderImpl.findPomProperties(new File(rootPath));
     if (file == null) {
       log.warn("Unable to find pom.properties in " + rootPath);
       return null;
     }
     reader = new InputStreamReader(new FileInputStream(file), IoUtils.UTF8_CHARSET);
     log.debug("Found and used pom.properties " + file);
     return StringUtils.toString(reader);
   } catch (Exception e) {
     log.warn(
         "Unable to load pom.properties tried recursing down from "
             + rootPath
             + "\n"
             + e.getMessage());
   } finally {
     if (reader != null) {
       try {
         reader.close();
       } catch (IOException e) {
         log.error("Error when closing InputStream to " + rootPath + "\n" + e.getMessage());
       }
     }
   }
   return null;
 }
  private void addKieModuleToRepo(KieModuleModel kieProject) {
    KieBuilderImpl.setDefaultsforEmptyKieModule(kieProject);

    InternalKieModule kJar = createKieModule(kieProject);

    if (kJar != null) {
      KieServices ks = KieServices.Factory.get();
      log.info("adding KieModule from " + configFileURL.toExternalForm() + " to repository.");
      ks.getRepository().addKieModule(kJar);
      KieSpringUtils.setReleaseIdForContext(releaseId, context);
    }
  }
Example #5
0
  private static String getPomPropertiesFromZipFile(String rootPath) {
    File actualZipFile = new File(rootPath);
    if (!actualZipFile.exists()) {
      log.error(
          "Unable to load pom.properties from"
              + rootPath
              + " as jarPath cannot be found\n"
              + rootPath);
      return null;
    }

    ZipFile zipFile = null;

    try {
      zipFile = new ZipFile(actualZipFile);

      String file = KieBuilderImpl.findPomProperties(zipFile);
      if (file == null) {
        log.warn("Unable to find pom.properties in " + rootPath);
        return null;
      }
      ZipEntry zipEntry = zipFile.getEntry(file);

      String pomProps =
          StringUtils.readFileAsString(
              new InputStreamReader(zipFile.getInputStream(zipEntry), IoUtils.UTF8_CHARSET));
      log.debug("Found and used pom.properties " + file);
      return pomProps;
    } catch (Exception e) {
      log.error("Unable to load pom.properties from " + rootPath + "\n" + e.getMessage());
    } finally {
      try {
        zipFile.close();
      } catch (IOException e) {
        log.error("Error when closing InputStream to " + rootPath + "\n" + e.getMessage());
      }
    }
    return null;
  }