Esempio n. 1
0
  private void runCompiler(String[] commandLine) {
    // hand crank it so we can add our own compiler configuration
    try {
      Options options = FileSystemCompiler.createCompilationOptions();

      CommandLineParser cliParser = new DefaultParser();

      CommandLine cli;
      cli = cliParser.parse(options, commandLine);

      configuration = FileSystemCompiler.generateCompilerConfigurationFromOptions(cli);
      configuration.setScriptExtensions(getScriptExtensions());
      String tmpExtension = getScriptExtension();
      if (tmpExtension.startsWith("*.")) tmpExtension = tmpExtension.substring(1);
      configuration.setDefaultScriptExtension(tmpExtension);

      // Load the file name list
      String[] filenames = FileSystemCompiler.generateFileNamesFromOptions(cli);
      boolean fileNameErrors = filenames == null;

      fileNameErrors = fileNameErrors || !FileSystemCompiler.validateFiles(filenames);

      if (targetBytecode != null) {
        configuration.setTargetBytecode(targetBytecode);
      }

      if (!fileNameErrors) {
        FileSystemCompiler.doCompilation(
            configuration, makeCompileUnit(), filenames, forceLookupUnnamedFiles);
      }

    } catch (Exception re) {
      Throwable t = re;
      if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
        // unwrap to the real exception
        t = re.getCause();
      }
      StringWriter writer = new StringWriter();
      new ErrorReporter(t, false).write(new PrintWriter(writer));
      String message = writer.toString();

      taskSuccess = false;
      if (errorProperty != null) {
        getProject().setNewProperty(errorProperty, "true");
      }

      if (failOnError) {
        log.error(message);
        throw new BuildException("Compilation Failed", t, getLocation());
      } else {
        log.error(message);
      }
    }
  }
  private void updatePackageBinaries(PackageItem item, PackageAssembler packageAssembler)
      throws DetailedSerializationException {
    try {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      ObjectOutput out = new DroolsObjectOutputStream(bout);
      out.writeObject(packageAssembler.getBinaryPackage());

      item.updateCompiledPackage(new ByteArrayInputStream(bout.toByteArray()));
      out.flush();
      out.close();

      item.updateBinaryUpToDate(true);

      RuleBase ruleBase =
          RuleBaseFactory.newRuleBase(new RuleBaseConfiguration(getClassLoaders(packageAssembler)));
      ruleBase.addPackage(packageAssembler.getBinaryPackage());

      rulesRepository.save();
    } catch (Exception e) {
      e.printStackTrace();
      log.error(
          "An error occurred building the package [" + item.getName() + "]: " + e.getMessage());
      throw new DetailedSerializationException(
          "An error occurred building the package.", e.getMessage());
    }
  }
Esempio n. 3
0
 private void runForked(String[] commandLine) {
   // use the main method in FileSystemCompiler
   final Execute executor =
       new Execute(); // new LogStreamHandler ( attributes , Project.MSG_INFO , Project.MSG_WARN )
                      // ) ;
   executor.setAntRun(getProject());
   executor.setWorkingDirectory(getProject().getBaseDir());
   executor.setCommandline(commandLine);
   try {
     executor.execute();
   } catch (final IOException ioe) {
     throw new BuildException("Error running forked groovyc.", ioe);
   }
   final int returnCode = executor.getExitValue();
   if (returnCode != 0) {
     taskSuccess = false;
     if (errorProperty != null) {
       getProject().setNewProperty(errorProperty, "true");
     }
     if (failOnError) {
       throw new BuildException("Forked groovyc returned error code: " + returnCode);
     } else {
       log.error("Forked groovyc returned error code: " + returnCode);
     }
   }
 }
Esempio n. 4
0
 private void addSourceFiles(List<String> commandLineList) {
   // check to see if an external file is needed
   int count = 0;
   if (fork) {
     for (File srcFile : compileList) {
       count += srcFile.getPath().length();
     }
     for (Object commandLineArg : commandLineList) {
       count += commandLineArg.toString().length();
     }
     count += compileList.length;
     count += commandLineList.size();
   }
   // 32767 is the command line length limit on Windows
   if (fork && (count > 32767)) {
     try {
       File tempFile = File.createTempFile("groovyc-files-", ".txt");
       temporaryFiles.add(tempFile);
       PrintWriter pw = new PrintWriter(new FileWriter(tempFile));
       for (File srcFile : compileList) {
         pw.println(srcFile.getPath());
       }
       pw.close();
       commandLineList.add("@" + tempFile.getPath());
     } catch (IOException e) {
       log.error("Error creating file list", e);
     }
   } else {
     for (File srcFile : compileList) {
       commandLineList.add(srcFile.getPath());
     }
   }
 }
  protected void removePackage(String uuid) {

    try {
      PackageItem item = rulesRepository.loadPackageByUUID(uuid);
      log.info("USER:"******" REMOVEING package [" + item.getName() + "]");
      item.remove();
      rulesRepository.save();
    } catch (RulesRepositoryException e) {
      log.error("Unable to remove package.", e);
      throw e;
    }
  }
  protected String copyPackage(String sourcePackageName, String destPackageName)
      throws SerializationException {

    try {
      log.info(
          "USER:"******" COPYING package ["
              + sourcePackageName
              + "] to  package ["
              + destPackageName
              + "]");

      return rulesRepository.copyPackage(sourcePackageName, destPackageName);
    } catch (RulesRepositoryException e) {
      log.error("Unable to copy package.", e);
      throw e;
    }
  }
  protected String[] listRulesInPackage(String packageName) throws SerializationException {
    // load package
    PackageItem item = rulesRepository.loadPackage(packageName);

    PackageDRLAssembler assembler = createPackageDRLAssembler(item);

    List<String> result = new ArrayList<String>();
    try {

      String drl = assembler.getDRL();
      if (drl == null || "".equals(drl)) {
        return new String[0];
      } else {
        parseRulesToPackageList(assembler, result);
      }

      return result.toArray(new String[result.size()]);
    } catch (DroolsParserException e) {
      log.error("Unable to list rules in package", e);
      return new String[0];
    }
  }