Author: rfscholte
Date: Thu Apr 12 19:55:06 2012
New Revision: 1325475
URL: http://svn.apache.org/viewvc?rev=1325475&view=rev
Log:
Fix MRELEASE-645: Allow File/Directory Patterns for the
checkModificationExcludes Option
Modified:
maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java
maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java
Modified:
maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java
URL:
http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java?rev=1325475&r1=1325474&r2=1325475&view=diff
==============================================================================
---
maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java
(original)
+++
maven/release/trunk/maven-release-manager/src/main/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhase.java
Thu Apr 12 19:55:06 2012
@@ -36,6 +36,7 @@ import org.apache.maven.shared.release.e
import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
+import org.codehaus.plexus.util.SelectorUtils;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
@@ -47,7 +48,7 @@ import java.util.Set;
/**
* See if there are any local modifications to the files before proceeding
with SCM operations and the release.
- *
+ *
* @author <a href="mailto:[email protected]">Brett Porter</a>
* @plexus.component role="org.apache.maven.shared.release.phase.ReleasePhase"
role-hint="scm-check-modifications"
*/
@@ -56,18 +57,20 @@ public class ScmCheckModificationsPhase
{
/**
* Tool that gets a configured SCM repository from release configuration.
- *
+ *
* @plexus.requirement
*/
private ScmRepositoryConfigurator scmRepositoryConfigurator;
/**
- * The files to exclude from the status check.
- *
+ * The filepatterns to exclude from the status check.
+ *
* @todo proper construction of filenames, especially release properties
*/
- private Set<String> excludedFiles = new HashSet<String>( Arrays.asList(
new String[] { "pom.xml.backup",
- "pom.xml.tag", "pom.xml.next", "pom.xml.branch", "release.properties",
"pom.xml.releaseBackup" } ) );
+ private Set<String> exclusionPatterns = new HashSet<String>(
Arrays.asList( new String[] {
+ "**" + File.separator + "pom.xml.backup", "**" + File.separator +
"pom.xml.tag",
+ "**" + File.separator + "pom.xml.next", "**" + File.separator +
"pom.xml.branch",
+ "**" + File.separator + "release.properties", "**" + File.separator +
"pom.xml.releaseBackup" } ) );
public ReleaseResult execute( ReleaseDescriptor releaseDescriptor,
ReleaseEnvironment releaseEnvironment,
List<MavenProject> reactorProjects )
@@ -79,14 +82,15 @@ public class ScmCheckModificationsPhase
if ( additionalExcludes != null )
{
- for ( int i1 = 0, additionalExcludesSize =
additionalExcludes.size(); i1 < additionalExcludesSize; i1++ )
+ // SelectorUtils expects OS-specific paths and patterns
+ for( String additionalExclude : additionalExcludes )
{
- excludedFiles.add( additionalExcludes.get( i1 ) );
+ exclusionPatterns.add( additionalExclude.replace( "\\",
File.separator ).replace( "/", File.separator ) );
}
}
logInfo( relResult, "Verifying that there are no local
modifications..." );
- logInfo( relResult, " ignoring changes on: " + StringUtils.join(
excludedFiles.toArray(), ", " ) );
+ logInfo( relResult, " ignoring changes on: " + StringUtils.join(
exclusionPatterns.toArray(), ", " ) );
ScmRepository repository;
ScmProvider provider;
@@ -99,8 +103,8 @@ public class ScmCheckModificationsPhase
}
catch ( ScmRepositoryException e )
{
- throw new ReleaseScmRepositoryException(
- e.getMessage() + " for URL: " +
releaseDescriptor.getScmSourceUrl(), e.getValidationMessages() );
+ throw new ReleaseScmRepositoryException( e.getMessage() + " for
URL: "
+ + releaseDescriptor.getScmSourceUrl(),
e.getValidationMessages() );
}
catch ( NoSuchScmProviderException e )
{
@@ -131,12 +135,16 @@ public class ScmCheckModificationsPhase
{
ScmFile f = i.next();
- String fileName = f.getPath().replace( '\\', '/' );
- fileName = fileName.substring( fileName.lastIndexOf( '/' ) + 1,
fileName.length() );
+ // SelectorUtils expects File.separator, don't standardize!
+ String fileName = f.getPath().replace( "\\", File.separator
).replace( "/", File.separator );
- if ( excludedFiles.contains( fileName ) )
+ for( String exclusionPattern : exclusionPatterns )
{
- i.remove();
+ if ( SelectorUtils.matchPath( exclusionPattern, fileName ) )
+ {
+ logDebug( relResult, "Ignoring changed file: " + fileName
);
+ i.remove();
+ }
}
}
@@ -150,8 +158,8 @@ public class ScmCheckModificationsPhase
message.append( "\n" );
}
- throw new ReleaseFailureException(
- "Cannot prepare the release because you have local
modifications : \n" + message );
+ throw new ReleaseFailureException( "Cannot prepare the release
because you have local modifications : \n"
+ + message );
}
relResult.setResultCode( ReleaseResult.SUCCESS );
@@ -166,4 +174,4 @@ public class ScmCheckModificationsPhase
// It makes no modifications, so simulate is the same as execute
return execute( releaseDescriptor, releaseEnvironment, reactorProjects
);
}
-}
+}
\ No newline at end of file
Modified:
maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java
URL:
http://svn.apache.org/viewvc/maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java?rev=1325475&r1=1325474&r2=1325475&view=diff
==============================================================================
---
maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java
(original)
+++
maven/release/trunk/maven-release-manager/src/test/java/org/apache/maven/shared/release/phase/ScmCheckModificationsPhaseTest.java
Thu Apr 12 19:55:06 2012
@@ -47,6 +47,7 @@ import org.apache.maven.scm.repository.S
import org.apache.maven.scm.repository.ScmRepositoryException;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
+import org.apache.maven.shared.release.ReleaseResult;
import org.apache.maven.shared.release.config.ReleaseDescriptor;
import org.apache.maven.shared.release.env.DefaultReleaseEnvironment;
import org.apache.maven.shared.release.scm.DefaultScmRepositoryConfigurator;
@@ -265,6 +266,22 @@ public class ScmCheckModificationsPhaseT
// successful execution is verification enough
assertTrue( true );
}
+
+ // MRELEASE-645: Allow File/Directory Patterns for the
checkModificationExcludes Option
+ public void testModificationsToCustomExcludedFilesOnly()
+ throws Exception
+ {
+ ReleaseDescriptor releaseDescriptor = createReleaseDescriptor();
+
+ releaseDescriptor.setCheckModificationExcludes(
Collections.singletonList( "**/keep.me" ) );
+
+ setChangedFiles( releaseDescriptor, Arrays.asList( new String[] {
"release.properties", "pom.xml.backup",
+ "pom.xml.tag", "pom.xml.next", "keep.me", "src/app/keep.me",
"config\\keep.me" } ) );
+
+ assertEquals( ReleaseResult.SUCCESS, phase.execute( releaseDescriptor,
new DefaultReleaseEnvironment(), null ).getResultCode() );
+
+ assertEquals( ReleaseResult.SUCCESS, phase.simulate(
releaseDescriptor, new DefaultReleaseEnvironment(), null ).getResultCode() );
+ }
public void testModificationsToPoms()
throws Exception