You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by bw...@apache.org on 2003/04/27 01:49:00 UTC
cvs commit: maven-new/plugins/jelly/src/java/org/apache/maven/plugins/jelly JellyPlugin.java DefaultJellyPlugin.java
bwalding 2003/04/26 16:48:59
Added: plugins/jelly .cvsignore
plugins/jelly/src/test/org/apache/maven/plugins/jelly
DefaultJellyPluginTest.java
plugins/jelly/src/java/org/apache/maven/plugins/jelly
JellyPlugin.java DefaultJellyPlugin.java
Log:
Continue cleanup after reorg
Revision Changes Path
1.1 maven-new/plugins/jelly/.cvsignore
Index: .cvsignore
===================================================================
*.log
target
.classpath
.project
1.1 maven-new/plugins/jelly/src/test/org/apache/maven/plugins/jelly/DefaultJellyPluginTest.java
Index: DefaultJellyPluginTest.java
===================================================================
/*
* Created on 26/04/2003
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code Template
*/
package org.apache.maven.plugins.jelly;
import java.io.File;
import java.util.List;
import org.apache.maven.plugin.PluginGoal;
import org.apache.plexus.PlexusTestCase;
import org.apache.plexus.context.DefaultPlexusContext;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: DefaultJellyPluginTest.java,v 1.1 2003/04/26 23:48:59 bwalding Exp $
*/
public class DefaultJellyPluginTest extends PlexusTestCase
{
/**
* @param arg0
*/
public DefaultJellyPluginTest(String arg0)
{
super(arg0);
// TODO Auto-generated constructor stub
}
DefaultJellyPlugin djp = null;
public void setUp()
{
// plexify
djp = new DefaultJellyPlugin();
djp.load(new File(System.getProperty("basedir") + "/src/test-input/jellyplugin-1"));
}
public void test()
{
List goals = djp.getGoals();
assertNotNull(goals);
assertEquals("goals.size()", 2, goals.size());
PluginGoal g0 = (PluginGoal) goals.get(0);
assertNotNull(g0);
PluginGoal g1 = (PluginGoal) goals.get(1);
assertNotNull(g1);
}
public void test2() throws Exception
{
djp.runGoal("goal1", new DefaultPlexusContext());
}
}
1.1 maven-new/plugins/jelly/src/java/org/apache/maven/plugins/jelly/JellyPlugin.java
Index: JellyPlugin.java
===================================================================
/*
* Created on 25/04/2003
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code Template
*/
package org.apache.maven.plugins.jelly;
import java.io.File;
import org.apache.maven.plugin.Plugin;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: JellyPlugin.java,v 1.1 2003/04/26 23:48:59 bwalding Exp $
*/
public interface JellyPlugin extends Plugin
{
static String ROLE = JellyPlugin.class.getName();
void load(File projectXML);
}
1.1 maven-new/plugins/jelly/src/java/org/apache/maven/plugins/jelly/DefaultJellyPlugin.java
Index: DefaultJellyPlugin.java
===================================================================
/*
* Created on 25/04/2003
*
* To change this generated comment go to
* Window>Preferences>Java>Code Generation>Code Template
*/
package org.apache.maven.plugins.jelly;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.avalon.framework.context.Context;
import org.apache.commons.jelly.Jelly;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyException;
import org.apache.commons.jelly.Tag;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.impl.StaticTagScript;
import org.apache.maven.plugin.PluginGoal;
import org.apache.maven.project.Project;
import org.apache.maven.project.builder.DefaultProjectUnmarshaller;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* @author <a href="bwalding@jakarta.org">Ben Walding</a>
* @version $Id: DefaultJellyPlugin.java,v 1.1 2003/04/26 23:48:59 bwalding Exp $
*/
public class DefaultJellyPlugin implements JellyPlugin
{
File pluginPath;
File projectFile;
Project project;
Jelly jelly;
File pluginJelly;
StaticTagScript script;
/* (non-Javadoc)
* @see org.apache.maven.plugins.jelly.JellyPlugin#load(java.io.File)
*/
public void load(File pluginPath)
{
this.pluginPath = pluginPath;
//XXX use container
DefaultProjectUnmarshaller dpu = new DefaultProjectUnmarshaller();
jelly = new Jelly();
try
{
projectFile = new File(pluginPath, "project.xml");
project = dpu.parse(new FileReader(projectFile));
pluginJelly = new File(pluginPath, "plugin.jelly");
jelly.setUrl(pluginJelly.toURL());
script = (StaticTagScript) jelly.compileScript();
System.out.println("Script:" + script.getClass().getName());
}
catch (Exception e)
{
e.printStackTrace();
}
}
/* (non-Javadoc)
* @see org.apache.maven.plugin.Plugin#getId()
*/
public String getId()
{
return null;
}
/* (non-Javadoc)
* @see org.apache.maven.plugin.Plugin#getGoals()
*/
public List getGoals()
{
List l = new ArrayList();
SAXReader reader = new SAXReader();
try
{
Tag t = script.getTag();
System.out.println(t);
Document document = reader.read(pluginJelly.toURL());
List nodes = document.selectNodes("/project/goal");
for (Iterator iter = nodes.iterator(); iter.hasNext();)
{
Node node = (Node) iter.next();
String name = node.selectSingleNode("@name").getStringValue();
String description = null;
Node descriptionNode = node.selectSingleNode("@description");
if (descriptionNode != null) {
description = descriptionNode.getStringValue();
}
PluginGoal goal = new PluginGoal(name, new ArrayList());
goal.setDescription(description);
l.add(goal);
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
throw new RuntimeException(e.getLocalizedMessage());
}
catch (DocumentException e)
{
e.printStackTrace();
throw new RuntimeException(e.getLocalizedMessage());
} catch (JellyException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return l;
}
/* (non-Javadoc)
* @see org.apache.maven.plugin.Plugin#runGoal(java.lang.String, org.apache.avalon.framework.context.Context)
*/
public void runGoal(String goal, Context context) throws Exception
{
XMLOutput xo = new XMLOutput();
xo.setContentHandler(new DefaultHandler()
{
StringBuffer result = new StringBuffer();
public String toString()
{
return result.toString();
}
public void startDocument() throws SAXException
{
result.setLength(0);
}
public void endDocument() throws SAXException
{
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
throws SAXException
{
result.append("<" + localName + ">");
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
result.append("</" + localName + ">");
}
public void characters(char[] ch, int start, int length) throws SAXException
{
result.append(ch, start, length);
}
});
JellyContext jc = new JellyContext();
jc.setVariable("context", context);
script.run(jc, xo);
System.out.println(xo.getContentHandler().toString());
for (Iterator iter = jc.getVariableNames(); iter.hasNext();)
{
String name = (String) iter.next();
System.out.println(name + " = " + jc.getVariable(name));
}
}
/* (non-Javadoc)
* @see org.apache.maven.plugin.Plugin#runGoal(org.apache.maven.plugin.PluginGoal, org.apache.avalon.framework.context.Context)
*/
public void runGoal(PluginGoal goal, Context context) throws Exception
{
// TODO Auto-generated method stub
}
private static final int BUFFER_SIZE = 16384;
/**
* Transfers all remaining data in the input stream to the output stream
*
* Neither stream will be closed at completion.
**/
public static void transferStream(InputStream is, OutputStream os) throws IOException
{
final byte[] buffer = new byte[BUFFER_SIZE];
while (true)
{
int bytesRead = is.read(buffer, 0, buffer.length);
if (bytesRead == -1)
break;
os.write(buffer, 0, bytesRead);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org