Index: C:/development/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/ScmCommitPhase.java =================================================================== --- C:/development/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/ScmCommitPhase.java (revision 440426) +++ C:/development/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/ScmCommitPhase.java (working copy) @@ -16,6 +16,14 @@ * limitations under the License. */ +import java.io.File; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.apache.maven.plugins.release.ReleaseExecutionException; import org.apache.maven.plugins.release.ReleaseFailureException; import org.apache.maven.plugins.release.config.ReleaseConfiguration; @@ -30,22 +38,20 @@ import org.apache.maven.scm.provider.ScmProvider; import org.apache.maven.scm.repository.ScmRepository; import org.apache.maven.scm.repository.ScmRepositoryException; +import org.apache.maven.settings.Profile; +import org.apache.maven.settings.Settings; -import java.io.File; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - /** * Commit the project to the SCM. - * + * * @author Brett Porter */ -public class ScmCommitPhase - extends AbstractReleasePhase -{ +public class ScmCommitPhase extends AbstractReleasePhase { + + public static final String TRUE = "true"; + + public static final String WINNTCVS = "winntcvs"; + /** * Tool that gets a configured SCM repository from release configuration. */ @@ -56,80 +62,165 @@ */ private String messageFormat; - public void execute( ReleaseConfiguration releaseConfiguration ) - throws ReleaseExecutionException, ReleaseFailureException - { - validateConfiguration( releaseConfiguration ); + public void execute(ReleaseConfiguration releaseConfiguration) + throws ReleaseExecutionException, ReleaseFailureException { + validateConfiguration(releaseConfiguration); - getLogger().info( "Checking in modified POMs..." ); + getLogger().info("Checking in modified POMs..."); ScmRepository repository; ScmProvider provider; - try - { - repository = scmRepositoryConfigurator.getConfiguredRepository( releaseConfiguration ); + try { + repository = scmRepositoryConfigurator + .getConfiguredRepository(releaseConfiguration); - provider = scmRepositoryConfigurator.getRepositoryProvider( repository ); + provider = scmRepositoryConfigurator + .getRepositoryProvider(repository); + } catch (ScmRepositoryException e) { + throw new ReleaseScmRepositoryException(e.getMessage(), e + .getValidationMessages()); + } catch (NoSuchScmProviderException e) { + throw new ReleaseExecutionException( + "Unable to configure SCM repository: " + e.getMessage(), e); } - catch ( ScmRepositoryException e ) - { - throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages() ); + + Collection pomFiles = createPomFiles(releaseConfiguration + .getReactorProjects()); + + File[] files; + + boolean winntcvs = isWinNtCvs(releaseConfiguration); + + getLogger().info("Using WinNT CVS:" + winntcvs); + + if (winntcvs) { + + // loop through each pom and submit it individually + for (Iterator itr = pomFiles.iterator(); itr.hasNext();) { + files = new File[] { (File) itr.next() }; + commitFiles(releaseConfiguration, repository, provider, files); + } + } - catch ( NoSuchScmProviderException e ) - { - throw new ReleaseExecutionException( "Unable to configure SCM repository: " + e.getMessage(), e ); + + else { + files = (File[]) pomFiles.toArray(new File[pomFiles.size()]); + commitFiles(releaseConfiguration, repository, provider, files); } - Collection pomFiles = createPomFiles( releaseConfiguration.getReactorProjects() ); - File[] files = (File[]) pomFiles.toArray( new File[pomFiles.size()] ); + } + public void simulate(ReleaseConfiguration releaseConfiguration) + throws ReleaseExecutionException, ReleaseFailureException { + validateConfiguration(releaseConfiguration); + + boolean winntcvs = isWinNtCvs(releaseConfiguration); + + getLogger().info("Using WinNT CVS:" + winntcvs); + + Collection pomFiles = createPomFiles(releaseConfiguration + .getReactorProjects()); + getLogger().info( + "Full run would be checking in " + pomFiles.size() + + " files with message: '" + + createMessage(releaseConfiguration) + "'"); + } + + /** + * Commit the files to cvs + * + * @param releaseConfiguration + * @param repository + * @param provider + * @param files + * @throws ReleaseExecutionException + * @throws ReleaseScmCommandException + */ + private void commitFiles(ReleaseConfiguration releaseConfiguration, + ScmRepository repository, ScmProvider provider, File[] files) + throws ReleaseExecutionException, ReleaseScmCommandException { CheckInScmResult result; - try - { - ScmFileSet fileSet = new ScmFileSet( releaseConfiguration.getWorkingDirectory(), files ); - result = provider.checkIn( repository, fileSet, null, createMessage( releaseConfiguration ) ); + try { + ScmFileSet fileSet = new ScmFileSet(releaseConfiguration + .getWorkingDirectory(), files); + result = provider.checkIn(repository, fileSet, null, + createMessage(releaseConfiguration)); + } catch (ScmException e) { + throw new ReleaseExecutionException( + "An error is occurred in the checkin process: " + + e.getMessage(), e); } - catch ( ScmException e ) - { - throw new ReleaseExecutionException( "An error is occurred in the checkin process: " + e.getMessage(), e ); + if (!result.isSuccess()) { + throw new ReleaseScmCommandException("Unable to commit files", + result); } - if ( !result.isSuccess() ) - { - throw new ReleaseScmCommandException( "Unable to commit files", result ); - } } - public void simulate( ReleaseConfiguration releaseConfiguration ) - throws ReleaseExecutionException, ReleaseFailureException - { - validateConfiguration( releaseConfiguration ); + /** + * Check if the user has winnt cvs + * + * @param releaseConfiguration + * @return + */ + private boolean isWinNtCvs(ReleaseConfiguration releaseConfiguration) { - Collection pomFiles = createPomFiles( releaseConfiguration.getReactorProjects() ); - getLogger().info( "Full run would be checking in " + pomFiles.size() + " files with message: '" + - createMessage( releaseConfiguration ) + "'" ); + Settings settings = releaseConfiguration.getSettings(); + + if (settings == null) { + return false; + } + + settings.flushProfileMap(); + // check each active profile for the setting + Map profiles = settings.getProfilesAsMap(); + + List activeProfiles = settings.getActiveProfiles(); + + String activeProfile; + Profile profile; + + for (int i = 0; activeProfiles != null && i < activeProfiles.size(); i++) { + + activeProfile = (String) activeProfiles.get(i); + + profile = (Profile) profiles.get(activeProfile); + + // profile is sometimes null, check the next one. + if (profile == null) { + getLogger().debug("Active profile not found. Did you misspell the active profile?"); + continue; + } + + String winnt = profile.getProperties().getProperty(WINNTCVS); + + if (TRUE.equals(winnt)) { + return true; + } + } + + // if we get here its not set. + return false; } - private static void validateConfiguration( ReleaseConfiguration releaseConfiguration ) - throws ReleaseFailureException - { - if ( releaseConfiguration.getReleaseLabel() == null ) - { - throw new ReleaseFailureException( "A release label is required for committing" ); + private static void validateConfiguration( + ReleaseConfiguration releaseConfiguration) + throws ReleaseFailureException { + if (releaseConfiguration.getReleaseLabel() == null) { + throw new ReleaseFailureException( + "A release label is required for committing"); } } - private String createMessage( ReleaseConfiguration releaseConfiguration ) - { - return MessageFormat.format( messageFormat, new Object[]{releaseConfiguration.getReleaseLabel()} ); + private String createMessage(ReleaseConfiguration releaseConfiguration) { + return MessageFormat.format(messageFormat, + new Object[] { releaseConfiguration.getReleaseLabel() }); } - private static Collection createPomFiles( List reactorProjects ) - { - List pomFiles = new ArrayList( reactorProjects.size() ); - for ( Iterator i = reactorProjects.iterator(); i.hasNext(); ) - { + private static Collection createPomFiles(List reactorProjects) { + List pomFiles = new ArrayList(reactorProjects.size()); + for (Iterator i = reactorProjects.iterator(); i.hasNext();) { MavenProject project = (MavenProject) i.next(); - pomFiles.add( project.getFile() ); + pomFiles.add(project.getFile()); } return pomFiles; }