You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2019/07/10 03:49:33 UTC

[servicecomb-toolkit] branch master updated (d53e829 -> c92635f)

This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git.


    from d53e829  Fix the Pull request link issue.
     new f6f0b5c  SCB-1351 Some issues about using toolkit plugin
     new e0a7d52  SCB-1351 Some issues about using toolkit plugin
     new 18d9dd7  SCB-1351 Some issues about using toolkit plugin
     new 15201b3  SCB-1351 Some issues about using toolkit plugin
     new 8138113  SCB-1351 Some issues about using toolkit plugin
     new 54fd93f  SCB-1351 Some issues about using toolkit plugin
     new 325d2bd  SCB-1351 Some issues about using toolkit plugin
     new c92635f  fix classmaker deadlock bug

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../servicecomb/toolkit/cli/DocGenerate.java       |   2 +-
 .../toolkit/common/ContractComparator.java         |   4 +-
 .../toolkit/common/DefaultContractsGenerator.java  |   2 +-
 .../servicecomb/toolkit/common/DocumentType.java   |   5 +-
 .../servicecomb/toolkit/common/SourceType.java     |   6 +-
 .../docgen/ContractsSwaggerUIGenerator.java        |   4 +-
 docgen/src/test/java/docgen/DocGeneratorTest.java  |   2 +-
 pom.xml                                            |   1 +
 .../toolkit/plugin/GenerateContractsDocMojo.java   |  80 ++++++++++---
 .../java/plugin/GenerateContractsDocMojoTest.java  | 131 +++++++++++++++++++--
 .../java/plugin/GenerateContractsMojoTest.java     |  14 ++-
 .../src/test/java/util/ClassMaker.java             |  86 ++++++++++++++
 .../src/test/projects/contract}/swagger.yaml       |   0
 .../pom-gencontract.xml}                           |  14 +++
 .../pom.xml                                        |  23 +++-
 .../src/main/java/demo/Application.java            |  22 ++--
 .../pom-gencontract.xml}                           |  19 +++
 .../pom.xml                                        |  24 +++-
 .../src/main/java/demo/Application.java            |  22 ++--
 .../src/main/java/demo/HelloEndPoint.java          |  34 +++---
 .../classes/demo/Application.class                 | Bin 745 -> 0 bytes
 .../classes/demo/HelloEndPoint.class               | Bin 1243 -> 0 bytes
 22 files changed, 403 insertions(+), 92 deletions(-)
 copy core/src/main/java/org/apache/servicecomb/toolkit/DocGenerator.java => common/src/main/java/org/apache/servicecomb/toolkit/common/DocumentType.java (89%)
 mode change 100755 => 100644
 copy core/src/main/java/org/apache/servicecomb/toolkit/DocGenerator.java => common/src/main/java/org/apache/servicecomb/toolkit/common/SourceType.java (89%)
 mode change 100755 => 100644
 create mode 100755 toolkit-maven-plugin/src/test/java/util/ClassMaker.java
 copy {codegen/src/test/resources => toolkit-maven-plugin/src/test/projects/contract}/swagger.yaml (100%)
 copy toolkit-maven-plugin/src/test/projects/{project-generateContracts/pom.xml => demo-non-contract/pom-gencontract.xml} (79%)
 rename toolkit-maven-plugin/src/test/projects/{project-generateContractsDoc => demo-non-contract}/pom.xml (70%)
 copy common/src/main/java/org/apache/servicecomb/toolkit/common/ComparisionType.java => toolkit-maven-plugin/src/test/projects/demo-non-contract/src/main/java/demo/Application.java (72%)
 copy toolkit-maven-plugin/src/test/projects/{project-generateContracts/pom.xml => demo-with-contract/pom-gencontract.xml} (75%)
 rename toolkit-maven-plugin/src/test/projects/{project-generateContracts => demo-with-contract}/pom.xml (68%)
 copy common/src/main/java/org/apache/servicecomb/toolkit/common/ComparisionType.java => toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/Application.java (72%)
 copy common/src/test/java/org/apache/servicecomb/toolkit/common/OtherContractsGenerator.java => toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/HelloEndPoint.java (62%)
 delete mode 100644 toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/Application.class
 delete mode 100644 toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/HelloEndPoint.class


[servicecomb-toolkit] 08/08: fix classmaker deadlock bug

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit c92635fd5bbefbcc10b4376d09029d185ca3ab6b
Author: MabinGo <bi...@huawei.com>
AuthorDate: Wed Jul 10 09:52:26 2019 +0800

    fix classmaker deadlock bug
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../java/plugin/GenerateContractsDocMojoTest.java  |  4 +-
 .../src/test/java/util/ClassMaker.java             | 59 ++++++++++++++++++++--
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
index e37770f..6237d7c 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
@@ -86,7 +86,7 @@ public class GenerateContractsDocMojoTest {
     final MavenProject project = mock(MavenProject.class);
 
     // code has no contract
-      ClassMaker.compile(testDirNonContract);
+    ClassMaker.compile(testDirNonContract);
 
     List<String> runtimeUrlPath = new ArrayList<>();
     runtimeUrlPath.add(testDirNonContract + classesPath);
@@ -106,7 +106,7 @@ public class GenerateContractsDocMojoTest {
     }
 
     // code has contract
-      ClassMaker.compile(testDir);
+    ClassMaker.compile(testDir);
 
     runtimeUrlPath.remove(0);
     runtimeUrlPath.add(testDir + classesPath);
diff --git a/toolkit-maven-plugin/src/test/java/util/ClassMaker.java b/toolkit-maven-plugin/src/test/java/util/ClassMaker.java
index 7c3f73b..2ea7822 100755
--- a/toolkit-maven-plugin/src/test/java/util/ClassMaker.java
+++ b/toolkit-maven-plugin/src/test/java/util/ClassMaker.java
@@ -18,16 +18,69 @@
 package util;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.commons.io.IOUtils;
 
 public class ClassMaker {
 
-  public static void compile(String projectPath) throws IOException {
+  public static void compile(String projectPath) throws IOException, TimeoutException, InterruptedException {
     Runtime runtime = Runtime.getRuntime();
     Process exec = runtime.exec("mvn clean package -f " + projectPath);
+
+    Worker worker = new Worker(exec);
+    worker.start();
+    ProcessStatus ps = worker.getProcessStatus();
+
     try {
-      exec.waitFor();
+      worker.join(30000);
+      if (ps.exitCode == ProcessStatus.CODE_STARTED) {
+        // not finished
+        worker.interrupt();
+        throw new TimeoutException();
+      }
     } catch (InterruptedException e) {
-      e.printStackTrace();
+      // canceled by other thread.
+      worker.interrupt();
+      throw e;
+    }
+  }
+
+  private static class Worker extends Thread {
+    private final Process process;
+
+    private ProcessStatus ps;
+
+    private Worker(Process process) {
+      this.process = process;
+      this.ps = new ProcessStatus();
     }
+
+    @Override
+    public void run() {
+      try {
+        InputStream is = process.getInputStream();
+        try {
+          ps.output = IOUtils.toString(is);
+        } catch (IOException ignore) {
+        }
+        ps.exitCode = process.waitFor();
+      } catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+      }
+    }
+
+    ProcessStatus getProcessStatus() {
+      return this.ps;
+    }
+  }
+
+  public static class ProcessStatus {
+    static final int CODE_STARTED = -257;
+
+    volatile int exitCode;
+
+    volatile String output;
   }
 }


[servicecomb-toolkit] 02/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit e0a7d52ad23002cee306fb4779e82905c4c3514a
Author: MabinGo <bi...@huawei.com>
AuthorDate: Fri Jul 5 23:32:35 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    fix bug about generating document
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../docgen/ContractsSwaggerUIGenerator.java        |  2 +-
 .../toolkit/plugin/GenerateContractsDocMojo.java   | 46 ++++++++++++++--------
 2 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
index 6926cdb..9387d2d 100755
--- a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
+++ b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
@@ -102,7 +102,7 @@ public class ContractsSwaggerUIGenerator implements DocGenerator {
   private String correctPath(String filepath) {
 
     if (!filepath.endsWith(DOC_SUFFIX)) {
-      return filepath + "-" + DOC_FORMAT + DOC_SUFFIX;
+      return filepath + DOC_SUFFIX;
     }
 
     return filepath;
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
index ba46c53..cb7a853 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
@@ -38,8 +38,10 @@ import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.project.MavenProject;
 import org.apache.servicecomb.swagger.SwaggerUtils;
-import org.apache.servicecomb.toolkit.GeneratorFactory;
 import org.apache.servicecomb.toolkit.DocGenerator;
+import org.apache.servicecomb.toolkit.GeneratorFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Mojo(name = "generateDoc", defaultPhase = LifecyclePhase.COMPILE, requiresDependencyResolution = ResolutionScope.COMPILE)
 @Execute(goal = "generateDoc",
@@ -47,44 +49,56 @@ import org.apache.servicecomb.toolkit.DocGenerator;
 )
 public class GenerateContractsDocMojo extends AbstractMojo {
 
-  @Parameter(defaultValue = "${project}", required = true, readonly = true)
+  private static Logger LOGGER = LoggerFactory.getLogger(ContractGenerator.class);
+
+  @Parameter(defaultValue = "${project}")
   private MavenProject project;
 
-  @Parameter(defaultValue = "contracts")
-  private String outputDir;
+  @Parameter(defaultValue = "contractLocation")
+  private String contractLocation;
 
-  @Parameter(defaultValue = ".yaml")
-  private String format;
+  @Parameter(defaultValue = "swagger-ui")
+  private String docType;
 
-  @Parameter(defaultValue = "build/doc")
-  private String docOutputDir;
+  @Parameter(defaultValue = "docOutput")
+  private String docOutput;
 
   @Override
   public void execute() throws MojoExecutionException, MojoFailureException {
 
-    ContractGenerator contractGenerator = new ContractGenerator(project);
-    contractGenerator.generateAndOutput(outputDir, format);
-
     try {
 
-      Files.walkFileTree(Paths.get(outputDir), new SimpleFileVisitor<Path>() {
+      if (!Files.exists(Paths.get(contractLocation))) {
+        throw new MojoFailureException("contractLocation directory is not exists");
+      }
+      if (Files.list(Paths.get(contractLocation)).count() == 0) {
+        throw new MojoFailureException(contractLocation + " has no contractLocation files");
+      }
+
+      DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, docType);
+      if (docGenerator == null) {
+        throw new MojoFailureException("DocGenerator's implementation is not found");
+      }
+
+      Files.walkFileTree(Paths.get(contractLocation), new SimpleFileVisitor<Path>() {
 
         @Override
         public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
 
-          DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, format);
           Map<String, Object> docGeneratorConfig = new HashMap<>();
           docGeneratorConfig.put("contractContent", SwaggerUtils.parseSwagger(file.toUri().toURL()));
-          docGeneratorConfig.put("outputPath",docOutputDir + File.separator
+          docGeneratorConfig.put("outputPath", docOutput + File.separator
               + file.toFile().getName().substring(0, file.toFile().getName().indexOf(".")));
           docGenerator.configure(docGeneratorConfig);
-          docGenerator.generate();
+          if (!docGenerator.generate()) {
+            throw new RuntimeException("Failed to generate doc base on file " + file.toFile().getName());
+          }
 
           return super.visitFile(file, attrs);
         }
       });
     } catch (IOException e) {
-      getLog().error(e.getMessage());
+      LOGGER.error(e.getMessage());
     }
   }
 }


[servicecomb-toolkit] 04/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 15201b370857bb25d4f62b017f438b883fcb9c61
Author: MabinGo <bi...@huawei.com>
AuthorDate: Sun Jul 7 14:45:53 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    fix bug about verifying contract
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../org/apache/servicecomb/toolkit/common/ContractComparator.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/ContractComparator.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/ContractComparator.java
index dba8dd9..417f150 100755
--- a/common/src/main/java/org/apache/servicecomb/toolkit/common/ContractComparator.java
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/ContractComparator.java
@@ -61,9 +61,9 @@ public class ContractComparator {
 
   public boolean equals() {
     if (comparisonList.size() > 0) {
-      return true;
-    } else {
       return false;
+    } else {
+      return true;
     }
   }
 


[servicecomb-toolkit] 05/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 8138113d4ceacf84f0e8cf8b8fb5ce5f42f43470
Author: MabinGo <bi...@huawei.com>
AuthorDate: Sun Jul 7 16:55:37 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    fix generating doc and UT
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../toolkit/plugin/GenerateContractsDocMojo.java   |  2 +-
 .../java/plugin/GenerateContractsDocMojoTest.java  | 27 ++++++++++++++--------
 2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
index af2cc8d..84ba37d 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
@@ -73,7 +73,7 @@ public class GenerateContractsDocMojo extends AbstractMojo {
       if (!file.exists()) {
         throw new MojoFailureException("contract location is not exists");
       }
-      if (Objects.requireNonNull(file.list()).length == 0) {
+      if (Objects.requireNonNull(file.listFiles()).length == 0) {
         throw new MojoFailureException(contractLocation + " has no contract files");
       }
 
diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
index 7992565..a6e5608 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
@@ -17,9 +17,11 @@
 
 package plugin;
 
+import static org.hamcrest.CoreMatchers.containsString;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -58,14 +60,19 @@ public class GenerateContractsDocMojoTest {
     assertNotNull(generateContractsDocMojo);
 
     String testProjectDir = baseDir + File.separator;
+    String testContractDir = testProjectDir + "contract";
+    String testDocumentDir = testProjectDir + "document";
+
+    if (!new File(testDocumentDir).exists()) {
+      assertTrue((new File(testDocumentDir)).mkdir());
+    }
 
     try {
-      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
-          testProjectDir + "contract");
-      rule.setVariableValueToObject(generateContractsDocMojo, "docOutput", testProjectDir + "document");
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testContractDir);
+      rule.setVariableValueToObject(generateContractsDocMojo, "docOutput", testDocumentDir);
       rule.setVariableValueToObject(generateContractsDocMojo, "docType", "swagger-ui");
       generateContractsDocMojo.execute();
-      assertNotEquals(0, Files.list(Paths.get(testProjectDir + "document")).count());
+      assertNotEquals(0, Files.list(Paths.get(testDocumentDir)).count());
     } catch (MojoFailureException | IOException e) {
       fail();
     }
@@ -79,17 +86,19 @@ public class GenerateContractsDocMojoTest {
       assertEquals("contract location is not exists", e.getMessage());
     }
 
+    String testEmptyDir = testProjectDir + "emptyDir";
+    if (!new File(testEmptyDir).exists()) {
+      assertTrue((new File(testEmptyDir)).mkdir());
+    }
     try {
-      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
-          testProjectDir + "emptyContractDir");
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testEmptyDir);
       generateContractsDocMojo.execute();
     } catch (MojoFailureException e) {
-      assertTrue(e.getMessage().contains("has no contract files"));
+      assertThat(e.getMessage(), containsString("has no contract files"));
     }
 
     try {
-      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
-          testProjectDir + "document");
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testDocumentDir);
       rule.setVariableValueToObject(generateContractsDocMojo, "docType", "nonImpl");
       generateContractsDocMojo.execute();
     } catch (MojoFailureException e) {


[servicecomb-toolkit] 06/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 54fd93f13b6fdb7efa8e06b2b85c19e2a0284a1c
Author: MabinGo <bi...@huawei.com>
AuthorDate: Mon Jul 8 10:29:42 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    Optimize the code according to user feedback and supplement UT
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../servicecomb/toolkit/cli/DocGenerate.java       |   2 +-
 .../servicecomb/toolkit/common/DocumentType.java   |  22 ++++++++
 .../servicecomb/toolkit/common/SourceType.java     |  23 ++++++++
 .../docgen/ContractsSwaggerUIGenerator.java        |   2 +-
 docgen/src/test/java/docgen/DocGeneratorTest.java  |   2 +-
 .../toolkit/plugin/GenerateContractsDocMojo.java   |  58 +++++++++++++++-----
 .../java/plugin/GenerateContractsDocMojoTest.java  |  59 +++++++++++++++++++--
 .../classes-no-contract/demo/Application.class     | Bin 0 -> 745 bytes
 .../classes/demo/Application.class                 | Bin 0 -> 745 bytes
 .../classes/demo/HelloEndPoint.class               | Bin 0 -> 1243 bytes
 .../projects/project-generateContractsDoc/pom.xml  |   4 +-
 11 files changed, 149 insertions(+), 23 deletions(-)

diff --git a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
index 889cd6c..3f880e6 100755
--- a/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
+++ b/cli/src/main/java/org/apache/servicecomb/toolkit/cli/DocGenerate.java
@@ -50,7 +50,7 @@ public class DocGenerate implements Runnable {
 
   @Option(name = {"-f", "--format"}, title = "document format", required = false,
       description = "format of document, as swagger-ui or asciidoc-html (swagger-ui by default)")
-  private String format = "swagger-ui";
+  private String format = "html";
 
   @Option(name = {"-o", "--output"}, title = "output directory",
       description = "location of the generated document (current dir by default)")
diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/DocumentType.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/DocumentType.java
new file mode 100644
index 0000000..d23f343
--- /dev/null
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/DocumentType.java
@@ -0,0 +1,22 @@
+/*
+ * 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.common;
+
+public enum DocumentType {
+  HTML
+}
diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/SourceType.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/SourceType.java
new file mode 100644
index 0000000..c92ea92
--- /dev/null
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/SourceType.java
@@ -0,0 +1,23 @@
+/*
+ * 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.common;
+
+public enum SourceType {
+  CODE,
+  CONTRACT
+}
diff --git a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
index 9387d2d..925a371 100755
--- a/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
+++ b/docgen/src/main/java/org/apache/servicecomb/toolkit/docgen/ContractsSwaggerUIGenerator.java
@@ -41,7 +41,7 @@ public class ContractsSwaggerUIGenerator implements DocGenerator {
 
   private static Pattern variablePattern = Pattern.compile("(?<=\\{\\{)[a-zA-Z0-9_-]*(?=\\}\\})");
 
-  private final static String DOC_FORMAT = "swagger-ui";
+  private final static String DOC_FORMAT = "html";
 
   private final static String DOC_SUFFIX = ".html";
 
diff --git a/docgen/src/test/java/docgen/DocGeneratorTest.java b/docgen/src/test/java/docgen/DocGeneratorTest.java
index ff21cf3..f7d4de5 100755
--- a/docgen/src/test/java/docgen/DocGeneratorTest.java
+++ b/docgen/src/test/java/docgen/DocGeneratorTest.java
@@ -56,7 +56,7 @@ public class DocGeneratorTest {
     Path tempDir = Files.createTempDirectory(null);
     Path outputPath = Paths.get(tempDir.toFile().getAbsolutePath()
         + File.separator + "swagger-ui.html");
-    DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, "swagger-ui");
+    DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, "html");
     Map<String, Object> docGeneratorConfig = new HashMap<>();
     docGeneratorConfig.put("contractContent", swagger);
     docGeneratorConfig.put("outputPath", outputPath.toFile().getCanonicalPath());
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
index 84ba37d..641441b 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
@@ -41,6 +41,7 @@ import org.apache.maven.project.MavenProject;
 import org.apache.servicecomb.swagger.SwaggerUtils;
 import org.apache.servicecomb.toolkit.DocGenerator;
 import org.apache.servicecomb.toolkit.GeneratorFactory;
+import org.apache.servicecomb.toolkit.common.SourceType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,34 +51,65 @@ import org.slf4j.LoggerFactory;
 )
 public class GenerateContractsDocMojo extends AbstractMojo {
 
-  private static Logger LOGGER = LoggerFactory.getLogger(ContractGenerator.class);
+  private static Logger LOGGER = LoggerFactory.getLogger(GenerateContractsDocMojo.class);
 
   @Parameter(defaultValue = "${project}")
   private MavenProject project;
 
+  @Parameter(defaultValue = "code")
+  private String sourceType;
+
   @Parameter(defaultValue = "contractLocation")
   private String contractLocation;
 
-  @Parameter(defaultValue = "swagger-ui")
-  private String docType;
+  @Parameter(defaultValue = "html")
+  private String documentType;
 
-  @Parameter(defaultValue = "docOutput")
-  private String docOutput;
+  @Parameter(defaultValue = "documentOutput")
+  private String documentOutput;
 
   @Override
   public void execute() throws MojoExecutionException, MojoFailureException {
 
     try {
 
-      File file = new File(contractLocation);
-      if (!file.exists()) {
-        throw new MojoFailureException("contract location is not exists");
-      }
-      if (Objects.requireNonNull(file.listFiles()).length == 0) {
-        throw new MojoFailureException(contractLocation + " has no contract files");
+      switch (SourceType.valueOf(sourceType.toUpperCase())) {
+        case CODE:
+          File tmpFileDir = new File("target/tmp-contract-dir");
+          if (!tmpFileDir.exists()) {
+            if (!tmpFileDir.mkdirs()) {
+              throw new MojoFailureException("fail to create directory to save contract");
+            }
+          }
+
+          Path tmpPath = Files.createTempDirectory(Paths.get(tmpFileDir.toURI()), "");
+          contractLocation = tmpPath.toFile().getCanonicalPath();
+          LOGGER.debug("temporary contract location is " + contractLocation);
+
+          ContractGenerator contractGenerator = new ContractGenerator(project);
+          contractGenerator.generateAndOutput(contractLocation, "");
+          if (Objects.requireNonNull(tmpFileDir.listFiles()).length == 0) {
+            LOGGER.info("no contract in the code");
+            return;
+          }
+
+          break;
+        case CONTRACT:
+          File file = new File(contractLocation);
+          if (!file.exists()) {
+            throw new MojoFailureException("contract location is not exists");
+          }
+
+          if (Objects.requireNonNull(file.listFiles()).length == 0) {
+            throw new MojoFailureException(contractLocation + " has no contract files");
+          }
+
+          break;
+        default:
+          throw new MojoFailureException(sourceType + " is not supported now");
       }
 
-      DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, docType);
+      DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, documentType);
       if (docGenerator == null) {
         throw new MojoFailureException("DocGenerator's implementation is not found");
       }
@@ -89,7 +121,7 @@ public class GenerateContractsDocMojo extends AbstractMojo {
 
           Map<String, Object> docGeneratorConfig = new HashMap<>();
           docGeneratorConfig.put("contractContent", SwaggerUtils.parseSwagger(file.toUri().toURL()));
-          docGeneratorConfig.put("outputPath", docOutput + File.separator
+          docGeneratorConfig.put("outputPath", documentOutput + File.separator
               + file.toFile().getName().substring(0, file.toFile().getName().indexOf(".")));
           docGenerator.configure(docGeneratorConfig);
           if (!docGenerator.generate()) {
diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
index a6e5608..1c301df 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
@@ -24,16 +24,22 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
 
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.MojoRule;
 import org.apache.maven.plugin.testing.resources.TestResources;
+import org.apache.maven.project.MavenProject;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -67,19 +73,48 @@ public class GenerateContractsDocMojoTest {
       assertTrue((new File(testDocumentDir)).mkdir());
     }
 
+    final MavenProject project = mock(MavenProject.class);
+
+    // code has no contract
+    List<String> runtimeUrlPath = new ArrayList<>();
+    runtimeUrlPath.add(baseDir + "/classes-no-contract");
+    given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
+    rule.setVariableValueToObject(generateContractsDocMojo, "project", project);
+
     try {
-      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testContractDir);
-      rule.setVariableValueToObject(generateContractsDocMojo, "docOutput", testDocumentDir);
-      rule.setVariableValueToObject(generateContractsDocMojo, "docType", "swagger-ui");
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "code");
+      generateContractsDocMojo.execute();
+
+      assertEquals(0, Objects.requireNonNull(
+          Paths.get(rule.getVariableValueFromObject(generateContractsDocMojo, "contractLocation").toString()).toFile()
+              .listFiles()).length);
+    } catch (MojoFailureException e) {
+      fail();
+    }
+
+    // code has contract
+    runtimeUrlPath.remove(0);
+    runtimeUrlPath.add(baseDir + "/classes");
+    given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
+    rule.setVariableValueToObject(generateContractsDocMojo, "project", project);
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "code");
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentOutput", testDocumentDir);
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "html");
       generateContractsDocMojo.execute();
+
       assertNotEquals(0, Files.list(Paths.get(testDocumentDir)).count());
     } catch (MojoFailureException | IOException e) {
       fail();
     }
 
     try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "contract");
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "html");
       rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", "");
       generateContractsDocMojo.execute();
+
       rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", "nonexitstdir");
       generateContractsDocMojo.execute();
     } catch (MojoFailureException e) {
@@ -91,6 +126,8 @@ public class GenerateContractsDocMojoTest {
       assertTrue((new File(testEmptyDir)).mkdir());
     }
     try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "contract");
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "html");
       rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testEmptyDir);
       generateContractsDocMojo.execute();
     } catch (MojoFailureException e) {
@@ -98,8 +135,20 @@ public class GenerateContractsDocMojoTest {
     }
 
     try {
-      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testDocumentDir);
-      rule.setVariableValueToObject(generateContractsDocMojo, "docType", "nonImpl");
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "contract");
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "html");
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testContractDir);
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "nonImpl");
+      generateContractsDocMojo.execute();
+    } catch (MojoFailureException e) {
+      assertEquals("DocGenerator's implementation is not found", e.getMessage());
+    }
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "contract");
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", "html");
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", testContractDir);
+      rule.setVariableValueToObject(generateContractsDocMojo, "documentType", testDocumentDir);
       generateContractsDocMojo.execute();
     } catch (MojoFailureException e) {
       assertEquals("DocGenerator's implementation is not found", e.getMessage());
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class
new file mode 100644
index 0000000..df126b8
Binary files /dev/null and b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class
new file mode 100644
index 0000000..df126b8
Binary files /dev/null and b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class
new file mode 100644
index 0000000..c90473d
Binary files /dev/null and b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
index 464dc22..a2d913e 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
@@ -37,8 +37,8 @@
         <extensions>true</extensions>
         <configuration>
           <contractLocation>./contract</contractLocation>
-          <docOutput>./document</docOutput>
-          <docType>swagger-ui</docType>
+          <documentOutput>./document</documentOutput>
+          <documentType>html</documentType>
         </configuration>
       </plugin>
     </plugins>


[servicecomb-toolkit] 03/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 18d9dd75048f22359dab5df4e38fa208c2a53956
Author: MabinGo <bi...@huawei.com>
AuthorDate: Sun Jul 7 14:43:28 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    add UT about generating document
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../toolkit/plugin/GenerateContractsDocMojo.java   |  10 +-
 .../java/plugin/GenerateContractsDocMojoTest.java  |  68 +-
 .../contract/swagger.yaml                          | 707 +++++++++++++++++++++
 .../projects/project-generateContractsDoc/pom.xml  |   6 +-
 4 files changed, 766 insertions(+), 25 deletions(-)

diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
index cb7a853..af2cc8d 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
@@ -27,6 +27,7 @@ import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -68,11 +69,12 @@ public class GenerateContractsDocMojo extends AbstractMojo {
 
     try {
 
-      if (!Files.exists(Paths.get(contractLocation))) {
-        throw new MojoFailureException("contractLocation directory is not exists");
+      File file = new File(contractLocation);
+      if (!file.exists()) {
+        throw new MojoFailureException("contract location is not exists");
       }
-      if (Files.list(Paths.get(contractLocation)).count() == 0) {
-        throw new MojoFailureException(contractLocation + " has no contractLocation files");
+      if (Objects.requireNonNull(file.list()).length == 0) {
+        throw new MojoFailureException(contractLocation + " has no contract files");
       }
 
       DocGenerator docGenerator = GeneratorFactory.getGenerator(DocGenerator.class, docType);
diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
index aedcb1c..7992565 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
@@ -18,18 +18,20 @@
 package plugin;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.MojoRule;
 import org.apache.maven.plugin.testing.resources.TestResources;
-import org.apache.maven.project.MavenProject;
-import org.apache.servicecomb.toolkit.plugin.GenerateContractsDocMojo;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -46,22 +48,52 @@ public class GenerateContractsDocMojoTest {
   @Rule
   public TestResources resources = new TestResources();
 
-
   @Test
   public void testGenerateContractsDoc() throws Exception {
+
     File baseDir = this.resources.getBasedir(TEST_PROJECT);
-    GenerateContractsDocMojo generateContractsDocMojo = mock(GenerateContractsDocMojo.class);
-    List<String> runtimeUrlPath = new ArrayList<>();
-    runtimeUrlPath.add(baseDir + "/target/classes");
-    final MavenProject project = mock(MavenProject.class);
-    given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
 
+    File pom = new File(baseDir, "pom.xml");
+    AbstractMojo generateContractsDocMojo = (AbstractMojo) this.rule.lookupMojo(PLUGIN_GOAL, pom);
     assertNotNull(generateContractsDocMojo);
-    rule.setVariableValueToObject(generateContractsDocMojo, "project", project);
-    rule.setVariableValueToObject(generateContractsDocMojo, "format", ".yaml");
-    assertNotNull(this.rule.getVariableValueFromObject(generateContractsDocMojo, "project"));
-    assertEquals(".yaml", this.rule.getVariableValueFromObject(generateContractsDocMojo, "format"));
-    rule.executeMojo(project, PLUGIN_GOAL);
-    generateContractsDocMojo.execute();
+
+    String testProjectDir = baseDir + File.separator;
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
+          testProjectDir + "contract");
+      rule.setVariableValueToObject(generateContractsDocMojo, "docOutput", testProjectDir + "document");
+      rule.setVariableValueToObject(generateContractsDocMojo, "docType", "swagger-ui");
+      generateContractsDocMojo.execute();
+      assertNotEquals(0, Files.list(Paths.get(testProjectDir + "document")).count());
+    } catch (MojoFailureException | IOException e) {
+      fail();
+    }
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", "");
+      generateContractsDocMojo.execute();
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation", "nonexitstdir");
+      generateContractsDocMojo.execute();
+    } catch (MojoFailureException e) {
+      assertEquals("contract location is not exists", e.getMessage());
+    }
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
+          testProjectDir + "emptyContractDir");
+      generateContractsDocMojo.execute();
+    } catch (MojoFailureException e) {
+      assertTrue(e.getMessage().contains("has no contract files"));
+    }
+
+    try {
+      rule.setVariableValueToObject(generateContractsDocMojo, "contractLocation",
+          testProjectDir + "document");
+      rule.setVariableValueToObject(generateContractsDocMojo, "docType", "nonImpl");
+      generateContractsDocMojo.execute();
+    } catch (MojoFailureException e) {
+      assertEquals("DocGenerator's implementation is not found", e.getMessage());
+    }
   }
 }
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/contract/swagger.yaml b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/contract/swagger.yaml
new file mode 100755
index 0000000..b97799c
--- /dev/null
+++ b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/contract/swagger.yaml
@@ -0,0 +1,707 @@
+---
+swagger: "2.0"
+info:
+  description: "This is a sample server Petstore server.  You can find out more about\
+    \ Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\
+    \  For this sample, you can use the api key `special-key` to test the authorization\
+    \ filters."
+  version: "1.0.0"
+  title: "Swagger Petstore"
+  termsOfService: "http://swagger.io/terms/"
+  contact:
+    email: "apiteam@swagger.io"
+  license:
+    name: "Apache 2.0"
+    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
+host: "petstore.swagger.io"
+basePath: "/v2"
+tags:
+- name: "pet"
+  description: "Everything about your Pets"
+  externalDocs:
+    description: "Find out more"
+    url: "http://swagger.io"
+- name: "store"
+  description: "Access to Petstore orders"
+- name: "user"
+  description: "Operations about user"
+  externalDocs:
+    description: "Find out more about our store"
+    url: "http://swagger.io"
+schemes:
+- "https"
+- "http"
+paths:
+  /pet:
+    post:
+      tags:
+      - "pet"
+      summary: "Add a new pet to the store"
+      description: ""
+      operationId: "addPet"
+      consumes:
+      - "application/json"
+      - "application/xml"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "Pet object that needs to be added to the store"
+        required: true
+        schema:
+          $ref: "#/definitions/Pet"
+      responses:
+        405:
+          description: "Invalid input"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+    put:
+      tags:
+      - "pet"
+      summary: "Update an existing pet"
+      description: ""
+      operationId: "updatePet"
+      consumes:
+      - "application/json"
+      - "application/xml"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "Pet object that needs to be added to the store"
+        required: true
+        schema:
+          $ref: "#/definitions/Pet"
+      responses:
+        400:
+          description: "Invalid ID supplied"
+        404:
+          description: "Pet not found"
+        405:
+          description: "Validation exception"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+  /pet/findByStatus:
+    get:
+      tags:
+      - "pet"
+      summary: "Finds Pets by status"
+      description: "Multiple status values can be provided with comma separated strings"
+      operationId: "findPetsByStatus"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "status"
+        in: "query"
+        description: "Status values that need to be considered for filter"
+        required: true
+        type: "array"
+        items:
+          type: "string"
+          enum:
+          - "available"
+          - "pending"
+          - "sold"
+          default: "available"
+        collectionFormat: "multi"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            type: "array"
+            items:
+              $ref: "#/definitions/Pet"
+        400:
+          description: "Invalid status value"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+  /pet/findByTags:
+    get:
+      tags:
+      - "pet"
+      summary: "Finds Pets by tags"
+      description: "Multiple tags can be provided with comma separated strings. Use\
+        \ tag1, tag2, tag3 for testing."
+      operationId: "findPetsByTags"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "tags"
+        in: "query"
+        description: "Tags to filter by"
+        required: true
+        type: "array"
+        items:
+          type: "string"
+        collectionFormat: "multi"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            type: "array"
+            items:
+              $ref: "#/definitions/Pet"
+        400:
+          description: "Invalid tag value"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+      deprecated: true
+  /pet/{petId}:
+    get:
+      tags:
+      - "pet"
+      summary: "Find pet by ID"
+      description: "Returns a single pet"
+      operationId: "getPetById"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "petId"
+        in: "path"
+        description: "ID of pet to return"
+        required: true
+        type: "integer"
+        format: "int64"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/Pet"
+        400:
+          description: "Invalid ID supplied"
+        404:
+          description: "Pet not found"
+      security:
+      - api_key: []
+    post:
+      tags:
+      - "pet"
+      summary: "Updates a pet in the store with form data"
+      description: ""
+      operationId: "updatePetWithForm"
+      consumes:
+      - "application/x-www-form-urlencoded"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "petId"
+        in: "path"
+        description: "ID of pet that needs to be updated"
+        required: true
+        type: "integer"
+        format: "int64"
+      - name: "name"
+        in: "formData"
+        description: "Updated name of the pet"
+        required: false
+        type: "string"
+      - name: "status"
+        in: "formData"
+        description: "Updated status of the pet"
+        required: false
+        type: "string"
+      responses:
+        405:
+          description: "Invalid input"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+    delete:
+      tags:
+      - "pet"
+      summary: "Deletes a pet"
+      description: ""
+      operationId: "deletePet"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "api_key"
+        in: "header"
+        required: false
+        type: "string"
+      - name: "petId"
+        in: "path"
+        description: "Pet id to delete"
+        required: true
+        type: "integer"
+        format: "int64"
+      responses:
+        400:
+          description: "Invalid ID supplied"
+        404:
+          description: "Pet not found"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+  /pet/{petId}/uploadImage:
+    post:
+      tags:
+      - "pet"
+      summary: "uploads an image"
+      description: ""
+      operationId: "uploadFile"
+      consumes:
+      - "multipart/form-data"
+      produces:
+      - "application/json"
+      parameters:
+      - name: "petId"
+        in: "path"
+        description: "ID of pet to update"
+        required: true
+        type: "integer"
+        format: "int64"
+      - name: "additionalMetadata"
+        in: "formData"
+        description: "Additional data to pass to server"
+        required: false
+        type: "string"
+      - name: "file"
+        in: "formData"
+        description: "file to upload"
+        required: false
+        type: "file"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/ApiResponse"
+      security:
+      - petstore_auth:
+        - "write:pets"
+        - "read:pets"
+  /store/inventory:
+    get:
+      tags:
+      - "store"
+      summary: "Returns pet inventories by status"
+      description: "Returns a map of status codes to quantities"
+      operationId: "getInventory"
+      produces:
+      - "application/json"
+      parameters: []
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            type: "object"
+            additionalProperties:
+              type: "integer"
+              format: "int32"
+      security:
+      - api_key: []
+  /store/order:
+    post:
+      tags:
+      - "store"
+      summary: "Place an order for a pet"
+      description: ""
+      operationId: "placeOrder"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "order placed for purchasing the pet"
+        required: true
+        schema:
+          $ref: "#/definitions/Order"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/Order"
+        400:
+          description: "Invalid Order"
+  /store/order/{orderId}:
+    get:
+      tags:
+      - "store"
+      summary: "Find purchase order by ID"
+      description: "For valid response try integer IDs with value >= 1 and <= 10.\
+        \ Other values will generated exceptions"
+      operationId: "getOrderById"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "orderId"
+        in: "path"
+        description: "ID of pet that needs to be fetched"
+        required: true
+        type: "integer"
+        maximum: 10.0
+        minimum: 1.0
+        format: "int64"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/Order"
+        400:
+          description: "Invalid ID supplied"
+        404:
+          description: "Order not found"
+    delete:
+      tags:
+      - "store"
+      summary: "Delete purchase order by ID"
+      description: "For valid response try integer IDs with positive integer value.\
+        \ Negative or non-integer values will generate API errors"
+      operationId: "deleteOrder"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "orderId"
+        in: "path"
+        description: "ID of the order that needs to be deleted"
+        required: true
+        type: "integer"
+        minimum: 1.0
+        format: "int64"
+      responses:
+        400:
+          description: "Invalid ID supplied"
+        404:
+          description: "Order not found"
+  /user:
+    post:
+      tags:
+      - "user"
+      summary: "Create user"
+      description: "This can only be done by the logged in user."
+      operationId: "createUser"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "Created user object"
+        required: true
+        schema:
+          $ref: "#/definitions/User"
+      responses:
+        default:
+          description: "successful operation"
+  /user/createWithArray:
+    post:
+      tags:
+      - "user"
+      summary: "Creates list of users with given input array"
+      description: ""
+      operationId: "createUsersWithArrayInput"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "List of user object"
+        required: true
+        schema:
+          type: "array"
+          items:
+            $ref: "#/definitions/User"
+      responses:
+        default:
+          description: "successful operation"
+  /user/createWithList:
+    post:
+      tags:
+      - "user"
+      summary: "Creates list of users with given input array"
+      description: ""
+      operationId: "createUsersWithListInput"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "List of user object"
+        required: true
+        schema:
+          type: "array"
+          items:
+            $ref: "#/definitions/User"
+      responses:
+        default:
+          description: "successful operation"
+  /user/login:
+    get:
+      tags:
+      - "user"
+      summary: "Logs user into the system"
+      description: ""
+      operationId: "loginUser"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "username"
+        in: "query"
+        description: "The user name for login"
+        required: true
+        type: "string"
+      - name: "password"
+        in: "query"
+        description: "The password for login in clear text"
+        required: true
+        type: "string"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            type: "string"
+          headers:
+            X-Rate-Limit:
+              type: "integer"
+              format: "int32"
+              description: "calls per hour allowed by the user"
+            X-Expires-After:
+              type: "string"
+              format: "date-time"
+              description: "date in UTC when token expires"
+        400:
+          description: "Invalid username/password supplied"
+  /user/logout:
+    get:
+      tags:
+      - "user"
+      summary: "Logs out current logged in user session"
+      description: ""
+      operationId: "logoutUser"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters: []
+      responses:
+        default:
+          description: "successful operation"
+  /user/{username}:
+    get:
+      tags:
+      - "user"
+      summary: "Get user by user name"
+      description: ""
+      operationId: "getUserByName"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "username"
+        in: "path"
+        description: "The name that needs to be fetched. Use user1 for testing. "
+        required: true
+        type: "string"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/User"
+        400:
+          description: "Invalid username supplied"
+        404:
+          description: "User not found"
+    put:
+      tags:
+      - "user"
+      summary: "Updated user"
+      description: "This can only be done by the logged in user."
+      operationId: "updateUser"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "username"
+        in: "path"
+        description: "name that need to be updated"
+        required: true
+        type: "string"
+      - in: "body"
+        name: "body"
+        description: "Updated user object"
+        required: true
+        schema:
+          $ref: "#/definitions/User"
+      responses:
+        400:
+          description: "Invalid user supplied"
+        404:
+          description: "User not found"
+    delete:
+      tags:
+      - "user"
+      summary: "Delete user"
+      description: "This can only be done by the logged in user."
+      operationId: "deleteUser"
+      produces:
+      - "application/xml"
+      - "application/json"
+      parameters:
+      - name: "username"
+        in: "path"
+        description: "The name that needs to be deleted"
+        required: true
+        type: "string"
+      responses:
+        400:
+          description: "Invalid username supplied"
+        404:
+          description: "User not found"
+securityDefinitions:
+  petstore_auth:
+    type: "oauth2"
+    authorizationUrl: "https://petstore.swagger.io/oauth/authorize"
+    flow: "implicit"
+    scopes:
+      write:pets: "modify pets in your account"
+      read:pets: "read your pets"
+  api_key:
+    type: "apiKey"
+    name: "api_key"
+    in: "header"
+definitions:
+  Order:
+    type: "object"
+    properties:
+      id:
+        type: "integer"
+        format: "int64"
+      petId:
+        type: "integer"
+        format: "int64"
+      quantity:
+        type: "integer"
+        format: "int32"
+      shipDate:
+        type: "string"
+        format: "date-time"
+      status:
+        type: "string"
+        description: "Order Status"
+        enum:
+        - "placed"
+        - "approved"
+        - "delivered"
+      complete:
+        type: "boolean"
+        default: false
+    xml:
+      name: "Order"
+  User:
+    type: "object"
+    properties:
+      id:
+        type: "integer"
+        format: "int64"
+      username:
+        type: "string"
+      firstName:
+        type: "string"
+      lastName:
+        type: "string"
+      email:
+        type: "string"
+      password:
+        type: "string"
+      phone:
+        type: "string"
+      userStatus:
+        type: "integer"
+        format: "int32"
+        description: "User Status"
+    xml:
+      name: "User"
+  Category:
+    type: "object"
+    properties:
+      id:
+        type: "integer"
+        format: "int64"
+      name:
+        type: "string"
+    xml:
+      name: "Category"
+  Tag:
+    type: "object"
+    properties:
+      id:
+        type: "integer"
+        format: "int64"
+      name:
+        type: "string"
+    xml:
+      name: "Tag"
+  Pet:
+    type: "object"
+    required:
+    - "name"
+    - "photoUrls"
+    properties:
+      id:
+        type: "integer"
+        format: "int64"
+      category:
+        $ref: "#/definitions/Category"
+      name:
+        type: "string"
+        example: "doggie"
+      photoUrls:
+        type: "array"
+        xml:
+          name: "photoUrl"
+          wrapped: true
+        items:
+          type: "string"
+      tags:
+        type: "array"
+        xml:
+          name: "tag"
+          wrapped: true
+        items:
+          $ref: "#/definitions/Tag"
+      status:
+        type: "string"
+        description: "pet status in the store"
+        enum:
+        - "available"
+        - "pending"
+        - "sold"
+    xml:
+      name: "Pet"
+  ApiResponse:
+    type: "object"
+    properties:
+      code:
+        type: "integer"
+        format: "int32"
+      type:
+        type: "string"
+      message:
+        type: "string"
+externalDocs:
+  description: "Find out more about Swagger"
+  url: "http://swagger.io"
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
index 0f97359..464dc22 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
@@ -36,9 +36,9 @@
         <version>${project.version}</version>
         <extensions>true</extensions>
         <configuration>
-          <outputDir>./target/plugin-test-output</outputDir>
-          <docOutputDir>./target/plugin-test-output</docOutputDir>
-          <format>.yaml</format>
+          <contractLocation>./contract</contractLocation>
+          <docOutput>./document</docOutput>
+          <docType>swagger-ui</docType>
         </configuration>
       </plugin>
     </plugins>


[servicecomb-toolkit] 07/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit 325d2bd335304031ea091f0ca3f3e5eb49b1bb65
Author: MabinGo <bi...@huawei.com>
AuthorDate: Tue Jul 9 18:47:05 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    Remove .class and compile source code to generate .class using the Runtime
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 pom.xml                                            |   1 +
 .../toolkit/plugin/GenerateContractsDocMojo.java   |   2 +-
 .../java/plugin/GenerateContractsDocMojoTest.java  |  35 ++++++++++++------
 .../java/plugin/GenerateContractsMojoTest.java     |  14 ++++++--
 .../src/test/java/util/ClassMaker.java             |  33 +++++++++++++++++
 .../contract/swagger.yaml                          |   0
 .../pom-gencontract.xml}                           |  14 ++++++++
 .../pom.xml                                        |  17 ++++++++-
 .../src/main/java/demo/Application.java            |  31 ++++++++++++++++
 .../pom-gencontract.xml}                           |  19 ++++++++++
 .../pom.xml                                        |  22 +++++++++++-
 .../src/main/java/demo/Application.java            |  31 ++++++++++++++++
 .../src/main/java/demo/HelloEndPoint.java          |  39 +++++++++++++++++++++
 .../classes/demo/Application.class                 | Bin 745 -> 0 bytes
 .../classes/demo/HelloEndPoint.class               | Bin 1243 -> 0 bytes
 .../classes-no-contract/demo/Application.class     | Bin 745 -> 0 bytes
 .../classes/demo/Application.class                 | Bin 745 -> 0 bytes
 .../classes/demo/HelloEndPoint.class               | Bin 1243 -> 0 bytes
 18 files changed, 242 insertions(+), 16 deletions(-)

diff --git a/pom.xml b/pom.xml
index bf8a1c7..6a92af8 100755
--- a/pom.xml
+++ b/pom.xml
@@ -260,6 +260,7 @@
           <plugin>
             <groupId>org.jacoco</groupId>
             <artifactId>jacoco-maven-plugin</artifactId>
+            <version>0.7.8</version>
           </plugin>
         </plugins>
       </build>
diff --git a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
index 641441b..866419c 100755
--- a/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
+++ b/toolkit-maven-plugin/src/main/java/org/apache/servicecomb/toolkit/plugin/GenerateContractsDocMojo.java
@@ -88,7 +88,7 @@ public class GenerateContractsDocMojo extends AbstractMojo {
 
           ContractGenerator contractGenerator = new ContractGenerator(project);
           contractGenerator.generateAndOutput(contractLocation, "");
-          if (Objects.requireNonNull(tmpFileDir.listFiles()).length == 0) {
+          if (Objects.requireNonNull(tmpPath.toFile().listFiles()).length == 0) {
             LOGGER.info("no contract in the code");
             return;
           }
diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
index 1c301df..e37770f 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsDocMojoTest.java
@@ -43,12 +43,18 @@ import org.apache.maven.project.MavenProject;
 import org.junit.Rule;
 import org.junit.Test;
 
+import util.ClassMaker;
+
 
 public class GenerateContractsDocMojoTest {
 
   private static final String PLUGIN_GOAL = "generateDoc";
 
-  private static final String TEST_PROJECT = "project-generateContractsDoc";
+  private static final String TEST_PROJECT_WITHCONTRACT = "demo-with-contract";
+
+  private static final String TEST_PROJECT_NOCONTRACT = "demo-non-contract";
+
+  private static final String TEST_PROJECT_CONTRACTLOCATION = "contract";
 
   @Rule
   public MojoRule rule = new MojoRule();
@@ -59,25 +65,32 @@ public class GenerateContractsDocMojoTest {
   @Test
   public void testGenerateContractsDoc() throws Exception {
 
-    File baseDir = this.resources.getBasedir(TEST_PROJECT);
+    File baseDir = this.resources.getBasedir(TEST_PROJECT_WITHCONTRACT);
+    File baseDirNonContract = this.resources.getBasedir(TEST_PROJECT_NOCONTRACT);
+    File contractLocation = this.resources.getBasedir(TEST_PROJECT_CONTRACTLOCATION);
 
     File pom = new File(baseDir, "pom.xml");
     AbstractMojo generateContractsDocMojo = (AbstractMojo) this.rule.lookupMojo(PLUGIN_GOAL, pom);
     assertNotNull(generateContractsDocMojo);
 
-    String testProjectDir = baseDir + File.separator;
-    String testContractDir = testProjectDir + "contract";
-    String testDocumentDir = testProjectDir + "document";
+    String testDir = baseDir + File.separator;
+    String testDirNonContract = baseDirNonContract + File.separator;
+    String classesPath = "target/classes";
+    String testDocumentDir = testDir + "document";
+    String testContractDir = contractLocation.getCanonicalPath();
 
     if (!new File(testDocumentDir).exists()) {
-      assertTrue((new File(testDocumentDir)).mkdir());
+      assertTrue((new File(testDocumentDir)).mkdirs());
     }
 
     final MavenProject project = mock(MavenProject.class);
 
     // code has no contract
+      ClassMaker.compile(testDirNonContract);
+
     List<String> runtimeUrlPath = new ArrayList<>();
-    runtimeUrlPath.add(baseDir + "/classes-no-contract");
+    runtimeUrlPath.add(testDirNonContract + classesPath);
+
     given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
     rule.setVariableValueToObject(generateContractsDocMojo, "project", project);
 
@@ -93,8 +106,10 @@ public class GenerateContractsDocMojoTest {
     }
 
     // code has contract
+      ClassMaker.compile(testDir);
+
     runtimeUrlPath.remove(0);
-    runtimeUrlPath.add(baseDir + "/classes");
+    runtimeUrlPath.add(testDir + classesPath);
     given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
     rule.setVariableValueToObject(generateContractsDocMojo, "project", project);
 
@@ -121,9 +136,9 @@ public class GenerateContractsDocMojoTest {
       assertEquals("contract location is not exists", e.getMessage());
     }
 
-    String testEmptyDir = testProjectDir + "emptyDir";
+    String testEmptyDir = testDir + "emptyDir";
     if (!new File(testEmptyDir).exists()) {
-      assertTrue((new File(testEmptyDir)).mkdir());
+      assertTrue((new File(testEmptyDir)).mkdirs());
     }
     try {
       rule.setVariableValueToObject(generateContractsDocMojo, "sourceType", "contract");
diff --git a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java
index 97c8273..0475a45 100755
--- a/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java
+++ b/toolkit-maven-plugin/src/test/java/plugin/GenerateContractsMojoTest.java
@@ -35,10 +35,14 @@ import org.apache.servicecomb.toolkit.plugin.GenerateContractsMojo;
 import org.junit.Rule;
 import org.junit.Test;
 
+import util.ClassMaker;
+
 public class GenerateContractsMojoTest {
 
   private static final String PLUGIN_GOAL = "generateContracts";
 
+  private static final String TEST_PROJECT_CONTRACT = "demo-with-contract";
+
   @Rule
   public MojoRule rule = new MojoRule();
 
@@ -47,7 +51,7 @@ public class GenerateContractsMojoTest {
 
   @Test
   public void testGenerateContracts() throws Exception {
-    executeMojo("project-generateContracts", PLUGIN_GOAL);
+    executeMojo(TEST_PROJECT_CONTRACT, PLUGIN_GOAL);
   }
 
   protected void executeMojo(String projectName, String goalName) throws Exception {
@@ -57,7 +61,8 @@ public class GenerateContractsMojoTest {
     assertTrue(baseDir.exists());
     assertTrue(baseDir.isDirectory());
 
-    File pom = new File(baseDir, "pom.xml");
+    String pomFile = "pom-gencontract.xml";
+    File pom = new File(baseDir, pomFile);
     AbstractMojo generateContractsMojo = (AbstractMojo) this.rule.lookupMojo(goalName, pom);
 
     assertNotNull(generateContractsMojo);
@@ -65,8 +70,11 @@ public class GenerateContractsMojoTest {
 
     final MavenProject project = mock(MavenProject.class);
     given(project.getFile()).willReturn(pom);
+
+    ClassMaker.compile(baseDir + File.separator + pomFile);
+
     List<String> runtimeUrlPath = new ArrayList<>();
-    runtimeUrlPath.add(baseDir + "/classes");
+    runtimeUrlPath.add(baseDir + File.separator + "target/classes");
     given(project.getRuntimeClasspathElements()).willReturn(runtimeUrlPath);
 
     rule.setVariableValueToObject(generateContractsMojo, "project", project);
diff --git a/toolkit-maven-plugin/src/test/java/util/ClassMaker.java b/toolkit-maven-plugin/src/test/java/util/ClassMaker.java
new file mode 100755
index 0000000..7c3f73b
--- /dev/null
+++ b/toolkit-maven-plugin/src/test/java/util/ClassMaker.java
@@ -0,0 +1,33 @@
+/*
+ * 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 util;
+
+import java.io.IOException;
+
+public class ClassMaker {
+
+  public static void compile(String projectPath) throws IOException {
+    Runtime runtime = Runtime.getRuntime();
+    Process exec = runtime.exec("mvn clean package -f " + projectPath);
+    try {
+      exec.waitFor();
+    } catch (InterruptedException e) {
+      e.printStackTrace();
+    }
+  }
+}
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/contract/swagger.yaml b/toolkit-maven-plugin/src/test/projects/contract/swagger.yaml
similarity index 100%
rename from toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/contract/swagger.yaml
rename to toolkit-maven-plugin/src/test/projects/contract/swagger.yaml
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml b/toolkit-maven-plugin/src/test/projects/demo-non-contract/pom-gencontract.xml
similarity index 79%
copy from toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml
copy to toolkit-maven-plugin/src/test/projects/demo-non-contract/pom-gencontract.xml
index 3af32db..c6adc8e 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/demo-non-contract/pom-gencontract.xml
@@ -29,6 +29,20 @@
   <name>This is for Test ONLY</name>
   <packaging>jar</packaging>
 
+  <parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.12.RELEASE</version>
+    <relativePath/> <!-- lookup parent from repository -->
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml b/toolkit-maven-plugin/src/test/projects/demo-non-contract/pom.xml
similarity index 78%
copy from toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
copy to toolkit-maven-plugin/src/test/projects/demo-non-contract/pom.xml
index a2d913e..025fe44 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/demo-non-contract/pom.xml
@@ -22,12 +22,27 @@
   <prerequisites>
     <maven>3.0.3</maven>
   </prerequisites>
+
   <groupId>org.apache.servicecomb.toolkit</groupId>
   <artifactId>this-is-for-test-only</artifactId>
-  <version>1.0-SNAPSHOT</version>
+  <version>0.1.0-SNAPSHOT</version>
   <name>This is for Test ONLY</name>
   <packaging>jar</packaging>
 
+  <parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.12.RELEASE</version>
+    <relativePath/> <!-- lookup parent from repository -->
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>
diff --git a/toolkit-maven-plugin/src/test/projects/demo-non-contract/src/main/java/demo/Application.java b/toolkit-maven-plugin/src/test/projects/demo-non-contract/src/main/java/demo/Application.java
new file mode 100755
index 0000000..4a4a3c2
--- /dev/null
+++ b/toolkit-maven-plugin/src/test/projects/demo-non-contract/src/main/java/demo/Application.java
@@ -0,0 +1,31 @@
+/*
+ * 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 demo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+  public Application() {
+  }
+
+  public static void main(String[] args) {
+    SpringApplication.run(Application.class, args);
+  }
+}
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml b/toolkit-maven-plugin/src/test/projects/demo-with-contract/pom-gencontract.xml
similarity index 75%
rename from toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml
rename to toolkit-maven-plugin/src/test/projects/demo-with-contract/pom-gencontract.xml
index 3af32db..99bebfe 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContracts/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/demo-with-contract/pom-gencontract.xml
@@ -29,6 +29,25 @@
   <name>This is for Test ONLY</name>
   <packaging>jar</packaging>
 
+  <parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.12.RELEASE</version>
+    <relativePath/> <!-- lookup parent from repository -->
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+    </dependency>
+
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml b/toolkit-maven-plugin/src/test/projects/demo-with-contract/pom.xml
similarity index 74%
rename from toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
rename to toolkit-maven-plugin/src/test/projects/demo-with-contract/pom.xml
index a2d913e..6c799da 100755
--- a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/pom.xml
+++ b/toolkit-maven-plugin/src/test/projects/demo-with-contract/pom.xml
@@ -22,12 +22,32 @@
   <prerequisites>
     <maven>3.0.3</maven>
   </prerequisites>
+
   <groupId>org.apache.servicecomb.toolkit</groupId>
   <artifactId>this-is-for-test-only</artifactId>
-  <version>1.0-SNAPSHOT</version>
+  <version>0.1.0-SNAPSHOT</version>
   <name>This is for Test ONLY</name>
   <packaging>jar</packaging>
 
+  <parent>
+    <groupId>org.springframework.boot</groupId>
+    <artifactId>spring-boot-starter-parent</artifactId>
+    <version>1.5.12.RELEASE</version>
+    <relativePath/> <!-- lookup parent from repository -->
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+    </dependency>
+
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>
diff --git a/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/Application.java b/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/Application.java
new file mode 100755
index 0000000..4a4a3c2
--- /dev/null
+++ b/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/Application.java
@@ -0,0 +1,31 @@
+/*
+ * 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 demo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+  public Application() {
+  }
+
+  public static void main(String[] args) {
+    SpringApplication.run(Application.class, args);
+  }
+}
diff --git a/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/HelloEndPoint.java b/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/HelloEndPoint.java
new file mode 100755
index 0000000..69e40c5
--- /dev/null
+++ b/toolkit-maven-plugin/src/test/projects/demo-with-contract/src/main/java/demo/HelloEndPoint.java
@@ -0,0 +1,39 @@
+/*
+ * 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 demo;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping({"/hello"})
+public class HelloEndPoint {
+  public HelloEndPoint() {
+  }
+
+  @GetMapping({"/sayHello"})
+  public String sayHello(String name) {
+    return "Hello, " + name;
+  }
+
+  @GetMapping({"/sayHi"})
+  public String sayHi(String name) {
+    return "Hi, " + name;
+  }
+}
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/Application.class b/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/Application.class
deleted file mode 100644
index df126b8..0000000
Binary files a/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/Application.class and /dev/null differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/HelloEndPoint.class b/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/HelloEndPoint.class
deleted file mode 100644
index c90473d..0000000
Binary files a/toolkit-maven-plugin/src/test/projects/project-generateContracts/classes/demo/HelloEndPoint.class and /dev/null differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class
deleted file mode 100644
index df126b8..0000000
Binary files a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes-no-contract/demo/Application.class and /dev/null differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class
deleted file mode 100644
index df126b8..0000000
Binary files a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/Application.class and /dev/null differ
diff --git a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class b/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class
deleted file mode 100644
index c90473d..0000000
Binary files a/toolkit-maven-plugin/src/test/projects/project-generateContractsDoc/classes/demo/HelloEndPoint.class and /dev/null differ


[servicecomb-toolkit] 01/08: SCB-1351 Some issues about using toolkit plugin

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git

commit f6f0b5c9dd5379eec3dd45654d5185c81535b65a
Author: MabinGo <bi...@huawei.com>
AuthorDate: Fri Jul 5 23:30:55 2019 +0800

    SCB-1351 Some issues about using toolkit plugin
    
    fix bug about generating contract file
    
    Signed-off-by: MabinGo <bi...@huawei.com>
---
 .../apache/servicecomb/toolkit/common/DefaultContractsGenerator.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/src/main/java/org/apache/servicecomb/toolkit/common/DefaultContractsGenerator.java b/common/src/main/java/org/apache/servicecomb/toolkit/common/DefaultContractsGenerator.java
index 590020f..d3f5973 100755
--- a/common/src/main/java/org/apache/servicecomb/toolkit/common/DefaultContractsGenerator.java
+++ b/common/src/main/java/org/apache/servicecomb/toolkit/common/DefaultContractsGenerator.java
@@ -50,7 +50,7 @@ public class DefaultContractsGenerator implements ContractsGenerator {
 
   private String outputDir = ".";
 
-  private String format = "yaml";
+  private String format = ".yaml";
 
   @Override
   public boolean canProcess(String type) {