move classloader tags into plugin so it can be used with maven 1.0
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@179518 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -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">
|
||||
|
||||
<j:new var="reports" className="java.util.ArrayList"/>
|
||||
|
||||
@@ -350,10 +351,7 @@
|
||||
<fmt:setBundle basename="plugin-resources/templates/templates" var="msg"/>
|
||||
<!-- User bundle -->
|
||||
<!-- Goal grabClassLoader should be call first -->
|
||||
<maven:grabClassLoader resource="${maven.xdoc.bundle.src}"/>
|
||||
<!-- Failed
|
||||
<doc:grabClassLoader resource="${maven.xdoc.bundle.src}"/>
|
||||
-->
|
||||
<xdoc:grabClassLoader resource="${maven.xdoc.bundle.src}"/>
|
||||
<fmt:setBundle basename="${maven.xdoc.bundle}" var="myMsg"/>
|
||||
|
||||
<!-- Echo information -->
|
||||
@@ -539,40 +537,6 @@
|
||||
<j:arg type="java.lang.String" value=" .,;!?/'\()[]{}+*°" useContextClassLoader="true"/>
|
||||
<j:arg type="java.lang.String" value="__________________" useContextClassLoader="true"/>
|
||||
</j:invokeStatic>${escapedtoken}</define:tag>
|
||||
|
||||
<!--
|
||||
Grab the existing classloader
|
||||
Create a new classloader that inherits the current one
|
||||
Add URL to the classloader
|
||||
|
||||
@resource
|
||||
-->
|
||||
<define:tag name="grabClassLoader">
|
||||
<maven:param-check value="${resource}" fail="true" message="'resource' must be specified"/>
|
||||
|
||||
<util:file var="dirResource" name="${resource}" />
|
||||
<j:set var="currentClassLoader" value="${context.getClassLoader()}"/>
|
||||
<log:debug>Start to grab the current class loader ${currentClassLoader}</log:debug>
|
||||
|
||||
<j:set var="dummy">${currentClassLoader.addURL(dirResource.toURL())}</j:set>
|
||||
|
||||
<j:new className="com.werken.forehead.ForeheadClassLoader" var="foreheadClassLoader">
|
||||
<j:arg value="${currentClassLoader}" />
|
||||
<j:arg value="${currentClassLoader.getName()}_TEMP" />
|
||||
</j:new>
|
||||
<j:set var="dummy">${context.setClassLoader(foreheadClassLoader)}</j:set>
|
||||
</define:tag>
|
||||
|
||||
<!--
|
||||
Returns the old classloader
|
||||
-->
|
||||
<define:tag name="unGrabClassLoader">
|
||||
<maven:param-check value="${foreheadClassLoader}" fail="true" message="Please call xdoc:grabClassLoader first"/>
|
||||
|
||||
<j:set var="currentClassLoader" value="${context.getClassLoader()}"/>
|
||||
<log:debug>Start to ungrab the current class loader ${currentClassLoader}</log:debug>
|
||||
<j:set var="dummy">${context.setClassLoader(currentClassLoader.getParent())}</j:set>
|
||||
</define:tag>
|
||||
</define:taglib>
|
||||
|
||||
<!-- ================================================================== -->
|
||||
@@ -996,10 +960,7 @@
|
||||
<attainGoal name="xdoc:copy-resources"/>
|
||||
<attainGoal name="xdoc:copy-user-resources"/>
|
||||
<attainGoal name="xdoc:jelly-transform"/>
|
||||
<maven:unGrabClassLoader/>
|
||||
<!-- Failed
|
||||
<doc:unGrabClassLoader/>
|
||||
-->
|
||||
<xdoc:unGrabClassLoader/>
|
||||
</goal>
|
||||
|
||||
<!-- ================================================================== -->
|
||||
|
||||
87
xdoc/src/main/org/apache/maven/xdoc/GrabClassLoaderTag.java
Normal file
87
xdoc/src/main/org/apache/maven/xdoc/GrabClassLoaderTag.java
Normal file
@@ -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 <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -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 <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton </a>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
39
xdoc/src/main/org/apache/maven/xdoc/XdocTagLibrary.java
Normal file
39
xdoc/src/main/org/apache/maven/xdoc/XdocTagLibrary.java
Normal file
@@ -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 <a href="mailto:brett@apache.org">Brett Porter</a>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user