maven-resources-plugin-2.3/ 0000755 0001750 0001750 00000000000 11117051511 015717 5 ustar twerner twerner maven-resources-plugin-2.3/src/ 0000755 0001750 0001750 00000000000 11117051502 016506 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/ 0000755 0001750 0001750 00000000000 11117051502 017465 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/unit-files/ 0000755 0001750 0001750 00000000000 11117051501 021543 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/ 0000755 0001750 0001750 00000000000 11117051501 025502 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/no-filter/ 0000755 0001750 0001750 00000000000 11117051501 027401 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/no-filter/config.properties 0000644 0001750 0001750 00000000016 11062560354 032773 0 ustar twerner twerner config=zorglub maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/filter-files/ 0000755 0001750 0001750 00000000000 11117051501 030067 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/filter-files/filter.txt 0000644 0001750 0001750 00000000007 11062560354 032124 0 ustar twerner twerner foo=bar maven-resources-plugin-2.3/src/test/unit-files/copy-resources-test/filtered-files/ 0000755 0001750 0001750 00000000000 11117051501 030400 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/ 0000755 0001750 0001750 00000000000 11117051501 020405 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/ 0000755 0001750 0001750 00000000000 11117051501 021174 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/apache/ 0000755 0001750 0001750 00000000000 11117051501 022415 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/apache/maven/ 0000755 0001750 0001750 00000000000 11117051501 023523 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/ 0000755 0001750 0001750 00000000000 11117051501 025021 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/ 0000755 0001750 0001750 00000000000 11117051502 027034 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/ 0000755 0001750 0001750 00000000000 11117051502 030011 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectResourcesStub.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectResource0000644 0001750 0001750 00000006722 11062560354 034061 0 ustar twerner twerner package org.apache.maven.plugin.resources.stub;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import org.apache.maven.model.Resource;
public class MavenProjectResourcesStub
extends MavenProjectBuildStub
{
private File baseDir;
public MavenProjectResourcesStub( String id )
throws Exception
{
super( id );
setupResources();
setupTestResources();
}
public void addInclude( String pattern )
{
( (Resource) build.getResources().get( 0 ) ).addInclude( pattern );
}
public void addExclude( String pattern )
{
( (Resource) build.getResources().get( 0 ) ).addExclude( pattern );
}
public void addTestInclude( String pattern )
{
( (Resource) build.getTestResources().get( 0 ) ).addInclude( pattern );
}
public void addTestExclude( String pattern )
{
( (Resource) build.getTestResources().get( 0 ) ).addExclude( pattern );
}
public void setTargetPath( String path )
{
( (Resource) build.getResources().get( 0 ) ).setTargetPath( path );
}
public void setTestTargetPath( String path )
{
( (Resource) build.getTestResources().get( 0 ) ).setTargetPath( path );
}
public void setDirectory( String dir )
{
( (Resource) build.getResources().get( 0 ) ).setDirectory( dir );
}
public void setTestDirectory( String dir )
{
( (Resource) build.getTestResources().get( 0 ) ).setDirectory( dir );
}
public void setResourceFiltering( int nIndex, boolean filter )
{
if ( build.getResources().size() > nIndex )
{
( (Resource) build.getResources().get( nIndex ) ).setFiltering( filter );
}
}
private void setupResources()
{
Resource resource = new Resource();
// see MavenProjectBasicStub for details
// of getBasedir
// setup default resources
resource.setDirectory( getBasedir().getPath() + "/src/main/resources" );
resource.setFiltering( false );
resource.setTargetPath( null );
build.addResource( resource );
}
private void setupTestResources()
{
Resource resource = new Resource();
// see MavenProjectBasicStub for details
// of getBasedir
// setup default test resources
resource.setDirectory( getBasedir().getPath() + "/src/test/resources" );
resource.setFiltering( false );
resource.setTargetPath( null );
build.addTestResource( resource );
}
public File getBaseDir()
{
return baseDir == null ? super.getBasedir() : baseDir;
}
public void setBaseDir( File baseDir )
{
this.baseDir = baseDir;
}
}
././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStub.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBuildStu0000644 0001750 0001750 00000017144 10771725356 034040 0 ustar twerner twerner package org.apache.maven.plugin.resources.stub;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.maven.model.Build;
import org.codehaus.plexus.util.FileUtils;
public class MavenProjectBuildStub
extends MavenProjectBasicStub
{
protected Build build;
protected String srcDirectory;
protected String targetDirectory;
protected String buildDirectory;
protected String outputDirectory;
protected String testOutputDirectory;
protected String resourcesDirectory;
protected String testResourcesDirectory;
protected String targetResourceDirectory;
protected String targetTestResourcesDirectory;
protected ArrayList fileList;
protected ArrayList directoryList;
protected HashMap dataMap;
public MavenProjectBuildStub( String key )
throws Exception
{
super( key );
build = new Build();
fileList = new ArrayList();
directoryList = new ArrayList();
dataMap = new HashMap();
setupBuild();
}
public void addDirectory( String name )
{
if ( isValidPath( name ) )
{
directoryList.add( name );
}
}
public void setOutputDirectory( String dir )
{
outputDirectory = buildDirectory + "/" + dir;
build.setOutputDirectory( outputDirectory );
}
public void addFile( String name )
{
if ( isValidPath( name ) )
{
fileList.add( name );
}
}
public void addFile( String name, String data )
{
File fileName = new File( name );
addFile( name );
dataMap.put( fileName.getName(), data );
}
public String getOutputDirectory()
{
return outputDirectory;
}
public String getTestOutputDirectory()
{
return testOutputDirectory;
}
public String getResourcesDirectory()
{
return resourcesDirectory;
}
public String getTestResourcesDirectory()
{
return testResourcesDirectory;
}
public Build getBuild()
{
return build;
}
/**
* returns true if the path is relative
* and false if absolute
* also returns false if it is relative to
* the parent
*
* @param path
* @return
*/
private boolean isValidPath( String path )
{
boolean bRetVal = true;
if ( path.startsWith( "c:" ) || path.startsWith( ".." ) || path.startsWith( "/" ) || path.startsWith( "\\" ) )
{
bRetVal = false;
}
return bRetVal;
}
private void setupBuild()
{
// check getBasedir method for the exact path
// we need to recreate the dir structure in
// an isolated environment
srcDirectory = testRootDir + "/src";
buildDirectory = testRootDir + "/target";
outputDirectory = buildDirectory + "/classes";
testOutputDirectory = buildDirectory + "/test-classes";
resourcesDirectory = srcDirectory + "/main/resources/";
testResourcesDirectory = srcDirectory + "/test/resources/";
build.setDirectory( buildDirectory );
build.setOutputDirectory( outputDirectory );
build.setTestOutputDirectory( testOutputDirectory );
}
public void setupBuildEnvironment()
throws Exception
{
// populate dummy resources and dummy test resources
// setup src dir
if ( !FileUtils.fileExists( resourcesDirectory ) )
{
FileUtils.mkdir( resourcesDirectory );
}
if ( !FileUtils.fileExists( testResourcesDirectory ) )
{
FileUtils.mkdir( testResourcesDirectory );
}
createDirectories( resourcesDirectory, testResourcesDirectory );
createFiles( resourcesDirectory, testResourcesDirectory );
// setup target dir
if ( !FileUtils.fileExists( outputDirectory ) )
{
FileUtils.mkdir( outputDirectory );
}
if ( !FileUtils.fileExists( testOutputDirectory ) )
{
FileUtils.mkdir( testOutputDirectory );
}
}
private void createDirectories( String parent, String testparent )
{
File currentDirectory;
for ( int nIndex = 0; nIndex < directoryList.size(); nIndex++ )
{
currentDirectory = new File( parent, "/" + (String) directoryList.get( nIndex ) );
if ( !currentDirectory.exists() )
{
currentDirectory.mkdirs();
}
// duplicate dir structure in test resources
currentDirectory = new File( testparent, "/" + (String) directoryList.get( nIndex ) );
if ( !currentDirectory.exists() )
{
currentDirectory.mkdirs();
}
}
}
private void createFiles( String parent, String testparent )
{
File currentFile;
for ( int nIndex = 0; nIndex < fileList.size(); nIndex++ )
{
currentFile = new File( parent, (String) fileList.get( nIndex ) );
// create the necessary parent directories
// before we create the files
if ( !currentFile.getParentFile().exists() )
{
currentFile.getParentFile().mkdirs();
}
if ( !currentFile.exists() )
{
try
{
currentFile.createNewFile();
populateFile( currentFile );
}
catch ( IOException io )
{
//TODO: handle exception
}
}
// duplicate file in test resources
currentFile = new File( testparent, (String) fileList.get( nIndex ) );
if ( !currentFile.getParentFile().exists() )
{
currentFile.getParentFile().mkdirs();
}
if ( !currentFile.exists() )
{
try
{
currentFile.createNewFile();
populateFile( currentFile );
}
catch ( IOException io )
{
//TODO: handle exception
}
}
}
}
private void populateFile( File file )
{
FileOutputStream outputStream;
String data = (String) dataMap.get( file.getName() );
if ( ( data != null ) && file.exists() )
{
try
{
outputStream = new FileOutputStream( file );
outputStream.write( data.getBytes() );
outputStream.flush();
outputStream.close();
}
catch ( IOException ex )
{
// TODO: handle exception here
}
}
}
}
././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBasicStub.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/stub/MavenProjectBasicStu0000644 0001750 0001750 00000005265 10771725356 034023 0 ustar twerner twerner package org.apache.maven.plugin.resources.stub;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.Properties;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.FileUtils;
public class MavenProjectBasicStub
extends MavenProjectStub
{
protected String identifier;
protected String testRootDir;
protected Properties properties;
protected String description;
public MavenProjectBasicStub( String id )
throws Exception
{
properties = new Properties();
identifier = id;
testRootDir = PlexusTestCase.getBasedir() + "/target/test-classes/unit/test-dir/" + identifier;
if ( !FileUtils.fileExists( testRootDir ) )
{
FileUtils.mkdir( testRootDir );
}
}
public String getName()
{
return "Test Project " + identifier;
}
public void setDescription( String desc )
{
description = desc;
}
public String getDescription()
{
if ( description == null )
{
return "this is a test project";
}
else
{
return description;
}
}
public File getBasedir()
{
// create an isolated environment
// see setupTestEnvironment for details
return new File( testRootDir );
}
public String getGroupId()
{
return "org.apache.maven.plugin.test";
}
public String getArtifactId()
{
return "maven-resource-plugin-test#" + identifier;
}
public String getPackaging()
{
return "org.apache.maven.plugin.test";
}
public String getVersion()
{
return identifier;
}
public void addProperty( String key, String value )
{
properties.put( key, value );
}
public Properties getProperties()
{
return properties;
}
}
maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/ResourcesMojoTest.java 0000644 0001750 0001750 00000050516 11060316055 033351 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.resources.stub.MavenProjectResourcesStub;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.FileUtils;
public class ResourcesMojoTest
extends AbstractMojoTestCase
{
protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml";
/**
* test mojo lookup, test harness should be working fine
*
* @throws Exception
*/
public void testHarnessEnvironment()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
assertNotNull( mojo );
}
/**
* @throws Exception
*/
public void testResourceDirectoryStructure()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceDirectoryStructure" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.txt" );
project.addFile( "package/file3.nottest" );
project.addFile( "notpackage/file1.include" );
project.addFile( "package/test/file1.txt" );
project.addFile( "notpackage/test/file2.txt" );
project.setupBuildEnvironment();
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/file3.nottest" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/test" ) );
}
/**
* @throws Exception
*/
public void testResourceDirectoryStructure_RelativePath()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceDirectoryStructure_RelativePath" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.setOutputDirectory( "../relative_dir" );
project.addFile( "file4.txt" );
project.addFile( "package/file3.nottest" );
project.addFile( "notpackage/file1.include" );
project.addFile( "package/test/file1.txt" );
project.addFile( "notpackage/test/file2.txt" );
project.setupBuildEnvironment();
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/file3.nottest" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/notpackage/test" ) );
}
/**
* @throws Exception
*/
public void testResourceEncoding()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "encoding" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.txt" );
project.setResourceFiltering( 0, true );
project.setupBuildEnvironment();
setVariableValueToObject( mojo, "encoding", "UTF-8" );
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/file4.txt" ) );
}
/**
* @throws Exception
*/
public void testResourceInclude()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceInclude" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file1.include" );
project.addFile( "file2.exclude" );
project.addFile( "file3.nottest" );
project.addFile( "file4.txt" );
project.addFile( "package/file1.include" );
project.addFile( "package/file2.exclude" );
project.addFile( "package/file3.nottest" );
project.addFile( "package/file4.txt" );
project.addFile( "notpackage/file1.include" );
project.addFile( "notpackage/file2.exclude" );
project.addFile( "notpackage/file3.nottest" );
project.addFile( "notpackage/file4.txt" );
project.addFile( "package/test/file1.txt" );
project.addFile( "package/nottest/file2.txt" );
project.addFile( "notpackage/test/file1.txt" );
project.addFile( "notpackage/nottest/file.txt" );
project.setupBuildEnvironment();
project.addInclude( "*.include" );
project.addInclude( "**/test" );
project.addInclude( "**/test/file*" );
project.addInclude( "**/package/*.include" );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/file1.include" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/file1.include" ) );
assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) );
assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/nottest/file.txt" ) );
}
/**
* @throws Exception
*/
public void testResourceExclude()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceExclude" );
List resources = project.getBuild().getResources();
;
assertNotNull( mojo );
project.addFile( "file1.include" );
project.addFile( "file2.exclude" );
project.addFile( "file3.nottest" );
project.addFile( "file4.txt" );
project.addFile( "package/file1.include" );
project.addFile( "package/file2.exclude" );
project.addFile( "package/file3.nottest" );
project.addFile( "package/file4.txt" );
project.addFile( "notpackage/file1.include" );
project.addFile( "notpackage/file2.exclude" );
project.addFile( "notpackage/file3.nottest" );
project.addFile( "notpackage/file4.txt" );
project.addFile( "package/test/file1.txt" );
project.addFile( "package/nottest/file2.txt" );
project.addFile( "notpackage/test/file1.txt" );
project.addFile( "notpackage/nottest/file.txt" );
project.setupBuildEnvironment();
project.addExclude( "**/*.exclude" );
project.addExclude( "**/nottest*" );
project.addExclude( "**/notest" );
project.addExclude( "**/notpackage*" );
project.addExclude( "**/notpackage*/**" );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/package/test" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/file1.include" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/package/file1.include" ) );
assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/file1.include" ) );
assertFalse( FileUtils.fileExists( resourcesDir + "/notpackage/nottest/file.txt" ) );
}
/**
* @throws Exception
*/
public void testResourceTargetPath()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceTargetPath" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.setTargetPath( "org/apache/maven/plugin/test" );
project.addFile( "file4.txt" );
project.addFile( "package/file3.nottest" );
project.addFile( "notpackage/file1.include" );
project.addFile( "package/test/file1.txt" );
project.addFile( "notpackage/test/file2.txt" );
project.setupBuildEnvironment();
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/file4.txt" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/package/file3.nottest" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/notpackage/file1.include" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/package/test" ) );
assertTrue( FileUtils.fileExists( resourcesDir + "/org/apache/maven/plugin/test/notpackage/test" ) );
}
/**
* @throws Exception
*/
public void testResourceSystemProperties_Filtering()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceSystemProperties_Filtering" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.txt", "current-working-directory = ${user.dir}" );
project.setResourceFiltering( 0, true );
project.setupBuildEnvironment();
//setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
MavenSession mavenSession = new MavenSession( null, null, null, null, null, null, null, System.getProperties(), null );
setVariableValueToObject( mojo, "session", mavenSession );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
File userDir = new File( System.getProperty( "user.dir" ) );
assertTrue( userDir.exists() );
Properties props = new Properties();
props.load( new FileInputStream( new File( resourcesDir + "/file4.txt" ) ) );
File fileFromFiltering = new File( props.getProperty( "current-working-directory" ) );
assertTrue( fileFromFiltering.exists() );
assertEquals( userDir.getAbsolutePath(), fileFromFiltering.getAbsolutePath() );
}
/**
* @throws Exception
*/
public void testResourceProjectProperties_Filtering()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourceProjectProperties_Filtering" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.txt", "current working directory = ${user.dir}" );
project.setResourceFiltering( 0, true );
project.addProperty( "user.dir", "FPJ kami!!!" );
project.setupBuildEnvironment();
//setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory = FPJ kami!!!";
assertContent( resourcesDir + "/file4.txt", checkString );
}
/**
* @throws Exception
*/
public void testProjectProperty_Filtering_PropertyDestination()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project =
new MavenProjectResourcesStub( "resourcePojectProperty_Filtering_PropertyDestination" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.properties", "current working directory=${description}" );
project.setResourceFiltering( 0, true );
project.setupBuildEnvironment();
// setup dummy property
project.setDescription( "c:\\\\org\\apache\\test" );
//setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory=c\\:\\\\\\\\org\\\\apache\\\\test";
assertContent( resourcesDir + "/file4.properties", checkString );
}
/**
* @throws Exception
*/
public void testPropertyFiles_Filtering()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "resourcePropertyFiles_Filtering" );
List resources = project.getBuild().getResources();
LinkedList filterList = new LinkedList();
assertNotNull( mojo );
project.addFile( "file4.properties", "current working directory=${dir}" );
project.addFile( "filter.properties", "dir:testdir" );
project.setResourceFiltering( 0, true );
project.setupBuildEnvironment();
filterList.add( project.getResourcesDirectory() + "filter.properties" );
//setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", filterList );
mojo.execute();
String resourcesDir = project.getOutputDirectory();
String checkString = "current working directory=testdir";
assertContent( resourcesDir + "/file4.properties", checkString );
}
/**
* Validates that a Filter token containing a project property will be
* resolved before the Filter is applied to the resources.
*
* @throws Exception
*/
public void testPropertyFiles_Filtering_TokensInFilters()
throws Exception
{
final File testPom = new File(getBasedir(), defaultPomFilePath);
final ResourcesMojo mojo = (ResourcesMojo) lookupMojo("resources", testPom);
final MavenProjectResourcesStub project = new MavenProjectResourcesStub(
"resourcePropertyFiles_Filtering_TokensInFilters");
final List resources = project.getBuild().getResources();
final LinkedList filterList = new LinkedList();
assertNotNull(mojo);
project.addFile("file4.properties", "current working directory=${filter.token}");
project.addFile("filter.properties", "filter.token=${pom-property}");
project.setResourceFiltering(0, true);
project.addProperty("pom-property", "foobar");
project.setupBuildEnvironment();
filterList.add(project.getResourcesDirectory() + "filter.properties");
// setVariableValueToObject(mojo,"encoding","UTF-8");
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "resources", resources);
setVariableValueToObject(mojo, "outputDirectory", new File( project.getBuild().getOutputDirectory() ) );
setVariableValueToObject(mojo, "filters", filterList);
mojo.execute();
final String resourcesDir = project.getOutputDirectory();
final String checkString = "current working directory=foobar";
assertContent(resourcesDir + "/file4.properties", checkString);
}
/**
* Ensures the file exists and its first line equals the given data.
*/
private void assertContent( String fileName, String data )
throws IOException
{
assertTrue( FileUtils.fileExists( fileName ) );
assertEquals( data, new BufferedReader( new FileReader( fileName ) ).readLine() );
}
}
maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/TestResourcesTest.java 0000644 0001750 0001750 00000006521 10771725356 033401 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import org.apache.maven.plugin.resources.stub.MavenProjectResourcesStub;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.FileUtils;
public class TestResourcesTest
extends AbstractMojoTestCase
{
protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml";
protected void setUp()
throws Exception
{
super.setUp();
}
protected void tearDown()
{
}
/**
* test mojo lookup, test harness should be working fine
*
* @throws Exception
*/
public void testHarnessEnvironment()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "testResources", testPom );
assertNotNull( mojo );
}
/**
* @throws Exception
*/
public void testTestResourceDirectoryCreation()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
TestResourcesMojo mojo = (TestResourcesMojo) lookupMojo( "testResources", testPom );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "testResourceDirectoryStructure" );
List resources = project.getBuild().getResources();
assertNotNull( mojo );
project.addFile( "file4.txt" );
project.addFile( "package/file3.nottest" );
project.addFile( "notpackage/file1.include" );
project.addFile( "package/test/file1.txt" );
project.addFile( "notpackage/test/file2.txt" );
project.setupBuildEnvironment();
setVariableValueToObject( mojo, "project", project );
setVariableValueToObject( mojo, "resources", resources );
setVariableValueToObject( mojo, "outputDirectory", new File( project.getBuild().getTestOutputDirectory() ) );
setVariableValueToObject( mojo, "filters", new LinkedList() );
mojo.execute();
String resorucesDir = project.getTestOutputDirectory();
assertTrue( FileUtils.fileExists( resorucesDir + "/file4.txt" ) );
assertTrue( FileUtils.fileExists( resorucesDir + "/package/file3.nottest" ) );
assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/file1.include" ) );
assertTrue( FileUtils.fileExists( resorucesDir + "/package/test" ) );
assertTrue( FileUtils.fileExists( resorucesDir + "/notpackage/test" ) );
}
}
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/AdvancePropertyUtilsTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/AdvancePropertyUtilsTest.0000644 0001750 0001750 00000006452 10771725356 034057 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.Properties;
public class AdvancePropertyUtilsTest
extends AbstractPropertyUtilsTest
{
final static protected String propFileName = "/target/test-classes/unit/propertiesutils-test/advance.properties";
final static protected String validationFileName =
"/target/test-classes/unit/propertiesutils-test/advance_validation.properties";
protected File getPropertyFile()
{
File propFile = new File( getBasedir(), propFileName );
if ( !propFile.exists() )
{
propFile = null;
}
return propFile;
}
protected File getValidationFile()
{
File validationFile = new File( getBasedir(), validationFileName );
if ( !validationFile.exists() )
{
validationFile = null;
}
return validationFile;
}
/**
* load property test case can be adjusted by modifying the advance.properties and
* advance_validation.properties
*
* @throws Exception
*/
public void testAdvanceLoadProperty_FF()
throws Exception
{
Properties prop;
boolean throwsException = false;
try
{
prop = PropertyUtils.loadPropertyFile( propertyFile, false, false );
}
catch ( Exception ex )
{
prop = null;
throwsException = true;
}
assertFalse( throwsException );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
/**
* load property test case can be adjusted by modifying the advance.properties and
* advance_validation properties
*
* @throws Exception
*/
public void testAdvanceLoadProperty_TF()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, false );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
/**
* load property test case can be adjusted by modifying the advance.properties and
* advance_validation properties
*
* @throws Exception
*/
public void testAdvanceLoadProperty_TT()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true );
// add system properties to our
// validation table
validationProp.putAll( System.getProperties() );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
}
././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/BasicPropertyUtilsTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/BasicPropertyUtilsTest.ja0000644 0001750 0001750 00000007703 10771725356 034052 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.Properties;
public class BasicPropertyUtilsTest
extends AbstractPropertyUtilsTest
{
final static protected String validationFileName =
"/target/test-classes/unit/propertiesutils-test/basic_validation.properties";
final static protected String propFileName = "/target/test-classes/unit/propertiesutils-test/basic.properties";
protected File getPropertyFile()
{
File propFile = new File( getBasedir(), propFileName );
if ( !propFile.exists() )
{
propFile = null;
}
return propFile;
}
protected File getValidationFile()
{
File validationFile = new File( getBasedir(), validationFileName );
if ( !validationFile.exists() )
{
validationFile = null;
}
return validationFile;
}
/**
* load property test case can be adjusted by modifying the basic.properties and
* basic_validation properties
*
* @throws Exception
*/
public void testBasicLoadProperty_FF()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, false, false );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
/**
* load property test case can be adjusted by modifying the basic.properties and
* basic_validation properties
*
* @throws Exception
*/
public void testBasicLoadProperty_TF()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, false );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
/**
* load property test case can be adjusted by modifying the basic.properties and
* basic_validation properties
*
* @throws Exception
*/
public void testBasicLoadProperty_TT()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true );
validationProp.putAll( System.getProperties() );
assertNotNull( prop );
assertTrue( validateProperties( prop ) );
}
/**
* load property test case can be adjusted by modifying the basic.properties and
* basic_validation properties
*
* @throws Exception
*/
public void testNonExistentProperty()
throws Exception
{
Properties prop = PropertyUtils.loadPropertyFile( propertyFile, true, true );
validationProp.putAll( System.getProperties() );
assertNotNull( prop );
assertNull( prop.getProperty( "does_not_exist" ) );
}
/**
* load property test case can be adjusted by modifying the basic.properties and
* basic_validation properties
*
* @throws Exception
*/
public void testException()
throws Exception
{
boolean failed = false;
try
{
Properties prop = PropertyUtils.loadPropertyFile( new File( "NON_EXISTENT_FILE" ), true, true );
}
catch ( Exception ex )
{
failed = true;
}
assertTrue( failed );
}
}
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/ReflectionPropertiesTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/ReflectionPropertiesTest.0000644 0001750 0001750 00000005217 10771725356 034075 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.plugin.resources.stub.MavenProjectBasicStub;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
public class ReflectionPropertiesTest
extends AbstractMojoTestCase
{
// data
final static protected String pomFilePath = "/target/test-classes/unit/reflectionproperties-test/plugin-config.xml";
protected void setUp()
throws Exception
{
super.setUp();
}
protected void tearDown()
throws Exception
{
}
public void testGet_escapeBackslashCharacterInPath()
throws Exception
{
// setup data
MavenProjectBasicStub project = new MavenProjectBasicStub( "escapeBackSlashCharacterInPath" );
// set dummy value
project.setDescription( "c:\\\\org\\apache\\test" );
ReflectionProperties reflectProp = new ReflectionProperties( project, true );
// project property to be verified
String reflectPropValue = (String) reflectProp.get( "description" );
// expected value is c\:\\\\org\\apache\\test
assertTrue( reflectPropValue.equals( "c\\:\\\\\\\\org\\\\apache\\\\test" ) );
}
public void testGet_dontEscapeBackslashCharacterInPath()
throws Exception
{
// setup data
MavenProjectBasicStub project = new MavenProjectBasicStub( "dontEscapeBackSlashCharacterInPath" );
// set dummy value
project.setDescription( "c:\\\\org\\apache\\test" );
// project property to be verified
ReflectionProperties reflectProp = new ReflectionProperties( project, false );
// project property to be verified
String reflectPropValue = (String) reflectProp.get( "description" );
// expected value is c:\\org\apache\test
assertTrue( reflectPropValue.equals( "c:\\\\org\\apache\\test" ) );
}
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/AbstractPropertyUtilsTest0000644 0001750 0001750 00000005266 10771725356 034205 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
/**
* Base class for propertyutils test case
*/
public abstract class AbstractPropertyUtilsTest
extends AbstractMojoTestCase
{
protected File propertyFile;
protected File validationFile;
protected Properties validationProp;
protected abstract File getPropertyFile();
protected abstract File getValidationFile();
protected void setUp()
throws Exception
{
super.setUp();
// load data
propertyFile = getPropertyFile();
assertNotNull( propertyFile );
validationFile = getValidationFile();
assertNotNull( validationFile );
loadValidationProperties( validationFile );
}
protected void tearDown()
{
}
protected boolean validateProperties( Properties prop )
{
boolean bRetVal = false;
Enumeration propKeys = prop.keys();
String key;
while ( propKeys.hasMoreElements() )
{
key = (String) propKeys.nextElement();
bRetVal = prop.getProperty( key ).equals( validationProp.getProperty( key ) );
if ( !bRetVal )
{
break;
}
}
return bRetVal;
}
/**
* load the property file for cross checking the
* values in the processed property file
*
* @param validationPropFile
*/
private void loadValidationProperties( File validationPropFile )
{
validationProp = new Properties();
try
{
validationProp.load( new FileInputStream( validationPropFile ) );
}
catch ( IOException ex )
{
// TODO: do error handling
}
}
}
././@LongLink 0000000 0000000 0000000 00000000146 00000000000 011566 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/CopyResourcesMojoTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/CopyResourcesMojoTest.jav0000644 0001750 0001750 00000005276 11062560354 034053 0 ustar twerner twerner package org.apache.maven.plugin.resources;
import java.io.File;
import java.util.Collections;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.resources.stub.MavenProjectResourcesStub;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.codehaus.plexus.util.FileUtils;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author olamy
* @version $Id: CopyResourcesMojoTest.java 694813 2008-09-12 21:36:44Z olamy $
*/
public class CopyResourcesMojoTest
extends AbstractMojoTestCase
{
protected final static String defaultPomFilePath = "/target/test-classes/unit/resources-test/plugin-config.xml";
File outputDirectory = new File( getBasedir(), "/target/copyResourcesTests" );
protected void setUp()
throws Exception
{
super.setUp();
if ( !outputDirectory.exists() )
{
outputDirectory.mkdirs();
}
else
{
FileUtils.cleanDirectory( outputDirectory );
}
}
public void testCopyWithoutFiltering()
throws Exception
{
File testPom = new File( getBasedir(), defaultPomFilePath );
ResourcesMojo mojo = (ResourcesMojo) lookupMojo( "resources", testPom );
mojo.setOutputDirectory( outputDirectory );
Resource resource = new Resource();
resource.setDirectory( getBasedir() + "/src/test/unit-files/copy-resources-test/no-filter" );
resource.setFiltering( false );
mojo.setResources( Collections.singletonList( resource ) );
MavenProjectResourcesStub project = new MavenProjectResourcesStub( "CopyResourcesMojoTest" );
File targetFile = new File( getBasedir(), "/target/copyResourcesTests" );
project.setBaseDir( targetFile );
setVariableValueToObject( mojo, "project", project );
mojo.execute();
assertTrue( new File( targetFile, "config.properties" ).exists() );
}
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/EnhancedPropertyUtilsTest.java maven-resources-plugin-2.3/src/test/java/org/apache/maven/plugin/resources/EnhancedPropertyUtilsTest0000644 0001750 0001750 00000006600 10771725356 034140 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.util.Properties;
/**
* Tests {@link PropertyUtils#loadPropertyFile(File, Properties)}.
*
* @author William Ferguson
*/
public class EnhancedPropertyUtilsTest
extends AbstractPropertyUtilsTest
{
private static final String validationFileName =
"/target/test-classes/unit/propertiesutils-test/enhanced_validation.properties";
private static final String propFileName = "/target/test-classes/unit/propertiesutils-test/enhanced.properties";
private final Properties baseProps = new Properties();
protected void setUp()
throws Exception
{
super.setUp();
this.baseProps.setProperty( "prop1", "valueOfProperty1" );
}
protected File getPropertyFile()
{
final File propFile = new File( getBasedir(), propFileName );
if ( !propFile.exists() )
{
return null;
}
return propFile;
}
protected File getValidationFile()
{
final File file = new File( getBasedir(), validationFileName );
if ( !file.exists() )
{
return null;
}
return file;
}
/**
* Load property test case can be adjusted by modifying the enhanced.properties and enhanced_validation properties.
*
* @throws Exception
*/
public void testBasicLoadProperty()
throws Exception
{
final Properties props = PropertyUtils.loadPropertyFile( this.propertyFile, this.baseProps );
assertNotNull( props );
assertTrue( validateProperties( props ) );
}
/**
* Load property test case can be adjusted by modifying the enhanced.properties and enhanced_validation properties.
*
* @throws Exception
*/
public void testNonExistentProperty()
throws Exception
{
final Properties props = PropertyUtils.loadPropertyFile( this.propertyFile, this.baseProps );
assertNotNull( props );
assertNull( props.getProperty( "does_not_exist" ) );
}
/**
* Load property test case can be adjusted by modifying the enhanced.properties and enhanced_validation properties.
*
* @throws Exception
*/
public void testException()
throws Exception
{
try
{
PropertyUtils.loadPropertyFile( new File( "NON_EXISTENT_FILE" ), this.baseProps );
fail( "Should not have been able to load properties from a non-existent file" );
}
catch ( IOException e )
{
// as expected.
}
}
}
maven-resources-plugin-2.3/src/test/resources/ 0000755 0001750 0001750 00000000000 11117051502 021477 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/resources/unit/ 0000755 0001750 0001750 00000000000 11117051502 022456 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/resources/unit/reflectionproperties-test/ 0000755 0001750 0001750 00000000000 11117051502 027702 5 ustar twerner twerner maven-resources-plugin-2.3/src/test/resources/unit/reflectionproperties-test/plugin-config.xml 0000644 0001750 0001750 00000002622 10771725356 033213 0 ustar twerner twerner
null
.
* @return true
if at least one resource uses filtering, false
otherwise.
*/
private boolean isFilteringEnabled( Collection resources )
{
if ( resources != null )
{
for ( Iterator i = resources.iterator(); i.hasNext(); )
{
Resource resource = (Resource) i.next();
if ( resource.isFiltering() )
{
return true;
}
}
}
return false;
}
public List getResources()
{
return resources;
}
public void setResources( List resources )
{
this.resources = resources;
}
public File getOutputDirectory()
{
return outputDirectory;
}
public void setOutputDirectory( File outputDirectory )
{
this.outputDirectory = outputDirectory;
}
public boolean isOverwrite()
{
return overwrite;
}
public void setOverwrite( boolean overwrite )
{
this.overwrite = overwrite;
}
public boolean isIncludeEmptyDirs()
{
return includeEmptyDirs;
}
public void setIncludeEmptyDirs( boolean includeEmptyDirs )
{
this.includeEmptyDirs = includeEmptyDirs;
}
}
maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/PropertyUtils.java 0000644 0001750 0001750 00000015450 11063170340 032520 0 ustar twerner twerner package org.apache.maven.plugin.resources;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
/**
* @deprecated use classes in the component maven-filtering
* TODO remove the class ?
* @author Kenney Westerhof
* @author William Ferguson
* @version $Id: PropertyUtils.java 695189 2008-09-14 11:09:20Z bentmann $
*/
public final class PropertyUtils
{
private PropertyUtils()
{
// prevent instantiation
}
/**
* Reads a property file, resolving all internal variables, using the supplied base properties.
*
* The properties are resolved iteratively, so if the value of property A refers to property B, then after * resolution the value of property B will contain the value of property B. *
* * @param propFile The property file to load. * @param baseProps Properties containing the initial values to subsitute into the properties file. * @return Properties object containing the properties in the file with their values fully resolved. * @throws IOException if profile does not exist, or cannot be read. */ public static Properties loadPropertyFile( File propFile, Properties baseProps ) throws IOException { if ( !propFile.exists() ) { throw new FileNotFoundException( propFile.toString() ); } final Properties fileProps = new Properties(); final FileInputStream inStream = new FileInputStream( propFile ); try { fileProps.load( inStream ); } finally { IOUtil.close( inStream ); } final Properties combinedProps = new Properties(); combinedProps.putAll( baseProps ); combinedProps.putAll( fileProps ); // The algorithm iterates only over the fileProps which is all that is required to resolve // the properties defined within the file. This is slighlty different to current, however // I suspect that this was the actual original intent. // // The difference is that #loadPropertyFile(File, boolean, boolean) also resolves System properties // whose values contain expressions. I believe this is unexpected and is not validated by the test cases, // as can be verified by replacing the implementation of #loadPropertyFile(File, boolean, boolean) // with the commented variant I have provided that reuses this method. for ( Iterator iter = fileProps.keySet().iterator(); iter.hasNext(); ) { final String k = (String) iter.next(); final String propValue = getPropertyValue( k, combinedProps ); fileProps.setProperty( k, propValue ); } return fileProps; } /** * Reads a property file, resolving all internal variables. * * @param propfile The property file to load * @param fail wheter to throw an exception when the file cannot be loaded or to return null * @param useSystemProps wheter to incorporate System.getProperties settings into the returned Properties object. * @return the loaded and fully resolved Properties object */ public static Properties loadPropertyFile( File propfile, boolean fail, boolean useSystemProps ) throws IOException { final Properties baseProps = new Properties(); if ( useSystemProps ) { baseProps.putAll( System.getProperties() ); } final Properties resolvedProps = new Properties(); try { resolvedProps.putAll( loadPropertyFile( propfile, baseProps ) ); } catch ( FileNotFoundException e ) { if ( fail ) { throw new FileNotFoundException( propfile.toString() ); } } if ( useSystemProps ) { resolvedProps.putAll( baseProps ); } return resolvedProps; } /** * Retrieves a property value, replacing values like ${token} * using the Properties to look them up. * * It will leave unresolved properties alone, trying for System * properties, and implements reparsing (in the case that * the value of a property contains a key), and will * not loop endlessly on a pair like * test = ${test}. */ private static String getPropertyValue( String k, Properties p ) { // This can also be done using InterpolationFilterReader, // but it requires reparsing the file over and over until // it doesn't change. String v = p.getProperty( k ); String ret = ""; int idx, idx2; while ( ( idx = v.indexOf( "${" ) ) >= 0 ) { // append prefix to result ret += v.substring( 0, idx ); // strip prefix from original v = v.substring( idx + 2 ); // if no matching } then bail idx2 = v.indexOf( '}' ); if ( idx2 < 0 ) { break; } // strip out the key and resolve it // resolve the key/value for the ${statement} String nk = v.substring( 0, idx2 ); v = v.substring( idx2 + 1 ); String nv = p.getProperty( nk ); // try global environment.. if ( nv == null ) { nv = System.getProperty( nk ); } // if the key cannot be resolved, // leave it alone ( and don't parse again ) // else prefix the original string with the // resolved property ( so it can be parsed further ) // taking recursion into account. if ( nv == null || nv.equals( k ) ) { ret += "${" + nk + "}"; } else { v = nv + v; } } return ret + v; } } maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/TestResourcesMojo.java 0000644 0001750 0001750 00000004024 11063264133 033311 0 ustar twerner twerner package org.apache.maven.plugin.resources; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.util.List; /** * Copy resources for the test source code to the test output directory. * * @author Michal Maczka * @author Jason van Zyl * @version $Id: TestResourcesMojo.java 695272 2008-09-14 19:39:07Z olamy $ * @goal testResources * @phase process-test-resources */ public class TestResourcesMojo extends ResourcesMojo { /** * The output directory into which to copy the resources. * * @parameter expression="${project.build.testOutputDirectory}" * @required */ private File outputDirectory; /** * The list of resources we want to transfer. * * @parameter expression="${project.testResources}" * @required * @readonly */ private List resources; public File getOutputDirectory() { return outputDirectory; } public void setOutputDirectory( File outputDirectory ) { this.outputDirectory = outputDirectory; } public List getResources() { return resources; } public void setResources( List resources ) { this.resources = resources; } } maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/Resource.java 0000644 0001750 0001750 00000002247 11063170340 031442 0 ustar twerner twerner package org.apache.maven.plugin.resources; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /** * @author olamy * @since 2.3 * @version $Id: Resource.java 695189 2008-09-14 11:09:20Z bentmann $ */ public class Resource extends org.apache.maven.model.Resource { // nothing to do here just a class prevent users adding an implementation attribute // in the mojo configuration } ././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/ReflectionProperties.java maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/ReflectionProperties.java0000644 0001750 0001750 00000004644 11063170340 034025 0 ustar twerner twerner package org.apache.maven.plugin.resources; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.introspection.ReflectionValueExtractor; import java.util.Properties; /** * @deprecated use classes in the component maven-filtering * TODO remove the class ? * @author Andreas Hoheneder (ahoh_at_inode.at) * @version $Id: ReflectionProperties.java 695189 2008-09-14 11:09:20Z bentmann $ */ public class ReflectionProperties extends Properties { private MavenProject project; private boolean escapedBackslashesInFilePath; public ReflectionProperties( MavenProject aProject, boolean escapedBackslashesInFilePath ) { super(); project = aProject; this.escapedBackslashesInFilePath = escapedBackslashesInFilePath; } public Object get( Object key ) { Object value = null; try { value = ReflectionValueExtractor.evaluate( "" + key, project ); if ( escapedBackslashesInFilePath && ( value instanceof String ) ) { String val = (String) value; // Check if it's a windows path if ( val.indexOf( ":\\" ) == 1 ) { value = StringUtils.replace( (String) value, "\\", "\\\\" ); value = StringUtils.replace( (String) value, ":", "\\:" ); } } } catch ( Exception e ) { // TODO: remove the try-catch block when ReflectionValueExtractor.evaluate() throws no more exceptions } return value; } } maven-resources-plugin-2.3/src/main/java/org/apache/maven/plugin/resources/CopyResourcesMojo.java 0000644 0001750 0001750 00000003772 11063170340 033311 0 ustar twerner twerner package org.apache.maven.plugin.resources; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import java.io.File; import java.util.List; /** * Copy resources of the configured plugin attribute resources * * @author olamy * @since 2.3 * @version $Id: CopyResourcesMojo.java 695189 2008-09-14 11:09:20Z bentmann $ * @goal copy-resources * @phase */ public class CopyResourcesMojo extends ResourcesMojo { /** * The output directory into which to copy the resources. * * @parameter * @required */ private File outputDirectory; /** * The list of resources we want to transfer. * * @parameter * @required */ private List resources; public File getOutputDirectory() { return outputDirectory; } public void setOutputDirectory( File outputDirectory ) { this.outputDirectory = outputDirectory; } public List getResources() { return resources; } public void setResources( List resources ) { this.resources = resources; } public List getFilters() { return filters; } public void setFilters( List filters ) { this.filters = filters; } } maven-resources-plugin-2.3/src/site/ 0000755 0001750 0001750 00000000000 11117051502 017452 5 ustar twerner twerner maven-resources-plugin-2.3/src/site/apt/ 0000755 0001750 0001750 00000000000 11117051502 020236 5 ustar twerner twerner maven-resources-plugin-2.3/src/site/apt/examples/ 0000755 0001750 0001750 00000000000 11117051502 022054 5 ustar twerner twerner maven-resources-plugin-2.3/src/site/apt/examples/encoding.apt 0000644 0001750 0001750 00000003232 11060312660 024352 0 ustar twerner twerner ------ Specifying a character encoding scheme ------ Franz Allan See ------ 2008-09-05 ------ ~~ Licensed to the Apache Software Foundation (ASF) under one ~~ or more contributor license agreements. See the NOTICE file ~~ distributed with this work for additional information ~~ regarding copyright ownership. The ASF licenses this file ~~ to you under the Apache License, Version 2.0 (the ~~ "License"); you may not use this file except in compliance ~~ with the License. You may obtain a copy of the License at ~~ ~~ http://www.apache.org/licenses/LICENSE-2.0 ~~ ~~ Unless required by applicable law or agreed to in writing, ~~ software distributed under the License is distributed on an ~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ~~ KIND, either express or implied. See the License for the ~~ specific language governing permissions and limitations ~~ under the License. ~~ NOTE: For help with the syntax of this file, see: ~~ http://maven.apache.org/doxia/references/apt-format.html Specifying a character encoding scheme A character encoding scheme such as <<Resources are non-source code files used by your project. Examples of these are properties files, images and XML files.
The Maven Resource Plugin simply copies resources from your source to your build output (with optional filtering). So if that's the only operation you are interested in, you can skip the other phases such as compilation and testing and simply do
For example, if you just debugged your configuration file and you want to manually test it in your container if it works, you can simply do
This will produce those configuration files on your output thus skipping the other phases which may eat up a huge amount of your time.
No. Your main resources and your test resources are separated from each other.
Your test resources should only be used by your tests. Thus, they are separated from the main to avoid any side effects that may occur.
The Maven Resource Plugin only allows encoding values representing
the charsets supported by the Java platform, namely US-ASCII
,
ISO-8859-1
, UTF-8
, UTF-16BE
, UTF-16LE
and UTF-16
.