org.apache.maven.scm.ScmFileSet Java Examples
The following examples show how to use
org.apache.maven.scm.ScmFileSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScmSpy.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
/** * 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; }
Example #2
Source File: ScmSpy.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
/** * 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<String,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<String, String> getChangeLog(String scmUrl, File workingDir) throws IOException, ScmException { Map<String, 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.scmType.name(), getScmType(scmUrl)); changeLogMap.put(ExtraManifestKeys.scmRevision.name(), changeSet.getRevision()); changeLogMap.put(ExtraManifestKeys.lastCommitTimestamp.name(), manifestTimestampFormat(changeSet.getDate())); changeLogMap.put(ExtraManifestKeys.author.name(), changeSet.getAuthor()); } } return changeLogMap; }
Example #3
Source File: GoogleFormatterMojo.java From googleformatter-maven-plugin with Apache License 2.0 | 6 votes |
private Set<File> filterUnchangedFiles(Set<File> originalFiles) throws MojoExecutionException { MavenProject topLevelProject = session.getTopLevelProject(); try { if (topLevelProject.getScm().getConnection() == null && topLevelProject.getScm().getDeveloperConnection() == null) { throw new MojoExecutionException( "You must supply at least one of scm.connection or scm.developerConnection in your POM file if you " + "specify the filterModified or filter.modified option."); } String connectionUrl = MoreObjects.firstNonNull(topLevelProject.getScm().getConnection(), topLevelProject.getScm().getDeveloperConnection()); ScmRepository repository = scmManager.makeScmRepository(connectionUrl); ScmFileSet scmFileSet = new ScmFileSet(topLevelProject.getBasedir()); String basePath = topLevelProject.getBasedir().getAbsoluteFile().getPath(); List<String> changedFiles = scmManager.status(repository, scmFileSet).getChangedFiles().stream() .map(f -> new File(basePath, f.getPath()).toString()) .collect(Collectors.toList()); return originalFiles.stream().filter(f -> changedFiles.contains(f.getPath())).collect(Collectors.toSet()); } catch (ScmException e) { throw new MojoExecutionException(e.getMessage(), e); } }
Example #4
Source File: AbstractScmMojo.java From buildnumber-maven-plugin with MIT License | 6 votes |
/** * Get info from scm. * * @param repository * @param fileSet * @return * @throws ScmException * @todo this should be rolled into org.apache.maven.scm.provider.ScmProvider and * org.apache.maven.scm.provider.svn.SvnScmProvider */ protected InfoScmResult info( ScmRepository repository, ScmFileSet fileSet ) throws ScmException { CommandParameters commandParameters = new CommandParameters(); // only for Git, we will make a test for shortRevisionLength parameter if ( GitScmProviderRepository.PROTOCOL_GIT.equals( scmManager.getProviderByRepository( repository ).getScmType() ) && this.shortRevisionLength > 0 ) { getLog().info( "ShortRevision tag detected. The value is '" + this.shortRevisionLength + "'." ); if ( shortRevisionLength >= 0 && shortRevisionLength < 4 ) { getLog().warn( "shortRevision parameter less then 4. ShortRevisionLength is relaying on 'git rev-parese --short=LENGTH' command, accordingly to Git rev-parse specification the LENGTH value is miminum 4. " ); } commandParameters.setInt( CommandParameter.SCM_SHORT_REVISION_LENGTH, this.shortRevisionLength ); } if ( !StringUtils.isBlank( scmTag ) && !"HEAD".equals( scmTag ) ) { commandParameters.setScmVersion( CommandParameter.SCM_VERSION, new ScmTag( scmTag ) ); } return scmManager.getProviderByRepository( repository ).info( repository.getProviderRepository(), fileSet, commandParameters ); }
Example #5
Source File: ScmUtils.java From gitflow-helper-maven-plugin with Apache License 2.0 | 5 votes |
private static String sha1ForHEAD(ScmLogger logger, ScmFileSet fileSet) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "rev-parse" ); cl.createArg().setValue("HEAD"); RevParseConsumer rpConsumer = new RevParseConsumer(logger); execGitCmd(logger, rpConsumer, cl); return rpConsumer.getRev(); }
Example #6
Source File: ScmUtils.java From gitflow-helper-maven-plugin with Apache License 2.0 | 5 votes |
private static Set<String> branchesForSha1(String sha1, ScmLogger logger, ScmFileSet fileSet) throws ScmException { Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "show-ref" ); ShowRefForSha1Consumer srConsumer = new ShowRefForSha1Consumer(sha1, logger); execGitCmd(logger, srConsumer, cl); return srConsumer.getBranches(); }
Example #7
Source File: CreateMojo.java From buildnumber-maven-plugin with MIT License | 5 votes |
public List<ScmFile> update() throws MojoExecutionException { try { ScmRepository repository = getScmRepository(); ScmProvider scmProvider = scmManager.getProviderByRepository( repository ); UpdateScmResult result = scmProvider.update( repository, new ScmFileSet( scmDirectory ) ); if ( result == null ) { return Collections.emptyList(); } checkResult( result ); if ( result instanceof UpdateScmResultWithRevision ) { String revision = ( (UpdateScmResultWithRevision) result ).getRevision(); getLog().info( "Got a revision during update: " + revision ); this.revision = revision; } return result.getUpdatedFiles(); } catch ( ScmException e ) { throw new MojoExecutionException( "Couldn't update project. " + e.getMessage(), e ); } }
Example #8
Source File: CreateMojo.java From buildnumber-maven-plugin with MIT License | 5 votes |
/** * Get the branch info for this revision from the repository. For svn, it is in svn info. * * @return * @throws MojoExecutionException * @throws MojoExecutionException */ public String getScmBranch() throws MojoExecutionException { try { ScmRepository repository = getScmRepository(); ScmProvider provider = scmManager.getProviderByRepository( repository ); /* git branch can be obtained directly by a command */ if ( GitScmProviderRepository.PROTOCOL_GIT.equals( provider.getScmType() ) ) { ScmFileSet fileSet = new ScmFileSet( scmDirectory ); return GitBranchCommand.getCurrentBranch( getLogger(), (GitScmProviderRepository) repository.getProviderRepository(), fileSet ); } else if ( provider instanceof HgScmProvider ) { /* hg branch can be obtained directly by a command */ HgOutputConsumer consumer = new HgOutputConsumer( getLogger() ); ScmResult result = HgUtils.execute( consumer, logger, scmDirectory, new String[] { "id", "-b" } ); checkResult( result ); if ( StringUtils.isNotEmpty( consumer.getOutput() ) ) { return consumer.getOutput(); } } } catch ( ScmException e ) { getLog().warn( "Cannot get the branch information from the git repository: \n" + e.getLocalizedMessage() ); } return getScmBranchFromUrl(); }
Example #9
Source File: ScmMojo.java From pitest with Apache License 2.0 | 5 votes |
private Set<String> localChanges(Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException { final StatusScmResult status = this.manager.status(repository, new ScmFileSet(scmRoot)); Set<String> affected = new LinkedHashSet<>(); for (final ScmFile file : status.getChangedFiles()) { if (statusToInclude.contains(file.getStatus())) { affected.add(file.getPath()); } } return affected; }
Example #10
Source File: ScmMojoTest.java From pitest with Apache License 2.0 | 5 votes |
private void setFileWithStatus(final ScmFileStatus status) throws ScmException { when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class))) .thenReturn( new StatusScmResult("", Arrays.asList(new ScmFile( "foo/bar/Bar.java", status)))); }
Example #11
Source File: ScmMojoTest.java From pitest with Apache License 2.0 | 5 votes |
public void testUnknownAndDeletedClassesAreNotMutationTested() throws Exception { setupConnection(); when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class))) .thenReturn( new StatusScmResult("", Arrays.asList(new ScmFile( "foo/bar/Bar.java", ScmFileStatus.DELETED), new ScmFile( "foo/bar/Bar.java", ScmFileStatus.UNKNOWN)))); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), any(ReportOptions.class), any(PluginServices.class), anyMap()); }
Example #12
Source File: TagMasterMojo.java From gitflow-helper-maven-plugin with Apache License 2.0 | 4 votes |
@Override protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionException, MojoFailureException { if (project.isExecutionRoot() && (gitBranchInfo.getType().equals(GitBranchType.MASTER) || gitBranchInfo.getType().equals(GitBranchType.SUPPORT))) { if (gitURLExpression == null) { gitURLExpression = ScmUtils.resolveUrlOrExpression(project); } String gitURL = resolveExpression(gitURLExpression); if (!gitURL.startsWith("scm:git:")) { gitURL = "scm:git:" + gitURL; } getLog().debug("gitURLExpression: '" + gitURLExpression + "' resolved to: '" + gitURL + "'"); ExpansionBuffer eb = new ExpansionBuffer(gitURL); if (!eb.hasMoreLegalPlaceholders()) { getLog().info("Tagging SCM for CI build matching branchPattern: [" + gitBranchInfo.getPattern() + "]"); try { ScmRepository repository = scmManager.makeScmRepository(gitURL); ScmProvider provider = scmManager.getProviderByRepository(repository); String sanitizedTag = provider.sanitizeTagName(tag); getLog().info("Sanitized tag: '" + sanitizedTag + "'"); ScmTagParameters tagParams = new ScmTagParameters("Release tag [" + sanitizedTag + "] generated by gitflow-helper-maven-plugin."); tagParams.setRemoteTagging(true); final TagScmResult tagScmResult = provider.tag(repository, new ScmFileSet(project.getBasedir()), sanitizedTag, tagParams); if (!tagScmResult.isSuccess()) { getLog().error("Provider message:"); getLog().error(tagScmResult.getProviderMessage()); getLog().error("Command output:"); getLog().error(tagScmResult.getCommandOutput()); throw new MojoFailureException(tagScmResult.getProviderMessage() ); } } catch (ScmException scme) { throw new MojoFailureException("Unable to tag master branch.", scme); } } else { throw new MojoFailureException("Unable to resolve gitURLExpression: " + gitURLExpression + ". Leaving build configuration unaltered."); } } }
Example #13
Source File: CreateMojo.java From buildnumber-maven-plugin with MIT License | 4 votes |
public List<ScmFile> getStatus() throws ScmException { ScmRepository repository = getScmRepository(); ScmProvider scmProvider = scmManager.getProviderByRepository( repository ); StatusScmResult result = scmProvider.status( repository, new ScmFileSet( scmDirectory ) ); if ( result == null ) { return Collections.emptyList(); } checkResult( result ); return result.getChangedFiles(); }
Example #14
Source File: ScmMojo.java From pitest with Apache License 2.0 | 4 votes |
private Set<String> lastCommitChanges(Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException { ChangeLogScmRequest scmRequest = new ChangeLogScmRequest(repository, new ScmFileSet(scmRoot)); scmRequest.setLimit(1); return pathsAffectedByChange(scmRequest, statusToInclude, 1); }
Example #15
Source File: ScmMojo.java From pitest with Apache License 2.0 | 4 votes |
private Set<String> changesBetweenBranchs(String origine, String destination, Set<ScmFileStatus> statusToInclude, ScmRepository repository, File scmRoot) throws ScmException { ChangeLogScmRequest scmRequest = new ChangeLogScmRequest(repository, new ScmFileSet(scmRoot)); scmRequest.setScmBranch(new ScmBranch(destination + ".." + origine)); return pathsAffectedByChange(scmRequest, statusToInclude, NO_LIMIT); }
Example #16
Source File: ScmMojoTest.java From pitest with Apache License 2.0 | 4 votes |
private void setupToReturnNoModifiedFiles() throws ScmException { when(this.manager.status(any(ScmRepository.class), any(ScmFileSet.class))) .thenReturn(new StatusScmResult("", Collections.<ScmFile> emptyList())); }