From d8aa8cea76e6599a900ed74e4d63713d22f55cfd Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Tue, 1 Mar 2005 02:54:54 +0000 Subject: [PATCH] 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 --- .../maven/it0015/tags/IT0015TagLibrary.java | 17 +++++ .../maven/it0015/tags/WriteFileTag.java | 63 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/IT0015TagLibrary.java create mode 100644 maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/WriteFileTag.java diff --git a/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/IT0015TagLibrary.java b/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/IT0015TagLibrary.java new file mode 100644 index 0000000000..abb777ade5 --- /dev/null +++ b/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/IT0015TagLibrary.java @@ -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); + } + +} diff --git a/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/WriteFileTag.java b/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/WriteFileTag.java new file mode 100644 index 0000000000..141af20099 --- /dev/null +++ b/maven-core-it/it0015/src/main/java/org/apache/maven/it0015/tags/WriteFileTag.java @@ -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) + { + } + } + } + } +}