You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ch...@apache.org on 2019/12/12 03:36:05 UTC
[servicecomb-toolkit] branch master updated: SCB-1651: toolkit
style check wrong exit code when not passed.
This is an automated email from the ASF dual-hosted git repository.
chanjarster pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git
The following commit(s) were added to refs/heads/master by this push:
new a734b44 SCB-1651: toolkit style check wrong exit code when not passed.
a734b44 is described below
commit a734b441fe26e79cac77fe57bc0a9e812d91acae
Author: Tang Cheng <ch...@supwisdom.com>
AuthorDate: Mon Dec 9 13:11:29 2019 +0800
SCB-1651: toolkit style check wrong exit code when not passed.
---
cli/pom.xml | 8 ++++++-
.../toolkit/cli/CheckCompatibilityBase.java | 2 +-
.../servicecomb/toolkit/cli/CheckStyleBase.java | 16 +++++++-------
.../servicecomb/toolkit/cli/ToolkitMain.java | 9 ++++++--
.../toolkit/cli/ValidationFailedException.java | 25 ++++++++++++++++++++++
.../apache/servicecomb/toolkit/cli/CliTest.java | 8 +++++++
pom.xml | 8 +++++++
7 files changed, 64 insertions(+), 12 deletions(-)
diff --git a/cli/pom.xml b/cli/pom.xml
index 5d0c5bf..3e4131d 100644
--- a/cli/pom.xml
+++ b/cli/pom.xml
@@ -31,7 +31,7 @@
<properties>
<main.class>org.apache.servicecomb.toolkit.cli.ToolkitMain</main.class>
-
+
</properties>
<dependencies>
@@ -86,6 +86,12 @@
<groupId>org.apache.servicecomb.toolkit</groupId>
<artifactId>oas-validator-compatibility</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>com.github.stefanbirkner</groupId>
+ <artifactId>system-rules</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckCompatibilityBase.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckCompatibilityBase.java
index 298132f..10792b1 100644
--- a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckCompatibilityBase.java
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckCompatibilityBase.java
@@ -80,7 +80,7 @@ public class CheckCompatibilityBase implements Runnable {
violation.getError()
);
}
- return;
+ throw new ValidationFailedException("check not passed");
}
LOGGER.info("Everything is good");
}
diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckStyleBase.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckStyleBase.java
index 615bd5f..cbc78e3 100644
--- a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckStyleBase.java
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/CheckStyleBase.java
@@ -21,6 +21,13 @@ import com.google.common.base.Charsets;
import io.airlift.airline.Option;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Properties;
+import java.util.StringJoiner;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.servicecomb.toolkit.oasv.FactoryOptions;
@@ -35,13 +42,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.Properties;
-import java.util.StringJoiner;
public class CheckStyleBase implements Runnable {
@@ -92,7 +92,7 @@ public class CheckStyleBase implements Runnable {
LOGGER.info("path : {}\nerror : {}\n------",
OasObjectPropertyLocation.toPathString(violation.getLocation()), violation.getError());
}
- return;
+ throw new ValidationFailedException("check not passed");
}
LOGGER.info("Everything is good");
}
diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java
index 5a75e86..8b637e7 100755
--- a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ToolkitMain.java
@@ -43,9 +43,14 @@ public class ToolkitMain {
CheckCompatibility.class, CheckCompatibilityAbbr.class,
Help.class
);
- Runnable cmd = builder.build().parse(args);
+ try {
+ Runnable cmd = builder.build().parse(args);
- cmd.run();
+ cmd.run();
+ } catch (ValidationFailedException ex) {
+ ex.printStackTrace(System.err);
+ System.exit(1);
+ }
}
private static void initialProjectVersion() {
diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ValidationFailedException.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ValidationFailedException.java
new file mode 100644
index 0000000..83fd541
--- /dev/null
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/ValidationFailedException.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.servicecomb.toolkit.cli;
+
+public class ValidationFailedException extends RuntimeException {
+ public ValidationFailedException(String msg) {
+ super(msg);
+ }
+}
diff --git a/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java b/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
index 0adc4a9..d3279d4 100755
--- a/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
+++ b/cli/src/test/java/org/apache/servicecomb/toolkit/cli/CliTest.java
@@ -18,7 +18,9 @@
package org.apache.servicecomb.toolkit.cli;
import org.junit.Assert;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import java.io.IOException;
import java.nio.file.Files;
@@ -27,6 +29,8 @@ import java.nio.file.Paths;
import java.util.Arrays;
public class CliTest {
+ @Rule
+ public final ExpectedSystemExit exit = ExpectedSystemExit.none();
@Test
public void testGenerateServiceCombCodeFromSingleContract() throws IOException {
@@ -93,6 +97,7 @@ public class CliTest {
@Test
public void testCheckStyle() throws IOException {
+ exit.expectSystemExitWithStatus(1);
String[] args = new String[] {
"checkstyle",
"-r",
@@ -105,6 +110,7 @@ public class CliTest {
@Test
public void testCheckStyleAbbr() throws IOException {
+ exit.expectSystemExitWithStatus(1);
String[] args = new String[] {
"cs",
"-r",
@@ -117,6 +123,7 @@ public class CliTest {
@Test
public void testCheckCompatibility() throws IOException {
+ exit.expectSystemExitWithStatus(1);
String[] args = new String[] {
"checkcompatibility",
Paths.get("./src/test/resources/oas/compatibility-left.yaml").toFile().getCanonicalPath(),
@@ -127,6 +134,7 @@ public class CliTest {
@Test
public void testCheckCompatibilityAbbr() throws IOException {
+ exit.expectSystemExitWithStatus(1);
String[] args = new String[] {
"cc",
Paths.get("./src/test/resources/oas/compatibility-left.yaml").toFile().getCanonicalPath(),
diff --git a/pom.xml b/pom.xml
index 4c59084..9c86a97 100644
--- a/pom.xml
+++ b/pom.xml
@@ -80,6 +80,7 @@
<apache-rat-plugin.version>0.13</apache-rat-plugin.version>
<license-maven-plugin.version>1.19</license-maven-plugin.version>
<jacoco-maven-plugin.version>0.7.8</jacoco-maven-plugin.version>
+ <system-rules.version>1.19.0</system-rules.version>
</properties>
<licenses>
@@ -460,6 +461,13 @@
<artifactId>bootstrap</artifactId>
<version>${webjars.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>com.github.stefanbirkner</groupId>
+ <artifactId>system-rules</artifactId>
+ <version>${system-rules.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>