From: <st...@us...> - 2008-04-28 13:21:31
|
Revision: 6428 http://smartfrog.svn.sourceforge.net/smartfrog/?rev=6428&view=rev Author: steve_l Date: 2008-04-28 06:19:49 -0700 (Mon, 28 Apr 2008) Log Message: ----------- SFOS-811 Create Velocity component -using sfInstaller as a template This is the component with source, one (simple) test and the relevant ivy/pom XML files to make the velocity component reusable Added Paths: ----------- trunk/core/components/velocity/ trunk/core/components/velocity/.svnignore trunk/core/components/velocity/build.xml trunk/core/components/velocity/ivy.xml trunk/core/components/velocity/project-template.pom trunk/core/components/velocity/src/ trunk/core/components/velocity/src/org/ trunk/core/components/velocity/src/org/smartfrog/ trunk/core/components/velocity/src/org/smartfrog/services/ trunk/core/components/velocity/src/org/smartfrog/services/velocity/ trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityLogBridge.java trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityTransformerImpl.java trunk/core/components/velocity/src/org/smartfrog/services/velocity/components.sf trunk/core/components/velocity/test/ trunk/core/components/velocity/test/org/ trunk/core/components/velocity/test/org/smartfrog/ trunk/core/components/velocity/test/org/smartfrog/services/ trunk/core/components/velocity/test/org/smartfrog/services/velocity/ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/TransformerTest.java trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/components.sf trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/testLoad.sf Added: trunk/core/components/velocity/.svnignore =================================================================== --- trunk/core/components/velocity/.svnignore (rev 0) +++ trunk/core/components/velocity/.svnignore 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,13 @@ +build +dist +build.properties +runtime.properties +common.properties +*.jpx +*.ipr +*.iml +*.iws +.classpath +.project +lib + Added: trunk/core/components/velocity/build.xml =================================================================== --- trunk/core/components/velocity/build.xml (rev 0) +++ trunk/core/components/velocity/build.xml 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<project name="velocity" default="default"> + + <!-- + (C) Copyright 2008 Hewlett-Packard Development Company, LP + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + For more information: www.smartfrog.org + + --> + + <description> + Velocity support. + Velocity can be used to transform template files into output text, XML or HTML files. + </description> + <!--we are a component --> + <property name="is.component" value="true"/> + <property name="ivy.enabled" value="true"/> + <property name="system.tests" value="true"/> + + <!-- override point --> + <property file="build.properties"/> + + + <echo message="==================================================================="/> + <echo message="= ${ant.project.name}"/> + + <!-- Import common stuff --> + <import file="../../common.xml"/> +</project> \ No newline at end of file Added: trunk/core/components/velocity/ivy.xml =================================================================== --- trunk/core/components/velocity/ivy.xml (rev 0) +++ trunk/core/components/velocity/ivy.xml 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,94 @@ +<?xml version="1.0" ?> +<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?> +<ivy-module version="1.0"> + <info organisation="org.smartfrog" module="sf-velocity"> + <license name="LGPL"/> + <ivyauthor name="Hewlett-Packard" url="http://www.smartfrog.org"/> + <description> + Velocity support + </description> + </info> + <!-- FIXME: Ivy 1.4.1 buildlist bug + <configurations defaultconfmapping="default"> + <include file="../../antbuild/ivy/configurations.xml"/> + </configurations> + --> + <configurations defaultconfmapping="default"> + <conf name="default" extends="master,runtime"/> + <conf name="build" visibility="private" + description="artifacts needed to build the application"/> + <conf name="compile" visibility="private" + description="artifacts needed to compile the application"/> + <conf name="daemon" visibility="private" + description="the classpath needed to run smartfrog daemons"/> + <conf name="test" extends="default" + description="the classpath needed to run tests"/> + <conf name="master" description="contains the artifact but no dependencies"/> + <conf name="redist" description="redistributals excluding smartfrog artifacts"/> + <conf name="runtime" description="runtime but not the artifact" + extends="redist"/> + <conf name="documentation" + description="all documentation artifacts"/> + </configurations> + + <publications> + <!--get the artifact from our module name--> + <artifact conf="master"/> + <artifact name="sf-velocity-javadocs" conf="documentation" ext="zip"/> + <artifact name="sf-velocity-documentation" conf="documentation" ext="zip"/> + </publications> + <dependencies> + <dependency org="org.smartfrog" + name="smartfrog" + changing="true" + rev="latest.integration" + conf="compile,runtime,daemon->services"/> + <dependency org="org.smartfrog" + name="sf-tasks" + rev="latest.integration" + conf="build->default"/> + <dependency org="org.smartfrog" + name="sf-testharness" + rev="latest.integration" + conf="test->default"/> + <!--gives us oro--> + <dependency org="org.smartfrog" + name="sf-net" + changing="true" + rev="latest.integration" + conf="redist->redist;runtime->default"/> + <dependency org="org.smartfrog" + name="sf-loggingservices" + changing="true" + rev="latest.integration" + conf="redist->redist;runtime->default"/> + <dependency org="commons-collections" + name="commons-collections" + rev="${commons-collections.version}" + conf="redist->master"/> + + <dependency org="commons-lang" + name="commons-lang" + rev="${commons-lang.version}" + conf="redist->master"/> + <!--for velocity <=1.4, use this template--> + <dependency org="velocity" + name="velocity" + rev="${velocity.version}" + conf="compile,redist->default"/> + + <!--for velocity >=1.5, use this template--> + <!-- +<dependency org="org.apache.velocity" + name="velocity" + rev="${velocity.version}" + conf="compile,redist->default"/>--> + <!-- + <dependency org="org.apache.velocity" + name="velocity-tools" + rev="${velocity.version}" + conf="compile,redist->master"/> + --> + + </dependencies> +</ivy-module> \ No newline at end of file Added: trunk/core/components/velocity/project-template.pom =================================================================== --- trunk/core/components/velocity/project-template.pom (rev 0) +++ trunk/core/components/velocity/project-template.pom 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,53 @@ +<!-- This POM file is authored by the SmartFrog project. + --> +<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"> + <!-- + ${pom.comments} + --> + <modelVersion>4.0.0</modelVersion> + <groupId>org.smartfrog</groupId> + <artifactId>sf-velocity</artifactId> + <packaging>jar</packaging> + <version>${smartfrog.version}</version> + <description>Velocity support</description> + <dependencies> + <dependency> + <groupId>org.smartfrog</groupId> + <artifactId>sfServices</artifactId> + <version>${smartfrog.version}</version> + </dependency> + <dependency> + <groupId>org.smartfrog</groupId> + <artifactId>sf-loggingservices</artifactId> + <version>${smartfrog.version}</version> + </dependency> + <dependency> + <groupId>org.smartfrog</groupId> + <artifactId>sf-net</artifactId> + <version>${smartfrog.version}</version> + </dependency> + + + <dependency> + <groupId>velocity</groupId> + <artifactId>velocity</artifactId> + <version>${velocity.version}</version> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>${commons-collections.version}</version> + </dependency> + + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>${commons-lang.version}</version> + </dependency> + + + </dependencies> +</project> \ No newline at end of file Added: trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityLogBridge.java =================================================================== --- trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityLogBridge.java (rev 0) +++ trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityLogBridge.java 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,57 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.velocity; + +import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.runtime.log.LogSystem; +import org.smartfrog.sfcore.logging.LogFactory; +import org.smartfrog.sfcore.logging.LogSF; + +/** + * This component bridges from the velocity log to SmartFrog log. It is deprecated from velocity 1.5+. + */ + + +public class VelocityLogBridge implements LogSystem { + private LogSF log; + + public void init(RuntimeServices runtimeServices) throws Exception { + log = LogFactory.getLog(VelocityLogBridge.class); + } + + public void logVelocityMessage(int level, String s) { + switch (level) { + case DEBUG_ID: + log.debug(s); + break; + case INFO_ID: + log.info(s); + break; + case WARN_ID: + ; + log.warn(s); + break; + case ERROR_ID: + default: + log.error(s); + break; + } + } +} Added: trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityTransformerImpl.java =================================================================== --- trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityTransformerImpl.java (rev 0) +++ trunk/core/components/velocity/src/org/smartfrog/services/velocity/VelocityTransformerImpl.java 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,82 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.velocity; + +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; +import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogLifecycleException; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.prim.PrimImpl; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.utils.ListUtils; +import org.smartfrog.sfcore.utils.PropertiesUtils; + +import java.rmi.RemoteException; +import java.util.Properties; + +/** + * Created 24-Apr-2008 14:26:28 + */ + +public class VelocityTransformerImpl extends PrimImpl { + private VelocityContext context; + private static final Reference ATTR_PROPERTYLIST = new Reference("propertyList"); + private static final Reference REF_PROPERTIES = new Reference("properties"); + private Properties velocityProperties; + private VelocityEngine engine; + + + public VelocityTransformerImpl() throws RemoteException { + } + + /** + * Can be called to start components. Subclasses should override to provide functionality Do not block in this call, + * but spawn off any main loops! + * + * @throws SmartFrogException failure while starting + * @throws RemoteException In case of network/rmi error + */ + public synchronized void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + Object value = sfResolve(REF_PROPERTIES, true); + if (value instanceof Prim) { + velocityProperties = PropertiesUtils.build((Prim) value); + } else if (value instanceof ComponentDescription) { + velocityProperties = PropertiesUtils.build((ComponentDescription) value); + } else { + throw new SmartFrogResolutionException(this.sfCompleteName(), REF_PROPERTIES, + "Unsupported property source "); + } + Properties listprops = ListUtils.resolveProperties(this, ATTR_PROPERTYLIST, true); + PropertiesUtils.concat(velocityProperties, listprops, true); + + try { + engine = new VelocityEngine(); + engine.init(velocityProperties); + } catch (Exception e) { + throw SmartFrogLifecycleException.forward("Failed to start velocity", e, this); + } + context = new VelocityContext(); + } + +} Added: trunk/core/components/velocity/src/org/smartfrog/services/velocity/components.sf =================================================================== --- trunk/core/components/velocity/src/org/smartfrog/services/velocity/components.sf (rev 0) +++ trunk/core/components/velocity/src/org/smartfrog/services/velocity/components.sf 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,73 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/components.sf" + +/** + * Velocity support + */ +VelocityTransformer extends Prim { + + sfClass "org.smartfrog.services.velocity.VelocityTransformerImpl"; + + /** + * filename or LAZY reference to a template file + */ + template TBD; + + /** + * Optional destination directory + */ + //destDir; + + /** + * Optional full destination filename + */ + //destFile; + + /** + A component description containing properties to use for the Velocity Engine. + It is not deployed, just parsed. + + See http://velocity.apache.org/engine/releases/velocity-1.5/developer-guide.html#velocity_configuration_keys_and_values + for a list + + */ + + + CLASSPATH_RESOURCE_LOADER "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"; + JAR_RESOURCE_LOADER "org.apache.velocity.runtime.resource.loader.JarResourceLoader"; + + engineProperties extends { + runtime.log.logsystem.class "org.smartfrog.services.velocity.VelocityLogBridge"; + resource.loader "jar"; + jar.resource.loader.class JAR_RESOURCE_LOADER; + }; + + /** + a component description containing properties to use. It is not deployed, just parsed. + */ + properties extends {}; + + /** + And a list of properties which are loaded afterwards; this is to support alternate + sources of properties + */ + propertyList []; +} Added: trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/TransformerTest.java =================================================================== --- trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/TransformerTest.java (rev 0) +++ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/TransformerTest.java 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,38 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +package org.smartfrog.services.velocity.test.system.transformer; + +import org.smartfrog.test.DeployingTestBase; + +/** + * Created 28-Apr-2008 13:49:46 + */ + +public class TransformerTest extends DeployingTestBase { + private static final String PACKAGE = "/org/smartfrog/services/velocity/test/system/transformer"; + + public TransformerTest(String name) { + super(name); + } + + public void testLoad() throws Throwable { + expectSuccessfulTestRun(PACKAGE, "testLoad"); + } +} Added: trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/components.sf =================================================================== --- trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/components.sf (rev 0) +++ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/components.sf 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,36 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/filesystem/components.sf" +#include "/org/smartfrog/services/assertions/components.sf" +#include "/org/smartfrog/services/velocity/components.sf"; + +Velocity extends VelocityTransformer { + +} + +testLoad extends ExpectDeploy { + action extends Velocity { + template ""; + } + + tests extends Sequence { + //no-op + } +} Added: trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/testLoad.sf =================================================================== --- trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/testLoad.sf (rev 0) +++ trunk/core/components/velocity/test/org/smartfrog/services/velocity/test/system/transformer/testLoad.sf 2008-04-28 13:19:49 UTC (rev 6428) @@ -0,0 +1,22 @@ +/* (C) Copyright 2008 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/services/velocity/test/system/transformer/components.sf" + +sfConfig testLoad; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |