Browse Source

* Add a converter to convert from <v-fileset> to <v-path>, rather

than doing so in the default <v-fileset> or <v-path> implementations.

* Add test <v-list-files> task.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271541 13f79535-47bb-0310-9956-ffa450edef68
master
adammurdoch 23 years ago
parent
commit
5168496109
5 changed files with 133 additions and 22 deletions
  1. +39
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetAdaptor.java
  2. +42
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java
  3. +47
    -0
      proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java
  4. +3
    -19
      proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java
  5. +2
    -3
      proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java

+ 39
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetAdaptor.java View File

@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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();
}
}

+ 42
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/FileSetToFileListConverter.java View File

@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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 );
}
}

+ 47
- 0
proposal/myrmidon/src/java/org/apache/antlib/vfile/ListFilesTask.java View File

@@ -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 <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @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() );
}
}
}

+ 3
- 19
proposal/myrmidon/src/java/org/apache/antlib/vfile/PatternFileSet.java View File

@@ -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 )
{


+ 2
- 3
proposal/myrmidon/src/java/org/apache/antlib/vfile/StringToFileObjectConverter.java View File

@@ -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}


Loading…
Cancel
Save