o Adding files excluded by default by eclipse CVS plugin.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163436 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-03-01 02:54:54 +00:00
parent 8e82989334
commit d8aa8cea76
2 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,17 @@
package org.apache.maven.it0015.tags;
import org.codehaus.marmalade.metamodel.AbstractMarmaladeTagLibrary;
/**
* @author jdcasey
*/
public class IT0015TagLibrary
extends AbstractMarmaladeTagLibrary
{
public IT0015TagLibrary()
{
registerTag("writeFile", WriteFileTag.class);
}
}

View File

@ -0,0 +1,63 @@
package org.apache.maven.it0015.tags;
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
import org.codehaus.marmalade.runtime.TagExecutionException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author jdcasey
*/
public class WriteFileTag
extends AbstractMarmaladeTag
{
public static final String FILE_ATTR = "path";
protected boolean alwaysProcessChildren()
{
return false;
}
protected void doExecute( MarmaladeExecutionContext context ) throws MarmaladeExecutionException
{
String content = (String) getBody(context, String.class);
String filename = (String) requireTagAttribute(FILE_ATTR, String.class, context);
File file = new File(filename);
File dir = file.getParentFile();
if(dir != null && !dir.exists())
{
dir.mkdirs();
}
FileOutputStream fOut = null;
try
{
fOut = new FileOutputStream(file);
fOut.write(content.getBytes());
}
catch ( IOException e )
{
throw new TagExecutionException(getTagInfo(), "Cannot write content to file: " + file, e);
}
finally
{
if(fOut != null)
{
try
{
fOut.flush();
fOut.close();
}
catch(Exception e)
{
}
}
}
}
}