Package eu.planets_project.services.utils

Examples of eu.planets_project.services.utils.ProcessRunner


    return result;
  }
 
 
  private static OdfValidatorResult validateSubFile(File odfSubFile, File schema, OdfValidatorResult result) {
    ProcessRunner validator = new ProcessRunner();
    validator.setCommand(getJingValidateCmd(odfSubFile, schema));
    validator.run();
   
    String out = validator.getProcessOutputAsString();
 
    if(out.equalsIgnoreCase("")) {
      result.setValid(odfSubFile, true);
      log.info("'" + checkParentName(odfSubFile) + odfSubFile.getName() + "' is valid: " + result.componentIsValid(odfSubFile));
     
View Full Code Here


    }
    return url;
  }
 
  public static String getToolVersion() {
    ProcessRunner cmd = new ProcessRunner(getJingVersionCmd());
    cmd.run();
    String out = cmd.getProcessOutputAsString();
    if(!out.equalsIgnoreCase("") && out!=null) {
      String[] parts = out.split("\n");
      String version = parts[0];
      String[] lineParts = version.split(" ");
      version = lineParts[2];
View Full Code Here

        } else {
            //fine, is alreade written
        }

        //Execute the tool
        final ProcessRunner toolProcessRunner = new ProcessRunner();
        ServiceReport serviceReport = executeToolProcess(toolProcessRunner,
                                                         command, processStandardInput);



        if (serviceReport.getType() == Type.ERROR) {
            String message = "Failed migrating object with title '"
                             + sourceObject.getTitle() + "' from format URI: "
                             + sourceFormat + " to " + destinationFormat
                             + " Standard output: "
                             + toolProcessRunner.getProcessOutputAsString()
                             + "\nStandard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.ERROR,
                                              Status.TOOL_ERROR, message);
            return new MigrateResult(null, serviceReport);
        }


        //cleanup
        if (migrationPath.useTempSourceFile()){
            migrationPath.getTempSourceFile().getFile().delete();
        }
        for (TempFile tempFile : migrationPath.getTempFileDeclarations()) {
            tempFile.getFile().delete();
        }


        //READING THE OUTPUT
        //TODO return a reference to the outputfile
        DigitalObject.Builder builder;


        if (migrationPath.useTempDestinationFile()){
            //we should read a temp file afterwards
            File outputfile = migrationPath.getTempOutputFile().getFile();
            if (returnByReference){
                builder = new DigitalObject.Builder(Content.byReference(outputfile));
            } else {
                builder = new DigitalObject.Builder(Content.byValue(outputfile));
                outputfile.delete();
            }


            String message = "Successfully migrated object with title '"
                             + sourceObject.getTitle() + "' from format URI: "
                             + sourceFormat + " to " + destinationFormat
                             + " Standard output: "
                             + toolProcessRunner.getProcessOutputAsString()
                             + "\nStandard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS,
                                              message);

        } else {

            if (returnByReference){
                //we should read the output
                builder = new DigitalObject.Builder(Content.byReference(toolProcessRunner.getProcessOutput()));
            } else{
                builder = new DigitalObject.Builder(Content.byValue(toolProcessRunner.getProcessOutput()));
            }
            String message = "Successfully migrated object with title '"
                             + sourceObject.getTitle() + "' from format URI: "
                             + sourceFormat + " to " + destinationFormat
                             + " Standard error output: "
                             + toolProcessRunner.getProcessErrorAsString();
            serviceReport = new ServiceReport(Type.INFO, Status.SUCCESS,
                                              message);


        }
View Full Code Here

            strings.add(commandString);
            for (String s : argsString.split(" ")) {
                strings.add(s);
            }

            ProcessRunner pr = new ProcessRunner(strings);
            pr.run();

            FileUtils.deleteQuietly(inputFile);
            FileUtils.deleteQuietly(outputFile);

            boolean toolError = pr.getReturnCode() == -1;
            ServiceReport log;
            if (toolError) {
                log = new ServiceReport(Type.ERROR, Status.TOOL_ERROR, pr
                        .getProcessErrorAsString());
            } else {
                log = new ServiceReport(Type.INFO, Status.SUCCESS, pr
                        .getProcessOutputAsString());
            }
            /*
             * log.properties = new ArrayList<Property>(); log.properties.add(
             * new Property( URI.create("planets:uri"), "name", "value") );
View Full Code Here

      }
      this.log.info("Executing command line: " + fullCommandLine);
  }

  // Execute the tool
  final ProcessRunner toolProcessRunner = new ProcessRunner();
  final boolean executionSuccessful = executeToolProcess(
    toolProcessRunner, prCommand, standardInputStream);

  // Delete temporary files. However, do NOT delete the output unless the
  // execution failed.

  final ToolIOProfile outputIOProfile = migrationPath
    .getToolOutputProfile();

  if ((outputIOProfile.usePipedIO() == false) && executionSuccessful) {
      // OK, there should exist an output file. Avoid deleting it.
      final String outputFileLabel = outputIOProfile
        .getCommandLineFileLabel();
      for (String tempFileLabel : temporaryFileMappings.keySet()) {
    if (outputFileLabel.equals(tempFileLabel) == false) {
        temporaryFileMappings.get(tempFileLabel).delete();
    }
      }
  } else {
      // The output has been returned through a pipe, so it is safe to
      // delete all files.
      for (File tempFile : temporaryFileMappings.values()) {
    tempFile.delete();
      }
  }

  if (executionSuccessful == false) {
      return buildMigrationResult(migrationPath, digitalObject, null,
        toolProcessRunner);
  }

  // Now create a digital object from the tools output.
  DigitalObject.Builder builder;

  final ParameterReader parameterReader = new ParameterReader(
    toolParameters);
  final boolean returnDataByReference = parameterReader
    .getBooleanParameter("returnByReference", true);

  final ToolIOProfile toolOutputProfile = migrationPath
    .getToolOutputProfile();
  if (toolOutputProfile.usePipedIO() == false) {

      // The tool has written the output to a temporary file. Create a
      // digital object based on that.
      final File outputFile = temporaryFileMappings.get(toolOutputProfile
        .getCommandLineFileLabel());
      if (returnDataByReference) {
    builder = new DigitalObject.Builder(Content
      .byReference(outputFile));
    // We cannot tell when the temporary file can be deleted, so let
    // it live.
      } else {
    builder = new DigitalObject.Builder(Content.byValue(outputFile));

    // It is now safe to delete the temporary file.
    outputFile.delete();
      }
  } else {

      // The tool has written the output to standard output. Create a
      // digital object based on that output.
      if (returnDataByReference) {
    // Direct the standard output contents to a temporary file.
    builder = new DigitalObject.Builder(Content
      .byReference(toolProcessRunner.getProcessOutput()));
      } else {
    // Return the standard output contents by value.
    builder = new DigitalObject.Builder(Content
      .byValue(toolProcessRunner.getProcessOutput()));
      }
  }

  final double migrationDuration = new Date().getTime()
    - migrationStartTime.getTime();
View Full Code Here

TOP

Related Classes of eu.planets_project.services.utils.ProcessRunner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.