plexus-io-1.0~alpha5/0000755000175000017500000000000011256764616013572 5ustar mkochmkochplexus-io-1.0~alpha5/NOTICE.txt0000644000175000017500000000014510777725005015310 0ustar mkochmkochThis product includes software developed by The Apache Software Foundation (http://www.apache.org/). plexus-io-1.0~alpha5/pom.xml0000644000175000017500000000225411253540014015067 0ustar mkochmkoch 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/0000755000175000017500000000000011256764616014361 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/0000755000175000017500000000000011256764615015337 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/0000755000175000017500000000000011256764615016260 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/0000755000175000017500000000000011256764615017047 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/0000755000175000017500000000000011256764615020642 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/0000755000175000017500000000000011256764615022162 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/0000755000175000017500000000000011256764615024347 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/0000755000175000017500000000000011256764616024757 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/0000755000175000017500000000000011256764616027145 5ustar mkochmkoch././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttr0000644000175000017500000000447411127423355033201 0ustar mkochmkochpackage 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() ); } }././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttrib0000644000175000017500000000154711127423355033173 0ustar mkochmkochpackage 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(); } }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.j0000644000175000017500000000760411127423355033102 0ustar mkochmkochpackage 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() ); } }././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttr0000644000175000017500000002455011127423355033171 0ustar mkochmkochpackage 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/0000755000175000017500000000000011256764616026771 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/0000755000175000017500000000000011256764616030152 5ustar mkochmkoch././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyRe0000644000175000017500000000306511207107052033157 0ustar mkochmkochpackage 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/0000755000175000017500000000000011256764616027266 5ustar mkochmkochplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java0000644000175000017500000002204011127423355032726 0ustar mkochmkochpackage 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 ); } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.javaplexus-io-1.0~alpha5/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.ja0000644000175000017500000001224511127423355033013 0ustar mkochmkochpackage 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>> goal, you would use the following configuration snipped: ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- The identity mapper uses the role hints "identity", or "default". * {File Extension Mapper} The {{{apidocs/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.html}file extension mapper}} changes the extension of the created files. For example, if you would use the XML Maven Plugin to convert Docbook into FOP or PDF files, then you would want the generated files to have the extension ".fo", or ".pdf". A configuration snippet for using the identity mapper within the XML Maven Plugins <<>> goal would look like this: ----------------------------------------------------------------------------- .pdf ----------------------------------------------------------------------------- The file extension mapper uses the role hints "fileExtension". * {Flattening File Mapper} The {{{apidocs/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.html}flattening file mapper}} is used to flatten a directory structure: It removes all directory components. For example, it would convert the name <<>> to <<>>. The flattening file mapper takes no configuration parameters. Consequently, a typical configuration snippet would look like this: ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- The flattening file mapper uses the role hint "flatten". * {Merging File Mapper} The {{{apidocs/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.html}merging file mapper}} merges all possible file names into one file name. In other words, it performs a constant mapping. For example, a merging file mapper, which maps all possible file names to <<>> would be configured as follows: ----------------------------------------------------------------------------- theOneAndOnlyFile ----------------------------------------------------------------------------- The merging file mapper uses the role hint "merge". plexus-io-1.0~alpha5/src/site/apt/index.apt0000644000175000017500000000210210777725005017715 0ustar mkochmkoch ------ Introduction ------ Plexus IO Plexus IO is a set of plexus components, which are designed for use in I/O operations. These I/O operations are doing nothing spectacular. For example, {{{http://jakarta.apache.org/commons/io}Commons IO}} is a much more powerful library in the same area. However, the implementation as a plexus component allows reuse in Maven. The following component groups are currently available: * {{{filemappers.html}File Mappers}} * {{{fileselectors.html}File Selectors}} Plexus IO components are typically very simple components, who could very well live as part of the {{{http://plexus.codehaus.org/plexus-utils} Plexus Utils}}. They do not, because Plexus Utils is a dependency of the {{{http://plexus.codehaus.org/plexus-container-default}Plexus Component API}}, which is in turn a dependency of the Plexus IO test suite (of course, a Plexus container is required to test components, even if they are POJO's). In other words, Plexus Utils cannot contain components, because that would introduce a circular dependency. plexus-io-1.0~alpha5/src/site/apt/fileselectors.apt0000644000175000017500000000475310777725005021467 0ustar mkochmkoch -------------- File Selectors -------------- File Selectors A file selector is a plexus component, which allows to select certain files out of a given set. For example, the {{{http://plexus.codehaus.org/plexus-archiver}Plexus Archiver}} uses file selectors to select the files being archived out of a base directory. Its counterpart, the Plexus Unarchiver allows to restrict the files to unarchive. File mappers are implementing the interface {{{apidocs/org/codehaus/plexus/components/io/fileselectors/FileSelector.html}FileSelector}}. Available file selectors are * The {{{#All Files Selector}All Files Selector}}; it uses the role hints "default", or "all". * The {{{#Standard File Selector}Standard File Selector}}; its role hint is "standard". * {All Files Selector} The {{{apidocs/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.html}selector for all files}} doesn't exclude any files. It is mainly useful when you want to avoid the value null for a file selector. A configuration snippet for using the selector for all files would look like this: ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- The selector for all files uses the role hints "all", or "default". * {Standard File Selector} The {{{apidocs/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector} standard file selector}} selects files based on include/exclude patterns. A configuration snippet for using the standard file selector would look like this: ----------------------------------------------------------------------------- **/*.gif **/*.png **/*.jpg **/*.jpeg bar/ true false ----------------------------------------------------------------------------- This would include all image files, with the exception of those in the directory <<>>. The default excludes (for example <<>>) would apply and file names would be treated case insensitive. plexus-io-1.0~alpha5/src/site/site.xml0000644000175000017500000000104611253264767017013 0ustar mkochmkoch plexus-io-1.0~alpha5/src/main/0000755000175000017500000000000011256764616015305 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/0000755000175000017500000000000011256764616016226 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/0000755000175000017500000000000011256764616017015 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/codehaus/0000755000175000017500000000000011256764616020610 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/0000755000175000017500000000000011256764616022130 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/0000755000175000017500000000000011256764616024315 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/0000755000175000017500000000000011256764616024724 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/0000755000175000017500000000000011256764616027567 5ustar mkochmkoch././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFil0000644000175000017500000001772111202103744033026 0ustar mkochmkochpackage org.codehaus.plexus.components.io.fileselectors; /* * 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 org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.SelectorUtils; /** * This file selector uses a set of patterns for including/excluding * files. */ public class IncludeExcludeFileSelector implements FileSelector { /** * The include/exclude file selectors role-hint: "standard". */ public static final String ROLE_HINT = "standard"; private static final String[] ALL_INCLUDES = new String[]{ getCanonicalName( "**/*" ) }; private static final String[] ZERO_EXCLUDES = new String[0]; private boolean isCaseSensitive = true; private boolean useDefaultExcludes = true; private String[] includes; private String[] excludes; private String[] computedIncludes = ALL_INCLUDES; private String[] computedExcludes = ZERO_EXCLUDES; /** * Tests whether or not a name matches against at least one exclude * pattern. * * @param name The name to match. Must not be null. * @return true when the name matches against at least one * exclude pattern, or false otherwise. */ protected boolean isExcluded( String name ) { for ( int i = 0; i < computedExcludes.length; i++ ) { if ( matchPath( computedExcludes[i], name, isCaseSensitive ) ) { return true; } } return false; } /** * Sets the list of include patterns to use. All '/' and '\' characters * are replaced by File.separatorChar, so the separator used * need not match File.separatorChar. *

* When a pattern ends with a '/' or '\', "**" is appended. * * @param includes A list of include patterns. * May be null, indicating that all files * should be included. If a non-null * list is given, all elements must be * non-null. */ public void setIncludes( String[] includes ) { this.includes = includes; if ( includes == null ) { computedIncludes = ALL_INCLUDES; } else { computedIncludes = new String[includes.length]; for ( int i = 0; i < includes.length; i++ ) { String pattern = asPattern( includes[i] ); computedIncludes[i] = pattern; } } } private static String getCanonicalName( String pName ) { return pName.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); } private String asPattern( String pPattern ) { String pattern = getCanonicalName( pPattern.trim() ); if ( pattern.endsWith( File.separator ) ) { pattern += "**"; } return pattern; } /** * Returns the list of include patterns to use. * * @return A list of include patterns. * May be null, indicating that all files * should be included. If a non-null * list is given, all elements must be * non-null. */ public String[] getIncludes() { return includes; } /** * Sets the list of exclude patterns to use. All '/' and '\' characters * are replaced by File.separatorChar, so the separator used * need not match File.separatorChar. *

* When a pattern ends with a '/' or '\', "**" is appended. * * @param excludes A list of exclude patterns. * May be null, indicating that no files * should be excluded. If a non-null list is * given, all elements must be non-null. */ public void setExcludes( String[] excludes ) { this.excludes = excludes; final String[] defaultExcludes = useDefaultExcludes ? FileUtils.getDefaultExcludes() : ZERO_EXCLUDES; if ( excludes == null ) { computedExcludes = defaultExcludes; } else { computedExcludes = new String[excludes.length + defaultExcludes.length]; for ( int i = 0; i < excludes.length; i++ ) { computedExcludes[i] = asPattern( excludes[i] ); } if ( defaultExcludes.length > 0 ) { System.arraycopy( defaultExcludes, 0, computedExcludes, excludes.length, defaultExcludes.length ); } } } /** * Returns the list of exclude patterns to use. * * @return A list of exclude patterns. * May be null, indicating that no files * should be excluded. If a non-null list is * given, all elements must be non-null. */ public String[] getExcludes() { return excludes; } /** * Tests, whether the given pattern is matching the given name. * @param pattern The pattern to match * @param name The name to test * @param isCaseSensitive Whether the pattern is case sensitive. * @return True, if the pattern matches, otherwise false */ protected boolean matchPath( String pattern, String name, boolean isCaseSensitive ) { return SelectorUtils.matchPath( pattern, name, isCaseSensitive ); } /** * Tests whether or not a name matches against at least one include * pattern. * * @param name The name to match. Must not be null. * @return true when the name matches against at least one * include pattern, or false otherwise. */ protected boolean isIncluded( String name ) { for ( int i = 0; i < computedIncludes.length; i++ ) { if ( matchPath( computedIncludes[i], name, isCaseSensitive ) ) { return true; } } return false; } public boolean isSelected( FileInfo fileInfo ) throws IOException { final String name = getCanonicalName( fileInfo.getName() ); return isIncluded( name ) && !isExcluded( name ); } /** * Returns, whether the include/exclude patterns are case sensitive. * @return True, if the patterns are case sensitive (default), or false. */ public boolean isCaseSensitive() { return isCaseSensitive; } /** * Sets, whether the include/exclude patterns are case sensitive. * @param caseSensitive True, if the patterns are case sensitive (default), or false. */ public void setCaseSensitive( boolean caseSensitive ) { isCaseSensitive = caseSensitive; } /** * Returns, whether to use the default excludes, as specified by * {@link FileUtils#getDefaultExcludes()}. */ public boolean isUseDefaultExcludes() { return useDefaultExcludes; } /** * Sets, whether to use the default excludes, as specified by * {@link FileUtils#getDefaultExcludes()}. */ public void setUseDefaultExcludes( boolean pUseDefaultExcludes ) { useDefaultExcludes = pUseDefaultExcludes; setExcludes( excludes ); } }././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java0000644000175000017500000000254111202103744032770 0ustar mkochmkochpackage org.codehaus.plexus.components.io.fileselectors; /* * 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; /** * Interface of a component, which selects/deselects files. */ public interface FileSelector { /** * Role used to register component implementations with the container. */ public static final String ROLE = FileSelector.class.getName(); /** * The default role-hint: "default". */ public static final String DEFAULT_ROLE_HINT = "default"; /** * Returns, whether the given file is selected. * @param An instance of FileInfo with the files meta data. * It is recommended, that the caller creates an instance * of {@link PlexusIoResource}. */ boolean isSelected( FileInfo fileInfo ) throws IOException; }././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelec0000644000175000017500000000201311127423355032742 0ustar mkochmkochpackage org.codehaus.plexus.components.io.fileselectors; /* * 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; /** * The default file selector: Selects all files. */ public class AllFilesFileSelector implements FileSelector { /** * The all files selectors role-hint: "all". */ public static final String ROLE_HINT = "all"; public boolean isSelected( FileInfo fileInfo ) throws IOException { return true; } }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/package.html0000644000175000017500000000115010603603131032020 0ustar mkochmkochFile Selectors

File Selectors

File selectors can be used to select or deselect a subset of files. For example, the plexus archivers or unarchivers use file selectors for selecting a subset of files in a directory.

Examples:

plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileInfo.java0000644000175000017500000000334111127423355032113 0ustar mkochmkochpackage org.codehaus.plexus.components.io.fileselectors; /* * 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; /** * An object implementing this interface is passed to the * file selector when the method * {@link FileSelector#isSelected(FileInfo)} * is invoked. This object provides information about * the file to select or deselect. */ public interface FileInfo { /** * Returns the resources name, which may include path components, * like directory names, or something like that. The resources name * is expected to be a relative name and the path components must * be separated by {@link java.io.File#pathSeparator} */ String getName(); /** * Creates an {@link InputStream}, which may be used to read * the files contents. This is useful, if the file selector * comes to a decision based on the files contents. */ InputStream getContents() throws IOException; /** * Returns, whether the {@link FileInfo} refers to a file. */ boolean isFile(); /** * Returns, whether the {@link FileInfo} refers to a directory. */ boolean isDirectory(); }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/0000755000175000017500000000000011256764616027112 5ustar mkochmkoch././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttrib0000644000175000017500000001222211127423355033130 0ustar mkochmkochpackage 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 SimpleResourceAttributes implements PlexusIoResourceAttributes { private int gid = -1; private int uid = -1; private String userName; private String groupName; private int mode; public SimpleResourceAttributes( int uid, String userName, int gid, String groupName, int mode ) { this.uid = uid; this.userName = userName; this.gid = gid; this.groupName = groupName; this.mode = mode; } public SimpleResourceAttributes() { } public int getOctalMode() { return mode; } public int getGroupId() { return gid; } public String getGroupName() { return groupName; } public int getUserId() { return uid; } public String getUserName() { return userName; } public boolean isGroupExecutable() { return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode ); } public boolean isGroupReadable() { return PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode ); } public boolean isGroupWritable() { return PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode ); } public boolean isOwnerExecutable() { return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode ); } public boolean isOwnerReadable() { return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode ); } public boolean isOwnerWritable() { return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode ); } public boolean isWorldExecutable() { return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode ); } public boolean isWorldReadable() { return PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode ); } public boolean isWorldWritable() { return PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode ); } public String getOctalModeString() { return Integer.toString( mode, 8 ); } public PlexusIoResourceAttributes setOctalMode( int mode ) { this.mode = mode; return this; } public PlexusIoResourceAttributes setGroupExecutable( boolean flag ) { set( AttributeConstants.OCTAL_GROUP_EXECUTE, flag ); return this; } public PlexusIoResourceAttributes setGroupId( int gid ) { this.gid = gid; return this; } public PlexusIoResourceAttributes setGroupName( String name ) { this.groupName = name; return this; } public PlexusIoResourceAttributes setGroupReadable( boolean flag ) { set( AttributeConstants.OCTAL_GROUP_READ, flag ); return this; } public PlexusIoResourceAttributes setGroupWritable( boolean flag ) { set( AttributeConstants.OCTAL_GROUP_WRITE, flag ); return this; } public PlexusIoResourceAttributes setOwnerExecutable( boolean flag ) { set( AttributeConstants.OCTAL_OWNER_EXECUTE, flag ); return this; } public PlexusIoResourceAttributes setOwnerReadable( boolean flag ) { set( AttributeConstants.OCTAL_OWNER_READ, flag ); return this; } public PlexusIoResourceAttributes setOwnerWritable( boolean flag ) { set( AttributeConstants.OCTAL_OWNER_WRITE, flag ); return this; } public PlexusIoResourceAttributes setUserId( int uid ) { this.uid = uid; return this; } public PlexusIoResourceAttributes setUserName( String name ) { this.userName = name; return this; } public PlexusIoResourceAttributes setWorldExecutable( boolean flag ) { set( AttributeConstants.OCTAL_WORLD_EXECUTE, flag ); return this; } public PlexusIoResourceAttributes setWorldReadable( boolean flag ) { set( AttributeConstants.OCTAL_WORLD_READ, flag ); return this; } public PlexusIoResourceAttributes setWorldWritable( boolean flag ) { set( AttributeConstants.OCTAL_WORLD_WRITE, flag ); return this; } private void set( int bit, boolean enabled ) { if ( enabled ) { mode |= bit; } else { mode &= ~bit; } } public PlexusIoResourceAttributes setOctalModeString( String mode ) { setOctalMode( Integer.parseInt( mode, 8 ) ); return this; } }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.j0000644000175000017500000000233211127423355033112 0ustar mkochmkochpackage 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 final class AttributeConstants { public static final int OCTAL_OWNER_READ = 0400; public static final int OCTAL_OWNER_WRITE = 0200; public static final int OCTAL_OWNER_EXECUTE = 0100; public static final int OCTAL_GROUP_READ = 040; public static final int OCTAL_GROUP_WRITE = 020; public static final int OCTAL_GROUP_EXECUTE = 010; public static final int OCTAL_WORLD_READ = 04; public static final int OCTAL_WORLD_WRITE = 02; public static final int OCTAL_WORLD_EXECUTE = 01; private AttributeConstants() { } }././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttr0000644000175000017500000000420311127423355033134 0ustar mkochmkochpackage 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 interface PlexusIoResourceAttributes { boolean isOwnerReadable(); boolean isOwnerWritable(); boolean isOwnerExecutable(); boolean isGroupReadable(); boolean isGroupWritable(); boolean isGroupExecutable(); boolean isWorldReadable(); boolean isWorldWritable(); boolean isWorldExecutable(); int getUserId(); int getGroupId(); String getUserName(); String getGroupName(); int getOctalMode(); String getOctalModeString(); PlexusIoResourceAttributes setOwnerReadable( boolean flag ); PlexusIoResourceAttributes setOwnerWritable( boolean flag ); PlexusIoResourceAttributes setOwnerExecutable( boolean flag ); PlexusIoResourceAttributes setGroupReadable( boolean flag ); PlexusIoResourceAttributes setGroupWritable( boolean flag ); PlexusIoResourceAttributes setGroupExecutable( boolean flag ); PlexusIoResourceAttributes setWorldReadable( boolean flag ); PlexusIoResourceAttributes setWorldWritable( boolean flag ); PlexusIoResourceAttributes setWorldExecutable( boolean flag ); PlexusIoResourceAttributes setUserId( int uid ); PlexusIoResourceAttributes setGroupId( int gid ); PlexusIoResourceAttributes setUserName( String name ); PlexusIoResourceAttributes setGroupName( String name ); PlexusIoResourceAttributes setOctalMode( int mode ); PlexusIoResourceAttributes setOctalModeString( String mode ); }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java0000644000175000017500000002253511207107052032667 0ustar mkochmkochpackage 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.util.Arrays; public class FileAttributes implements PlexusIoResourceAttributes { protected static final char VALUE_DISABLED_MODE = '-'; protected static final char VALUE_WRITABLE_MODE = 'w'; protected static final char VALUE_READABLE_MODE = 'r'; protected static final char VALUE_EXECUTABLE_MODE = 'x'; protected static final int INDEX_WORLD_EXECUTE = 9; protected static final int INDEX_WORLD_WRITE = 8; protected static final int INDEX_WORLD_READ = 7; protected static final int INDEX_GROUP_EXECUTE = 6; protected static final int INDEX_GROUP_WRITE = 5; protected static final int INDEX_GROUP_READ = 4; protected static final int INDEX_OWNER_EXECUTE = 3; protected static final int INDEX_OWNER_WRITE = 2; protected static final int INDEX_OWNER_READ = 1; private int groupId = -1; private String groupName; private int userId = -1; private String userName; private char[] mode; public FileAttributes( int userId, String userName, int groupId, String groupName, char[] mode ) { this.groupId = groupId; this.groupName = groupName; this.userId = userId; this.userName = userName; setLsModeParts( mode ); } public FileAttributes() { mode = new char[10]; Arrays.fill( mode, VALUE_DISABLED_MODE ); } protected char[] getLsModeParts() { return mode; } protected void setLsModeParts( char[] mode ) { if( mode.length < 10 ) { this.mode = new char[10]; System.arraycopy( mode, 0, this.mode, 0, mode.length ); for ( int i = mode.length; i < 10; i++ ) { this.mode[i] = VALUE_DISABLED_MODE; } } else { this.mode = mode; } } public int getGroupId() { return groupId; } public String getGroupName() { return groupName; } public int getUserId() { return userId; } public String getUserName() { return userName; } public boolean isGroupExecutable() { return checkFlag( '-', INDEX_GROUP_EXECUTE ); } private boolean checkFlag( char disabledValue, int idx ) { return mode == null ? false : mode[idx] != disabledValue; } public boolean isGroupReadable() { return checkFlag( '-', INDEX_GROUP_READ ); } public boolean isGroupWritable() { return checkFlag( '-', INDEX_GROUP_WRITE ); } public boolean isOwnerExecutable() { return checkFlag( '-', INDEX_OWNER_EXECUTE ); } public boolean isOwnerReadable() { return checkFlag( '-', INDEX_OWNER_READ ); } public boolean isOwnerWritable() { return checkFlag( '-', INDEX_OWNER_WRITE ); } public boolean isWorldExecutable() { return checkFlag( '-', INDEX_WORLD_EXECUTE ); } public boolean isWorldReadable() { return checkFlag( '-', INDEX_WORLD_READ ); } public boolean isWorldWritable() { return checkFlag( '-', INDEX_WORLD_WRITE ); } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "\nFile Attributes:\n------------------------------\nuser: " ); sb.append( userName == null ? "" : userName ); sb.append( "\ngroup: " ); sb.append( groupName == null ? "" : groupName ); sb.append( "\nuid: " ); sb.append( userId == -1 ? "" : Integer.toString( userId ) ); sb.append( "\ngid: " ); sb.append( groupId == -1 ? "" : Integer.toString( groupId ) ); sb.append( "\nmode: " ); sb.append( mode == null ? "" : String.valueOf( mode ) ); return sb.toString(); } public int getOctalMode() { int result = 0; if ( isOwnerReadable() ) { result |= AttributeConstants.OCTAL_OWNER_READ; } if ( isOwnerWritable() ) { result |= AttributeConstants.OCTAL_OWNER_WRITE; } if ( isOwnerExecutable() ) { result |= AttributeConstants.OCTAL_OWNER_EXECUTE; } if ( isGroupReadable() ) { result |= AttributeConstants.OCTAL_GROUP_READ; } if ( isGroupWritable() ) { result |= AttributeConstants.OCTAL_GROUP_WRITE; } if ( isGroupExecutable() ) { result |= AttributeConstants.OCTAL_GROUP_EXECUTE; } if ( isWorldReadable() ) { result |= AttributeConstants.OCTAL_WORLD_READ; } if ( isWorldWritable() ) { result |= AttributeConstants.OCTAL_WORLD_WRITE; } if ( isWorldExecutable() ) { result |= AttributeConstants.OCTAL_WORLD_EXECUTE; } return result; } public String getOctalModeString() { return Integer.toString( getOctalMode(), 8 ); } public PlexusIoResourceAttributes setGroupExecutable( boolean flag ) { setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_EXECUTE ); return this; } public PlexusIoResourceAttributes setGroupId( int gid ) { this.groupId = gid; return this; } public PlexusIoResourceAttributes setGroupName( String name ) { this.groupName = name; return this; } public PlexusIoResourceAttributes setGroupReadable( boolean flag ) { setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_READ ); return this; } public PlexusIoResourceAttributes setGroupWritable( boolean flag ) { setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_GROUP_WRITE ); return this; } public PlexusIoResourceAttributes setOwnerExecutable( boolean flag ) { setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_EXECUTE ); return this; } public PlexusIoResourceAttributes setOwnerReadable( boolean flag ) { setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_READ ); return this; } public PlexusIoResourceAttributes setOwnerWritable( boolean flag ) { setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_OWNER_WRITE ); return this; } public PlexusIoResourceAttributes setUserId( int uid ) { this.userId = uid; return this; } public PlexusIoResourceAttributes setUserName( String name ) { this.userName = name; return this; } public PlexusIoResourceAttributes setWorldExecutable( boolean flag ) { setMode( flag ? VALUE_EXECUTABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_EXECUTE ); return this; } public PlexusIoResourceAttributes setWorldReadable( boolean flag ) { setMode( flag ? VALUE_READABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_READ ); return this; } public PlexusIoResourceAttributes setWorldWritable( boolean flag ) { setMode( flag ? VALUE_WRITABLE_MODE : VALUE_DISABLED_MODE, INDEX_WORLD_WRITE ); return this; } public PlexusIoResourceAttributes setLsModeline( String modeLine ) { setLsModeParts( modeLine.toCharArray() ); return this; } private void setMode( char value, int modeIdx ) { char[] mode = getLsModeParts(); mode[modeIdx] = value; setLsModeParts( mode ); } public PlexusIoResourceAttributes setOctalMode( int mode ) { setGroupExecutable( PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode ) ); setGroupReadable( PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode ) ); setGroupWritable( PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode ) ); setOwnerExecutable( PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode ) ); setOwnerReadable( PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode ) ); setOwnerWritable( PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode ) ); setWorldExecutable( PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode ) ); setWorldReadable( PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode ) ); setWorldWritable( PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode ) ); return this; } public PlexusIoResourceAttributes setOctalModeString( String mode ) { setOctalMode( Integer.parseInt( mode, 8 ) ); return this; } }././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttr0000644000175000017500000003642611207107052033140 0ustar mkochmkochpackage 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.text.ParseException; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.console.ConsoleLogger; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; public final class PlexusIoResourceAttributeUtils { private PlexusIoResourceAttributeUtils() { } public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttributes override, PlexusIoResourceAttributes base, PlexusIoResourceAttributes def ) { if ( override == null ) { return base; } SimpleResourceAttributes result; if ( base == null ) { result = new SimpleResourceAttributes(); } else { result = new SimpleResourceAttributes( base.getUserId(), base.getUserName(), base.getGroupId(), base.getGroupName(), base.getOctalMode() ); } if ( override.getGroupId() != -1 ) { result.setGroupId( override.getGroupId() ); } if ( def != null && result.getGroupId() < 0 ) { result.setGroupId( def.getGroupId() ); } if ( override.getGroupName() != null ) { result.setGroupName( override.getGroupName() ); } if ( def != null && result.getGroupName() == null ) { result.setGroupName( def.getGroupName() ); } if ( override.getUserId() != -1 ) { result.setUserId( override.getUserId() ); } if ( def != null && result.getUserId() < 0 ) { result.setUserId( def.getUserId() ); } if ( override.getUserName() != null ) { result.setUserName( override.getUserName() ); } if ( def != null && result.getUserName() == null ) { result.setUserName( def.getUserName() ); } if ( override.getOctalMode() > 0 ) { result.setOctalMode( override.getOctalMode() ); } if ( def != null && result.getOctalMode() < 0 ) { result.setOctalMode( def.getOctalMode() ); } return result; } public static boolean isGroupExecutableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_EXECUTE ); } public static boolean isGroupReadableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_READ ); } public static boolean isGroupWritableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_WRITE ); } public static boolean isOwnerExecutableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_EXECUTE ); } public static boolean isOwnerReadableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_READ ); } public static boolean isOwnerWritableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_WRITE ); } public static boolean isWorldExecutableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_EXECUTE ); } public static boolean isWorldReadableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_READ ); } public static boolean isWorldWritableInOctal( int mode ) { return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_WRITE ); } public static boolean isOctalModeEnabled( int mode, int targetMode ) { return ( mode & targetMode ) != 0; } public static PlexusIoResourceAttributes getFileAttributes( File file ) throws IOException { Map byPath = getFileAttributesByPath( file, null, Logger.LEVEL_DEBUG, false ); return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() ); } public static PlexusIoResourceAttributes getFileAttributes( File file, Logger logger ) throws IOException { Map byPath = getFileAttributesByPath( file, logger, Logger.LEVEL_DEBUG, false ); return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() ); } public static PlexusIoResourceAttributes getFileAttributes( File file, Logger logger, int logLevel ) throws IOException { Map byPath = getFileAttributesByPath( file, logger, logLevel, false ); return (PlexusIoResourceAttributes) byPath.get( file.getAbsolutePath() ); } public static Map getFileAttributesByPath( File dir ) throws IOException { return getFileAttributesByPath( dir, null, Logger.LEVEL_DEBUG, true ); } public static Map getFileAttributesByPath( File dir, Logger logger ) throws IOException { return getFileAttributesByPath( dir, logger, Logger.LEVEL_DEBUG, true ); } public static Map getFileAttributesByPath( File dir, Logger logger, int logLevel ) throws IOException { return getFileAttributesByPath( dir, logger, Logger.LEVEL_DEBUG, true ); } public static Map getFileAttributesByPath( File dir, Logger logger, int logLevel, boolean recursive ) throws IOException { if ( !enabledOnCurrentOperatingSystem() ) { return Collections.EMPTY_MAP; } if ( logger == null ) { logger = new ConsoleLogger( Logger.LEVEL_INFO, "Internal" ); } LoggerStreamConsumer loggerConsumer = new LoggerStreamConsumer( logger, logLevel ); AttributeParser parser = new AttributeParser( loggerConsumer, logger ); String lsOptions = "-1nla" + ( recursive ? "R" : "d" ); try { executeLs( dir, lsOptions, loggerConsumer, parser, logger ); } catch ( CommandLineException e ) { IOException error = new IOException( "Failed to quote directory: '" + dir + "'" ); error.initCause( e ); throw error; } parser.secondPass = true; parser.extractNames = true; lsOptions = "-1la" + ( recursive ? "R" : "d" ); try { executeLs( dir, lsOptions, loggerConsumer, parser, logger ); } catch ( CommandLineException e ) { IOException error = new IOException( "Failed to quote directory: '" + dir + "'" ); error.initCause( e ); throw error; } return parser.attributesByPath; } private static boolean enabledOnCurrentOperatingSystem() { return !Os.isFamily( Os.FAMILY_WINDOWS ) && !Os.isFamily( Os.FAMILY_WIN9X ); } private static void executeLs( File dir, String options, LoggerStreamConsumer loggerConsumer, StreamConsumer parser, Logger logger ) throws IOException, CommandLineException { Commandline numericCli = new Commandline(); numericCli.getShell().setQuotedArgumentsEnabled( true ); numericCli.getShell().setQuotedExecutableEnabled( false ); numericCli.setExecutable( "ls" ); numericCli.createArg().setLine( options ); numericCli.createArg().setValue( dir.getAbsolutePath() ); if ( logger.isDebugEnabled() ) { logger.debug( "Executing:\n\n" + numericCli.toString() + "\n" ); } try { int result = CommandLineUtils.executeCommandLine( numericCli, parser, loggerConsumer ); if ( result != 0 ) { throw new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString() + "'" ); } } catch ( CommandLineException e ) { IOException error = new IOException( "Failed to retrieve numeric file attributes using: '" + numericCli.toString() + "'" ); error.initCause( e ); throw error; } } private static final class LoggerStreamConsumer implements StreamConsumer { private Logger logger; private int level; public LoggerStreamConsumer( Logger logger, int level ) { this.logger = logger; this.level = level; } public void consumeLine( String line ) { switch ( level ) { case Logger.LEVEL_DEBUG: logger.debug( line ); break; case Logger.LEVEL_ERROR: logger.error( line ); break; case Logger.LEVEL_FATAL: logger.fatalError( line ); break; case Logger.LEVEL_WARN: logger.warn( line ); break; default: logger.info( line ); break; } } } private static final SimpleDateFormat[] LS_DATE_FORMATS = { new SimpleDateFormat( "MMM dd yyyy" ), new SimpleDateFormat( "MMM dd HH:mm" ), new SimpleDateFormat( "yyyy-MM-dd HH:mm" ), }; private static final int[] LS_LAST_DATE_PART_INDICES = { 7, 7, 6 }; private static int verifyParsability( String line, String[] parts, Logger logger ) { if ( parts.length > 7 ) { String dateCandidate = parts[5] + " " + parts[6] + " " + parts[7]; for ( int i = 0; i < LS_DATE_FORMATS.length; i++ ) { try { LS_DATE_FORMATS[i].parse( dateCandidate ); return LS_LAST_DATE_PART_INDICES[i]; } catch ( ParseException e ) { if ( logger.isDebugEnabled() ) { logger.debug( "Failed to parse date: '" + dateCandidate + "' using format: " + LS_DATE_FORMATS[i].toPattern(), e ); } } } } if ( logger.isDebugEnabled() ) { logger.debug( "Unparseable line: '" + line + "'\nReason: unrecognized date format; ambiguous start-index for path in listing." ); } return -1; } private static final class AttributeParser implements StreamConsumer { private final StreamConsumer delegate; private Map attributesByPath = new LinkedHashMap(); private final Logger logger; private boolean nextIsPathPrefix = false; private String pathPrefix = ""; private boolean extractNames = false; private boolean secondPass = false; public AttributeParser( StreamConsumer delegate, Logger logger ) { this.delegate = delegate; this.logger = logger; } public void consumeLine( String line ) { if ( line.startsWith( "total " ) ) { // skip it. } else if ( line.trim().length() == 0 ) { nextIsPathPrefix = true; if ( logger.isDebugEnabled() ) { logger.debug( "Anticipating path prefix in next line" ); } } else if ( nextIsPathPrefix ) { if ( !line.endsWith( ":" ) ) { if ( logger.isDebugEnabled() ) { logger.debug( "Path prefix not found. Checking next line." ); } } else { nextIsPathPrefix = false; pathPrefix = line.substring( 0, line.length() - 1 ); if ( !pathPrefix.endsWith( "/" ) ) { pathPrefix += "/"; } if ( logger.isDebugEnabled() ) { logger.debug( "Set path prefix to: " + pathPrefix ); } } } else { String[] parts = line.split( "\\s+" ); int lastDatePart = verifyParsability( line, parts, logger ); if ( lastDatePart > 0 ) { int idx = line.indexOf( parts[lastDatePart] ) + parts[lastDatePart].length() + 1; String path = pathPrefix + line.substring( idx ); while ( path.length() > 0 && Character.isWhitespace( path.charAt( 0 ) ) ) { path = path.substring( 1 ); } if ( logger.isDebugEnabled() ) { logger.debug( "path: '" + path + "'" ); logger.debug( "mode: '" + parts[0] + "'" ); logger.debug( "uid: '" + parts[2] ); logger.debug( "gid: '" + parts[3] ); } FileAttributes attributes = null; if ( secondPass ) { attributes = (FileAttributes) attributesByPath.get( path ); } else { attributes = new FileAttributes(); attributes.setLsModeline( parts[0] ); attributesByPath.put( path, attributes ); } if ( attributes != null ) { if ( extractNames ) { attributes.setUserName( parts[2] ); attributes.setGroupName( parts[3] ); } else { attributes.setUserId( Integer.parseInt( parts[2] ) ); attributes.setGroupId( Integer.parseInt( parts[3] ) ); } } } } delegate.consumeLine( line ); } } }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/0000755000175000017500000000000011256764616026736 5ustar mkochmkoch././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceWithAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceWithA0000644000175000017500000000166511127423355033073 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.components.io.attributes.PlexusIoResourceAttributes; public interface PlexusIoResourceWithAttributes extends PlexusIoResource { PlexusIoResourceAttributes getAttributes(); void setAttributes( PlexusIoResourceAttributes attributes ); }././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.0000644000175000017500000000643311207364141033006 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.IOException; import java.io.InputStream; import java.net.URL; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; /** * Implementation of {@link PlexusIoResource} for files. */ public class PlexusIoFileResource extends AbstractPlexusIoResourceWithAttributes implements PlexusIoResourceWithAttributes { private File file; /** * Creates a new instance. */ public PlexusIoFileResource() { // Does nothing } /** * Creates a new instance. */ public PlexusIoFileResource( File file ) { this( file, file.getPath().replace( '\\', '/' ) ); } /** * Creates a new instance. */ public PlexusIoFileResource( File file, PlexusIoResourceAttributes attrs ) { this( file, file.getPath().replace( '\\', '/' ), attrs ); } /** * Creates a new instance. */ public PlexusIoFileResource( File file, String name ) { setFile( file ); setName( name ); } public PlexusIoFileResource( File file, String name, PlexusIoResourceAttributes attrs ) { setName( name ); setAttributes( attrs ); setFile( file ); } /** * Sets the resources file. */ public void setFile( File file ) { this.file = file; setLastModified( file.lastModified() ); setSize( file.length() ); setFile( file.isFile() ); setDirectory( file.isDirectory() ); setExisting( file.exists() ); } /** * Returns the resources file. */ public File getFile() { return file; } public InputStream getContents() throws IOException { return new FileInputStream( getFile() ); } public URL getURL() throws IOException { return getFile().toURI().toURL(); } public long getLastModified() { return getFile().lastModified(); } public long getSize() { return getFile().length(); } public boolean isDirectory() { return getFile().isDirectory(); } public boolean isExisting() { return getFile().exists(); } public boolean isFile() { return getFile().isFile(); } public void setDirectory( boolean isDirectory ) { } public void setExisting( boolean isExisting ) { } public void setFile( boolean isFile ) { } public void setLastModified( long lastModified ) { file.setLastModified( lastModified ); } public void setSize( long size ) { } }././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResource.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResou0000644000175000017500000000550411207364141033120 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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. */ /** * Default implementation of {@link PlexusIoResource}. */ public abstract class AbstractPlexusIoResource implements PlexusIoResource { private String name; private long lastModified, size; private boolean isFile, isDirectory, isExisting; /** * Creates a new instance with default settings. */ public AbstractPlexusIoResource() { } /** * Sets the date, when the resource was last modified. * @param Date of last modification, if known. * Otherwise, {@link #UNKNOWN_MODIFICATION_DATE}. * @see java.io.File#lastModified() */ public void setLastModified( long lastModified ) { this.lastModified = lastModified; } public long getLastModified() { return lastModified; } /** * Sets the resources name, which may include path components, * like directory names, or something like that. The resources name * is expected to be a relative name and the path components must * be separated by {@link java.io.File#pathSeparator} */ public void setName( String name ) { this.name = name; } public String getName() { return name; } /** * Sets the resources size. * @param size The resources size, if known. Otherwise returns * {@link #UNKNOWN_RESOURCE_SIZE}. * @see java.io.File#length() */ public void setSize( long size ) { this.size = size; } public long getSize() { return size; } /** * Sets, whether the resource is a directory. */ public void setDirectory( boolean isDirectory ) { this.isDirectory = isDirectory; } public boolean isDirectory() { return isDirectory; } /** * Sets, whether the resource exists. */ public void setExisting( boolean isExisting ) { this.isExisting = isExisting; } public boolean isExisting() { return isExisting; } /** * Sets, whether the resource is a file. */ public void setFile( boolean isFile ) { this.isFile = isFile; } public boolean isFile() { return isFile; } }././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceWithAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResou0000644000175000017500000000233311242611447033120 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.components.io.attributes.PlexusIoResourceAttributes; public abstract class AbstractPlexusIoResourceWithAttributes extends AbstractPlexusIoResource implements PlexusIoResourceWithAttributes { private PlexusIoResourceAttributes attributes; public AbstractPlexusIoResourceWithAttributes() { super(); } public PlexusIoResourceAttributes getAttributes() { return attributes; } public void setAttributes( PlexusIoResourceAttributes attributes ) { this.attributes = attributes; } }././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchi0000644000175000017500000000434511127423355033057 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.plexus.logging.Logger; /** * Default implementation of {@link PlexusIoFileResourceCollection} for * zip files, tar files, etc. * @author jwi * */ public abstract class AbstractPlexusIoArchiveResourceCollection extends AbstractPlexusIoResourceCollection implements PlexusIoArchivedResourceCollection { private File file; protected AbstractPlexusIoArchiveResourceCollection() { } protected AbstractPlexusIoArchiveResourceCollection( Logger logger ) { super( logger ); } /** * Sets the zip file */ public void setFile( File file ) { this.file = file; } /** * Returns the zip file */ public File getFile() { return file; } /** * Returns an iterator over the archives entries. */ protected abstract Iterator getEntries() throws IOException; public Iterator getResources() throws IOException { final List result = new ArrayList(); for (Iterator it = getEntries(); it.hasNext(); ) { final PlexusIoResource res = (PlexusIoResource) it.next(); if ( isSelected( res ) ) { result.add( res ); } } return result.iterator(); } public long getLastModified() throws IOException { File f = getFile(); return f == null ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : f.lastModified(); } }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.j0000644000175000017500000000210111127423355032733 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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; public class PlexusIoURLResource extends AbstractPlexusIoResource { private URL url; public InputStream getContents() throws IOException { return getURL().openStream(); } public URL getURL() throws IOException { return url; } public void setURL( URL pUrl ) { url = pUrl; } }././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResou0000644000175000017500000000202211127423355033076 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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; /** * Extension of {@link PlexusIoResourceCollection} for archive * files: Zip, tar, gzip, bzip2, etc. files. */ public interface PlexusIoArchivedResourceCollection extends PlexusIoResourceCollection { /** * Sets the arcihve file */ void setFile( File file ); /** * Returns the archive file */ File getFile(); }././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIOResourceCollectionWithAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIOResourceColle0000644000175000017500000000300611207107052033034 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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 interface PlexusIOResourceCollectionWithAttributes { /** * Sets the file and directory attributes to use as defaults. * * @param uid * @param userName * @param gid * @param groupName * @param fileMode The octal mode to use for files * @param dirMode The octal mode to use for directories */ void setDefaultAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ); /** * Sets the file and directory attributes to use as overrides. * * @param uid * @param userName * @param gid * @param groupName * @param fileMode The octal mode to use for files * @param dirMode The octal mode to use for directories */ void setOverrideAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ); }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/package.html0000644000175000017500000000102610641020212031164 0ustar mkochmkochResources and Resource Collections

Resources and Resource Collections

This package implements ideas, which have been shamelessly copied from Ants resource collection framework. Basically, a resource is an abstraction of file-like entities: An actual file, an URL, a zip entry, and so on. On the other hand, a resource collections is a collection of resources.

Resource collections can be copied, moved, archived, unarchived, and so on.

././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoZipFileResour0000644000175000017500000000545011207107052033075 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.Enumeration; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class PlexusIoZipFileResourceCollection extends AbstractPlexusIoArchiveResourceCollection { /** * The zip file resource collections role hint. */ public static final String ROLE_HINT = "zipFile"; /** * The zip file resource collections role hint for jar files. */ public static final String JAR_ROLE_HINT = "jarFile"; public PlexusIoZipFileResourceCollection() { } protected Iterator getEntries() throws IOException { final File f = getFile(); if ( f == null ) { throw new IOException( "The zip file has not been set." ); } final URL url = new URL( "jar:" + f.toURI().toURL() + "!/"); final ZipFile zipFile = new ZipFile( f ); final Enumeration en = zipFile.entries(); return new Iterator(){ public boolean hasNext() { return en.hasMoreElements(); } public Object next() { final ZipEntry entry = (ZipEntry) en.nextElement(); final PlexusIoURLResource res = new PlexusIoURLResource(){ public URL getURL() throws IOException { return new URL( url, entry.getName() ); } }; final boolean dir = entry.isDirectory(); res.setName( entry.getName() ); res.setDirectory( dir ); res.setExisting( true ); res.setFile( !dir ); long l = entry.getTime(); res.setLastModified( l == -1 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l ); res.setSize( dir ? PlexusIoResource.UNKNOWN_RESOURCE_SIZE : entry.getSize() ); return res; } public void remove() { throw new UnsupportedOperationException( "Removing isn't implemented." ); } }; } }././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java0000644000175000017500000000356711202103744033050 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.net.URL; import org.codehaus.plexus.components.io.fileselectors.FileInfo; /** * A resource is a file-like entity. It may be an actual file, * an URL, a zip entry, or something like that. */ public interface PlexusIoResource extends FileInfo { /** * Unknown resource size. */ public static final long UNKNOWN_RESOURCE_SIZE = -1; /** * Unknown modification date */ public static final long UNKNOWN_MODIFICATION_DATE = 0; /** * Returns the date, when the resource was last modified, if known. * Otherwise, returns {@link #UNKNOWN_MODIFICATION_DATE}. * @see java.io.File#lastModified() */ long getLastModified(); /** * Returns, whether the resource exists. */ boolean isExisting(); /** * Returns the resources size, if known. Otherwise returns * {@link #UNKNOWN_RESOURCE_SIZE}. */ long getSize(); /** * Returns an {@link URL}, which may be used to reference the * resource, if possible. * @return An URL referencing the resource, if possible, or null. * In the latter case, you are forced to use {@link #getInputStream()}. */ URL getURL() throws IOException; }././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceC0000644000175000017500000001364611207107052033033 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.DirectoryScanner; /** * Implementation of {@link PlexusIoResourceCollection} for the set * of files in a common directory. */ public class PlexusIoFileResourceCollection extends AbstractPlexusIoResourceCollection implements PlexusIOResourceCollectionWithAttributes { /** * Role hint of this component */ public static final String ROLE_HINT = "files"; private File baseDir; private boolean isFollowingSymLinks = true; private FileAttributes defaultFileAttributes; private FileAttributes defaultDirAttributes; private FileAttributes overrideFileAttributes; private FileAttributes overrideDirAttributes; public PlexusIoFileResourceCollection() { } public PlexusIoFileResourceCollection( Logger logger ) { super( logger ); } public void setDefaultAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ) { defaultFileAttributes = new FileAttributes( uid, userName, gid, groupName, new char[]{} ); defaultFileAttributes.setOctalMode( fileMode ); defaultDirAttributes = new FileAttributes( uid, userName, gid, groupName, new char[]{} ); defaultDirAttributes.setOctalMode( dirMode ); } public void setOverrideAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ) { overrideFileAttributes = new FileAttributes( uid, userName, gid, groupName, new char[]{} ); overrideFileAttributes.setOctalMode( fileMode ); overrideDirAttributes = new FileAttributes( uid, userName, gid, groupName, new char[]{} ); overrideDirAttributes.setOctalMode( dirMode ); } /** * Sets the file collections base directory. */ public void setBaseDir( File baseDir ) { this.baseDir = baseDir; } /** * Returns the file collections base directory. */ public File getBaseDir() { return baseDir; } /** * Returns, whether symbolic links should be followed. * Defaults to true. */ public boolean isFollowingSymLinks() { return isFollowingSymLinks; } /** * Returns, whether symbolic links should be followed. * Defaults to true. */ public void setFollowingSymLinks( boolean pIsFollowingSymLinks ) { isFollowingSymLinks = pIsFollowingSymLinks; } private void addResources( List list, String[] resources, Map attributesByPath ) throws IOException { final File dir = getBaseDir(); for ( int i = 0; i < resources.length; i++ ) { String name = resources[i]; String sourceDir = name.replace( '\\', '/' ); File f = new File( dir, sourceDir ); PlexusIoResourceAttributes attrs = (PlexusIoResourceAttributes) attributesByPath.get( name.length() > 0 ? name : "." ); if ( attrs == null ) { attrs = (PlexusIoResourceAttributes) attributesByPath.get( f.getAbsolutePath() ); } if ( f.isDirectory() ) { attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideDirAttributes, attrs, defaultDirAttributes ); } else { attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideFileAttributes, attrs, defaultFileAttributes ); } PlexusIoFileResource resource = new PlexusIoFileResource( f, name, attrs ); if ( isSelected( resource ) ) { list.add( resource ); } } } public Iterator getResources() throws IOException { final DirectoryScanner ds = new DirectoryScanner(); final File dir = getBaseDir(); ds.setBasedir( dir ); final String[] inc = getIncludes(); if ( inc != null && inc.length > 0 ) { ds.setIncludes( inc ); } final String[] exc = getExcludes(); if ( exc != null && exc.length > 0 ) { ds.setExcludes( exc ); } if ( isUsingDefaultExcludes() ) { ds.addDefaultExcludes(); } ds.setCaseSensitive( isCaseSensitive() ); ds.setFollowSymlinks( isFollowingSymLinks() ); ds.scan(); Map attributesByPath = PlexusIoResourceAttributeUtils.getFileAttributesByPath( getBaseDir() ); final List result = new ArrayList(); if ( isIncludingEmptyDirectories() ) { String[] dirs = ds.getIncludedDirectories(); addResources( result, dirs, attributesByPath ); } String[] files = ds.getIncludedFiles(); addResources( result, files, attributesByPath ); return result.iterator(); } }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/0000755000175000017500000000000011256764616030117 5ustar mkochmkoch././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceWithAttributes.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyRe0000644000175000017500000000355111242611447033133 0ustar mkochmkochpackage 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.components.io.resources.AbstractPlexusIoResourceWithAttributes; import org.codehaus.plexus.components.io.resources.PlexusIoResourceWithAttributes; import java.io.IOException; import java.io.InputStream; import java.net.URL; public class PlexusIoProxyResourceWithAttributes extends AbstractPlexusIoResourceWithAttributes { private final PlexusIoResourceWithAttributes src; public PlexusIoProxyResourceWithAttributes( PlexusIoResourceWithAttributes plexusIoResource ) { this.src = plexusIoResource; setName( src.getName() ); setAttributes( src.getAttributes() ); } public long getLastModified() { return src.getLastModified(); } public long getSize() { return src.getSize(); } public boolean isDirectory() { return src.isDirectory(); } public boolean isExisting() { return src.isExisting(); } public boolean isFile() { return src.isFile(); } public URL getURL() throws IOException { return src.getURL(); } public InputStream getContents() throws IOException { return src.getContents(); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyRe0000644000175000017500000001505511207107052033126 0ustar mkochmkochpackage 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.components.io.attributes.PlexusIoResourceAttributeUtils; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; import org.codehaus.plexus.components.io.filemappers.FileMapper; import org.codehaus.plexus.components.io.fileselectors.FileSelector; import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIOResourceCollectionWithAttributes; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoResourceWithAttributes; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * Implementation of {@link PlexusIoResourceCollection} for an archives * contents. */ public class PlexusIoProxyResourceCollection extends AbstractPlexusIoResourceCollection implements PlexusIOResourceCollectionWithAttributes { private PlexusIoResourceCollection src; private SimpleResourceAttributes defaultFileAttributes; private SimpleResourceAttributes defaultDirAttributes; private PlexusIoResourceAttributes overrideFileAttributes; private PlexusIoResourceAttributes overrideDirAttributes; /** * Sets the archive to read. */ public void setSrc( PlexusIoResourceCollection src ) { this.src = src; } /** * Returns the archive to read. */ public PlexusIoResourceCollection getSrc() { return src; } protected FileSelector getDefaultFileSelector() { IncludeExcludeFileSelector fileSelector = new IncludeExcludeFileSelector(); fileSelector.setIncludes( getIncludes() ); fileSelector.setExcludes( getExcludes() ); fileSelector.setCaseSensitive( isCaseSensitive() ); fileSelector.setUseDefaultExcludes( isUsingDefaultExcludes() ); return fileSelector; } public Iterator getResources() throws IOException { final List result = new ArrayList(); final FileSelector fileSelector = getDefaultFileSelector(); String prefix = getPrefix(); if ( prefix != null && prefix.length() == 0 ) { prefix = null; } for ( Iterator iter = getSrc().getResources(); iter.hasNext(); ) { PlexusIoResource plexusIoResource = (PlexusIoResource) iter.next(); PlexusIoResourceAttributes attrs = null; if ( plexusIoResource instanceof PlexusIoResourceWithAttributes ) { attrs = ((PlexusIoResourceWithAttributes)plexusIoResource).getAttributes(); } if ( plexusIoResource.isDirectory() ) { attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideDirAttributes, attrs, defaultDirAttributes ); } else { attrs = PlexusIoResourceAttributeUtils.mergeAttributes( overrideFileAttributes, attrs, defaultFileAttributes ); } if ( !fileSelector.isSelected( plexusIoResource ) ) { continue; } if ( !isSelected( plexusIoResource ) ) { continue; } if ( plexusIoResource.isDirectory() && !isIncludingEmptyDirectories() ) { continue; } if ( prefix != null ) { String name = plexusIoResource.getName(); if ( plexusIoResource instanceof PlexusIoResourceWithAttributes ) { plexusIoResource = new PlexusIoProxyResourceWithAttributes( (PlexusIoResourceWithAttributes) plexusIoResource ); } else { plexusIoResource = new PlexusIoProxyResource( plexusIoResource ); } ( (AbstractPlexusIoResource) plexusIoResource ).setName( prefix + name ); } result.add( plexusIoResource ); } return result.iterator(); } public String getName( PlexusIoResource resource ) throws IOException { String name = resource.getName(); final FileMapper[] mappers = getFileMappers(); if ( mappers != null ) { for ( int i = 0; i < mappers.length; i++ ) { name = mappers[i].getMappedFileName( name ); } } /* * The prefix is applied when creating the resource. * return PrefixFileMapper.getMappedFileName( getPrefix(), name ); */ return name; } public long getLastModified() throws IOException { return src.getLastModified(); } public void setDefaultAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ) { defaultFileAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode ); defaultFileAttributes.setOctalMode( fileMode ); defaultDirAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode ); defaultDirAttributes.setOctalMode( dirMode ); } public void setOverrideAttributes( int uid, String userName, int gid, String groupName, int fileMode, int dirMode ) { overrideFileAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode ); overrideDirAttributes = new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode ); } }././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResource.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyRe0000644000175000017500000000333111242611447033127 0ustar mkochmkochpackage 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.components.io.resources.AbstractPlexusIoResource; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import java.io.IOException; import java.io.InputStream; import java.net.URL; public class PlexusIoProxyResource extends AbstractPlexusIoResource { private final PlexusIoResource src; public PlexusIoProxyResource( PlexusIoResource plexusIoResource ) { this.src = plexusIoResource; setName( src.getName() ); } public long getLastModified() { return src.getLastModified(); } public long getSize() { return src.getSize(); } public boolean isDirectory() { return src.isDirectory(); } public boolean isExisting() { return src.isExisting(); } public boolean isFile() { return src.isFile(); } public URL getURL() throws IOException { return src.getURL(); } public InputStream getContents() throws IOException { return src.getContents(); } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResou0000644000175000017500000001517011127423355033124 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.util.Iterator; import org.codehaus.plexus.components.io.filemappers.FileMapper; import org.codehaus.plexus.components.io.filemappers.PrefixFileMapper; import org.codehaus.plexus.components.io.fileselectors.FileSelector; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; /** * Default implementation of a resource collection. */ public abstract class AbstractPlexusIoResourceCollection implements PlexusIoResourceCollection, LogEnabled { private String prefix; private String[] includes; private String[] excludes; private FileSelector[] fileSelectors; private boolean caseSensitive = true; private boolean usingDefaultExcludes = true; private boolean includingEmptyDirectories = true; private FileMapper[] fileMappers; private Logger logger; protected AbstractPlexusIoResourceCollection() { } protected AbstractPlexusIoResourceCollection( Logger logger ) { this.logger = logger; } protected Logger getLogger() { return logger; } /** * Sets a string of patterns, which excluded files * should match. */ public void setExcludes( String[] excludes ) { this.excludes = excludes; } /** * Returns a string of patterns, which excluded files * should match. */ public String[] getExcludes() { return excludes; } /** * Sets a set of file selectors, which should be used * to select the included files. */ public void setFileSelectors( FileSelector[] fileSelectors ) { this.fileSelectors = fileSelectors; } /** * Returns a set of file selectors, which should be used * to select the included files. */ public FileSelector[] getFileSelectors() { return fileSelectors; } /** * Sets a string of patterns, which included files * should match. */ public void setIncludes( String[] includes ) { this.includes = includes; } /** * Returns a string of patterns, which included files * should match. */ public String[] getIncludes() { return includes; } /** * Sets the prefix, which the file sets contents shall * have. */ public void setPrefix( String prefix ) { this.prefix = prefix; } /** * Returns the prefix, which the file sets contents shall * have. */ public String getPrefix() { return prefix; } /** * Sets, whether the include/exclude patterns are * case sensitive. Defaults to true. */ public void setCaseSensitive( boolean caseSensitive ) { this.caseSensitive = caseSensitive; } /** * Returns, whether the include/exclude patterns are * case sensitive. Defaults to true. */ public boolean isCaseSensitive() { return caseSensitive; } /** * Sets, whether the default excludes are being * applied. Defaults to true. */ public void setUsingDefaultExcludes( boolean usingDefaultExcludes ) { this.usingDefaultExcludes = usingDefaultExcludes; } /** * Returns, whether the default excludes are being * applied. Defaults to true. */ public boolean isUsingDefaultExcludes() { return usingDefaultExcludes; } /** * Sets, whether empty directories are being included. Defaults * to true. */ public void setIncludingEmptyDirectories( boolean includingEmptyDirectories ) { this.includingEmptyDirectories = includingEmptyDirectories; } /** * Returns, whether empty directories are being included. Defaults * to true. */ public boolean isIncludingEmptyDirectories() { return includingEmptyDirectories; } protected boolean isSelected( PlexusIoResource plexusIoResource ) throws IOException { FileSelector[] fileSelectors = getFileSelectors(); if ( fileSelectors != null ) { for ( int i = 0; i < fileSelectors.length; i++ ) { if ( !fileSelectors[i].isSelected( plexusIoResource ) ) { return false; } } } return true; } /** * Returns the file name mappers, which are used to transform * the resource names. */ public FileMapper[] getFileMappers() { return fileMappers; } /** * Sets the file name mappers, which are used to transform * the resource names. */ public void setFileMappers( FileMapper[] fileMappers ) { this.fileMappers = fileMappers; } public String getName( PlexusIoResource resource ) throws IOException { String name = resource.getName(); final FileMapper[] mappers = getFileMappers(); if ( mappers != null ) { for ( int i = 0; i < mappers.length; i++ ) { name = mappers[i].getMappedFileName( name ); } } return PrefixFileMapper.getMappedFileName( getPrefix(), name ); } public long getLastModified() throws IOException { long lastModified = PlexusIoResource.UNKNOWN_MODIFICATION_DATE; for ( final Iterator iter = getResources(); iter.hasNext(); ) { final PlexusIoResource res = (PlexusIoResource) iter.next(); long l = res.getLastModified(); if ( l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE ) { return PlexusIoResource.UNKNOWN_MODIFICATION_DATE; } if ( lastModified == PlexusIoResource.UNKNOWN_MODIFICATION_DATE || l > lastModified ) { lastModified = l; } } return lastModified; } public void enableLogging( Logger logger ) { this.logger = logger; } }././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceColle0000644000175000017500000000411711202103744033077 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.util.Iterator; /** * A resource collection is a set of {@link PlexusIoResource} instances. */ public interface PlexusIoResourceCollection { /** * Role of the ResourceCollection component. */ public static final String ROLE = PlexusIoResourceCollection.class.getName(); /** * Role hint of the default resource collection, which is a set * of files in a base directory. */ public static final String DEFAULT_ROLE_HINT = "default"; /** * Returns an iterator over the resources in the collection. */ Iterator getResources() throws IOException; /** * Returns the resources suggested name. This is used for * integrating file mappers. * @param resource A resource, which has been obtained by * calling {@link #getResources()}. */ String getName( PlexusIoResource resource ) throws IOException; /** * Returns the collections last modification time. For a * collection of files, this might be the last modification * time of the file, which has been modified at last. For an * archive file, this might be the modification time of the * archive file. * @return {@link PlexusIoResource#UNKNOWN_MODIFICATION_DATE}, * if the collections last modification time is unknown, * otherwise the last modification time in milliseconds. */ long getLastModified() throws IOException; }././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFil0000644000175000017500000000564411207107052033077 0ustar mkochmkochpackage org.codehaus.plexus.components.io.resources; /* * 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.io.InputStream; import java.util.Collections; import java.util.Iterator; /** * Abstract base class for compressed files, aka singleton * resource collections. */ public abstract class PlexusIoCompressedFileResourceCollection implements PlexusIoArchivedResourceCollection { private File file; private String path; public File getFile() { return file; } public void setFile( File file ) { this.file = file; } public String getPath() { return path; } public void setPath( String path ) { this.path = path; } public Iterator getResources() throws IOException { final File f = getFile(); final String p = (getPath() == null ? getName( f ) : getPath()).replace( '\\', '/' ); if ( f == null ) { throw new IOException( "No archive file is set." ); } if ( ! f.isFile() ) { throw new IOException( "The archive file " + f.getPath() + " does not exist or is no file." ); } final PlexusIoResource resource = new PlexusIoFileResource(f, p) { public InputStream getContents() throws IOException { return getInputStream( f ); } }; return Collections.singleton( resource ).iterator(); } protected String getName( File file ) throws IOException { final String name = file.getPath(); final String ext = getDefaultExtension(); if ( ext != null && ext.length() > 0 && name.endsWith( ext ) ) { return name.substring( 0, name.length() - ext.length() ); } return name; } protected abstract String getDefaultExtension(); protected abstract InputStream getInputStream( File file ) throws IOException; public String getName( PlexusIoResource resource ) throws IOException { return resource.getName(); } public long getLastModified() throws IOException { File f = getFile(); return f == null ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : f.lastModified(); } }plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/0000755000175000017500000000000011256764616027233 5ustar mkochmkoch././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.jav0000644000175000017500000000373511242610621032726 0ustar mkochmkochpackage 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. */ /** * A file mapper, which maps to a constant target name. */ public class MergeFileMapper extends AbstractFileMapper { /** * The merge mappers role-hint: "merge". */ public static final String ROLE_HINT = "merge"; private String targetName; /** * Sets the merge mappers target name. * * @throws IllegalArgumentException * The target name is null or empty. */ public void setTargetName( String pName ) { if ( pName == null ) { throw new IllegalArgumentException( "The target name is null." ); } if ( pName.length() == 0 ) { throw new IllegalArgumentException( "The target name is empty." ); } targetName = pName; } /** * Returns the merge mappers target name. * * @throws IllegalArgumentException * The target name is null or empty. */ public String getTargetName() { return targetName; } public String getMappedFileName( String pName ) { final String name = getTargetName(); if ( name == null ) { throw new IllegalStateException( "The target file name has not been set." ); } super.getMappedFileName( pName ); // Check for null, etc. return name; } }././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper0000644000175000017500000000472411242610621033063 0ustar mkochmkochpackage 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. */ /** * An implementation of {@link FileMapper}, which changes the files extension. */ public class FileExtensionMapper extends AbstractFileMapper { /** * The file extension mappers role-hint: "fileExtension". */ public static final String ROLE_HINT = "fileExtension"; private String targetExtension; /** * Sets the target files extension. * * @throws IllegalArgumentException * The target extension is null or empty. */ public void setTargetExtension( String pTargetExtension ) { if ( pTargetExtension == null ) { throw new IllegalArgumentException( "The target extension is null." ); } if ( pTargetExtension.length() == 0 ) { throw new IllegalArgumentException( "The target extension is empty." ); } if ( pTargetExtension.charAt( 0 ) == '.' ) { targetExtension = pTargetExtension; } else { targetExtension = '.' + pTargetExtension; } } /** * Returns the target files extension. */ public String getTargetExtension() { return targetExtension; } public String getMappedFileName( String pName ) { final String ext = getTargetExtension(); if ( ext == null ) { throw new IllegalStateException( "The target extension has not been set." ); } final String name = super.getMappedFileName( pName ); // Check arguments final int dirSep = Math.max( pName.lastIndexOf( '/' ), pName.lastIndexOf( '\\' ) ); final int offset = pName.lastIndexOf( '.' ); if ( offset <= dirSep ) { return name + ext; } else { return name.substring( 0, offset ) + ext; } } }././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.ja0000644000175000017500000000320111242610621032722 0ustar mkochmkochpackage 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. */ /** * A file mapper, which maps by adding a prefix. */ public class PrefixFileMapper extends AbstractFileMapper { /** * The merge mappers role-hint: "prefix". */ public static final String ROLE_HINT = "prefix"; private String prefix; public String getMappedFileName( String name ) { final String s = super.getMappedFileName( name ); // Check for null, etc. return getMappedFileName( prefix, s ); } /** * Returns the prefix to add. */ public String getPrefix() { return prefix; } /** * Sets the prefix to add. */ public void setPrefix( String prefix ) { this.prefix = prefix; } /** * Performs the mapping of a file name by adding a prefix. */ public static String getMappedFileName( String prefix, String name ) { if ( prefix == null || prefix.length() == 0 ) { return name; } return prefix + name; } }././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java0000644000175000017500000000230011242610621033004 0ustar mkochmkochpackage 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. */ /** * Default implementation of {@link FileMapper}, which performs the identity mapping: All names are left unchanged. */ public class IdentityMapper extends AbstractFileMapper { /** * The identity mappers role-hint: "identity". */ public static final String ROLE_HINT = "identity"; public String getMappedFileName( String pName ) { if ( pName == null || pName.length() == 0 ) { throw new IllegalArgumentException( "The source name must not be null." ); } return pName; } }././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.0000644000175000017500000000241511242611447032732 0ustar mkochmkochpackage 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. */ /** * Abstract base class for deriving file mappers. It is recommended * to use this class, if your implement your own file mappers, as * this might allow to extend the FileMapper interface later on * without loosing upwards compatibility. */ public abstract class AbstractFileMapper implements FileMapper { /** * Checks the input and returns it without modifications. */ public String getMappedFileName( String pName ) { if ( pName == null || pName.length() == 0 ) { throw new IllegalArgumentException( "The source name must not be null." ); } return pName; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.ja0000644000175000017500000000470111242611447032674 0ustar mkochmkochpackage 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.util.regex.Matcher; import java.util.regex.Pattern; /** * Implementation of a file mapper, which uses regular expressions. */ public class RegExpFileMapper extends AbstractFileMapper { /** * The regexp mappers role-hint: "regexp". */ public static final String ROLE_HINT = "regexp"; private Pattern pattern; private String replacement; private boolean replaceAll; /** * Sets the regular expression pattern. */ public void setPattern(String pPattern) { pattern = Pattern.compile(pPattern); } /** * Returns the regular expression pattern. */ public String getPattern() { return pattern == null ? null : pattern.pattern(); } /** * Sets the replacement string. */ public void setReplacement(String pReplacement) { replacement = pReplacement; } /** * Returns the replacement string. */ public String getReplacement() { return replacement; } /** * Returns, whether to replace the first occurrency of the pattern * (default), or all. */ public boolean getReplaceAll() { return replaceAll; } /** * Sets, whether to replace the first occurrency of the pattern * (default), or all. */ public void setReplaceAll(boolean pReplaceAll) { replaceAll = pReplaceAll; } public String getMappedFileName(String pName) { final String name = super.getMappedFileName(pName); if (pattern == null) { throw new IllegalStateException("The regular expression pattern has not been set."); } if (replacement == null) { throw new IllegalStateException("The pattern replacement string has not been set."); } final Matcher matcher = pattern.matcher(name); if (!matcher.find()) { return name; } if (!getReplaceAll()) { return matcher.replaceFirst(replacement); } return matcher.replaceAll(replacement); } } plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/package.html0000644000175000017500000000155510576130520031503 0ustar mkochmkochFile Mappers

File Mappers

File mappers can be used, for example, when files are being copied, moved, archived, or unarchived. The purpose of a file mapper is to select the target files name and destination.

Examples:

  • The IdentityMapper is a trivial file mapper, which leaves all file names are unchanged. This is mainly useful as a default file mapper.
  • The FileNameExtensionMapper changes the file names extension. This can be used, for example, when you run the FOP transformer to produce PDF. Of course, you would want the created files to have the extension .pdf, rather than .xml.
plexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java0000644000175000017500000000251611127423355032113 0ustar mkochmkochpackage 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. */ /** * Interface of a component, which may be used to map file names. */ public interface FileMapper { /** * Role used to register component implementations with the container. */ public static final String ROLE = FileMapper.class.getName(); /** * The default role-hint: "default". */ public static final String DEFAULT_ROLE_HINT = "default"; /** * Maps the given source name to a target name. * * @param pName * The source name. * @return The target name. * @throws IllegalArgumentException * The source name is null or empty. */ public String getMappedFileName( String pName ); }././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.javaplexus-io-1.0~alpha5/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.j0000644000175000017500000000255011242610621032727 0ustar mkochmkochpackage 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. */ /** * Implementation of a flattening file mapper: Removes all directory parts. */ public class FlattenFileMapper extends AbstractFileMapper { /** * The flatten file mappers role-hint: "flatten". */ public static final String ROLE_HINT = "flatten"; public String getMappedFileName( String pName ) { String name = super.getMappedFileName( pName ); // Check for null, etc. int offset = pName.lastIndexOf( '/' ); if ( offset >= 0 ) { name = name.substring( offset + 1 ); } offset = pName.lastIndexOf( '\\' ); if ( offset >= 0 ) { name = name.substring( offset + 1 ); } return name; } }plexus-io-1.0~alpha5/src/main/resources/0000755000175000017500000000000011256764616017317 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/resources/META-INF/0000755000175000017500000000000011256764616020457 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/resources/META-INF/plexus/0000755000175000017500000000000011256764616021777 5ustar mkochmkochplexus-io-1.0~alpha5/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000001134011242610621024662 0ustar mkochmkoch org.codehaus.plexus.components.io.filemappers.FileMapper identity org.codehaus.plexus.components.io.filemappers.IdentityMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper default org.codehaus.plexus.components.io.filemappers.IdentityMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper fileExtension org.codehaus.plexus.components.io.filemappers.FileExtensionMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper flatten org.codehaus.plexus.components.io.filemappers.FlattenFileMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper merge org.codehaus.plexus.components.io.filemappers.MergeFileMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper prefix org.codehaus.plexus.components.io.filemappers.PrefixFileMapper per-lookup org.codehaus.plexus.components.io.filemappers.FileMapper regexp org.codehaus.plexus.components.io.filemappers.RegExpFileMapper per-lookup org.codehaus.plexus.components.io.fileselectors.FileSelector default org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector singleton org.codehaus.plexus.components.io.fileselectors.FileSelector all org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector singleton org.codehaus.plexus.components.io.fileselectors.FileSelector standard org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector singleton org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection default org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection per-lookup org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection files org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection per-lookup org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection zipFile org.codehaus.plexus.components.io.resources.PlexusIoZipFileResourceCollection per-lookup org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection jarFile org.codehaus.plexus.components.io.resources.PlexusIoZipFileResourceCollection per-lookup