You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by neykov <gi...@git.apache.org> on 2016/10/21 08:50:19 UTC
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
GitHub user neykov opened a pull request:
https://github.com/apache/brooklyn-server/pull/392
[WIP] $brooklyn:self().template("freemarker")
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/neykov/brooklyn-server format-string
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/392.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #392
----
commit 0af28629036dd9f915be25ddabfe30c5f80bda21
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date: 2016-08-09T14:06:46Z
format string
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server issue #392: [WIP] $brooklyn:self().template("freemarker")
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:
https://github.com/apache/brooklyn-server/pull/392
Closing in favour of https://github.com/apache/brooklyn-server/pull/786.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/392#discussion_r85093511
--- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/parse/DslParser.java ---
@@ -52,7 +53,29 @@ public Object next() {
if (index >= expression.length())
throw new IllegalStateException("Unexpected end of expression to parse, looking for content since position "+start);
- if (expression.charAt(index)=='"') {
+ String multilineTemplatePrefix = "$brooklyn:template";
+ if (expression.regionMatches(index, multilineTemplatePrefix, 0, multilineTemplatePrefix.length())) {
+ // skip to next line
+ char c;
+ do {
+ c = expression.charAt(index);
+ index++;
+ } while(c != '\n' && index<expression.length());
+ if (index < expression.length()) {
+ int stringStart = index;
+ index = expression.length();
+ return new QuotedString('"' + JavaStringEscapes.escapeJavaString(expression.substring(stringStart, index)) + '"');
--- End diff --
Need to skip trailing newline/whitespace on the expression: I tried updating the test to add further text:
```java
protected Entity entityWithMultilineTemplatedString() throws Exception {
return setupAndCheckTestEntityInBasicYamlWith(
" id: x",
" brooklyn.config:",
" test.sourceName: hello world",
" test.confName: |",
" $brooklyn:template",
" ${config['test.sourceName']}",
" test.other: something else");
}
```
and it breaks with
```
java.lang.AssertionError: expected [hello world] but found [hello world
]
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by neykov <gi...@git.apache.org>.
Github user neykov closed the pull request at:
https://github.com/apache/brooklyn-server/pull/392
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/392#discussion_r85084528
--- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/parse/DslParser.java ---
@@ -52,7 +53,29 @@ public Object next() {
if (index >= expression.length())
throw new IllegalStateException("Unexpected end of expression to parse, looking for content since position "+start);
- if (expression.charAt(index)=='"') {
+ String multilineTemplatePrefix = "$brooklyn:template";
+ if (expression.regionMatches(index, multilineTemplatePrefix, 0, multilineTemplatePrefix.length())) {
+ // skip to next line
+ char c;
+ do {
+ c = expression.charAt(index);
+ index++;
+ } while(c != '\n' && index<expression.length());
+ if (index < expression.length()) {
+ int stringStart = index;
+ index = expression.length();
+ return new QuotedString('"' + JavaStringEscapes.escapeJavaString(expression.substring(stringStart, index)) + '"');
--- End diff --
This is doing escapes, while the non-multiline version below does not (line 91) - should they be consistent?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/392#discussion_r85079113
--- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/BrooklynDslInterpreter.java ---
@@ -147,7 +147,7 @@ public Object evaluate(Object f, boolean deepEvaluation) {
}
if (f instanceof QuotedString) {
- return ((QuotedString)f).unwrapped();
+ return BrooklynDslCommon.template(((QuotedString)f).unwrapped());
--- End diff --
Does this turn *every* quoted string into a template? Is that perhaps too broad a change - maybe better to restrict to explicit `$brooklyn:template()` to avoid possibility of starting to interpret text as templates, perhaps in formatString expressions? I dare say it's unlikely, but possible.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/392#discussion_r85094334
--- Diff: core/src/test/java/org/apache/brooklyn/util/core/text/TemplateProcessorTest.java ---
@@ -71,6 +71,15 @@ public void testEntityConfig() {
}
@Test
+ public void testDsl() {
+ TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+ .configure(TestEntity.CONF_NAME, "myval"));
+ String templateContents = "${brooklyn(\"id\")}";
--- End diff --
Surely should be
```java
String templateContents = "${config['" + TestEntity.CONF_NAME.getName() + "']}";
```
As written this test breaks for me.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] brooklyn-server pull request #392: [WIP] $brooklyn:self().template("freemark...
Posted by geomacy <gi...@git.apache.org>.
Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/392#discussion_r85089421
--- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/parse/DslParser.java ---
@@ -52,7 +53,29 @@ public Object next() {
if (index >= expression.length())
throw new IllegalStateException("Unexpected end of expression to parse, looking for content since position "+start);
- if (expression.charAt(index)=='"') {
+ String multilineTemplatePrefix = "$brooklyn:template";
--- End diff --
Seems odd to have just `$brooklyn:template` and then the line break - can this not be done something like
```
$brooklyn:template: |
my ${template} here
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---