Skip to content

Commit

Permalink
#21 Support exploded classified artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
rfscholte committed Dec 14, 2018
1 parent e19cf75 commit b4304ef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
4 changes: 3 additions & 1 deletion mrm-maven-plugin/src/site/apt/examples/invoker-tests.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ Using with Maven Invoker and Repositories

* <<<**/*.pom>>>

* <<<**/*-\{classifier\}.xml>>>, which will use the GAV of the corresponding <<<pom>>> -file (e.g. <<<mojo-parent-10.pom>>> with <<<mojo-parent-10-site.xml>>> )
* <<<**/*-\{classifier\}.{type}>>> as file, which will use the GAV of the corresponding <<<pom>>> -file (e.g. <<<mojo-parent-10.pom>>> with <<<mojo-parent-10-site.xml>>> )

* <<<**/*.jar>>> as directory, which will use the GAV of the corresponding <<<pom>>> -file. MRM will create an archive of this directory.

* <<<**/*-\{classifier\}.jar>>> as directory, which will use the GAV of the corresponding <<<pom>>> -file. MRM will create an archive of this directory.

* <<<archetype-catalog.xml>>>

[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -86,15 +87,12 @@ public class MockArtifactStore
*/
public static final String[] POM_EXTENSIONS = { "pom" };

private static final String[] CLASSIFIER_EXTENSIONS = { "xml" };

/**
* The contents of this artifact store.
*
* @since 1.0
*/
private Map<String, Map<String, Map<String, Map<Artifact, Content>>>> contents =
new HashMap<String, Map<String, Map<String, Map<Artifact, Content>>>>();
private Map<String, Map<String, Map<String, Map<Artifact, Content>>>> contents = new HashMap<>();


private Content archetypeCatalog;
Expand Down Expand Up @@ -176,18 +174,32 @@ else if ( "maven-plugin".equals( model.getPackaging() ) )
version ) ) );
}

Collection<File> classifiedFiles = Arrays.asList( file.getParentFile().listFiles( new FilenameFilter()
{
@Override
public boolean accept( File dir, String name )
{
return FilenameUtils.getBaseName( name ).startsWith( basename + '-' );
}
} ) );

Collection<File> classifiedFiles = FileUtils.listFiles( root, CLASSIFIER_EXTENSIONS, false );
for ( File classifiedFile : classifiedFiles )
{
if ( FilenameUtils.getBaseName( classifiedFile.getName() ).startsWith( basename + '-' ) )
String type = org.codehaus.plexus.util.FileUtils.extension( classifiedFile.getName() );
String classifier =
FilenameUtils.getBaseName( classifiedFile.getName() ).substring( basename.length() + 1 );

Content content;
if( classifiedFile.isDirectory() )
{
String type = org.codehaus.plexus.util.FileUtils.extension( classifiedFile.getName() );
String classifier =
FilenameUtils.getBaseName( classifiedFile.getName() ).substring( basename.length() + 1 );
set( new Artifact( groupId, model.getArtifactId(), version, classifier, type ),
new FileContent( classifiedFile ) );
content = new DirectoryContent( classifiedFile, lazyArchiver );
}
else
{
content = new FileContent( classifiedFile );
}

set( new Artifact( groupId, model.getArtifactId(), version, classifier, type ), content );
}
}
catch ( IOException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,17 @@ public void testDirectoryContent() throws Exception

assertTrue( names.contains( "README.txt" ) );
}

@Test
public void testDirectoryWithClassifierContent() throws Exception
{
MockArtifactStore artifactStore = new MockArtifactStore( new File( "target/test-classes/mrm-xx" ) );

Artifact pomArtifact = new Artifact( "localhost", "mrm-xx", "1.0", "pom" );
assertNotNull( artifactStore.get( pomArtifact ) );
assertTrue( "Content equals", IOUtils.contentEquals( new FileInputStream( "target/test-classes/mrm-xx/mrm-xx-1.0.pom" ), artifactStore.get( pomArtifact ) ) );

Artifact classifiedArtifact = new Artifact( "localhost", "mrm-xx", "1.0", "javadoc-resources", "jar" );
assertNotNull( artifactStore.get( classifiedArtifact ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.foo.bar
6 changes: 6 additions & 0 deletions mrm-servlet/src/test/resources/mrm-xx/mrm-xx-1.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>mrm-xx</artifactId>
<version>1.0</version>
</project>

0 comments on commit b4304ef

Please sign in to comment.