Permalink
Browse files

Initial import of the maven plug-in.

  • Loading branch information...
0 parents commit 92cd10b67a7e5b4504b06949cdb714690143cea3 Richard L. Burton III committed Mar 3, 2010
57 pom.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<project>
+
+ <parent>
+ <artifactId>sitemesh-parent</artifactId>
+ <groupId>org.sitemesh</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.sitemesh</groupId>
+ <artifactId>maven-sitemesh3-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>SiteMesh Maven Plug-in</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <developers>
+ <developer>
+ <id>rburton</id>
+ <name>Richard L. Burton III</name>
+ <email>rburton at smartcodellc dot com</email>
+ <timezone>EST</timezone>
+ </developer>
+ </developers>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>file-management</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>sitemesh</artifactId>
+ <groupId>org.sitemesh</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <version>1.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
@@ -0,0 +1,99 @@
+package org.sitemesh.maven;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.shared.model.fileset.util.FileSetManager;
+import org.apache.maven.shared.model.fileset.FileSet;
+import org.sitemesh.builder.SiteMeshOfflineBuilder;
+import org.sitemesh.config.xml.XmlOfflineConfigurator;
+import org.sitemesh.config.ObjectFactory;
+import org.sitemesh.offline.SiteMeshOffline;
+import org.w3c.dom.Element;
+
+import static javax.xml.parsers.DocumentBuilderFactory.newInstance;
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * A SiteMesh Maven Mojo for version 3.x
+ *
+ * @author Richard L. Burton III - SmartCode LLC
+ * @goal sitemesh
+ */
+public class SiteMeshMojo extends AbstractMojo {
+
+ /**
+ * The destination directory where the decorated files will be placed.
+ *
+ * @parameter expression="${basedir}" default-value="${basedir}"
+ * @required
+ */
+ private File destDir;
+
+ /**
+ * The sitemesh configuration file.
+ *
+ * @parameter expression="${config}"
+ */
+ private File config;
+
+ /**
+ * @parameter
+ */
+ private FileSet fileset;
+
+ public void execute() throws MojoExecutionException {
+ SiteMeshOffline siteMeshOffline = createSiteMeshOffline();
+ FileSetManager filesetManager = new FileSetManager();
+ String[] files = filesetManager.getIncludedFiles(fileset);
+ try {
+ for (String file : files) {
+ siteMeshOffline.process(file);
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException(e.getMessage());
+ }
+ }
+
+ protected SiteMeshOffline createSiteMeshOffline() throws MojoExecutionException {
+ SiteMeshOfflineBuilder builder = new SiteMeshOfflineBuilder();
+ if (config != null) {
+ XmlOfflineConfigurator offlineConfigurator = new XmlOfflineConfigurator(new ObjectFactory.Default(), parseSiteMeshXmlConfig(config));
+ offlineConfigurator.configureOffline(builder);
+ }
+
+ return builder.setDestinationDirectory(destDir)
+ .setSourceDirectory(fileset.getDirectory())
+ .create();
+ }
+
+
+ protected Element parseSiteMeshXmlConfig(File config) throws MojoExecutionException {
+ try {
+ return newInstance().newDocumentBuilder().parse(config).getDocumentElement();
+ } catch (Exception e) {
+ throw new MojoExecutionException("Could not parse " + config.getAbsolutePath() + " : " + e.getMessage(), e);
+ }
+ }
+
+ public File getDestDir() {
+ return destDir;
+ }
+
+ public void setDestDir(File destDir) {
+ this.destDir = destDir;
+ }
+
+ public File getConfig() {
+ return config;
+ }
+
+ public void setConfig(File config) {
+ this.config = config;
+ }
+
+ public void setFileset(FileSet fileset) {
+ this.fileset = fileset;
+ }
+}
+
No changes.
@@ -0,0 +1,22 @@
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.sitemesh.maven.SiteMeshMojo;
+
+import java.io.File;
+
+/**
+ * @author Richard L. Burton III - SmartCode LLC
+ */
+public class SiteMeshMojoTestCase extends AbstractMojoTestCase {
+
+
+ /**
+ * @throws Exception
+ */
+ public void testMojoGoal() throws Exception {
+ File testPom = new File(getBasedir(), "src/test/resources/test1/sitemesh-test-plugin-config.xml");
+ SiteMeshMojo mojo = (SiteMeshMojo) lookupMojo("sitemesh", testPom);
+ assertNotNull(mojo);
+ mojo.execute();
+ }
+
+}
@@ -0,0 +1,3 @@
+<html>
+ <body>DECORATOR{{{<sitemesh:write property='body'/>}}}</body>
+</html>
@@ -0,0 +1,5 @@
+<html>
+ <body>
+ body
+ </body>
+</html>
@@ -0,0 +1,5 @@
+<html>
+<body>
+Sample
+</body>
+</html>
@@ -0,0 +1,5 @@
+<html>
+ <body>DECORATOR{{{
+ body
+ }}}</body>
+</html>
@@ -0,0 +1,5 @@
+<html>
+ <body>DECORATOR{{{
+Sample
+}}}</body>
+</html>
@@ -0,0 +1,33 @@
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-sitemesh3-plugin</artifactId>
+ <configuration>
+ <config>src/test/resources/test1/sitemesh3.xml</config>
+ <destDir>src/test/resources/test1/out</destDir>
+ <fileset>
+ <directory>src/test/resources/test1/in</directory>
+ <includes>
+ <include>**/*.html</include>
+ </includes>
+ <excludes>
+ <exclude>**/decorators/*</exclude>
+ <exclude>*.xml</exclude>
+ </excludes>
+ </fileset>
+ </configuration>
+ <executions>
+ <execution>
+ <id>sitemesh</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>sitemesh</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
@@ -0,0 +1,3 @@
+<sitemesh>
+ <mapping path="/*" decorator="/decorators/decorator.html"/>
+</sitemesh>

0 comments on commit 92cd10b

Please sign in to comment.