openrewrite / rewrite-build-gradle-plugin

Common build logic for building OpenRewrite and recipe jars.
Apache License 2.0
4 stars 5 forks source link

Update examples extractor to support multiple sources and path in an example #12

Closed kunli2 closed 1 year ago

kunli2 commented 1 year ago

Update examples extractor to support

  1. multiple sources
  2. file path

Here is an example of an extracted example :

type: specs.openrewrite.org/v1beta/example
recipeName: org.openrewrite.java.migrate.UpgradeToJava17
examples:
  - description: ""
    sources:
      - before: |
          <project>
            <modelVersion>4.0.0</modelVersion>

            <properties>
              <java.version>1.8</java.version>
              <maven.compiler.source>1.8</maven.compiler.source>
              <maven.compiler.target>1.8</maven.compiler.target>
            </properties>

            <groupId>com.mycompany.app</groupId>
            <artifactId>my-app</artifactId>
            <version>1</version>
          </project>
        after: |
          <project>
            <modelVersion>4.0.0</modelVersion>

            <properties>
              <java.version>17</java.version>
              <maven.compiler.source>17</maven.compiler.source>
              <maven.compiler.target>17</maven.compiler.target>
            </properties>

            <groupId>com.mycompany.app</groupId>
            <artifactId>my-app</artifactId>
            <version>1</version>
          </project>
        path: pom.xml
        language: xml
      - before: |
          package com.abc;

          import java.util.Collections;
          import java.util.List;
          import java.util.Map;
          import java.util.Set;

          class A {
             private static final List<String> staticList = Collections.singletonList("0");

             /* This is a comment */
             public void test() {
                 // This is a comment
                 Set<String> stringSet = Collections.singleton("aaa");
                 List<String> stringList = Collections.singletonList("bbb");
                 Map<String, Object> stringMap = Collections.singletonMap("a-key", "a-value");
             }
          }
        after: |
          package com.abc;

          import java.util.List;
          import java.util.Map;
          import java.util.Set;

          class A {
             private static final List<String> staticList = List.of("0");

             /* This is a comment */
             public void test() {
                 // This is a comment
                 Set<String> stringSet = Set.of("aaa");
                 List<String> stringList = List.of("bbb");
                 Map<String, Object> stringMap = Map.of("a-key", "a-value");
             }
          }
        language: java