Skip to content

Commit

Permalink
[MRELEASE-1107] Respect "lineSeparator" also on "mvn release:prepare"
Browse files Browse the repository at this point in the history
This closes #154
  • Loading branch information
Captain-P-Goldfish authored and michael-o committed Oct 15, 2022
1 parent 83deb62 commit b1840a4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
Expand Up @@ -257,6 +257,14 @@ public void setPomFileName( String pomFileName )
this.pomFileName = pomFileName;
}

/**
* only used for unit tests in which some required values of the project would be null
*/
protected MavenProject getProject()
{
return this.project;
}

/**
* Gets the list of projects in the build reactor.
*
Expand Down
Expand Up @@ -387,10 +387,7 @@ protected void prepareRelease( boolean generateReleasePoms )
config.setScmReleaseCommitComment( scmReleaseCommitComment );
config.setAutoResolveSnapshots( autoResolveSnapshots );
config.setPinExternals( pinExternals );
if ( generateReleasePoms )
{
config.setLineSeparator( resolveLineSeparator() );
}
config.setLineSeparator( resolveLineSeparator() );

if ( checkModificationExcludeList != null )
{
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.apache.maven.shared.release.env.ReleaseEnvironment;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

Expand All @@ -72,6 +73,7 @@ public void testPrepare()
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareReleaseMojo mojo = spy((PrepareReleaseMojo) lookupMojo( "prepare", testFile ));
mojo.getProject().setFile(testFile);
setDefaults( mojo );
mojo.setBasedir( testFile.getParentFile() );
mojo.setPomFileName( "pom.xml" );
Expand Down Expand Up @@ -127,6 +129,7 @@ public void testPrepareWithExecutionException()
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile );
mojo.getProject().setFile(testFile);
setDefaults( mojo );
mojo.setBasedir( testFile.getParentFile() );
mojo.setPomFileName( "pom.xml" );
Expand Down Expand Up @@ -169,6 +172,7 @@ public void testPrepareWithExecutionFailure()
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile );
mojo.getProject().setFile(testFile);
setDefaults( mojo );
mojo.setBasedir( testFile.getParentFile() );
mojo.setPomFileName( "pom.xml" );
Expand Down Expand Up @@ -211,6 +215,7 @@ public void testLineSeparatorInPrepareWithPom()
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareWithPomReleaseMojo mojo = (PrepareWithPomReleaseMojo) lookupMojo( "prepare-with-pom", testFile );
mojo.getProject().setFile(testFile);
setDefaults( mojo );
setVariableValueToObject( mojo, "generateReleasePoms", Boolean.TRUE );
mojo.setBasedir( testFile.getParentFile() );
Expand Down Expand Up @@ -242,7 +247,43 @@ public List<MavenProject> getProjects()
testLineSeparator("system", System.lineSeparator(), mojo, mock, times++);
}

private void testLineSeparator( String lineSeparator, String expected, PrepareWithPomReleaseMojo mojo,
public void testLineSeparatorInPrepare()
throws Exception
{
File testFile = getTestFile( "target/test-classes/mojos/prepare/prepare.xml" );
final PrepareReleaseMojo mojo = (PrepareReleaseMojo) lookupMojo( "prepare", testFile );
mojo.getProject().setFile(testFile);
setDefaults( mojo );
mojo.setBasedir( testFile.getParentFile() );
mojo.setPomFileName( "pom.xml" );
mojo.project.setFile( testFile );
mojo.session = new MavenSession( null, null, null, null, null, null, null, null, null )
{
public Properties getExecutionProperties()
{
return new Properties();
};

@Override
public List<MavenProject> getProjects()
{
return Collections.singletonList( mojo.project );
}
};

ReleaseManager mock = mock( ReleaseManager.class );
mojo.setReleaseManager( mock );

int times = 1;
testLineSeparator(null, "\n", mojo, mock, times++);
testLineSeparator("source", "\n", mojo, mock, times++);
testLineSeparator("cr", "\r", mojo, mock, times++);
testLineSeparator("lf", "\n", mojo, mock, times++);
testLineSeparator("crlf", "\r\n", mojo, mock, times++);
testLineSeparator("system", System.lineSeparator(), mojo, mock, times++);
}

private void testLineSeparator( String lineSeparator, String expected, PrepareReleaseMojo mojo,
ReleaseManager releaseManager, int times )
throws Exception
{
Expand Down

0 comments on commit b1840a4

Please sign in to comment.