@Test public void testCreatePomFilesSuppressCommitBeforeTag() throws Exception { ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor(); releaseDescriptor.setSuppressCommitBeforeTagOrBranch(true); List<File> files = AbstractScmCommitPhase.createPomFiles( releaseDescriptor, createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); assertEquals("Number of created files", files.size(), 1); assertTrue(files.contains(new File("pom.xml"))); }
@Test public void testCreatePomFilesWithReleasePom() throws Exception { ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor(); releaseDescriptor.setGenerateReleasePoms(true); List<File> files = AbstractScmCommitPhase.createPomFiles( releaseDescriptor, createProject("artifactId", "1.0-SNAPSHOT", new File("pom.xml"))); assertEquals("Number of created files", files.size(), 2); assertTrue(files.contains(new File("pom.xml"))); assertTrue(files.contains(new File("release-pom.xml"))); }
public ReleaseResult execute( ReleaseDescriptor releaseDescriptor, ReleaseEnvironment releaseEnvironment, List reactorProjects) throws ReleaseExecutionException, ReleaseFailureException { ReleaseResult relResult = new ReleaseResult(); List additionalExcludes = releaseDescriptor.getCheckModificationExcludes(); if (additionalExcludes != null) { for (int i1 = 0, additionalExcludesSize = additionalExcludes.size(); i1 < additionalExcludesSize; i1++) { // fail fast if it is not a string String exclude = (String) additionalExcludes.get(i1); excludedFiles.add(exclude); } } logInfo(relResult, "Verifying that there are no local modifications..."); logInfo(relResult, " ignoring changes on: " + StringUtils.join(excludedFiles, ", ")); ScmRepository repository; ScmProvider provider; try { repository = scmRepositoryConfigurator.getConfiguredRepository( releaseDescriptor, releaseEnvironment.getSettings()); provider = scmRepositoryConfigurator.getRepositoryProvider(repository); } catch (ScmRepositoryException e) { throw new ReleaseScmRepositoryException( e.getMessage() + " for URL: " + releaseDescriptor.getScmSourceUrl(), e.getValidationMessages()); } catch (NoSuchScmProviderException e) { throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e); } StatusScmResult result; try { result = provider.status( repository, new ScmFileSet(new File(releaseDescriptor.getWorkingDirectory()))); } catch (ScmException e) { throw new ReleaseExecutionException( "An error occurred during the status check process: " + e.getMessage(), e); } if (!result.isSuccess()) { throw new ReleaseScmCommandException("Unable to check for local modifications", result); } List changedFiles = result.getChangedFiles(); // TODO: would be nice for SCM status command to do this for me. for (Iterator i = changedFiles.iterator(); i.hasNext(); ) { ScmFile f = (ScmFile) i.next(); String fileName = f.getPath().replace('\\', '/'); fileName = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length()); if (excludedFiles.contains(fileName)) { i.remove(); } } if (!changedFiles.isEmpty()) { StringBuffer message = new StringBuffer(); for (Iterator i = changedFiles.iterator(); i.hasNext(); ) { ScmFile file = (ScmFile) i.next(); message.append(file.toString()); message.append("\n"); } throw new ReleaseFailureException( "Cannot prepare the release because you have local modifications : \n" + message); } relResult.setResultCode(ReleaseResult.SUCCESS); return relResult; }
/** {@inheritDoc} */ public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); ReleaseDescriptor config = createReleaseDescriptor(); config.setAddSchema(addSchema); config.setScmUseEditMode(useEditMode); config.setUpdateDependencies(updateDependencies); config.setAutoVersionSubmodules(autoVersionSubmodules); config.setScmReleaseLabel(branchName); config.setScmBranchBase(branchBase); config.setBranchCreation(true); config.setUpdateBranchVersions(updateBranchVersions); config.setUpdateWorkingCopyVersions(updateWorkingCopyVersions); config.setUpdateVersionsToSnapshot(updateVersionsToSnapshot); config.setRemoteTagging(remoteTagging); config.setDefaultReleaseVersion(releaseVersion); config.setDefaultDevelopmentVersion(developmentVersion); config.setSuppressCommitBeforeTagOrBranch(suppressCommitBeforeBranch); // Create a config containing values from the session properties (ie command line properties // with cli). ReleaseDescriptor sysPropertiesConfig = ReleaseUtils.copyPropertiesToReleaseDescriptor(session.getExecutionProperties()); mergeCommandLineConfig(config, sysPropertiesConfig); if (checkModificationExcludeList != null) { checkModificationExcludes = checkModificationExcludeList.replaceAll("\\s", "").split(","); } if (checkModificationExcludes != null) { config.setCheckModificationExcludes(Arrays.asList(checkModificationExcludes)); } try { releaseManager.branch(config, getReleaseEnvironment(), getReactorProjects(), dryRun); } catch (ReleaseExecutionException e) { throw new MojoExecutionException(e.getMessage(), e); } catch (ReleaseFailureException e) { throw new MojoFailureException(e.getMessage(), e); } }