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:
1 parent
54624a1258
commit
1fa742b9af
4 files changed
+188
-43
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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