plexus-io-1.0~alpha5/ 0000755 0001750 0001750 00000000000 11256764616 013572 5 ustar mkoch mkoch plexus-io-1.0~alpha5/NOTICE.txt 0000644 0001750 0001750 00000000145 10777725005 015310 0 ustar mkoch mkoch This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
plexus-io-1.0~alpha5/pom.xml 0000644 0001750 0001750 00000002254 11253540014 015067 0 ustar mkoch mkoch
4.0.0
plexus-components
org.codehaus.plexus
1.1.15
plexus-io
1.0-alpha-5
Plexus IO Components
scm:svn:http://svn.codehaus.org/plexus/plexus-components/tags/plexus-io-1.0-alpha-5
scm:svn:https://svn.codehaus.org/plexus/plexus-components/tags/plexus-io-1.0-alpha-5
http://fisheye.codehaus.org/browse/plexus/plexus-components/tags/plexus-io-1.0-alpha-5
org.codehaus.plexus
plexus-utils
org.codehaus.plexus
plexus-container-default
provided
plexus-io-1.0~alpha5/src/ 0000755 0001750 0001750 00000000000 11256764616 014361 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/ 0000755 0001750 0001750 00000000000 11256764615 015337 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/ 0000755 0001750 0001750 00000000000 11256764615 016260 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/ 0000755 0001750 0001750 00000000000 11256764615 017047 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/ 0000755 0001750 0001750 00000000000 11256764615 020642 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/ 0000755 0001750 0001750 00000000000 11256764615 022162 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/ 0000755 0001750 0001750 00000000000 11256764615 024347 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/ 0000755 0001750 0001750 00000000000 11256764616 024757 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/ 0000755 0001750 0001750 00000000000 11256764616 027145 5 ustar mkoch mkoch ././@LongLink 0000000 0000000 0000000 00000000170 00000000000 011563 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttr0000644 0001750 0001750 00000004474 11127423355 033201 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.attributes;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.net.URL;
import java.util.Map;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.Os;
import junit.framework.TestCase;
public class PlexusIoResourceAttributeUtilsTest
extends TestCase
{
public void testGetAttributesForThisTestClass()
throws IOException
{
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
{
System.out.println( "WARNING: Unsupported OS, skipping test" );
return;
}
URL resource =
Thread.currentThread().getContextClassLoader().getResource(
getClass().getName().replace( '.', '/' )
+ ".class" );
if ( resource == null )
{
throw new IllegalStateException( "SOMETHING IS VERY WRONG. CANNOT FIND THIS TEST CLASS IN THE CLASSLOADER." );
}
File f = new File( resource.getPath().replaceAll( "%20", " " ) );
Map attrs = PlexusIoResourceAttributeUtils.getFileAttributesByPath( f, new ConsoleLogger( Logger.LEVEL_INFO, "test" ), Logger.LEVEL_DEBUG );
FileAttributes fileAttrs = (FileAttributes) attrs.get( f.getAbsolutePath() );
System.out.println( "Got attributes for: " + f.getAbsolutePath() + fileAttrs );
assertNotNull( fileAttrs );
assertTrue( fileAttrs.isOwnerReadable() );
assertEquals( System.getProperty( "user.name" ), fileAttrs.getUserName() );
}
} ././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttrib0000644 0001750 0001750 00000001547 11127423355 033173 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.attributes;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.
*/
public class SimpleResourceAttributesTest
extends AbstractResourceAttributesTCK
{
protected PlexusIoResourceAttributes newAttributes()
{
return new SimpleResourceAttributes();
}
} ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.j0000644 0001750 0001750 00000007604 11127423355 033102 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.attributes;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.
*/
public class FileAttributesTest
extends AbstractResourceAttributesTCK
{
protected PlexusIoResourceAttributes newAttributes()
{
return new FileAttributes();
}
public void testSetLsMode_OwnerModes()
{
verifyLsModeSet( "-rwS------", new boolean[]{ true, true, true, false, false, false, false, false, false } );
verifyLsModeSet( "-rwx------", new boolean[]{ true, true, true, false, false, false, false, false, false } );
verifyLsModeSet( "-rw-------", new boolean[]{ true, true, false, false, false, false, false, false, false } );
verifyLsModeSet( "-r--------", new boolean[]{ true, false, false, false, false, false, false, false, false } );
verifyLsModeSet( "--w-------", new boolean[]{ false, true, false, false, false, false, false, false, false } );
}
public void testSetLsMode_GroupModes()
{
verifyLsModeSet( "----rwS---", new boolean[]{ false, false, false, true, true, true, false, false, false } );
verifyLsModeSet( "----rwx---", new boolean[]{ false, false, false, true, true, true, false, false, false } );
verifyLsModeSet( "----rw----", new boolean[]{ false, false, false, true, true, false, false, false, false } );
verifyLsModeSet( "----r-----", new boolean[]{ false, false, false, true, false, false, false, false, false } );
verifyLsModeSet( "-----w----", new boolean[]{ false, false, false, false, true, false, false, false, false } );
}
public void testSetLsMode_WorldModes()
{
verifyLsModeSet( "-------rwx", new boolean[]{ false, false, false, false, false, false, true, true, true } );
verifyLsModeSet( "-------rw-", new boolean[]{ false, false, false, false, false, false, true, true, false } );
verifyLsModeSet( "-------r--", new boolean[]{ false, false, false, false, false, false, true, false, false } );
verifyLsModeSet( "--------w-", new boolean[]{ false, false, false, false, false, false, false, true, false } );
}
private void verifyLsModeSet( String mode, boolean[] checkValues )
{
FileAttributes attrs = (FileAttributes) newAttributes();
assertFalse( attrs.isOwnerReadable() );
assertFalse( attrs.isOwnerWritable() );
assertFalse( attrs.isOwnerExecutable() );
assertFalse( attrs.isGroupReadable() );
assertFalse( attrs.isGroupWritable() );
assertFalse( attrs.isGroupExecutable() );
assertFalse( attrs.isWorldReadable() );
assertFalse( attrs.isWorldWritable() );
assertFalse( attrs.isWorldExecutable() );
attrs.setLsModeline( mode );
assertEquals( checkValues[0], attrs.isOwnerReadable() );
assertEquals( checkValues[1], attrs.isOwnerWritable() );
assertEquals( checkValues[2], attrs.isOwnerExecutable() );
assertEquals( checkValues[3], attrs.isGroupReadable() );
assertEquals( checkValues[4], attrs.isGroupWritable() );
assertEquals( checkValues[5], attrs.isGroupExecutable() );
assertEquals( checkValues[6], attrs.isWorldReadable() );
assertEquals( checkValues[7], attrs.isWorldWritable() );
assertEquals( checkValues[8], attrs.isWorldExecutable() );
}
} ././@LongLink 0000000 0000000 0000000 00000000163 00000000000 011565 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttr0000644 0001750 0001750 00000024550 11127423355 033171 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.attributes;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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 junit.framework.TestCase;
public abstract class AbstractResourceAttributesTCK
extends TestCase
{
protected AbstractResourceAttributesTCK()
{
}
protected abstract PlexusIoResourceAttributes newAttributes();
public void testSetAndGetUserId()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertEquals( -1, attrs.getUserId() );
int uid = 501;
attrs.setUserId( uid );
assertEquals( uid, attrs.getUserId() );
}
public final void testSetAndGetGroupId()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertEquals( -1, attrs.getGroupId() );
int gid = 501;
attrs.setGroupId( gid );
assertEquals( gid, attrs.getGroupId() );
}
public final void testSetAndGetUserName()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertNull( attrs.getUserName() );
String name = "me";
attrs.setUserName( name );
assertEquals( name, attrs.getUserName() );
}
public final void testSetAndGetGroupName()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertNull( attrs.getGroupName() );
String name = "me";
attrs.setGroupName( name );
assertEquals( name, attrs.getGroupName() );
}
public final void testSetAndGetOwnerReadable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isOwnerReadable() );
attrs.setOwnerReadable( true );
assertTrue( attrs.isOwnerReadable() );
}
public final void testSetAndGetOwnerWritable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isOwnerWritable() );
attrs.setOwnerWritable( true );
assertTrue( attrs.isOwnerWritable() );
}
public final void testSetAndGetOwnerExecutable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isOwnerExecutable() );
attrs.setOwnerExecutable( true );
assertTrue( attrs.isOwnerExecutable() );
}
public final void testSetAndGetGroupReadable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isGroupReadable() );
attrs.setGroupReadable( true );
assertTrue( attrs.isGroupReadable() );
}
public final void testSetAndGetGroupWritable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isGroupWritable() );
attrs.setGroupWritable( true );
assertTrue( attrs.isGroupWritable() );
}
public final void testSetAndGetGroupExecutable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isGroupExecutable() );
attrs.setGroupExecutable( true );
assertTrue( attrs.isGroupExecutable() );
}
public final void testSetAndGetWorldReadable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isWorldReadable() );
attrs.setWorldReadable( true );
assertTrue( attrs.isWorldReadable() );
}
public final void testSetAndGetWorldWritable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isWorldWritable() );
attrs.setWorldWritable( true );
assertTrue( attrs.isWorldWritable() );
}
public final void testSetAndGetWorldExecutable()
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isWorldExecutable() );
attrs.setWorldExecutable( true );
assertTrue( attrs.isWorldExecutable() );
}
public final void testSetOctalModeString_OwnerModes()
{
verifyStringOctalModeSet( "700", new boolean[]{ true, true, true, false, false, false, false, false, false } );
verifyStringOctalModeSet( "600", new boolean[]{ true, true, false, false, false, false, false, false, false } );
verifyStringOctalModeSet( "400", new boolean[]{ true, false, false, false, false, false, false, false, false } );
verifyStringOctalModeSet( "200", new boolean[]{ false, true, false, false, false, false, false, false, false } );
}
public final void testSetOctalModeString_GroupModes()
{
verifyStringOctalModeSet( "070", new boolean[]{ false, false, false, true, true, true, false, false, false } );
verifyStringOctalModeSet( "060", new boolean[]{ false, false, false, true, true, false, false, false, false } );
verifyStringOctalModeSet( "040", new boolean[]{ false, false, false, true, false, false, false, false, false } );
verifyStringOctalModeSet( "020", new boolean[]{ false, false, false, false, true, false, false, false, false } );
}
public final void testSetOctalModeString_WorldModes()
{
verifyStringOctalModeSet( "007", new boolean[]{ false, false, false, false, false, false, true, true, true } );
verifyStringOctalModeSet( "006", new boolean[]{ false, false, false, false, false, false, true, true, false } );
verifyStringOctalModeSet( "004", new boolean[]{ false, false, false, false, false, false, true, false, false } );
verifyStringOctalModeSet( "002", new boolean[]{ false, false, false, false, false, false, false, true, false } );
}
public final void testSetOctalMode_OwnerModes()
{
verifyOctalModeSet( "700", new boolean[]{ true, true, true, false, false, false, false, false, false } );
verifyOctalModeSet( "600", new boolean[]{ true, true, false, false, false, false, false, false, false } );
verifyOctalModeSet( "400", new boolean[]{ true, false, false, false, false, false, false, false, false } );
verifyOctalModeSet( "200", new boolean[]{ false, true, false, false, false, false, false, false, false } );
}
public final void testSetOctalMode_GroupModes()
{
verifyOctalModeSet( "070", new boolean[]{ false, false, false, true, true, true, false, false, false } );
verifyOctalModeSet( "060", new boolean[]{ false, false, false, true, true, false, false, false, false } );
verifyOctalModeSet( "040", new boolean[]{ false, false, false, true, false, false, false, false, false } );
verifyOctalModeSet( "020", new boolean[]{ false, false, false, false, true, false, false, false, false } );
}
public final void testSetOctalMode_WorldModes()
{
verifyOctalModeSet( "007", new boolean[]{ false, false, false, false, false, false, true, true, true } );
verifyOctalModeSet( "006", new boolean[]{ false, false, false, false, false, false, true, true, false } );
verifyOctalModeSet( "004", new boolean[]{ false, false, false, false, false, false, true, false, false } );
verifyOctalModeSet( "002", new boolean[]{ false, false, false, false, false, false, false, true, false } );
}
private void verifyStringOctalModeSet( String mode, boolean[] checkValues )
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isOwnerReadable() );
assertFalse( attrs.isOwnerWritable() );
assertFalse( attrs.isOwnerExecutable() );
assertFalse( attrs.isGroupReadable() );
assertFalse( attrs.isGroupWritable() );
assertFalse( attrs.isGroupExecutable() );
assertFalse( attrs.isWorldReadable() );
assertFalse( attrs.isWorldWritable() );
assertFalse( attrs.isWorldExecutable() );
attrs.setOctalModeString( mode );
assertEquals( checkValues[0], attrs.isOwnerReadable() );
assertEquals( checkValues[1], attrs.isOwnerWritable() );
assertEquals( checkValues[2], attrs.isOwnerExecutable() );
assertEquals( checkValues[3], attrs.isGroupReadable() );
assertEquals( checkValues[4], attrs.isGroupWritable() );
assertEquals( checkValues[5], attrs.isGroupExecutable() );
assertEquals( checkValues[6], attrs.isWorldReadable() );
assertEquals( checkValues[7], attrs.isWorldWritable() );
assertEquals( checkValues[8], attrs.isWorldExecutable() );
}
private void verifyOctalModeSet( String mode, boolean[] checkValues )
{
PlexusIoResourceAttributes attrs = newAttributes();
assertFalse( attrs.isOwnerReadable() );
assertFalse( attrs.isOwnerWritable() );
assertFalse( attrs.isOwnerExecutable() );
assertFalse( attrs.isGroupReadable() );
assertFalse( attrs.isGroupWritable() );
assertFalse( attrs.isGroupExecutable() );
assertFalse( attrs.isWorldReadable() );
assertFalse( attrs.isWorldWritable() );
assertFalse( attrs.isWorldExecutable() );
attrs.setOctalMode( Integer.parseInt( mode, 8 ) );
assertEquals( checkValues[0], attrs.isOwnerReadable() );
assertEquals( checkValues[1], attrs.isOwnerWritable() );
assertEquals( checkValues[2], attrs.isOwnerExecutable() );
assertEquals( checkValues[3], attrs.isGroupReadable() );
assertEquals( checkValues[4], attrs.isGroupWritable() );
assertEquals( checkValues[5], attrs.isGroupExecutable() );
assertEquals( checkValues[6], attrs.isWorldReadable() );
assertEquals( checkValues[7], attrs.isWorldWritable() );
assertEquals( checkValues[8], attrs.isWorldExecutable() );
}
} plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/ 0000755 0001750 0001750 00000000000 11256764616 026771 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ 0000755 0001750 0001750 00000000000 11256764616 030152 5 ustar mkoch mkoch ././@LongLink 0000000 0000000 0000000 00000000176 00000000000 011571 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyRe0000644 0001750 0001750 00000003065 11207107052 033157 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.resources.proxy;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.PlexusTestCase;
import org.codehaus.plexus.components.io.resources.proxy.PlexusIoProxyResourceCollection;
/**
* Test case for {@link PlexusIoProxyResourceCollection}.
*/
public class PlexusIoProxyResourceCollectionTest extends PlexusTestCase
{
private final String [] SAMPLE_INCLUDES = {"junk.*", "test/**", "dir*/file.xml"};
private final String [] SAMPLE_EXCLUDES = {"*.junk", "somwhere/**"};
public void testGetDefaultFileSelector() throws Exception
{
PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection();
// This will throw an exception if there is a bug
resCol.getDefaultFileSelector();
resCol.setIncludes( SAMPLE_INCLUDES );
resCol.setExcludes( SAMPLE_EXCLUDES );
// This will throw an exception if there is a bug
resCol.getDefaultFileSelector();
}
} plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/ 0000755 0001750 0001750 00000000000 11256764616 027266 5 ustar mkoch mkoch plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java 0000644 0001750 0001750 00000022040 11127423355 032726 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.filemappers;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResource;
import org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection;
import org.codehaus.plexus.components.io.resources.PlexusIoZipFileResourceCollection;
import org.codehaus.plexus.util.FileUtils;
/**
* Test case for resource collections.
*/
public class ResourcesTest extends PlexusTestCase
{
private static final String X_PATH = "x";
private static final String A_PATH = X_PATH + "/a";
private static final String B_PATH = X_PATH + "/b";
private static final String Y_PATH = "y";
private File getTestDir() {
final String testDirPath = System.getProperty( "plexus.io.testDirPath" );
return new File( testDirPath == null ? "target/plexus.io.testDir" : testDirPath );
}
private File getFilesDir() {
return new File( getTestDir(), "files" );
}
private void createFiles() throws IOException {
final File baseDir = getFilesDir();
FileUtils.deleteDirectory( baseDir );
FileUtils.mkdir( baseDir.getPath() );
final File aFile = new File( baseDir, A_PATH );
FileUtils.mkdir( aFile.getParentFile().getPath() );
FileOutputStream fos = new FileOutputStream( aFile );
fos.write( "0123456789".getBytes( "US-ASCII" ) );
fos.close();
final File bFile = new File( baseDir, B_PATH );
fos = new FileOutputStream( bFile );
fos.write( "abcdefghijklmnopqrstuvwxyz".getBytes( "US-ASCII" ) );
fos.close();
final File yDir = new File( baseDir, Y_PATH );
FileUtils.mkdir( yDir.getPath() );
}
private void addDirToZipFile( ZipOutputStream zos, File dir, String path )
throws IOException
{
final String prefix = path == null ? "" : (path + "/");
File[] files = dir.listFiles();
for ( int i = 0; i < files.length; i++ )
{
File f = files[i];
final String entryName = prefix + f.getName();
ZipEntry ze = new ZipEntry( entryName );
if ( f.isFile() )
{
ze.setSize( f.length() );
zos.putNextEntry( ze );
FileInputStream fis = new FileInputStream( f );
byte[] buffer = new byte[ 1024 ];
for (;;)
{
int res = fis.read( buffer );
if ( res == -1 )
{
break;
}
if ( res > 0 )
{
zos.write( buffer, 0, res );
}
}
fis.close();
ze.setTime( f.lastModified() );
zos.closeEntry();
}
else
{
addDirToZipFile( zos, f, entryName );
}
}
}
private void createZipFile( File dest, File dir ) throws IOException
{
FileOutputStream fos = new FileOutputStream( dest );
ZipOutputStream zos = new ZipOutputStream( fos );
addDirToZipFile( zos, dir, null );
zos.close();
}
private void compare( InputStream in, File file )
throws IOException
{
InputStream fIn = new FileInputStream( file );
try
{
for ( ;; )
{
int i1 = in.read();
int i2 = fIn.read();
assertEquals( i2, i1 );
if ( i1 == -1 )
{
break;
}
}
}
finally
{
fIn.close();
}
}
private void compare( PlexusIoResource res, File file )
throws IOException
{
assertTrue( res.getLastModified() != PlexusIoResource.UNKNOWN_MODIFICATION_DATE );
if ( res instanceof PlexusIoFileResource )
{
assertEquals( res.getLastModified(), file.lastModified() );
}
assertTrue( res.getSize() != PlexusIoResource.UNKNOWN_RESOURCE_SIZE );
assertEquals( res.getSize(), file.length() );
InputStream in = res.getContents();
compare( in, file );
in.close();
in = res.getURL().openStream();
compare( in, file );
in.close();
}
private void testPlexusIoResourceCollection( PlexusIoResourceCollection plexusIoResourceCollection )
throws IOException
{
boolean xPathSeen = false;
boolean yPathSeen = false;
boolean aFileSeen = false;
boolean bFileSeen = false;
for ( Iterator iter = plexusIoResourceCollection.getResources(); iter.hasNext(); )
{
PlexusIoResource res = (PlexusIoResource) iter.next();
final String resName = res.getName().replace( File.separatorChar, '/' );
if ( res.isDirectory() )
{
assertFalse( "The directory " + resName + " is a file.", res.isFile() );
if ( X_PATH.equals( resName ) )
{
xPathSeen = true;
}
else if ( Y_PATH.equals( resName ) )
{
yPathSeen = true;
}
else if ( "".equals( resName ) || ".".equals( resName ) )
{
// Ignore me
}
else
{
fail( "Unexpected directory entry: " + resName );
}
final File dir = new File( getFilesDir(), resName );
assertTrue( "The directory " + dir + " doesn't exist.", dir.isDirectory() );
}
else
{
assertTrue( "The file " + resName + " isn't reported to be a file.", res.isFile() );
assertTrue( "The file " + resName + " doesn't exist.", res.isExisting() );
final File f = new File( getFilesDir(), resName );
assertTrue( "A file " + f + " doesn't exist.", f.isFile() && f.exists() );
if ( A_PATH.equals( resName ) )
{
aFileSeen = true;
}
else if ( B_PATH.equals( resName ) )
{
bFileSeen = true;
}
else
{
fail( "Unexpected file entry: " + resName );
}
compare( res, f );
}
}
assertTrue( aFileSeen );
assertTrue( bFileSeen );
}
private void testFileResourceCollection( PlexusIoFileResourceCollection resourceCollection )
throws IOException
{
resourceCollection.setBaseDir( getFilesDir() );
testPlexusIoResourceCollection( resourceCollection );
}
public void testFileCollection() throws Exception
{
createFiles();
testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.ROLE, PlexusIoResourceCollection.DEFAULT_ROLE_HINT ) );
testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.ROLE, PlexusIoFileResourceCollection.ROLE_HINT ) );
}
private void testZipFileCollection( AbstractPlexusIoArchiveResourceCollection resourceCollection, File zipFile )
throws IOException
{
resourceCollection.setFile( zipFile );
testPlexusIoResourceCollection( resourceCollection );
}
public void testZipFileCollection() throws Exception
{
createFiles();
final File zipFile = new File( getTestDir(), "files.zip" );
createZipFile( zipFile, getFilesDir() );
testZipFileCollection( (AbstractPlexusIoArchiveResourceCollection) lookup( PlexusIoResourceCollection.ROLE, PlexusIoZipFileResourceCollection.ROLE_HINT ), zipFile );
testZipFileCollection( (AbstractPlexusIoArchiveResourceCollection) lookup( PlexusIoResourceCollection.ROLE, PlexusIoZipFileResourceCollection.JAR_ROLE_HINT ), zipFile );
}
} ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011567 L ustar root root plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java plexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.ja0000644 0001750 0001750 00000012245 11127423355 033013 0 ustar mkoch mkoch package org.codehaus.plexus.components.io.filemappers;
/*
* Copyright 2007 The Codehaus Foundation.
*
* Licensed 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.IOException;
import java.io.InputStream;
import java.net.URL;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector;
import org.codehaus.plexus.components.io.fileselectors.FileSelector;
import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
/**
* Test case for implementations of {@link FileSelector}.
*/
public class FileSelectorTest extends PlexusTestCase
{
protected void testFileSelector( FileSelector pSelector, String[] pInput, boolean[] pOutput)
throws IOException
{
for ( int i = 0; i < pInput.length; i++ )
{
final String name = pInput[i];
AbstractPlexusIoResource resource = new AbstractPlexusIoResource(){
public InputStream getContents() throws IOException
{
throw new IllegalStateException( "Not implemented" );
}
public URL getURL() throws IOException
{
throw new IllegalStateException( "Not implemented" );
}
};
resource.setName( name );
resource.setDirectory( false );
resource.setFile( true );
boolean result = pSelector.isSelected( resource );
if ( result != pOutput[i] )
{
fail( "Test fails for selector " + pSelector.getClass().getName()
+ " and input " + name + ": Expected "
+ pOutput[i] );
}
}
}
protected static final String[] SAMPLES =
new String[]
{
"foo/x.gif",
"foo/y.png",
"bar/x.gif"
};
protected void testFileSelector( AllFilesFileSelector pSelector ) throws Exception
{
final boolean[] trues = getAllTrues();
testFileSelector( pSelector, SAMPLES, trues );
}
private boolean[] getAllTrues()
{
final boolean[] trues = new boolean[SAMPLES.length];
for ( int i = 0; i < trues.length; i++ )
{
trues[i] = true;
}
return trues;
}
public void testAllFilesFileSelector() throws Exception
{
testFileSelector( new AllFilesFileSelector() );
testFileSelector( (AllFilesFileSelector) lookup( FileSelector.ROLE, FileSelector.DEFAULT_ROLE_HINT ) );
testFileSelector( (AllFilesFileSelector) lookup( FileSelector.ROLE, AllFilesFileSelector.ROLE_HINT ) );
}
protected boolean[] getIncludeGifs( String[] pSamples )
{
boolean[] result = new boolean[pSamples.length];
for ( int i = 0; i < pSamples.length; i++ )
{
result[i] = pSamples[i].endsWith( ".gif" );
}
return result;
}
protected boolean[] getExcludeBar( String[] pSamples, boolean[] pResult )
{
for ( int i = 0; i < pSamples.length; i++ )
{
if ( pSamples[i].startsWith( "bar/" ) )
{
pResult[i] = false;
}
}
return pResult;
}
protected void testFileSelector( IncludeExcludeFileSelector pSelector ) throws Exception
{
testFileSelector( pSelector, SAMPLES, getAllTrues() );
pSelector.setIncludes( new String[] { "**/*.gif" } );
testFileSelector( pSelector, SAMPLES, getIncludeGifs( SAMPLES ) );
pSelector.setExcludes( new String[] { "bar/*" } );
testFileSelector( pSelector, SAMPLES, getExcludeBar( SAMPLES, getIncludeGifs( SAMPLES ) ) );
pSelector.setIncludes( null );
testFileSelector( pSelector, SAMPLES, getExcludeBar( SAMPLES, getAllTrues() ) );
}
public void testIncludeExcludeFileSelector() throws Exception
{
testFileSelector( new IncludeExcludeFileSelector() );
testFileSelector( (IncludeExcludeFileSelector) lookup( FileSelector.ROLE, IncludeExcludeFileSelector.ROLE_HINT ) );
}
public void testIncludeExcludeFileSelector_SetExcludes() throws Exception
{
IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector();
// Test that the setExcludes method does not modify the excludes.
selector.setExcludes( SAMPLES );
String [] sltrExcludes = selector.getExcludes();
assertEquals( SAMPLES.length, sltrExcludes.length );
for (int i=0; i