package com.perforce.common; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import com.perforce.common.node.PathMapEntry; import com.perforce.common.node.PathMapTranslator; import com.perforce.config.CFG; import com.perforce.config.Config; import com.perforce.config.ConfigException; public class TestPathMap { @Before public void before() { PathMapTranslator.clear(); } @Test public void testBasicMap() { PathMapEntry entry = new PathMapEntry("(main)/projFoo/(bar/.*)", "//depot/proj.FooBar/{1}/{2}"); PathMapTranslator.add(entry); String path = "main/projFoo/bar/src/baz.txt"; String base = "//depot/proj.FooBar/main/bar/src/baz.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } @Test public void testMultiMap() { PathMapEntry entry1 = new PathMapEntry("(.*)/projFoo/(bar/.*)", "//depot/proj.FooBar/{1}/{2}"); PathMapEntry entry2 = new PathMapEntry("(rel1)/projFoo/(bar/.*)", "//depot/proj.FooBar/{1}-{2}"); // add inserts entry at the top of list, so entry2 will be checked // first. PathMapTranslator.add(entry1); PathMapTranslator.add(entry2); String path1 = "rel1/projFoo/bar/src/baz.txt"; String base1 = "//depot/proj.FooBar/rel1-bar/src/baz.txt"; Assert.assertEquals(base1, PathMapTranslator.translate(path1)); String path2 = "main/projFoo/bar/src/baz.txt"; String base2 = "//depot/proj.FooBar/main/bar/src/baz.txt"; Assert.assertEquals(base2, PathMapTranslator.translate(path2)); } @Test public void testPartMap() { PathMapEntry entry = new PathMapEntry("RELEASE_(.*)/projFoo/(bar/.*)", "//depot/R{1}/{2}"); PathMapTranslator.add(entry); String path = "RELEASE_1.0.2/projFoo/bar/src/baz.txt"; String base = "//depot/R1.0.2/bar/src/baz.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } @Test public void testRegexCharsInPath() { PathMapEntry entry = new PathMapEntry("RELEASE_(.*)/projFoo/(bar/.*)", "//depot/R{1}/{2}"); PathMapTranslator.add(entry); String path = "RELEASE_1.*.2/projFoo/bar/(src)/baz.txt"; String base = "//depot/R1.*.2/bar/(src)/baz.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } @Test public void testDefautMap() throws ConfigException { Config.setDefault(); Config.set(CFG.P4_DEPOT_SUB, "sub/"); PathMapTranslator.setDefault(); String path = "main/src/baz.txt"; String base = "//import/sub/main/src/baz.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } @Test public void testNullPath() throws ConfigException { Config.setDefault(); Config.set(CFG.P4_DEPOT_SUB, "sub/"); PathMapTranslator.setDefault(); String path = null; String base = "//import/sub/"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } @Test public void testRegexPath() throws ConfigException { Config.setDefault(); PathMapTranslator.setDefault(); String path = "trunk/{1}/foo.txt"; String base = "//import/trunk/{1}/foo.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); path = "trunk/$foo.txt"; base = "//import/trunk/$foo.txt"; Assert.assertEquals(base, PathMapTranslator.translate(path)); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12446 | Paul Allen | Branching using p4convert-rusty | ||
//guest/perforce_software/p4convert/test/com/perforce/common/TestPathMap.java | |||||
#4 | 11309 | Paul Allen |
CVS/SVN: Support for URI paths. To avoid double encoding a URI path the converter decodes the path and stores it in UTF8. - CVS Test Case 052 |
||
#3 | 11171 | Paul Allen |
CVS/SVN: Path translation support for '$' and other regex chars. @rjackson found that a $ in the path will raise an IllegalArgumentException: Illegal group reference - Fix includes unit test |
||
#2 | 11156 | Paul Allen |
CVS/SVN: Path translation support for {nnn} Some SCM path contail '{nnn}' where nnn is a number, this caused the group regex to fail. - includes a unit test to verify fix. |
||
#1 | 11071 | Paul Allen |
Path map translator for CVS and SVN paths. (undoc) To use create a path.map file with regex and group match. Only the first matching entry is used. The regex and group match are seperated by ', ' (or in regex terms ',\s+'). Lines starting with '#' are ignored. For example, 'trunk' is renamed to 'main', but other entries are left as-is. # path.map trunk/(.*), //import/main/{1} (.*), //import/{1} Note: if no file is found the default 'depot' and 'subPath' options are used to generate the map, preserving the original behaviour. CVS paths will always stat with the 'branch' name. 'main' for 1.1 and the symbol for other branches. # path.map main/projA/(.*), //import/projA/MAIN/{1} release_(.*)/projA/(.*), //import/projA/REL{1}/{2} (.*)/projA/(.*), //import/projA/TAG-{1}/{2} (.*), //import/unexpected/{1} Node: adding a catch all is a good idea. |