diff --git a/xdoc/plugin.jelly b/xdoc/plugin.jelly index 0d1a04e5..86c31b8d 100644 --- a/xdoc/plugin.jelly +++ b/xdoc/plugin.jelly @@ -29,7 +29,8 @@ xmlns:velocity="jelly:velocity" xmlns:ant="jelly:ant" xmlns:fmt="jelly:fmt" - xmlns:doc="doc"> + xmlns:doc="doc" + xmlns:xdoc="jelly:org.apache.maven.xdoc.XdocTagLibrary"> @@ -350,10 +351,7 @@ - - + @@ -539,40 +537,6 @@ ${escapedtoken} - - - - - - - - Start to grab the current class loader ${currentClassLoader} - - ${currentClassLoader.addURL(dirResource.toURL())} - - - - - - ${context.setClassLoader(foreheadClassLoader)} - - - - - - - - Start to ungrab the current class loader ${currentClassLoader} - ${context.setClassLoader(currentClassLoader.getParent())} - @@ -996,10 +960,7 @@ - - + diff --git a/xdoc/src/main/org/apache/maven/xdoc/GrabClassLoaderTag.java b/xdoc/src/main/org/apache/maven/xdoc/GrabClassLoaderTag.java new file mode 100644 index 00000000..ab472bdd --- /dev/null +++ b/xdoc/src/main/org/apache/maven/xdoc/GrabClassLoaderTag.java @@ -0,0 +1,87 @@ +package org.apache.maven.xdoc; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import java.io.File; +import java.net.MalformedURLException; + +import org.apache.commons.jelly.JellyTagException; +import org.apache.commons.jelly.MissingAttributeException; +import org.apache.commons.jelly.TagSupport; +import org.apache.commons.jelly.XMLOutput; + +import com.werken.forehead.ForeheadClassLoader; + +/** + * Add a specific ressource to the current Maven context + * + * @author Vincent Siveton + * @version 1.0 + */ +public class GrabClassLoaderTag extends TagSupport { + /** Resource to include in the Maven context. */ + private String resource; + + /* + * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) + */ + public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { + if (getContext() == null) { + throw new JellyTagException("The current MavenContext is null!"); + } + + ForeheadClassLoader currentClassLoader = null; + try { + currentClassLoader = (ForeheadClassLoader) getContext().getClassLoader(); + } catch (ClassCastException e) { + throw new JellyTagException("The current classloader in the MavenContext is not an instance of ForeheadClassLoader"); + } + + if (currentClassLoader == null) { + throw new JellyTagException("No classloader found in the current MavenContext"); + } + + try { + File f = new File(this.resource); + + currentClassLoader.addURL(f.toURL()); + } catch (MalformedURLException e) { + throw new JellyTagException("The directory to include specified by " + getResource() + " is malformed"); + } + + ForeheadClassLoader newClassLoader = new ForeheadClassLoader(currentClassLoader, currentClassLoader.getName() + "_TEMP"); + getContext().setClassLoader(newClassLoader); + } + + /** + * Get the includeDir. + * + * @return the includeDir. + */ + public String getResource() { + return this.resource; + } + /** + * Set the includeDir + * + * @param includeDir includeDir to set. + */ + public void setResource(String includeDir) { + this.resource = includeDir; + } +} diff --git a/xdoc/src/main/org/apache/maven/xdoc/UnGrabClassLoaderTag.java b/xdoc/src/main/org/apache/maven/xdoc/UnGrabClassLoaderTag.java new file mode 100644 index 00000000..c86ff63a --- /dev/null +++ b/xdoc/src/main/org/apache/maven/xdoc/UnGrabClassLoaderTag.java @@ -0,0 +1,58 @@ +package org.apache.maven.xdoc; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.commons.jelly.JellyTagException; +import org.apache.commons.jelly.MissingAttributeException; +import org.apache.commons.jelly.TagSupport; +import org.apache.commons.jelly.XMLOutput; + +import com.werken.forehead.ForeheadClassLoader; + +/** + * Return to the old classloader + * + * @see GrabClassLoaderTag + * + * @author Vincent Siveton + * @version 1.0 + */ +public class UnGrabClassLoaderTag extends TagSupport { + /* + * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput) + */ + public void doTag(XMLOutput arg0) throws MissingAttributeException, JellyTagException { + if (getContext() == null) { + throw new JellyTagException("The current MavenContext is null!"); + } + + ForeheadClassLoader currentClassLoader = null; + try { + currentClassLoader = (ForeheadClassLoader) getContext().getClassLoader(); + } catch (ClassCastException e) { + throw new JellyTagException("The current classloader in the MavenContext is not an instance of ForeheadClassLoader"); + } + + if (currentClassLoader == null) { + throw new JellyTagException("No classloader found in the current MavenContext"); + } + + ClassLoader oldClassLoader = currentClassLoader.getParent(); + getContext().setClassLoader(oldClassLoader); + } +} diff --git a/xdoc/src/main/org/apache/maven/xdoc/XdocTagLibrary.java b/xdoc/src/main/org/apache/maven/xdoc/XdocTagLibrary.java new file mode 100644 index 00000000..237418ba --- /dev/null +++ b/xdoc/src/main/org/apache/maven/xdoc/XdocTagLibrary.java @@ -0,0 +1,39 @@ +package org.apache.maven.xdoc; + +/* ==================================================================== + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +import org.apache.commons.jelly.TagLibrary; + +/** + * MavenSession tag library for use in Jelly scripts. + * + * @author Brett Porter + * @version $Id$ + */ +public class XdocTagLibrary extends TagLibrary +{ + /** + * Create an instance of the {@link MavenTagLibrary}, registering related + * tag libraries + */ + public XdocTagLibrary() + { + registerTag( "grabClassLoader", GrabClassLoaderTag.class); + registerTag( "unGrabClassLoader", UnGrabClassLoaderTag.class); + } +}