From 53ed4accc64ce3b5c00e29c2d9c12591b60e96a7 Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Thu, 3 Oct 2019 16:25:23 -0400 Subject: [PATCH 1/4] Add production protection directive --- build.gradle | 1 + .../java/gyro/sample/ProdutionGyroUi.java | 70 +++++++++++++++++++ ...roductionProtectionDirectiveProcessor.java | 23 ++++++ 3 files changed, 94 insertions(+) create mode 100644 src/main/java/gyro/sample/ProdutionGyroUi.java create mode 100644 src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java diff --git a/build.gradle b/build.gradle index 90b58e4..da2b6d5 100644 --- a/build.gradle +++ b/build.gradle @@ -53,6 +53,7 @@ dependencies { implementation 'com.psddev:dari-util:3.3.607-xe0f27a' implementation 'org.yaml:snakeyaml:1.24' implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.0.201906121030-r' + implementation 'org.fusesource.jansi:jansi:1.16' implementation 'us.monoid.web:resty:0.3.2' implementation 'gyro:gyro-aws-provider:0.15-SNAPSHOT' implementation enforcedPlatform('software.amazon.awssdk:bom:2.5.70') diff --git a/src/main/java/gyro/sample/ProdutionGyroUi.java b/src/main/java/gyro/sample/ProdutionGyroUi.java new file mode 100644 index 0000000..d91e3b2 --- /dev/null +++ b/src/main/java/gyro/sample/ProdutionGyroUi.java @@ -0,0 +1,70 @@ +package gyro.sample; + +import gyro.core.GyroUI; +import org.fusesource.jansi.AnsiRenderer; + +public class ProdutionGyroUi implements GyroUI { + + private GyroUI delegate; + + public ProdutionGyroUi(GyroUI delegate) { + this.delegate = delegate; + } + + @Override + public boolean isVerbose() { + return delegate.isVerbose(); + } + + @Override + public void setVerbose(boolean b) { + delegate.setVerbose(b); + } + + @Override + public boolean readBoolean(Boolean aBoolean, String s, Object... objects) { + s = AnsiRenderer.render("[PRODUCTION] " + s, AnsiRenderer.Code.FG_RED.toString()); + return delegate.readBoolean(aBoolean, s, objects); + } + + @Override + public void readEnter(String s, Object... objects) { + delegate.readEnter(s, objects); + } + + @Override + public > E readNamedOption(E e) { + return delegate.readNamedOption(e); + } + + @Override + public String readPassword(String s, Object... objects) { + return delegate.readPassword(s, objects); + } + + @Override + public String readText(String s, Object... objects) { + return delegate.readText(s, objects); + } + + @Override + public void indent() { + delegate.indent(); + } + + @Override + public void unindent() { + delegate.unindent(); + } + + @Override + public void write(String s, Object... objects) { + delegate.write(s, objects); + } + + @Override + public void replace(String s, Object... objects) { + delegate.replace(s, objects); + } + +} diff --git a/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java b/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java new file mode 100644 index 0000000..a3048bb --- /dev/null +++ b/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java @@ -0,0 +1,23 @@ +package gyro.sample.directive; + +import gyro.core.GyroCore; +import gyro.core.GyroUI; +import gyro.core.Type; +import gyro.core.directive.DirectiveProcessor; +import gyro.core.scope.RootScope; +import gyro.lang.ast.block.DirectiveNode; +import gyro.sample.ProdutionGyroUi; + +@Type("production") +public class ProductionProtectionDirectiveProcessor extends DirectiveProcessor { + + @Override + public void process(RootScope rootScope, DirectiveNode directiveNode) throws Exception { + GyroUI ui = GyroCore.popUi(); + if (!(ui instanceof ProdutionGyroUi)) { + ui = new ProdutionGyroUi(ui); + } + + GyroCore.pushUi(ui); + } +} From 2d2100786605c10f31d7dfc0bab39f115087b395 Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Thu, 3 Oct 2019 11:48:06 -0400 Subject: [PATCH 2/4] Update sample plugin and core dependency version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index da2b6d5..d12ddc1 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ if (System.getenv('TRAVIS_BRANCH') && System.getenv('TRAVIS_PULL_REQUEST') == 'f } group = 'gyro' -version = '0.15-SNAPSHOT' +version = '0.99.0-SNAPSHOT' java { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -48,7 +48,7 @@ repositories { } dependencies { - api 'gyro:gyro-core:0.15-SNAPSHOT' + api 'gyro:gyro-core:0.99.0-SNAPSHOT' implementation 'com.psddev:dari-util:3.3.607-xe0f27a' implementation 'org.yaml:snakeyaml:1.24' From e75789452feb68a66dcd43fca2dea96a0b879d3a Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Thu, 3 Oct 2019 13:50:22 -0400 Subject: [PATCH 3/4] Update aws provider dependency version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d12ddc1..0d69297 100644 --- a/build.gradle +++ b/build.gradle @@ -55,7 +55,7 @@ dependencies { implementation 'org.eclipse.jgit:org.eclipse.jgit:5.4.0.201906121030-r' implementation 'org.fusesource.jansi:jansi:1.16' implementation 'us.monoid.web:resty:0.3.2' - implementation 'gyro:gyro-aws-provider:0.15-SNAPSHOT' + implementation 'gyro:gyro-aws-provider:0.99.0-SNAPSHOT' implementation enforcedPlatform('software.amazon.awssdk:bom:2.5.70') implementation 'software.amazon.awssdk:s3' implementation 'software.amazon.awssdk:apache-client' From bff40089cb7e43fdf6d6c75a67341377c5b15b7d Mon Sep 17 00:00:00 2001 From: Hao Sun Date: Thu, 3 Oct 2019 18:13:04 -0400 Subject: [PATCH 4/4] Change production directive to FileScope based --- .../directive/ProductionProtectionDirectiveProcessor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java b/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java index a3048bb..903cb88 100644 --- a/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java +++ b/src/main/java/gyro/sample/directive/ProductionProtectionDirectiveProcessor.java @@ -4,15 +4,15 @@ import gyro.core.GyroUI; import gyro.core.Type; import gyro.core.directive.DirectiveProcessor; -import gyro.core.scope.RootScope; +import gyro.core.scope.FileScope; import gyro.lang.ast.block.DirectiveNode; import gyro.sample.ProdutionGyroUi; @Type("production") -public class ProductionProtectionDirectiveProcessor extends DirectiveProcessor { +public class ProductionProtectionDirectiveProcessor extends DirectiveProcessor { @Override - public void process(RootScope rootScope, DirectiveNode directiveNode) throws Exception { + public void process(FileScope fileScope, DirectiveNode directiveNode) throws Exception { GyroUI ui = GyroCore.popUi(); if (!(ui instanceof ProdutionGyroUi)) { ui = new ProdutionGyroUi(ui);