diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetAdaptor.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetAdaptor.java new file mode 100644 index 000000000..755e241a3 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetAdaptor.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.vfile; + +import org.apache.aut.vfs.FileObject; +import org.apache.myrmidon.api.TaskContext; +import org.apache.myrmidon.api.TaskException; + +/** + * An adaptor from a {@link FileSet} to a {@link FileList}. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + */ +public class FileSetAdaptor + implements FileList +{ + private final FileSet m_fileset; + + public FileSetAdaptor( final FileSet fileset ) + { + m_fileset = fileset; + } + + /** + * Returns the files in the list. + */ + public FileObject[] listFiles( TaskContext context ) + throws TaskException + { + final FileSetResult result = m_fileset.getResult( context ); + return result.getFiles(); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java new file mode 100644 index 000000000..fc085e8e6 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.vfile; + +import org.apache.aut.converter.AbstractConverter; +import org.apache.aut.converter.ConverterException; +import org.apache.myrmidon.api.TaskContext; + +/** + * A converter from {@link FileSet} to {@link FileList}. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:converter source="org.apache.antlib.vfile.FileSet" + * destination="org.apache.antlib.vfile.FileList" + */ +public class FileSetToFileListConverter + extends AbstractConverter +{ + public FileSetToFileListConverter() + { + super( FileSet.class, FileList.class ); + } + + /** + * Do the conversion. + */ + protected Object convert( final Object original, final Object context ) + throws ConverterException + { + final TaskContext taskContext = (TaskContext)context; + final FileSet src = (FileSet)original; + + return new FileSetAdaptor( src ); + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java new file mode 100644 index 000000000..7bea957e3 --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE.txt file. + */ +package org.apache.antlib.vfile; + +import org.apache.aut.vfs.FileObject; +import org.apache.myrmidon.api.AbstractTask; +import org.apache.myrmidon.api.TaskException; + +/** + * A debug task, which prints out the files in a file list. + * + * @author Adam Murdoch + * @version $Revision$ $Date$ + * + * @ant:task name="v-list-files" + */ +public class ListFilesTask + extends AbstractTask +{ + private final DefaultFileList m_files = new DefaultFileList(); + + public void add( final FileList files ) + { + m_files.add( files ); + } + + /** + * Execute task. + * + * @exception TaskException if an error occurs + */ + public void execute() + throws TaskException + { + final FileObject[] files = m_files.listFiles( getContext() ); + for( int i = 0; i < files.length; i++ ) + { + FileObject file = files[i ]; + getLogger().info( file.toString() ); + } + } +} diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java index 53d477a03..e624b107b 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java @@ -26,7 +26,7 @@ import org.apache.myrmidon.framework.AbstractFileSet; */ public class PatternFileSet extends AbstractFileSet - implements FileList, FileSet + implements FileSet { private final static Resources REZ = ResourceManager.getPackageResources( PatternFileSet.class ); @@ -41,27 +41,11 @@ public class PatternFileSet m_dir = dir; } - /** - * Returns the root directory - */ - public FileObject getDir() - { - return m_dir; - } - - /** - * Returns the list of files, in depthwise order. - */ - public FileObject[] listFiles( TaskContext context ) throws TaskException - { - final FileSetResult result = getResult( context ); - return result.getFiles(); - } - /** * Returns the contents of the set. */ - public FileSetResult getResult( TaskContext context ) throws TaskException + public FileSetResult getResult( final TaskContext context ) + throws TaskException { if( m_dir == null ) { diff --git a/proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java b/proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java index 30bea473d..1044cc2a6 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java @@ -7,14 +7,13 @@ */ package org.apache.antlib.vfile; +import org.apache.aut.converter.AbstractConverter; +import org.apache.aut.converter.ConverterException; import org.apache.aut.vfs.FileObject; import org.apache.aut.vfs.FileSystemManager; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; -import org.apache.avalon.framework.context.Context; import org.apache.myrmidon.api.TaskContext; -import org.apache.aut.converter.AbstractConverter; -import org.apache.aut.converter.ConverterException; /** * Converts a String to a {@link FileObject}