Skip to content

Latest commit

 

History

History
175 lines (148 loc) · 4.49 KB

addcommenttoxmltag.md

File metadata and controls

175 lines (148 loc) · 4.49 KB

Add a comment to a XML tag

org.openrewrite.xml.AddCommentToXmlTag

Adds a comment as the first element in a XML tag.

Source

GitHub, Issue Tracker, Maven Central

  • groupId: org.openrewrite
  • artifactId: rewrite-xml
  • version: 8.1.3

Options

Type Name Description
String xPath An XPath expression used to find matching tags.
String commentText The text to add as a comment..

Example

Parameters
Parameter Value
xPath /project/dependencies/
commentText Comment text

{% tabs %} {% tab title="pom.xml" %}

Before

{% code title="pom.xml" %}

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>29.0-jre</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

{% endcode %}

After

{% code title="pom.xml" %}

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
  <dependencies>
    <!-- Comment text -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>29.0-jre</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

{% endcode %}

{% endtab %} {% tab title="Diff" %} {% code %}

--- pom.xml
+++ pom.xml
@@ -7,0 +7,1 @@
  <version>1</version>
  <dependencies>
+   <!-- Comment text -->
    <dependency>

{% endcode %} {% endtab %} {% endtabs %}

Usage

This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly. To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml create a new recipe with a unique name. For example: com.yourorg.AddCommentToXmlTagExample. Here's how you can define and customize such a recipe within your rewrite.yml:

{% code title="rewrite.yml" %}

---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.AddCommentToXmlTagExample
displayName: Add a comment to a `XML` tag example
recipeList:
  - org.openrewrite.xml.AddCommentToXmlTag:
      xPath: /project/dependencies/dependency
      commentText: This is excluded due to CVE <X> and will be removed when we upgrade the next version is available.

{% endcode %}

Now that com.yourorg.AddCommentToXmlTagExample has been defined activate it in your build file: {% tabs %} {% tab title="Gradle" %} {% code title="build.gradle" %}

plugins {
    id("org.openrewrite.rewrite") version("6.1.4")
}

rewrite {
    activeRecipe("com.yourorg.AddCommentToXmlTagExample")
}

repositories {
    mavenCentral()
}

{% endcode %} {% endtab %} {% tab title="Maven" %} {% code title="pom.xml" %}

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>5.2.4</version>
        <configuration>
          <activeRecipes>
            <recipe>com.yourorg.AddCommentToXmlTagExample</recipe>
          </activeRecipes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

{% endcode %} {% endtab %} {% endtabs %}

Contributors

See how this recipe works across multiple open-source repositories

Moderne Link Image

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.