commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Libbrecht <p...@activemath.org>
Subject [jelly] a first draft of jellypack...
Date Tue, 22 Jul 2003 21:57:36 GMT

Hi,

Down here, I've pasted a script that should be the start of a jelly 
wrapping function.
The main functionality is to find the taglibs for a given jelly file 
then collect all dependencies.
With these, one can do several things.

Currently, one can generate a classpath to be used straight in the java 
command (using org.apache.commons.jelly.Jelly as main class).
Use:
	maven jellypack:generate-classpath \
		-Djelly_file=file://<pathToJellyFile>
		-Djelly_home=<pathToJellyHome>
		-Dclasspath_file=<classpathFileToGenerate>
which you can then use with something like
java -classpath `cat <classpathFile>` \
	org.apache.commons.jelly.Jelly <pathToJellyFile>



One can also create project.xml's dependency element which can be 
included in a project.xml to be completed (with meta-information).
Use:
maven jellypack:produce-dependency \
	-Djelly_file=file://pathToJellyFile \
	-Djelly_home=<pathToJelly> \
	-Djellypack_dependencyFile=<pathToFileToOutput

This script can be pasted in jelly's maven.xml and needs (oh shame) a 
dependency in jelly's project.xml on the xml tag-library.
Putting the jelly file's jelly-element's content as a goal in the 
maven.xml aside of the project.xml allows then such deployments as 
double-clickable jars webstart...

There's a whole lot more that could be done (including straight running 
(!), automating the possible products of the maven project generation), 
but... it's a start.

I am not too clear wether this script (well, an enhanced version of it) 
should actually be created as a maven plugin... probably.
The trouble is that its aim is to jumpstart people writing simple 
jelly-files... maybe as a subproject within jelly (so as to avoid 
jelly's dependency on xml-taglib) ?

Paul





   <goal
     name="jellypack:get-all-taglibs-projects"
     description="Creates the jellyNeededProjects list of poms"
     >
     <!-- goes through the namespaces of the jelly file and collects them
       inferring from there the tag-libraries location. -->
     <!-- requires properties:
       jelly_file:   the jelly-file-name to be parsed
       jelly_home:   the root directory containing the jelly src and 
jelly-tags directories
       -->

     <!-- parse the jelly file -->
     <x:parse xml="${jelly_file}" var="jelly_src"/>
     <!-- find all namespace declarations in there, there must be 
faster! -->
     <j:set var="jellyTaglibNames"/>
     <j:new className="java.util.HashSet" var="namespaces"/>
     <x:forEach var="elt" select="$jelly_src//*" > <!-- ??? -->
       <j:if test="${elt.getNamespace().getURI() != null}">
         ${namespaces.add(elt.getNamespace().getURI().substring(6))}
         </j:if>
       <!-- <j:set var="jellyTaglibNames">${jellyTaglibNames}, 
${elt.getNamespace().getURI().substring(6)}</j:set>  -->
       </x:forEach>
     <echo>namespaces is "${namespaces}".</echo>
       <!--       ${namespaces.addAll(elt.additionalNamespaces())} -->

     <!-- go over the namespaces and fail if it's not jelly tag-libs -->
     <j:set var="jellyTaglibNames"/>
     <j:forEach var="tlName" items="${namespaces}">
       <echo>Considering taglib tlName "${tlName}".</echo>
       <j:if test="${'core' ne tlName}">
         <j:if test="${jellyTaglibNames.length() > 0}"><j:set 
var="jellyTaglibNames" trim="false">${jellyTaglibNames},</j:set></j:if>
         <j:set 
var="jellyTaglibNames">${jellyTaglibNames}jelly-tags/${tlName}/project.xml</j:set>
         </j:if>
       </j:forEach>

     <echo>jellyTaglibNames is ${jellyTaglibNames}</echo>

     <maven:reactor
       basedir="${jelly_home}"
       postProcessing="true"
       includes="${jellyTaglibNames},project.xml"
       ignoreFailures="false">
         </maven:reactor>

     <j:set var="jellyNeededProjects" value="${reactorProjects}"/>
   </goal>

   <goal
       name="jellypack:compute-all-dependencies"
       prereqs="jellypack:get-all-taglibs-projects">
       <!-- defines
         allDependencies: a set of dependency objects (all merged)
         -->

     <j:new className="java.util.HashSet" var="allDependencies"/>
     <!-- put all project dependencies and project produced artifacts -->
     <j:forEach var="project" items="${jellyNeededProjects}">
       <!-- we iterate over a Project objects, see 
http://maven.apache.org/apidocs/org/apache/maven/project/Project.html -->
       <echo>Project ${project}</echo>
       <j:new className="org.apache.maven.project.Dependency" 
var="projDep"/>
         ${projDep.setArtifactId(project.getArtifactId())}
         ${projDep.setGroupId(project.getGroupId())}
         ${projDep.setVersion(project.getCurrentVersion())}
       ${allDependencies.add(projDep)}
       ${allDependencies.addAll(project.getDependencies())}
       </j:forEach>
     </goal>

   <goal
     name="jellypack:generate-classpath"
     prereqs="jellypack:compute-all-dependencies"
     description="Generates the classpath needed to run the jelly-file 
from jars in the repository">

     <j:if test="${jelly_file.startsWith('file:')}">
       <j:set var="jelly_file" value="${jelly_file.substring(5)}"/>
       </j:if>
     <property name="classpath_file" value="${jelly_file}.classpath"/>

     <x:parse var="trash">
       <j:new className="java.lang.StringBuffer" var="classpath"/>
       <j:forEach var="dep" items="${allDependencies}">
         <!-- we iterate over 
http://maven.apache.org/apidocs/org/apache/maven/project/Dependency.html -->
         <j:set 
var="pathToDep">${maven.repo.local}/${dep.getArtifactDirectory()}/jars/${dep.getArtifactId()}-${dep.getVersion()}.jar</j:set>
         ${classpath.append(pathToDep).append(":")}
         <!-- fixme... path is windows compatible ? -->
         <available file="${pathToDep}" property="depExists"/>
         <echo>Depfile ${pathToDep} exists ? ${depExists}</echo>
         </j:forEach>
         </x:parse>

     <echo file="${classpath_file}">${classpath}</echo>
     <echo>Output classpath to file ${classpath_file}</echo>
     </goal>

   <goal name="jellypack:generate-maven-dependencies"
       description="creates the project.xml dependencies element to be 
included in a project.xml"
       prereqs="jellypack:compute-all-dependencies">
     <x:parse var="project-dependencies">
       <dependencies>
       <j:forEach items="${allDependencies}" var="dep">
         <dependency>
           <groupId>${dep.getGroupId()}</groupId>
           <artifactId>${dep.getArtifactId()}</artifactId>
           <version>${dep.getVersion()}</version>
           </dependency>
         </j:forEach>
         </dependencies>
       </x:parse>
     </goal>

   <goal name="jellypack:produce-dependency"
       description="produce the dependency project.xml element inside a 
file jellypack_dependencyFile"
       prereqs="jellypack:generate-maven-dependencies">
     <property name="jellypack_dependencyFile" 
value="j${jelly_file.dependencyElement}"/>
     <!-- <j:if test="${jellypack_dependencyFile eq 'dont obey 
me'}"><fail message="Please define property 
jellypack.dependencyFile"/></j:if> -->
     <j:file name="${jellypack_dependencyFile}" prettyPrint="true">
       <x:copyOf select="$project-dependencies"/>
     </j:file>
     </goal>







Mime
View raw message