Refine search
revisionInterval.toString() }; HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern ); ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd ); endDate = logEntries.get( logEntries.size() - 1 ).getDate(); ChangeLogSet changeLogSet = new ChangeLogSet( logEntries, startDate, endDate ); changeLogSet.setStartVersion( startVersion ); changeLogSet.setEndVersion( endVersion ); return new ChangeLogScmResult( changeLogSet, result );
public void testChangeLogCommandFromHeadToStartOfRepository() throws Exception { Thread.sleep( SLEEP_TIME_IN_MILLIS ); ScmRepository scmRepository = getScmRepository(); ScmProvider provider = getScmManager().getProviderByRepository( scmRepository ); ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() ); ChangeLogScmRequest clr = new ChangeLogScmRequest( scmRepository, fileSet ); String version = "HEAD"; clr.setRevision( new ScmRevision( version ) ); ChangeLogScmResult changelogResult = provider.changeLog( clr ); List<ChangeSet> logEntries = changelogResult.getChangeLog().getChangeSets(); assertEquals( String.format( "changelog for %s returned bad number of commits", version ), 5, logEntries.size() ); }
ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() ); assertTrue( firstResult.getProviderMessage() + ": " + firstResult.getCommandLine() + "\n" + firstResult.getCommandOutput(), firstResult.isSuccess() ); int firstLogSize = firstResult.getChangeLog().getChangeSets().size(); assertTrue( "Unexpected initial log size", firstLogSize >= 1 ); assertTrue( secondResult.getProviderMessage(), secondResult.isSuccess() ); assertEquals( firstLogSize + 1, secondResult.getChangeLog().getChangeSets().size() ); assertTrue( thirdResult.getProviderMessage(), thirdResult.isSuccess() ); assertEquals( 1, thirdResult.getChangeLog().getChangeSets().size() ); ChangeSet changeset = thirdResult.getChangeLog().getChangeSets().get( 0 ); assertTrue( changeset.getDate().after( timeBeforeSecond ) );
private Set<String> pathsAffectedByChange(ChangeLogScmRequest scmRequest, Set<ScmFileStatus> statusToInclude, int limit) throws ScmException { Set<String> affected = new LinkedHashSet<>(); ChangeLogScmResult changeLogScmResult = this.manager.changeLog(scmRequest); if (changeLogScmResult.isSuccess()) { List<ChangeSet> changeSets = limit(changeLogScmResult.getChangeLog().getChangeSets(),limit); for (ChangeSet change : changeSets) { List<ChangeFile> files = change.getFiles(); for (final ChangeFile changeFile : files) { if (statusToInclude.contains(changeFile.getAction())) { affected.add(changeFile.getName()); } } } } return affected; }
/** * This method extracts the simple metadata such as revision, lastCommitTimestamp of the commit/hash, author of the commit * from the Changelog available in the SCM repository * @param scmUrl - the SCM url to get the SCM connection * @param workingDir - the Working Copy or Directory of the SCM repo * @return a {@link Map<ExtraManifestKeys,String>} of values extracted form the changelog, with Keys from {@link ExtraManifestKeys} * @throws IOException - any error that might occur while manipulating the SCM Changelog * @throws ScmException - other SCM related exceptions */ public Map<ExtraManifestKeys, String> getChangeLog(String scmUrl, File workingDir) throws IOException, ScmException { Map<ExtraManifestKeys, String> changeLogMap = new HashMap<>(); ScmRepository scmRepository = scmManager.makeScmRepository(scmUrl); ChangeLogScmResult scmResult = scmManager.changeLog(new ChangeLogScmRequest(scmRepository, new ScmFileSet(workingDir, "*"))); if (scmResult.isSuccess()) { List<ChangeSet> changeSetList = scmResult.getChangeLog().getChangeSets(); if (changeSetList != null && !changeSetList.isEmpty()) { //get the latest changelog ChangeSet changeSet = changeSetList.get(0); changeLogMap.put(ExtraManifestKeys.SCM_TYPE, getScmType(scmUrl)); changeLogMap.put(ExtraManifestKeys.SCM_REVISION, changeSet.getRevision()); changeLogMap.put(ExtraManifestKeys.LAST_COMMIT_TIMESTAMP, manifestTimestampFormat(changeSet.getDate())); changeLogMap.put(ExtraManifestKeys.SCM_AUTHOR, changeSet.getAuthor()); } } return changeLogMap; } }
private ChangeLogScmResult executeChangeLogCommand( ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit ) throws ScmException { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); StringBuilder dateInterval = new StringBuilder(); // TRICK: Mercurial 1.9.3 don't accept 1970-01-01 dateInterval.append( dateFormat.format( startDate == null ? new Date( 1000L * 60 * 60 * 24 ) : startDate ) ); // From 2. Jan 1970 dateInterval.append( " to " ); dateInterval.append( dateFormat.format( endDate == null ? new Date() : endDate ) ); // Upto now List<String> cmd = new ArrayList<String>(); cmd.addAll( Arrays.asList( HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.DATE_OPTION, dateInterval.toString() ) ); if ( limit != null && limit > 0 ) { cmd.add( HgCommandConstants.LIMIT_OPTION ); cmd.add( Integer.toString( limit ) ); } HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern ); ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd.toArray( new String[cmd.size()] ) ); List<ChangeSet> logEntries = consumer.getModifications(); ChangeLogSet changeLogSet = new ChangeLogSet( logEntries, startDate, endDate ); return new ChangeLogScmResult( changeLogSet, result ); }
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository r, ScmFileSet f, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { List<ChangeSet> changeLogs = new ArrayList<ChangeSet>(); Iterator<File> iter = f.getFileList().iterator(); if ( !iter.hasNext() ) { List<File> dir = new ArrayList<File>(); // No files to iterate dir.add( f.getBasedir() ); iter = dir.iterator(); } TfsCommand command = null; // tf history takes only one file arg while ( iter.hasNext() ) { TfsChangeLogConsumer out = new TfsChangeLogConsumer( getLogger() ); ErrorStreamConsumer err = new ErrorStreamConsumer(); command = createCommand( r, f, ( (File) iter.next() ) ); int status = command.execute( out, err ); if ( status != 0 || ( !out.hasBeenFed() && err.hasBeenFed() ) ) { return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - " + status, err.getOutput(), false ); } changeLogs.addAll( out.getLogs() ); } return new ChangeLogScmResult( command.getCommandString(), new ChangeLogSet( changeLogs, startDate, endDate ) ); }
/** {@inheritDoc} */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { VssScmProviderRepository repo = (VssScmProviderRepository) repository; Commandline cl = buildCmdLine( repo, fileSet, startDate, endDate ); if ( getLogger().isInfoEnabled() ) { getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); } VssChangeLogConsumer consumer = new VssChangeLogConsumer( repo, datePattern, getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); } return new ChangeLogScmResult( cl.toString(), new ChangeLogSet( consumer.getModifications(), startDate, endDate ) ); }
/** {@inheritDoc} */ protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary ) throws ScmException { VssScmProviderRepository repo = (VssScmProviderRepository) repository; if ( fileSet.getFileList().isEmpty() ) { throw new ScmException( "You must provide at least one file/directory to add" ); } Commandline cl = buildCmdLine( repo, fileSet ); VssAddConsumer consumer = new VssAddConsumer( getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); if ( getLogger().isInfoEnabled() ) { getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); } int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); } return new AddScmResult( cl.toString(), consumer.getAddedFiles() ); }
cl.setWorkingDirectory( fileSet.getBasedir().getAbsolutePath() ); getLogger().debug( "Working directory: " + fileSet.getBasedir().getAbsolutePath() ); getLogger().debug( "Command line: " + cl ); return new ChangeLogScmResult( cl.toString(), "The cvs command failed.", stderr.getOutput(), false ); return new ChangeLogScmResult( cl.toString(), consumer.getModifications() );
getChangeLog( changelogStream, streamDifferences, streamHistory, workspaceHistory, startDate, endDate ); changeLog.setEndVersion( endVersion ); changeLog.setStartVersion( startVersion ); return new ChangeLogScmResult( accurev.getCommandLines(), changeLog ); return new ChangeLogScmResult( accurev.getCommandLines(), "AccuRev errors: " + errorMessage, accurev.getErrorOutput(), false );
/** * {@inheritDoc} */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repo, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repo; SVNRevision startRevision = ( startDate != null ) ? SVNRevision.create( startDate ) : SVNRevision.UNDEFINED; SVNRevision endRevision = ( endDate != null ) ? SVNRevision.create( endDate ) : SVNRevision.HEAD; try { SVNURL url = javaRepo.getSvnUrl(); if ( branch != null ) { url = SVNURL.parseURIEncoded( SvnTagBranchUtils.resolveBranchUrl( javaRepo, branch ) ); } ChangeLogHandler handler = new ChangeLogHandler( startDate, endDate ); SvnJavaUtil.changelog( javaRepo.getClientManager(), url, startRevision, endRevision, true, // stopOnCopy true, // reportPaths handler ); return new ChangeLogScmResult( SvnJavaScmProvider.COMMAND_LINE, handler.getChangeSets() ); } catch ( SVNException e ) { return new ChangeLogScmResult( SvnJavaScmProvider.COMMAND_LINE, "SVN Changelog failed.", e.getMessage(), false ); } }
@SuppressWarnings( "deprecation" ) private void testChangeLog( Date startDate, Date endDate, int changeLogSize, String branch ) throws Exception { if ( !isSystemCmd( CvsScmTestUtils.CVS_COMMAND_LINE ) ) { ScmTestCase.printSystemCmdUnavail( CvsScmTestUtils.CVS_COMMAND_LINE, getName() ); return; } ScmManager scmManager = getScmManager(); CvsScmTestUtils.executeCVS( getWorkingDirectory(), "-f -d " + getTestFile( "src/test/repository/" ) + " co " + getModule() ); ChangeLogScmResult changeLogResult = scmManager.getProviderByRepository( getScmRepository() ).changeLog( getScmRepository(), getScmFileSet(), startDate, endDate, 0, branch ); if ( !changeLogResult.isSuccess() ) { fail( changeLogResult.getProviderMessage() + "\n" + changeLogResult.getCommandOutput() ); } ChangeLogSet changeLogSet = changeLogResult.getChangeLog(); assertNotNull( changeLogSet ); assertEquals( changeLogSize, changeLogSet.getChangeSets().size() ); } }
private Date getLatestUpdateDate( ChangeLogScmResult changeLogScmResult ) { ChangeLogSet changeLogSet = changeLogScmResult.getChangeLog(); if ( changeLogSet != null ) { List<ChangeSet> changes = changeLogSet.getChangeSets(); if ( changes != null && !changes.isEmpty() ) { long date = 0; for ( ChangeSet change : changes ) { if ( date < change.getDate().getTime() ) { date = change.getDate().getTime(); } } if ( date != 0 ) { return new Date( date ); } } } return null; }
public void execute( Map context ) throws Exception { Project project = ContinuumBuildAgentUtil.getProject( context ); try { File workingDirectory = buildAgentConfigurationService.getWorkingDirectory( project.getId() ); ContinuumScmConfiguration config = createScmConfiguration( project, workingDirectory ); config.setLatestUpdateDate( ContinuumBuildAgentUtil.getLatestUpdateDate( context ) ); getLogger().info( "Getting changeLog of project: " + project.getName() ); ChangeLogScmResult changeLogResult = scm.changeLog( config ); if ( !changeLogResult.isSuccess() ) { getLogger().warn( "Error getting change log of project " + project.getName() ); getLogger().warn( "Command Output: " + changeLogResult.getCommandOutput() ); getLogger().warn( "Provider Message: " + changeLogResult.getProviderMessage() ); } context.put( ContinuumBuildAgentUtil.KEY_LATEST_UPDATE_DATE, getLatestUpdateDate( changeLogResult ) ); } catch ( ScmException e ) { context.put( ContinuumBuildAgentUtil.KEY_LATEST_UPDATE_DATE, null ); getLogger().error( e.getMessage(), e ); } }
private ChangeLogScmResult executeChangeLogCommand( ScmFileSet fileSet, Date startDate, Date endDate, String datePattern, Integer limit ) throws ScmException { SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); StringBuilder dateInterval = new StringBuilder(); // TRICK: Mercurial 1.9.3 don't accept 1970-01-01 dateInterval.append( dateFormat.format( startDate == null ? new Date( 1000L * 60 * 60 * 24 ) : startDate ) ); // From 2. Jan 1970 dateInterval.append( " to " ); dateInterval.append( dateFormat.format( endDate == null ? new Date() : endDate ) ); // Upto now List<String> cmd = new ArrayList<String>(); cmd.addAll( Arrays.asList( HgCommandConstants.LOG_CMD, HgCommandConstants.TEMPLATE_OPTION, HgCommandConstants.TEMPLATE_FORMAT, HgCommandConstants.NO_MERGES_OPTION, HgCommandConstants.DATE_OPTION, dateInterval.toString() ) ); if ( limit != null && limit > 0 ) { cmd.add( HgCommandConstants.LIMIT_OPTION ); cmd.add( Integer.toString( limit ) ); } HgChangeLogConsumer consumer = new HgChangeLogConsumer( getLogger(), datePattern ); ScmResult result = HgUtils.execute( consumer, getLogger(), fileSet.getBasedir(), cmd.toArray( new String[cmd.size()] ) ); List<ChangeSet> logEntries = consumer.getModifications(); ChangeLogSet changeLogSet = new ChangeLogSet( logEntries, startDate, endDate ); return new ChangeLogScmResult( changeLogSet, result ); }
protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository r, ScmFileSet f, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { List<ChangeSet> changeLogs = new ArrayList<ChangeSet>(); Iterator<File> iter = f.getFileList().iterator(); if ( !iter.hasNext() ) { List<File> dir = new ArrayList<File>(); // No files to iterate dir.add( f.getBasedir() ); iter = dir.iterator(); } TfsCommand command = null; // tf history takes only one file arg while ( iter.hasNext() ) { TfsChangeLogConsumer out = new TfsChangeLogConsumer( getLogger() ); ErrorStreamConsumer err = new ErrorStreamConsumer(); command = createCommand( r, f, ( (File) iter.next() ) ); int status = command.execute( out, err ); if ( status != 0 || ( !out.hasBeenFed() && err.hasBeenFed() ) ) { return new ChangeLogScmResult( command.getCommandString(), "Error code for TFS changelog command - " + status, err.getOutput(), false ); } changeLogs.addAll( out.getLogs() ); } return new ChangeLogScmResult( command.getCommandString(), new ChangeLogSet( changeLogs, startDate, endDate ) ); }
final ScmTag scmTag = (tag == null) ? null : new ScmTag(tag); final ScmFileSet fileSet = new ScmFileSet(mojo.getBasedir()); IWFCEnum.checkState(macroDefinition.getOnMissingProperty(), result.isSuccess(), "scm revision '" + rev + "'"); if (!result.isSuccess()) { return ""; final List<ChangeSet> changeSets = result.getChangeLog().getChangeSets(); Preconditions.checkState(changeSets != null && changeSets.size() > 0, "no change sets found!"); return changeSets.get(0).getRevision();
/** {@inheritDoc} */ protected ChangeLogScmResult executeChangeLogCommand( ScmProviderRepository repository, ScmFileSet fileSet, Date startDate, Date endDate, ScmBranch branch, String datePattern ) throws ScmException { VssScmProviderRepository repo = (VssScmProviderRepository) repository; Commandline cl = buildCmdLine( repo, fileSet, startDate, endDate ); if ( getLogger().isInfoEnabled() ) { getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); } VssChangeLogConsumer consumer = new VssChangeLogConsumer( repo, datePattern, getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); } return new ChangeLogScmResult( cl.toString(), new ChangeLogSet( consumer.getModifications(), startDate, endDate ) ); }
/** {@inheritDoc} */ protected ScmResult executeAddCommand( ScmProviderRepository repository, ScmFileSet fileSet, String message, boolean binary ) throws ScmException { VssScmProviderRepository repo = (VssScmProviderRepository) repository; if ( fileSet.getFileList().isEmpty() ) { throw new ScmException( "You must provide at least one file/directory to add" ); } Commandline cl = buildCmdLine( repo, fileSet ); VssAddConsumer consumer = new VssAddConsumer( getLogger() ); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); if ( getLogger().isInfoEnabled() ) { getLogger().info( "Executing: " + cl ); getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath() ); } int exitCode = VssCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); if ( exitCode != 0 ) { return new ChangeLogScmResult( cl.toString(), "The vss command failed.", stderr.getOutput(), false ); } return new AddScmResult( cl.toString(), consumer.getAddedFiles() ); }