@Override public Reader getReader(String resourceName) { Path.Relative partialPath = (Path.Relative)Path.parse(resourceName); Timestamped<Resource> partial = context.resolveResource(partialPath); if (partial != null) { return new StringReader(partial.getObject().getCharSequence().toString()); } else { return null; } }
@Override public Reader getReader(String resourceName) { Path.Relative partialPath = (Path.Relative)Path.parse(resourceName); Timestamped<Resource> partial = context.resolveResource(partialPath); if (partial != null) { return new StringReader(partial.getObject().getCharSequence().toString()); } else { return null; } }
@Override public void compile(ProcessPhase phase, ASTNode.Tag tag, TemplateModel t) throws TemplateException { String path = tag.getArgs().get("path"); Path.Absolute template = phase.resolveTemplate(Path.parse(path)); tag.getArgs().put("path", template.getCanonical()); }
@Override public void compile(ProcessPhase phase, ASTNode.Tag tag, TemplateModel t) throws TemplateException { String path = tag.getArgs().get("path"); Path.Absolute template = phase.resolveTemplate(Path.parse(path)); tag.getArgs().put("path", template.getCanonical()); }
@Override public Path.Absolute resolveTemplate(Path path) { if (path.getCanonical().equals("index.gtmpl")) { return (Path.Absolute)Path.parse("/plugin/template/tag/decorate/templates/index.gtmpl"); } else { return null; } } });
private void assertIAE(String path) { try { Path.parse(path); throw AbstractTestCase.failure("Was expecting parsing of " + path + " to throw an IAE"); } catch (IllegalArgumentException e) { // Ok } }
@Override public void compile(ProcessPhase phase, ASTNode.Tag tag, TemplateModel t) throws TemplateException { String path = tag.getArgs().get("path"); Path.Absolute resolved = phase.resolveTemplate(Path.parse(path)); if (resolved == null) { throw TemplateMetaModel.TEMPLATE_NOT_RESOLVED.failure(path); } else { tag.getArgs().put("path", resolved.getCanonical()); } }
@Override public Path.Absolute resolveTemplate(Path path) { if (path.getCanonical().equals("index.gtmpl")) { return (Path.Absolute)Path.parse("/plugin/template/tag/decorate/templates/index.gtmpl"); } else { return null; } } });
@Override public void compile(ProcessPhase phase, ASTNode.Tag tag, TemplateModel t) throws TemplateException { String path = tag.getArgs().get("path"); Path.Absolute resolved = phase.resolveTemplate(Path.parse(path)); if (resolved == null) { throw TemplateMetaModel.TEMPLATE_NOT_RESOLVED.failure(path); } else { tag.getArgs().put("path", resolved.getCanonical()); } }
private void assertIAE(String path) { try { Path.parse(path); throw AbstractTestCase.failure("Was expecting parsing of " + path + " to throw an IAE"); } catch (IllegalArgumentException e) { // Ok } }
@Test public void testResolveBug() { Path.Absolute path = (Path.Absolute)Path.parse("/plugin/less/ancestor/assets/folder/stylesheet.less"); Name dirs = path.getDirs(); Path.Absolute resolved = dirs.resolve("../stylesheet.less"); assertEquals(Path.parse("/plugin/less/ancestor/assets/stylesheet.less"), resolved); } }
@Test public void testResolveBug() { Path.Absolute path = (Path.Absolute)Path.parse("/plugin/less/ancestor/assets/folder/stylesheet.less"); Name dirs = path.getDirs(); Path.Absolute resolved = dirs.resolve("../stylesheet.less"); assertEquals(Path.parse("/plugin/less/ancestor/assets/stylesheet.less"), resolved); } }
private void assertIAE(String prefixPath, String path) { Path p = Path.parse(prefixPath); try { p.append(path); throw AbstractTestCase.failure("Was expecting parsing of " + path + " to throw an IAE"); } catch (IllegalArgumentException e) { // Ok } }
@Test public void testAppendIAE() { assertPath(false, new String[]{}, "b", null, Path.parse("").append("b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("./b")); assertPath(false, new String[]{}, "c", null, Path.parse("a/b").append("../c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("a/../b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{"a"}, "c", null, Path.parse("a/b").append("c")); assertPath(false, new String[]{"a"}, "d", null, Path.parse("a/b.c").append("d")); }
private void assertIAE(String prefixPath, String path) { Path p = Path.parse(prefixPath); try { p.append(path); throw AbstractTestCase.failure("Was expecting parsing of " + path + " to throw an IAE"); } catch (IllegalArgumentException e) { // Ok } }
@Test public void testAppendIAE() { assertPath(false, new String[]{}, "b", null, Path.parse("").append("b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("./b")); assertPath(false, new String[]{}, "c", null, Path.parse("a/b").append("../c")); assertPath(false, new String[]{}, "b", null, Path.parse("").append("a/../b")); assertPath(false, new String[]{}, "b", "c", Path.parse("").append("b.c")); assertPath(false, new String[]{"a"}, "c", null, Path.parse("a/b").append("c")); assertPath(false, new String[]{"a"}, "d", null, Path.parse("a/b.c").append("d")); }
@Override public void processAnnotationRemoved(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = metaModel.getChild(TemplateContainerMetaModel.KEY); Path removedPath = Path.parse((String)removed.get("value")); Path.Absolute absRemoved = templates.resolvePath(removedPath); metaModel.processingContext.info("Removing template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absRemoved); templates.remove(variableElt); } } }
@Override public void processAnnotationRemoved(ApplicationMetaModel metaModel, AnnotationKey key, AnnotationState removed) { if (key.getType().toString().equals(juzu.Path.class.getName())) { if (key.getElement() instanceof ElementHandle.Field) { ElementHandle.Field variableElt = (ElementHandle.Field)key.getElement(); TemplateContainerMetaModel templates = metaModel.getChild(TemplateContainerMetaModel.KEY); Path removedPath = Path.parse((String)removed.get("value")); Path.Absolute absRemoved = templates.resolvePath(removedPath); metaModel.processingContext.info("Removing template ref " + variableElt.getTypeName() + "#" + variableElt.getName() + " " + absRemoved); templates.remove(variableElt); } } }
@Test public void testResolveDotInRawName() throws Exception { Name name = Name.parse("foo"); Path path = Path.parse("a.b.c"); Path.Absolute file = name.resolve(path); assertEquals("foo", file.getDirs().toString()); assertEquals("a.b.c", file.getSimpleName()); assertEquals("b.c", file.ext); assertEquals("a", file.getRawName()); assertEquals("foo.a", file.getName().toString()); }
@Test public void testResolveDotInRawName() throws Exception { Name name = Name.parse("foo"); Path path = Path.parse("a.b.c"); Path.Absolute file = name.resolve(path); assertEquals("foo", file.getDirs().toString()); assertEquals("a.b.c", file.getSimpleName()); assertEquals("b.c", file.ext); assertEquals("a", file.getRawName()); assertEquals("foo.a", file.getName().toString()); }