cl.addArguments( new String[] { "-E", "%{_host_vendor}" } ); final StringStreamConsumer stdout = new StringStreamConsumer(); final StreamConsumer stderr = new LogStreamConsumer( LogStreamConsumer.INFO, log ); try log.debug( "About to execute \'" + cl.toString() + "\'" ); + "\' executing \'" + cl.toString() + "\'" ); return stdout.getOutput().trim();
public static File getRepositoryRootDirectory(File someDirectoryInTheRepo, ScmLogger logger) throws ScmException { // Factored out from GitStatusCommand. Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(someDirectoryInTheRepo, "rev-parse"); cl.createArg().setValue("--show-toplevel"); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = GitCommandLineUtils.execute(cl, stdout, stderr, logger); if (exitCode != 0) { // git-status returns non-zero if nothing to do if (logger.isInfoEnabled()) { logger.info( "Could not resolve toplevel from " + someDirectoryInTheRepo); } } else { String absoluteRepositoryRoot = stdout.getOutput().trim(); // This comes back unquoted! if (!Strings.isNullOrEmpty(absoluteRepositoryRoot)) { return new File(absoluteRepositoryRoot); } } return null; }
public static boolean isCvsNT() throws ScmException { Commandline cl = new Commandline(); cl.setExecutable( "cvs" ); cl.createArg().setValue( "-v" ); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); try { CommandLineUtils.executeCommandLine( cl, stdout, stderr ); } catch ( CommandLineException e ) { throw new ScmException( "Error while executing command.", e ); } return stdout.getOutput().indexOf( "CVSNT" ) >= 0; }
private static void execGitCmd(ScmLogger logger, StreamConsumer consumer, Commandline cl) throws ScmException { CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = GitCommandLineUtils.execute(cl, consumer, stderr, logger); if (exitCode != 0) { throw new ScmException("Git command failed: " + stderr.getOutput()); } }
public static boolean isCvsNT() throws ScmException { Commandline cl = new Commandline(); cl.setExecutable( "cvs" ); cl.createArg().setValue( "-v" ); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); try { CommandLineUtils.executeCommandLine( cl, stdout, stderr ); } catch ( CommandLineException e ) { throw new ScmException( "Error while executing command.", e ); } return stdout.getOutput().indexOf( "CVSNT" ) >= 0; }
/** * Helper function to detect the current branch */ public static String getCurrentBranch( ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet ) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "symbolic-ref" ); cl.createArg().setValue( "HEAD" ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); GitCurrentBranchConsumer cbConsumer = new GitCurrentBranchConsumer( logger ); int exitCode; exitCode = GitCommandLineUtils.execute( cl, cbConsumer, stderr, logger ); if ( exitCode != 0 ) { throw new ScmException( "Detecting the current branch failed: " + stderr.getOutput() ); } return cbConsumer.getBranchName(); } }
/** * Helper function to detect the current branch */ public static String getCurrentBranch( ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet ) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "symbolic-ref" ); cl.createArg().setValue( "HEAD" ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); GitCurrentBranchConsumer cbConsumer = new GitCurrentBranchConsumer( logger ); int exitCode; exitCode = GitCommandLineUtils.execute( cl, cbConsumer, stderr, logger ); if ( exitCode != 0 ) { throw new ScmException( "Detecting the current branch failed: " + stderr.getOutput() ); } return cbConsumer.getBranchName(); } }
/** * Get Database delimiter * * @param logger a logger. * @param ccmAddr Synergy session ID. * @return delimiter of the database (i.e. ~). */ public static String delimiter( ScmLogger logger, String ccmAddr ) throws ScmException { if ( logger.isDebugEnabled() ) { logger.debug( "Synergy : Entering delimiter method" ); } Commandline cl = SynergyCCM.delimiter( ccmAddr ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); executeSynergyCommand( logger, cl, stderr, stdout, true ); return stdout.getOutput(); }
/** * Get Database delimiter * * @param logger a logger. * @param ccmAddr Synergy session ID. * @return delimiter of the database (i.e. ~). */ public static String delimiter( ScmLogger logger, String ccmAddr ) throws ScmException { if ( logger.isDebugEnabled() ) { logger.debug( "Synergy : Entering delimiter method" ); } Commandline cl = SynergyCCM.delimiter( ccmAddr ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); executeSynergyCommand( logger, cl, stderr, stdout, true ); return stdout.getOutput(); }
public String eval( String expression ) throws RpmEvalException { String result = null; Commandline cmdLine = new Commandline(); cmdLine.setExecutable( "rpm" ); cmdLine.createArgument().setLine( "--eval \"%{" + expression + "}\"" ); try { CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer(); int exitValue = cliManager.execute( cmdLine, consumer, cliManager.newDebugStreamConsumer() ); if ( exitValue != 0 ) { throw new RpmEvalException( "RPM evaluation exited abnormally for expression: " + expression + "(returned: " + exitValue + ")." ); } result = consumer.getOutput().trim(); } catch ( CommandLineException e ) { throw new RpmEvalException( "Error evaluating RPM expression: " + expression, e ); } return result; }
/** * Get the dir relative to the repository root. * * @param caller the caller command. * @param fileSet in which subdir to execute. * @return the relative URI. * @throws ScmException if execute() fails. */ public static URI getRelativeCWD( AbstractCommand caller, ScmFileSet fileSet ) throws ScmException { Commandline clRevparse = createRevparseShowPrefix( fileSet ); CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); URI relativeRepositoryPath = null; int exitCode = GitCommandLineUtils.execute( clRevparse, stdout, stderr, caller.getLogger() ); if ( exitCode != 0 ) { // git-status returns non-zero if nothing to do if ( caller.getLogger().isInfoEnabled() ) { caller.getLogger().info( "Could not resolve prefix" ); } } else { relativeRepositoryPath = GitStatusConsumer.uriFromPath( stdout.getOutput().trim() ); } return relativeRepositoryPath; }
/** * Gets the architecure for system by executing <i>rpm -E %{_arch}</i>. */ public String getArch() throws MojoExecutionException { final Commandline cl = new Commandline(); cl.setExecutable( "rpm" ); cl.addArguments( new String[] { "-E", "%{_arch}" } ); final StringStreamConsumer stdConsumer = new StringStreamConsumer(); final StreamConsumer errConsumer = new LogStreamConsumer( LogStreamConsumer.INFO, mojo.getLog() ); try { if ( mojo.getLog().isDebugEnabled() ) mojo.getLog().debug( "About to execute \'" + cl.toString() + "\'" ); final int result = CommandLineUtils.executeCommandLine( cl, stdConsumer, errConsumer ); if ( result != 0 ) throw new MojoExecutionException( "rpm -E %{_arch} returned: \'" + result + "\' executing \'" + cl.toString() + "\'" ); } catch ( CommandLineException e ) { throw new MojoExecutionException( "Unable get system architecture", e ); } return stdConsumer.getOutput().trim(); } }
/** * Gets the architecure for system by executing <i>rpm -E %{_arch}</i>. */ public String getArch() throws MojoExecutionException { final Commandline cl = new Commandline(); cl.setExecutable( "rpm" ); cl.addArguments( new String[] { "-E", "%{_arch}" } ); final StringStreamConsumer stdConsumer = new StringStreamConsumer(); final StreamConsumer errConsumer = new LogStreamConsumer( LogStreamConsumer.INFO, mojo.getLog() ); try { if ( mojo.getLog().isDebugEnabled() ) mojo.getLog().debug( "About to execute \'" + cl.toString() + "\'" ); final int result = CommandLineUtils.executeCommandLine( cl, stdConsumer, errConsumer ); if ( result != 0 ) throw new MojoExecutionException( "rpm -E %{_arch} returned: \'" + result + "\' executing \'" + cl.toString() + "\'" ); } catch ( CommandLineException e ) { throw new MojoExecutionException( "Unable get system architecture", e ); } return stdConsumer.getOutput().trim(); } }
/** * {@inheritDoc} */ protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet files, String message ) throws ScmException { Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files ); PerforceRemoveConsumer consumer = new PerforceRemoveConsumer(); try { CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); if ( exitCode != 0 ) { String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); msg.append( '\n' ); msg.append( "Command line was:" + cmdLine ); throw new CommandLineException( msg.toString() ); } } catch ( CommandLineException e ) { throw new ScmException( "CommandLineException " + e.getMessage(), e ); } return new RemoveScmResult( cl.toString(), consumer.getRemovals() ); }
/** * {@inheritDoc} */ protected ScmResult executeRemoveCommand( ScmProviderRepository repo, ScmFileSet files, String message ) throws ScmException { Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files ); PerforceRemoveConsumer consumer = new PerforceRemoveConsumer(); try { CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); if ( exitCode != 0 ) { String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); msg.append( '\n' ); msg.append( "Command line was:" + cmdLine ); throw new CommandLineException( msg.toString() ); } } catch ( CommandLineException e ) { throw new ScmException( "CommandLineException " + e.getMessage(), e ); } return new RemoveScmResult( cl.toString(), consumer.getRemovals() ); }
/** {@inheritDoc} */ protected ScmResult executeAddCommand( ScmProviderRepository repo, ScmFileSet files, String message, boolean binary ) throws ScmException { Commandline cl = createCommandLine( (PerforceScmProviderRepository) repo, files.getBasedir(), files ); PerforceAddConsumer consumer = new PerforceAddConsumer(); try { CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); int exitCode = CommandLineUtils.executeCommandLine( cl, consumer, err ); if ( exitCode != 0 ) { String cmdLine = CommandLineUtils.toString( cl.getCommandline() ); StringBuilder msg = new StringBuilder( "Exit code: " + exitCode + " - " + err.getOutput() ); msg.append( '\n' ); msg.append( "Command line was:" + cmdLine ); throw new CommandLineException( msg.toString() ); } } catch ( CommandLineException e ) { if ( getLogger().isErrorEnabled() ) { getLogger().error( "CommandLineException " + e.getMessage(), e ); } } return new AddScmResult( cl.toString(), consumer.getAdditions() ); }
/** {@inheritDoc} */ protected ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters ) throws ScmException { if ( !fileSet.getFileList().isEmpty() ) { throw new ScmException( "This provider doesn't support tagging subsets of a directory" ); } if ( tag == null || tag.trim().length() == 0 ) { throw new ScmException( "tag must be specified" ); } if ( getLogger().isInfoEnabled() ) { getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); } StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo; StarteamTagConsumer consumer = new StarteamTagConsumer( getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); Commandline cl = createCommandLine( repository, fileSet.getBasedir(), tag ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new TagScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false ); } return new TagScmResult( cl.toString(), consumer.getTaggedFiles() ); }
/** {@inheritDoc} */ protected ScmResult executeTagCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag, ScmTagParameters scmTagParameters ) throws ScmException { if ( !fileSet.getFileList().isEmpty() ) { throw new ScmException( "This provider doesn't support tagging subsets of a directory" ); } if ( tag == null || tag.trim().length() == 0 ) { throw new ScmException( "tag must be specified" ); } if ( getLogger().isInfoEnabled() ) { getLogger().info( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); } StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo; StarteamTagConsumer consumer = new StarteamTagConsumer( getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); Commandline cl = createCommandLine( repository, fileSet.getBasedir(), tag ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new TagScmResult( cl.toString(), "The starteam command failed.", stderr.getOutput(), false ); } return new TagScmResult( cl.toString(), consumer.getTaggedFiles() ); }
/** {@inheritDoc} */ protected AddScmResult executeCvsCommand( Commandline cl, List<ScmFile> addedFiles ) throws ScmException { CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode; try { exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); } catch ( CommandLineException ex ) { throw new ScmException( "Error while executing command.", ex ); } // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses? if ( exitCode != 0 ) { return new AddScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false ); } return new AddScmResult( cl.toString(), addedFiles ); } }
/** {@inheritDoc} */ protected RemoveScmResult executeCvsCommand( Commandline cl, List<ScmFile> removedFiles ) throws ScmException { CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode; try { exitCode = CommandLineUtils.executeCommandLine( cl, consumer, stderr ); } catch ( CommandLineException ex ) { throw new ScmException( "Error while executing command.", ex ); } // TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses? if ( exitCode != 0 ) { return new RemoveScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false ); } return new RemoveScmResult( cl.toString(), removedFiles ); } }