Skip to content

Commit

Permalink
[MASSEMBLY-932] resource filtering skipped for resources in the curre…
Browse files Browse the repository at this point in the history
…nt project
  • Loading branch information
rfscholte committed Apr 20, 2020
1 parent 0692744 commit 3a58218
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ else if ( assemblyWorkPath.startsWith( fsPath ) )
dfs.setIncludes( newIn.toArray( new String[newIn.size()] ) );
dfs.setIncludingEmptyDirectories( fs.isIncludingEmptyDirectories() );
dfs.setPrefix( fs.getPrefix() );
dfs.setUsingDefaultExcludes( fs.isUsingDefaultExcludes() );
dfs.setStreamTransformer( fs.getStreamTransformer() );

delegate.addFileSet( dfs );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@
* under the License.
*/

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.codehaus.plexus.archiver.Archiver;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.FileSet;
import org.codehaus.plexus.archiver.diags.TrackingArchiver;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.components.io.fileselectors.FileInfo;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.functions.InputStreamTransformer;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.EasyMock;
import org.easymock.classextension.EasyMockSupport;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;

import javax.annotation.Nonnull;
import java.io.File;
Expand All @@ -43,11 +53,6 @@
import java.util.Arrays;
import java.util.List;

import static org.easymock.EasyMock.anyObject;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class AssemblyProxyArchiverTest
{
@Rule
Expand Down Expand Up @@ -114,34 +119,23 @@ public void addFileSet_addExcludeWhenSourceContainsAssemblyWorkDir()
public void addFile_NoPerms_CallAcceptFilesOnlyOnce()
throws IOException, ArchiverException
{
EasyMockSupport mm = new EasyMockSupport();
final Archiver delegate = mm.createMock( Archiver.class );

delegate.addFile( (File) anyObject(), (String) anyObject() );
EasyMock.expectLastCall().anyTimes();

delegate.setForced( true );
EasyMock.expectLastCall().anyTimes();
final Archiver delegate = mock( Archiver.class );

final CounterSelector counter = new CounterSelector( true );
final List<FileSelector> selectors = new ArrayList<>();
selectors.add( counter );

mm.replayAll();

final AssemblyProxyArchiver archiver =
new AssemblyProxyArchiver( "", delegate, null, selectors, null, new File( "." ),
new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );

archiver.setForced( true );

final File inputFile = temporaryFolder.newFile();

archiver.addFile( inputFile, "file.txt" );

assertEquals( 1, counter.getCount() );

mm.verifyAll();
verify( delegate ).addFile( inputFile, "file.txt" );
verify( delegate ).setForced( true );
}

@Test
Expand Down Expand Up @@ -173,6 +167,36 @@ public void addDirectory_NoPerms_CallAcceptFilesOnlyOnce()

assertEquals( 1, counter.getCount() );
}

@Test
public void assemblyWorkDir()
{
final Archiver delegate = mock( Archiver.class );
final List<FileSelector> selectors = new ArrayList<>();

final AssemblyProxyArchiver archiver =
new AssemblyProxyArchiver( "prefix", delegate, null, selectors, null,
new File( temporaryFolder.getRoot(), "module1" ),
new ConsoleLogger( Logger.LEVEL_DEBUG, "test" ) );

FileSet fileSet = mock( FileSet.class );
when( fileSet.getDirectory() ).thenReturn( temporaryFolder.getRoot() );
when( fileSet.getStreamTransformer() ).thenReturn( mock( InputStreamTransformer.class ) );

archiver.addFileSet( fileSet );

ArgumentCaptor<FileSet> delFileSet = ArgumentCaptor.forClass( FileSet.class );
verify( delegate ).addFileSet( delFileSet.capture() );

assertThat( delFileSet.getValue().getDirectory(), is( fileSet.getDirectory() ) );
assertThat( delFileSet.getValue().getExcludes(), is( new String[] { "module1" } ) );
assertThat( delFileSet.getValue().getFileMappers(), is( fileSet.getFileMappers() ) );
assertThat( delFileSet.getValue().getFileSelectors(), is( fileSet.getFileSelectors() ) );
assertThat( delFileSet.getValue().getIncludes(), is( new String[0] ) );
assertThat( delFileSet.getValue().getPrefix(), is( "prefix/" ) );
assertThat( delFileSet.getValue().getStreamTransformer(), is( fileSet.getStreamTransformer() ) );
}


private static final class CounterSelector
implements FileSelector
Expand Down

0 comments on commit 3a58218

Please sign in to comment.