private List<ScmFile> checkOut( File source, File baseDestination, List<File> files, String module ) throws ScmException, IOException { String sourcePath = source.getAbsolutePath(); List<ScmFile> checkedOutFiles = new ArrayList<ScmFile>(); for ( File file : files ) { String dest = file.getAbsolutePath(); dest = dest.substring( sourcePath.length() + 1 ); File destination = new File( baseDestination, dest ); destination = destination.getParentFile(); if ( !destination.exists() && !destination.mkdirs() ) { throw new ScmException( "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } FileUtils.copyFileToDirectory( file, destination ); File parent = file.getParentFile(); // TODO: Add more excludes here if ( parent != null && parent.getName().equals( "CVS" ) ) { continue; } String fileName = "/" + module + "/" + dest; checkedOutFiles.add( new ScmFile( fileName, ScmFileStatus.CHECKED_OUT ) ); } return checkedOutFiles; }
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()); } }
@Override protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) throws ScmException, AccuRevException { ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null ); File basedir = fileSet.getBasedir(); String outputDirectory = parameters.getString( CommandParameter.OUTPUT_DIRECTORY, null ); if ( outputDirectory != null ) { basedir = new File( outputDirectory ); } if ( !basedir.exists() ) { basedir.mkdirs(); } if ( !basedir.isDirectory() || basedir.list().length != 0 ) { throw new ScmException( "Checkout directory " + basedir.getAbsolutePath() + " not empty" ); } AccuRevVersion accuRevVersion = repository.getAccuRevVersion( scmVersion ); List<File> checkedOutFiles = extractSource( repository, basedir, accuRevVersion ); List<ScmFile> scmFiles = checkedOutFiles == null ? null : getScmFiles( checkedOutFiles, ScmFileStatus.CHECKED_OUT ); return getScmResult( repository, scmFiles, scmVersion ); }
public static Commandline createSpecificPushCommandLine(ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine(fileSet.getBasedir(), "push"); String branch = GitBranchCommand.getCurrentBranch(logger, repository, fileSet); if (branch == null || branch.length() == 0) { throw new ScmException("Could not detect the current branch. Don't know where I should push to!"); } // Overloaded branch name here : if repository.getUrl() is kept, during checkin(), current *local* branch // reference is not updated, whereas by using origin, it will be done ! cl.createArg().setValue("origin"); cl.createArg().setValue(branch + ":" + branch); return cl; }
@Override protected ScmResult executeAccurevCommand( AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters ) throws ScmException, AccuRevException { ScmVersion scmVersion = parameters.getScmVersion( CommandParameter.SCM_VERSION, null ); File basedir = fileSet.getBasedir(); String outputDirectory = parameters.getString( CommandParameter.OUTPUT_DIRECTORY, null ); if ( outputDirectory != null ) { basedir = new File( outputDirectory ); } if ( !basedir.exists() ) { basedir.mkdirs(); } if ( !basedir.isDirectory() || basedir.list().length != 0 ) { throw new ScmException( "Checkout directory " + basedir.getAbsolutePath() + " not empty" ); } AccuRevVersion accuRevVersion = repository.getAccuRevVersion( scmVersion ); List<File> checkedOutFiles = extractSource( repository, basedir, accuRevVersion ); List<ScmFile> scmFiles = checkedOutFiles == null ? null : getScmFiles( checkedOutFiles, ScmFileStatus.CHECKED_OUT ); return getScmResult( repository, scmFiles, scmVersion ); }
private List<ScmFile> checkOut( File source, File baseDestination, List<File> files, String module ) throws ScmException, IOException { String sourcePath = source.getAbsolutePath(); List<ScmFile> checkedOutFiles = new ArrayList<ScmFile>(); for ( File file : files ) { String dest = file.getAbsolutePath(); dest = dest.substring( sourcePath.length() + 1 ); File destination = new File( baseDestination, dest ); destination = destination.getParentFile(); if ( !destination.exists() && !destination.mkdirs() ) { throw new ScmException( "Could not create destination directory '" + destination.getAbsolutePath() + "'." ); } FileUtils.copyFileToDirectory( file, destination ); File parent = file.getParentFile(); // TODO: Add more excludes here if ( parent != null && parent.getName().equals( "CVS" ) ) { continue; } String fileName = "/" + module + "/" + dest; checkedOutFiles.add( new ScmFile( fileName, ScmFileStatus.CHECKED_OUT ) ); } return checkedOutFiles; }
public static Commandline createPushCommandLine( ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version ) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "push" ); String branch = GitBranchCommand.getCurrentBranch( logger, repository, fileSet ); if ( branch == null || branch.length() == 0 ) { throw new ScmException( "Could not detect the current branch. Don't know where I should push to!" ); } cl.createArg().setValue( repository.getPushUrl() ); cl.createArg().setValue( "refs/heads/" + branch + ":" + "refs/heads/" + branch ); return cl; }
private void deleteLocal( StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version ) throws ScmException { if ( fileSet.getFileList().size() != 0 ) { return; } Commandline cl = createDeleteLocalCommand( repo, fileSet, version ); StreamConsumer consumer = new DefaultConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { throw new ScmException( "Error executing delete-local: " + stderr.toString() ); } }
/** {@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() ); }
static Commandline buildCmd( File workingDir, String[] cmdAndArgs ) throws ScmException { Commandline cmd = new Commandline(); cmd.setExecutable( BazaarConstants.EXEC ); cmd.setWorkingDirectory( workingDir.getAbsolutePath() ); cmd.addArguments( cmdAndArgs ); if ( !workingDir.exists() ) { boolean success = workingDir.mkdirs(); if ( !success ) { String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir; throw new ScmException( msg ); } } return cmd; }
public static Commandline createPushCommandLine( ScmLogger logger, GitScmProviderRepository repository, ScmFileSet fileSet, ScmVersion version ) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "push" ); String branch = GitBranchCommand.getCurrentBranch( logger, repository, fileSet ); if ( branch == null || branch.length() == 0 ) { throw new ScmException( "Could not detect the current branch. Don't know where I should push to!" ); } cl.createArg().setValue( repository.getPushUrl() ); cl.createArg().setValue( "refs/heads/" + branch + ":" + "refs/heads/" + branch ); return cl; }
private void deleteLocal( StarteamScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version ) throws ScmException { if ( fileSet.getFileList().size() != 0 ) { return; } Commandline cl = createDeleteLocalCommand( repo, fileSet, version ); StreamConsumer consumer = new DefaultConsumer(); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { throw new ScmException( "Error executing delete-local: " + stderr.toString() ); } }
/** {@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() ); }
private static Commandline buildPythonCmd( File workingDir, String[] cmdAndArgs ) throws ScmException { Commandline cmd = new Commandline(); cmd.setExecutable( PYTHON_EXEC ); cmd.setWorkingDirectory( workingDir.getAbsolutePath() ); cmd.addArguments( cmdAndArgs ); if ( !workingDir.exists() ) { boolean success = workingDir.mkdirs(); if ( !success ) { String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir; throw new ScmException( msg ); } } return cmd; }
/** * @see org.apache.maven.scm.command.blame.AbstractBlameCommand#executeBlameCommand(org.apache.maven.scm.provider.ScmProviderRepository, * org.apache.maven.scm.ScmFileSet, java.lang.String) */ @Override public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet workingDirectory, String filename ) throws ScmException { try { SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repo; javaRepo.getClientManager(); AnnotationHandler handler = new AnnotationHandler(); SvnJavaUtil.blame( javaRepo.getClientManager(), new File( workingDirectory.getBasedir(), filename ), handler ); return new BlameScmResult( "", handler.lines ); } catch ( SVNException e ) { throw new ScmException( e.getMessage(), e ); } }
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; }
File workingDirectory = scmFileSet.getBasedir(); command.setWorkingDirectory( workingDirectory.getAbsolutePath() ); if ( files.isEmpty() ) throw new ScmException( "There are no files in the fileset to check in!" ); command.createArg().setValue( file.getAbsolutePath() );
static Commandline buildCmd( File workingDir, String[] cmdAndArgs ) throws ScmException { Commandline cmd = new Commandline(); cmd.setExecutable( HgCommandConstants.EXEC ); cmd.addArguments( cmdAndArgs ); if ( workingDir != null ) { cmd.setWorkingDirectory( workingDir.getAbsolutePath() ); if ( !workingDir.exists() ) { boolean success = workingDir.mkdirs(); if ( !success ) { String msg = "Working directory did not exist" + " and it couldn't be created: " + workingDir; throw new ScmException( msg ); } } } return cmd; }
@Override protected DiffScmResult executeDiffCommand( ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision ) throws ScmException { Git git = null; try { git = JGitUtils.openRepo( fileSet.getBasedir() ); DiffScmResult diff = callDiff( git, startRevision, endRevision ); git.getRepository().close(); return diff; } catch ( Exception e ) { throw new ScmException( "JGit diff failure!", e ); } finally { JGitUtils.closeRepo( git ); } }
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; }