Revision: 66 http://mvn-infix.svn.sourceforge.net/mvn-infix/?rev=66&view=rev Author: bindul Date: 2010-11-29 12:48:54 +0000 (Mon, 29 Nov 2010)
Log Message: ----------- Weekend work: 1. Further refactoring for velocity 2. Build/plugin updates in parent 3. Site id change in piwik 4. Updated modello handling Modified Paths: -------------- shared/infix-plugins-common/trunk/infix-mojo-utils/pom.xml shared/infix-plugins-common/trunk/infix-mojo-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/mojo/MojoInfo.java Added Paths: ----------- shared/infix-plugins-common/trunk/infix-velocity-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/velocity/AbstractVelocityExecutor.java Property Changed: ---------------- shared/infix-plugins-common/trunk/ Property changes on: shared/infix-plugins-common/trunk ___________________________________________________________________ Modified: svn:ignore - .project + .project .settings target Modified: shared/infix-plugins-common/trunk/infix-mojo-utils/pom.xml =================================================================== --- shared/infix-plugins-common/trunk/infix-mojo-utils/pom.xml 2010-11-29 12:48:12 UTC (rev 65) +++ shared/infix-plugins-common/trunk/infix-mojo-utils/pom.xml 2010-11-29 12:48:54 UTC (rev 66) @@ -31,5 +31,9 @@ <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + </dependency> </dependencies> </project> Modified: shared/infix-plugins-common/trunk/infix-mojo-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/mojo/MojoInfo.java =================================================================== --- shared/infix-plugins-common/trunk/infix-mojo-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/mojo/MojoInfo.java 2010-11-29 12:48:12 UTC (rev 65) +++ shared/infix-plugins-common/trunk/infix-mojo-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/mojo/MojoInfo.java 2010-11-29 12:48:54 UTC (rev 66) @@ -22,6 +22,7 @@ import java.io.File; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; @@ -53,6 +54,12 @@ public File getWorkDirectory(); /** + * The session the maven execution is running in. + * @return The maven session the execution is running in. + */ + public MavenSession getSession(); + + /** * Returns the maven project helper * @return The project helper */ Added: shared/infix-plugins-common/trunk/infix-velocity-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/velocity/AbstractVelocityExecutor.java =================================================================== --- shared/infix-plugins-common/trunk/infix-velocity-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/velocity/AbstractVelocityExecutor.java (rev 0) +++ shared/infix-plugins-common/trunk/infix-velocity-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/velocity/AbstractVelocityExecutor.java 2010-11-29 12:48:54 UTC (rev 66) @@ -0,0 +1,108 @@ +/* + * $HeadURL$ + * + * Copyright (c) 2010 MindTree Ltd. + * + * This file is part of Infix Maven Plugins + * + * Infix Maven Plugins is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * Infix Maven Plugins is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * Infix Maven Plugins. If not, see <http://www.gnu.org/licenses/>. + */ +package com.mindtree.techworks.infix.pluginscommon.velocity; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Map; + +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.apache.velocity.runtime.resource.loader.FileResourceLoader; + +import com.mindtree.techworks.infix.pluginscommon.mojo.MojoInfo; + +/** + * @author Bindul Bhowmik + * @version $Revision$ $Date$ + * + */ +public abstract class AbstractVelocityExecutor { + + /** + * Utility method to process a velocity template. + * @param templateName The name of the template to process + * @param contextInfo The map of contexts being used from the template + * @param outputFile The output file + * @throws Exception If there is an exception processing the template + */ + protected void processVelocityTemplate(String templateName, + Map<String, Object> contextInfo, File outputFile, boolean loadResourceFromClasspath) throws Exception { + + VelocityEngine engine = new VelocityEngine(); + engine.addProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new MavenVelocityLogChute(getMojoInfo().getLog())); + engine.addProperty("userdirective", RenderStringWithNewLine.class.getName()); + + if (loadResourceFromClasspath) { + engine.addProperty(Velocity.RESOURCE_LOADER, "class, file"); + engine.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); + } + + StringBuilder pathBuilder = new StringBuilder(); + pathBuilder.append(getMojoInfo().getProject().getBasedir().getAbsolutePath()); + pathBuilder.append(", "); + pathBuilder.append(new File(System.getProperty("java.io.tmpdir")).getAbsolutePath()); + engine.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, pathBuilder.toString()); + engine.addProperty("file.resource.loader.class", FileResourceLoader.class.getName()); + engine.init(); + VelocityContext context = new VelocityContext(contextInfo); + + Template template = null; + + try { + template = engine.getTemplate(templateName); + } catch (ResourceNotFoundException e) { + getMojoInfo().getLog().error("Unable to load required velocity template", e); + throw e; + } catch (ParseErrorException e) { + getMojoInfo().getLog().error("Invalid velocity template", e); + throw e; + } + + FileWriter fileWriter = null; + + try { + fileWriter = new FileWriter(outputFile); + template.merge(context, fileWriter); + } finally { + if (null != fileWriter) { + try { + fileWriter.close(); + } catch (IOException e) { + // Ignore + } + } + } + } + + /** + * Returns the mojo info which has the log and project + * + * @return The project info which is executing this plug-in + */ + protected abstract MojoInfo getMojoInfo(); +} Property changes on: shared/infix-plugins-common/trunk/infix-velocity-utils/src/main/java/com/mindtree/techworks/infix/pluginscommon/velocity/AbstractVelocityExecutor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Increase Visibility of Your 3D Game App & Earn a Chance To Win $500! Tap into the largest installed PC base & get more eyes on your game by optimizing for Intel(R) Graphics Technology. Get started today with the Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs. http://p.sf.net/sfu/intelisp-dev2dev _______________________________________________ mvn-Infix-commits mailing list mvn-Infix-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mvn-infix-commits