Hi dIon, I had a look at MakeRelativePathTag but it's not working in the same way at all. Here's an example
Basedir/Rootdir="c:/apps/myroject" Path="c:/apps/myproject/dir1/dir2/mysubproject" Result of RootRelativePathTag = "../../.." Result of MakeRelativePathTag = "dir/dir2/mysubproject" However, when property inheritance is there this will no longer be needed. -Vincent > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: 09 October 2003 09:02 > To: Maven Developers List > Subject: Re: cvs commit: maven/src/java/org/apache/maven/jelly/tags/maven > RootRelativePathTag.java MavenTagLibrary.java > > Vincent, how is this different to the MakeRelativePathTag? > -- > dIon Gillard, Multitask Consulting > Blog: http://blogs.codehaus.org/people/dion/ > > > [EMAIL PROTECTED] wrote on 09/10/2003 09:44:04 AM: > > > vmassol 2003/10/08 16:44:04 > > > > Modified: src/java/org/apache/maven/jelly/tags/maven > > MavenTagLibrary.java > > Added: src/test/java/org/apache/maven/jelly/tags/maven > > RootRelativePathTagTest.java > > src/java/org/apache/maven/jelly/tags/maven > > RootRelativePathTag.java > > Log: > > Added new tag which can be used to implement property inheritance > > while waiting for the final fix in maven 2.0... > > > > > > > > The way to use it is by adding the following lines in your top > > level maven.xml (outside of any goal): > > > > > > > > <maven:rootRelativePath rootdir="your absolute root to where your > > top level maven.xml is located" path="${basedir}" var="relpath"/> > > > > <u:properties file="${relpath}/project.properties"/> > > > > <u:properties file="${relpath}/build.properties"/> > > > > > > > > Note: I haven't tried a full functional test yet (but I will > > tomorrow) but it should work :-) > > > > Revision Changes Path > > 1.1 > > > maven/src/test/java/org/apache/maven/jelly/tags/maven/RootRelativePathTa gT > est. > > java > > > > Index: RootRelativePathTagTest.java > > =================================================================== > > package org.apache.maven.jelly.tags.maven; > > > > /* > ==================================================================== > > * The Apache Software License, Version 1.1 > > * > > * Copyright (c) 2003 The Apache Software Foundation. All rights > > * reserved. > > * > > * Redistribution and use in source and binary forms, with or without > > * modification, are permitted provided that the following conditions > > * are met: > > * > > * 1. Redistributions of source code must retain the above copyright > > * notice, this list of conditions and the following disclaimer. > > * > > * 2. Redistributions in binary form must reproduce the above > copyright > > * notice, this list of conditions and the following disclaimer in > > * the documentation and/or other materials provided with the > > * distribution. > > * > > * 3. The end-user documentation included with the redistribution, > > * if any, must include the following acknowledgment: > > * "This product includes software developed by the > > * Apache Software Foundation (http://www.apache.org/)." > > * Alternately, this acknowledgment may appear in the software > itself, > > * if and wherever such third-party acknowledgments normally > appear. > > * > > * 4. The names "Apache" and "Apache Software Foundation" and > > * "Apache Maven" must not be used to endorse or promote products > > * derived from this software without prior written permission. For > > * written permission, please contact [EMAIL PROTECTED] > > * > > * 5. Products derived from this software may not be called "Apache", > > * "Apache Maven", nor may "Apache" appear in their name, without > > * prior written permission of the Apache Software Foundation. > > * > > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED > > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES > > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > > * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR > > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF > > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND > > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, > > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT > > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > > * SUCH DAMAGE. > > * > ==================================================================== > > * > > * This software consists of voluntary contributions made by many > > * individuals on behalf of the Apache Software Foundation. For more > > * information on the Apache Software Foundation, please see > > * <http://www.apache.org/>. > > * > > * > ==================================================================== > > */ > > > > import java.io.File; > > import java.io.IOException; > > > > import junit.framework.TestCase; > > > > /** > > * Tests for [EMAIL PROTECTED] RootRelativePathTag}. > > * > > * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> > > * @version $Id: RootRelativePathTagTest.java,v 1.1 2003/10/08 23: > > 44:04 vmassol Exp $ > > */ > > public class RootRelativePathTagTest extends TestCase > > { > > /** > > * The tag to test > > */ > > private RootRelativePathTag tag; > > > > /** > > * @see TestCase#setUp() > > */ > > protected void setUp() > > { > > tag = new RootRelativePathTag(); > > } > > > > public void testComputePathOk() throws Exception > > { > > tag.setPath("c:/apps/myproject/path/subproject2"); > > tag.setRootdir(new File("c:/apps/myproject")); > > String result = tag.computePath(); > > assertEquals("./../..", result); > > } > > > > public void testComputePathWithEndingSeparator() throws Exception > > { > > tag.setPath("c:/apps/myproject/path/subproject2"); > > tag.setRootdir(new File("c:/apps/myproject/")); > > String result = tag.computePath(); > > assertEquals("./../..", result); > > } > > > > public void testComputePathOk2() throws Exception > > { > > tag.setPath("c:/apps/myproject"); > > tag.setRootdir(new File("c:/apps/myproject")); > > String result = tag.computePath(); > > assertEquals(".", result); > > } > > > > public void testComputePathOk3() throws Exception > > { > > tag.setPath("c:\\apps\\myproject\\path\\subproject2"); > > tag.setRootdir(new File("c:\\apps\\myproject")); > > String result = tag.computePath(); > > assertEquals("./../..", result); > > } > > > > public void testComputePathWhenPathNotSubsetRootdir() throws > Exception > > { > > tag.setPath("c:/apps/myproject/path/subproject2"); > > tag.setRootdir(new File("c:/somethingelse")); > > > > try > > { > > tag.computePath(); > > fail("should have thrown an exception"); > > } > > catch (IOException expected) > > { > > assertTrue(true); > > } > > } > > } > > > > > > > > 1.12 +4 -3 > > maven/src/java/org/apache/maven/jelly/tags/maven/MavenTagLibrary.java > > > > Index: MavenTagLibrary.java > > =================================================================== > > RCS file: > > > /home/cvs/maven/src/java/org/apache/maven/jelly/tags/maven/MavenTagLibra ry > . > > java,v > > retrieving revision 1.11 > > retrieving revision 1.12 > > diff -u -r1.11 -r1.12 > > --- MavenTagLibrary.java 20 Aug 2003 12:37:18 -0000 1.11 > > +++ MavenTagLibrary.java 8 Oct 2003 23:44:04 -0000 1.12 > > @@ -63,10 +63,10 @@ > > * > > * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> > > * @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a> > > + * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> > > * @version $Id$ > > */ > > -public class MavenTagLibrary > > - extends BaseTagLibrary > > +public class MavenTagLibrary extends BaseTagLibrary > > { > > /** > > * Create an instance of the [EMAIL PROTECTED] MavenTagLibrary}, > > registering related > > @@ -86,6 +86,7 @@ > > registerTag( "userCheck", UserCheck.class); > > registerTag( "paramCheck", ParamCheck.class); > > registerTag( "copyResources", CopyResources.class); > > + registerTag( "rootRelativePath", RootRelativePathTag.class ); > > // Remove the following deprecated forms > > registerTag( "user-check", UserCheck.class); > > registerTag( "param-check", ParamCheck.class); > > > > > > > > 1.1 > > > maven/src/java/org/apache/maven/jelly/tags/maven/RootRelativePathTag.jav a > > > > Index: RootRelativePathTag.java > > =================================================================== > > package org.apache.maven.jelly.tags.maven; > > > > /* > ==================================================================== > > * The Apache Software License, Version 1.1 > > * > > * Copyright (c) 2003 The Apache Software Foundation. All rights > > * reserved. > > * > > * Redistribution and use in source and binary forms, with or without > > * modification, are permitted provided that the following conditions > > * are met: > > * > > * 1. Redistributions of source code must retain the above copyright > > * notice, this list of conditions and the following disclaimer. > > * > > * 2. Redistributions in binary form must reproduce the above > copyright > > * notice, this list of conditions and the following disclaimer in > > * the documentation and/or other materials provided with the > > * distribution. > > * > > * 3. The end-user documentation included with the redistribution, > > * if any, must include the following acknowledgment: > > * "This product includes software developed by the > > * Apache Software Foundation (http://www.apache.org/)." > > * Alternately, this acknowledgment may appear in the software > itself, > > * if and wherever such third-party acknowledgments normally > appear. > > * > > * 4. The names "Apache" and "Apache Software Foundation" and > > * "Apache Maven" must not be used to endorse or promote products > > * derived from this software without prior written permission. For > > * written permission, please contact [EMAIL PROTECTED] > > * > > * 5. Products derived from this software may not be called "Apache", > > * "Apache Maven", nor may "Apache" appear in their name, without > > * prior written permission of the Apache Software Foundation. > > * > > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED > > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES > > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE > > * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR > > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF > > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND > > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, > > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT > > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > > * SUCH DAMAGE. > > * > ==================================================================== > > * > > * This software consists of voluntary contributions made by many > > * individuals on behalf of the Apache Software Foundation. For more > > * information on the Apache Software Foundation, please see > > * <http://www.apache.org/>. > > * > > * > ==================================================================== > > */ > > > > import java.io.File; > > import java.io.IOException; > > import java.util.StringTokenizer; > > > > import org.apache.commons.jelly.JellyTagException; > > import org.apache.commons.jelly.MissingAttributeException; > > import org.apache.commons.jelly.XMLOutput; > > import org.apache.maven.jelly.tags.BaseTagSupport; > > > > /** > > * Converts an absolute path into a path relative to a root dir. For > > * example, if the root dir is "c:/apps/myproject" and the absolute > > * path is "c:/apps/myproject/path/subproject2" then the computed > > * relative path is "../..". > > * > > * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a> > > * @version $Id: RootRelativePathTag.java,v 1.1 2003/10/08 23:44: > > 04 vmassol Exp $ > > */ > > public class RootRelativePathTag extends BaseTagSupport > > { > > /** The root dir. */ > > private File rootdir; > > > > /** The path to convert. */ > > private String path; > > > > /** The jelly variable to store the result into. */ > > private String var; > > > > /** > > * Set the root directory. > > * @param rootdir the root directory > > */ > > public void setRootdir(File rootdir) > > { > > this.rootdir = rootdir; > > } > > > > /** > > * Set the path. > > * @param path the path. > > */ > > public void setPath(String path) > > { > > this.path = path; > > } > > > > /** > > * Set the result variable. > > * @param var the result variable name. > > */ > > public void setVar(String var) > > { > > this.var = var; > > } > > > > /** > > * @see Tag#doTag(XMLOutput) > > */ > > public void doTag(XMLOutput output) > > throws MissingAttributeException, JellyTagException > > { > > checkAttribute(rootdir, "rootdir"); > > checkAttribute(path, "path"); > > checkAttribute(var, "var"); > > > > String result; > > try > > { > > result = computePath(); > > } > > catch (IOException e) > > { > > throw new JellyTagException( "Unable to create > > relative path", e ); > > } > > getContext().setVariable(var, result); > > } > > > > /** > > * @return the compute relative path to the root dir > > * @throws IOException on error > > */ > > public String computePath() throws IOException > > { > > String canonicalRootdir = rootdir.getCanonicalPath(); > > String canonicalPath = new File(path).getCanonicalPath(); > > if (canonicalPath.equals(canonicalRootdir)) > > { > > return "."; > > } > > else if (canonicalPath.startsWith(canonicalRootdir)) > > { > > canonicalPath = canonicalPath.substring( > > canonicalRootdir.length()); > > } > > else > > { > > throw new IOException("Path [" + canonicalPath > > + "] is not a subset of [" + canonicalRootdir + "]"); > > } > > > > StringBuffer result = new StringBuffer("."); > > StringTokenizer tokens = new StringTokenizer(canonicalPath, > "/\\" ); > > while (tokens.hasMoreTokens()) > > { > > String token = (String) tokens.nextToken(); > > result.append("/.."); > > } > > return result.toString(); > > } > > } > > > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
