|
From: <ian...@us...> - 2007-08-31 15:42:33
|
Revision: 306
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=306&view=rev
Author: iansmith
Date: 2007-08-31 08:31:42 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
Moved plugin repo to sourceforge.
Added Paths:
-----------
maven/trunk/dev-plugins/.classpath
maven/trunk/dev-plugins/.project
maven/trunk/dev-plugins/pom.xml
maven/trunk/dev-plugins/src/
maven/trunk/dev-plugins/src/main/
maven/trunk/dev-plugins/src/main/java/
maven/trunk/dev-plugins/src/main/java/com/
maven/trunk/dev-plugins/src/main/java/com/transmutable/
maven/trunk/dev-plugins/src/main/java/com/transmutable/plugin/
maven/trunk/dev-plugins/src/main/java/com/transmutable/plugin/StaticVelocitySitePlugin.java
maven/trunk/dev-plugins/src/main/resources/
maven/trunk/dev-plugins/src/test/
maven/trunk/dev-plugins/src/test/java/
maven/trunk/dev-plugins/src/test/resources/
Property Changed:
----------------
maven/trunk/dev-plugins/
Property changes on: maven/trunk/dev-plugins
___________________________________________________________________
Name: svn:ignore
+ target
Added: maven/trunk/dev-plugins/.classpath
===================================================================
--- maven/trunk/dev-plugins/.classpath (rev 0)
+++ maven/trunk/dev-plugins/.classpath 2007-08-31 15:31:42 UTC (rev 306)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: maven/trunk/dev-plugins/.project
===================================================================
--- maven/trunk/dev-plugins/.project (rev 0)
+++ maven/trunk/dev-plugins/.project 2007-08-31 15:31:42 UTC (rev 306)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dev-plugins</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: maven/trunk/dev-plugins/pom.xml
===================================================================
--- maven/trunk/dev-plugins/pom.xml (rev 0)
+++ maven/trunk/dev-plugins/pom.xml 2007-08-31 15:31:42 UTC (rev 306)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.ogoglio</groupId>
+ <artifactId>dev-plugins</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <skip>true</skip><!-- this is critical to avoid running unit tests -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.velocity</groupId>
+ <artifactId>velocity</artifactId>
+ <version>1.5</version>
+ </dependency>
+ </dependencies>
+
+</project>
+
Added: maven/trunk/dev-plugins/src/main/java/com/transmutable/plugin/StaticVelocitySitePlugin.java
===================================================================
--- maven/trunk/dev-plugins/src/main/java/com/transmutable/plugin/StaticVelocitySitePlugin.java (rev 0)
+++ maven/trunk/dev-plugins/src/main/java/com/transmutable/plugin/StaticVelocitySitePlugin.java 2007-08-31 15:31:42 UTC (rev 306)
@@ -0,0 +1,103 @@
+package com.transmutable.plugin;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+
+/**
+ * @goal buildHtml
+ */
+public class StaticVelocitySitePlugin extends AbstractMojo {
+
+ /**
+ * @parameter
+ */
+ private File templateDirectory;
+ /**
+ * @parameter
+ */
+ private File targetDirectory;
+
+ public void execute() throws MojoExecutionException {
+
+ if (targetDirectory.exists()==false) {
+ if (targetDirectory.mkdir()==false) {
+ getLog().error("Unable to create target directory:"+targetDirectory.getName());
+ throw new MojoExecutionException("Bad target directory");
+ }
+ }
+
+ try {
+ VelocityEngine engine = new VelocityEngine();
+ engine.setProperty("file.resource.loader.path", templateDirectory.getCanonicalPath());
+ engine.init();
+
+ VelocityContext velocityContext = new VelocityContext();
+
+ File[] children = templateDirectory.listFiles();
+ for (int i = 0; children != null && i < children.length; i++) {
+ if (children[i].getName().endsWith(".html")) {
+ Template template = engine.getTemplate(children[i].getName());
+ File output = new File(targetDirectory, children[i].getName());
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
+ template.merge(velocityContext, writer);
+ writer.flush();
+ writer.close();
+ } else if (children[i].getName().endsWith(".vm")) { //ignore velocity fragments
+ continue;
+ } else if(children[i].getName().equals(".svn")) { //ignore svn dir
+ continue;
+ } else {
+ copy(children[i], targetDirectory);
+ }
+ }
+ } catch (ResourceNotFoundException rnfe) {
+ getLog().error(rnfe);
+ throw new MojoExecutionException("Can't find resource",rnfe);
+ } catch (ParseErrorException pee) {
+ getLog().warn("Syntax error in template:" + pee);
+ throw new MojoExecutionException("Bad syntax",pee);
+ } catch (Exception e) {
+ throw new MojoExecutionException("Unexpected exception",e);
+ }
+
+ }
+
+ private void copy(File source, File destinationDirectory) throws IOException {
+ if(source.isDirectory()){
+ File newDir = new File(destinationDirectory, source.getName());
+ newDir.mkdir();
+ File[] children = source.listFiles();
+ for (int i = 0; i < children.length; i++) {
+ copy(children[i], newDir);
+ }
+ } else {
+ File newFile = new File(destinationDirectory, source.getName());
+ if(newFile.exists() && source.lastModified() == newFile.lastModified()){
+ return;
+ }
+ FileOutputStream output = new FileOutputStream(newFile);
+ FileInputStream input = new FileInputStream(source);
+ byte[] buff = new byte[2048];
+ int read = 0;
+ while( (read = input.read(buff)) > 0){
+ output.write(buff, 0, read);
+ }
+ output.flush();
+ output.close();
+ input.close();
+ }
+ }
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|