Skip to content

Commit

Permalink
More Path replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Mar 4, 2018
1 parent 52bfff2 commit 45cd37f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -221,33 +222,28 @@ private ReleaseResult performCheckout( ReleaseDescriptor releaseDescriptor, Rele
String scmRelativePathProjectDirectory = scmResult.getRelativePathProjectDirectory();
if ( StringUtils.isEmpty( scmRelativePathProjectDirectory ) )
{
String basedir;
Path basedir;
try
{
basedir = ReleaseUtil.getCommonBasedir( reactorProjects ).toString();
basedir = ReleaseUtil.getCommonBasedir( reactorProjects );
}
catch ( IOException e )
{
throw new ReleaseExecutionException( "Exception occurred while calculating common basedir: "
+ e.getMessage(), e );
}

String rootProjectBasedir = rootProject.getBasedir().getAbsolutePath();
Path rootProjectBasedir;
try
{
if ( ReleaseUtil.isSymlink( rootProject.getBasedir() ) )
{
rootProjectBasedir = rootProject.getBasedir().getCanonicalPath();
}
rootProjectBasedir = rootProject.getBasedir().toPath().toRealPath();
}
catch ( IOException e )
{
throw new ReleaseExecutionException( e.getMessage(), e );
}
if ( rootProjectBasedir.length() > basedir.length() )
{
scmRelativePathProjectDirectory = rootProjectBasedir.substring( basedir.length() + 1 );
}

scmRelativePathProjectDirectory = basedir.relativize( rootProjectBasedir ).toString();
}
releaseDescriptor.setScmRelativePathProjectDirectory( scmRelativePathProjectDirectory );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ public static String realignScmUrl( int parentLevels, String url )
return url;
}

public static boolean isSymlink( File file )
throws IOException
{
return !file.getAbsolutePath().equals( file.getCanonicalPath() );
}

public static String interpolate( String value, Model model )
throws ReleaseExecutionException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,8 @@ public void testScmResultFailure()

fail( "commit should have failed" );
}
catch ( ReleaseScmCommandException e )
catch ( ReleaseExecutionException e )
{
assertNull( "check no other cause", e.getCause() );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* under the License.
*/

import org.apache.maven.shared.release.phase.AbstractReleaseTestCase;
import org.apache.maven.shared.release.scm.IdentifiedScm;
import org.codehaus.plexus.PlexusTestCase;
import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
Expand Down Expand Up @@ -66,7 +65,7 @@ public void testReadFromFileUsingWorkingDirectory()
throws Exception
{
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
builder.setWorkingDirectory( AbstractReleaseTestCase.getPath( getTestFile( "target/test-classes" ) ) );
builder.setWorkingDirectory( getTestFile( "target/test-classes" ).getAbsolutePath() );
ReleaseDescriptor config = store.read( builder ).build();

ReleaseDescriptorBuilder expected = createExpectedReleaseConfiguration();
Expand Down Expand Up @@ -145,12 +144,12 @@ public void testWriteToWorkingDirectory()
file.getParentFile().mkdirs();

ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting();
config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) );
config.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

store.write( config.build() );

ReleaseDescriptorBuilder rereadDescriptorBuilder = store.read( file );
rereadDescriptorBuilder.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) );
rereadDescriptorBuilder.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

assertAndAdjustScmPassword( config, rereadDescriptorBuilder.build() );
assertAndAdjustScmPrivateKeyPassPhrase( config, rereadDescriptorBuilder.build() );
Expand Down Expand Up @@ -258,7 +257,7 @@ public void testDeleteFile()
assertTrue( "Check file already exists", file.exists() );

ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting();
config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) );
config.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

store.delete( config.build() );

Expand All @@ -274,7 +273,7 @@ public void testMissingDeleteFile()
assertFalse( "Check file already exists", file.exists() );

ReleaseDescriptorBuilder config = createReleaseConfigurationForWriting();
config.setWorkingDirectory( AbstractReleaseTestCase.getPath( file.getParentFile() ) );
config.setWorkingDirectory( file.getParentFile().getAbsolutePath() );

store.delete( config.build() );

Expand Down Expand Up @@ -359,7 +358,7 @@ public ReleaseDescriptorBuilder createMergeConfiguration()
releaseDescriptor.setScmSourceUrl( "scm-url" );
releaseDescriptor.setScmUsername( "username" );
// Not setting other optional SCM settings for brevity
releaseDescriptor.setWorkingDirectory( AbstractReleaseTestCase.getPath( getTestFile( "target/test-working-directory" ) ) );
releaseDescriptor.setWorkingDirectory( getTestFile( "target/test-working-directory" ).getAbsolutePath() );
// Not setting non-override setting completedPhase

return releaseDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.model.Scm;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder.BuilderReleaseDescriptor;
import org.apache.maven.shared.release.phase.AbstractReleaseTestCase;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -134,7 +133,7 @@ private static void doEqualsAssertions( ReleaseDescriptorBuilder releaseDescript

if ( otherFile != null )
{
configBuilder.setWorkingDirectory( AbstractReleaseTestCase.getPath( otherFile ) );
configBuilder.setWorkingDirectory( otherFile.getAbsolutePath() );
assertFalse( "Check original comparison", configBuilder.build().equals( origConfig ) );
}

Expand Down Expand Up @@ -265,7 +264,7 @@ private static ReleaseDescriptorBuilder createReleaseDescriptor()
{
File workingDirectory = new File( "." );

return createReleaseDescriptor(AbstractReleaseTestCase.getPath( workingDirectory ) );
return createReleaseDescriptor( workingDirectory.getAbsolutePath() );
}

private static ReleaseDescriptorBuilder createReleaseDescriptor( String workingDirectory )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.apache.maven.repository.internal.MavenRepositorySystemSession;
import org.apache.maven.shared.release.PlexusJUnit4TestCase;
import org.apache.maven.shared.release.config.ReleaseDescriptorBuilder;
import org.apache.maven.shared.release.util.ReleaseUtil;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.sonatype.aether.repository.WorkspaceReader;
import org.sonatype.aether.repository.WorkspaceRepository;
Expand Down Expand Up @@ -336,12 +335,6 @@ private String getRemoteRepositoryURL()
return "file://" + getTestFile( "src/test/remote-repository" ).getCanonicalPath().replace( '\\', '/' );
}

public static String getPath( File file )
throws IOException
{
return ReleaseUtil.isSymlink( file ) ? file.getCanonicalPath() : file.getAbsolutePath();
}

/**
* WorkspaceReader to find versions and artifacts from reactor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -78,12 +77,6 @@ public void setUp()
phase = lookup( ReleasePhase.class, "scm-branch" );
}

public static String getPath( File file )
throws IOException
{
return ReleaseUtil.isSymlink( file ) ? file.getCanonicalPath() : file.getAbsolutePath();
}

@Test
public void testBranch()
throws Exception
Expand All @@ -93,7 +86,7 @@ public void testBranch()
List<MavenProject> reactorProjects = createReactorProjects();
builder.setScmSourceUrl( "scm-url" );
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) );
builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() );
builder.setScmReleaseLabel( "release-label" );
builder.setScmCommentPrefix( "[my prefix] " );

Expand All @@ -103,7 +96,7 @@ public void testBranch()
when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...",
Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ),
Collections.singletonList( new ScmFile( rootProject.getFile().getAbsolutePath(),
ScmFileStatus.TAGGED ) ) ) );
ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
stub.setScmProvider( scmProviderMock );
Expand Down Expand Up @@ -131,7 +124,7 @@ public void testCommitMultiModuleDeepFolders()
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
builder.setScmSourceUrl( scmUrl );
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) );
builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() );
builder.setScmReleaseLabel( "release-label" );
builder.setScmCommentPrefix( "[my prefix] " );
builder.setScmBranchBase( "http://svn.example.com/repos/project/branches/" );
Expand All @@ -145,7 +138,7 @@ public void testCommitMultiModuleDeepFolders()
when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...",
Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ),
Collections.singletonList( new ScmFile( rootProject.getFile().getAbsolutePath(),
ScmFileStatus.TAGGED ) ) ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
Expand All @@ -172,7 +165,7 @@ public void testCommitForFlatMultiModule()
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
builder.setScmSourceUrl( rootProject.getScm().getConnection() );
builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) );
builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() );
builder.setScmReleaseLabel( "release-label" );
builder.setScmCommentPrefix( "[my prefix] " );

Expand All @@ -186,7 +179,7 @@ public void testCommitForFlatMultiModule()
when( scmProviderMock.branch( eq( repository ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...",
Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ),
Collections.singletonList( new ScmFile( rootProject.getFile().getAbsolutePath(),
ScmFileStatus.TAGGED ) ) ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
Expand All @@ -213,7 +206,7 @@ public void testCommitMultiModule()
List<MavenProject> reactorProjects = createReactorProjects( dir, dir, null );
builder.setScmSourceUrl( "scm-url" );
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) );
builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() );
builder.setScmReleaseLabel( "release-label" );
builder.setScmCommentPrefix( "[my prefix] " );

Expand All @@ -223,7 +216,7 @@ public void testCommitMultiModule()
when( scmProviderMock.branch( isA( ScmRepository.class ), argThat( new IsScmFileSetEquals( fileSet ) ),
eq( "release-label" ),
argThat( new IsScmBranchParametersEquals( new ScmBranchParameters( "[my prefix] copy for branch release-label" ) ) ) ) ).thenReturn( new BranchScmResult( "...",
Collections.singletonList( new ScmFile( getPath( rootProject.getFile() ),
Collections.singletonList( new ScmFile( rootProject.getFile().getAbsolutePath(),
ScmFileStatus.TAGGED ) ) ) );

ScmManagerStub stub = (ScmManagerStub) lookup( ScmManager.class );
Expand Down Expand Up @@ -265,7 +258,7 @@ public void testSimulateBranch()
List<MavenProject> reactorProjects = createReactorProjects();
builder.setScmSourceUrl( "scm-url" );
MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects );
builder.setWorkingDirectory( getPath( rootProject.getFile().getParentFile() ) );
builder.setWorkingDirectory( rootProject.getFile().getParentFile().getAbsolutePath() );
builder.setScmReleaseLabel( "release-label" );

ScmProvider scmProviderMock = mock( ScmProvider.class );
Expand Down Expand Up @@ -421,7 +414,7 @@ private static ReleaseDescriptorBuilder createReleaseDescriptorBuilder()
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
builder.setScmSourceUrl( "scm-url" );
builder.setScmReleaseLabel( "release-label" );
builder.setWorkingDirectory( getPath( getTestFile( "target/test/checkout" ) ) );
builder.setWorkingDirectory( getTestFile( "target/test/checkout" ).getAbsolutePath() );
return builder;
}
}
Loading

0 comments on commit 45cd37f

Please sign in to comment.