generated from moderneinc/rewrite-recipe-starter
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/security-scan
- Loading branch information
Showing
56 changed files
with
7,403 additions
and
1,587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[src/test*/java/**.java] | ||
indent_size = 4 | ||
ij_continuation_indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: comment-pr | ||
|
||
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow | ||
on: | ||
workflow_run: | ||
workflows: ["receive-pr"] | ||
types: | ||
- completed | ||
|
||
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
# Since this pull request has write permissions on the target repo, we should **NOT** execute any untrusted code. | ||
jobs: | ||
post-suggestions: | ||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||
uses: openrewrite/gh-automation/.github/workflows/comment-pr.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: receive-pr | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: '${{ github.workflow }} @ ${{ github.ref }}' | ||
cancel-in-progress: true | ||
|
||
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | ||
# Since this pull request receives untrusted code, we should **NOT** have any secrets in the environment. | ||
jobs: | ||
upload-patch: | ||
uses: openrewrite/gh-automation/.github/workflows/receive-pr.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionSha256Sum=57dafb5c2622c6cc08b993c85b7c06956a2f53536432a30ead46166dbca0f1e9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/org/openrewrite/jenkins/AddJellyXmlDeclaration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* <p> | ||
* Licensed 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 | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.openrewrite.jenkins; | ||
|
||
import org.openrewrite.ExecutionContext; | ||
import org.openrewrite.Recipe; | ||
import org.openrewrite.text.PlainText; | ||
import org.openrewrite.text.PlainTextVisitor; | ||
|
||
/** | ||
* Recipe to add an XML declaration to Jelly files. | ||
*/ | ||
public class AddJellyXmlDeclaration extends Recipe { | ||
private static final String JELLY_DECLARATION = "<?jelly escape-by-default='true'?>"; | ||
|
||
/** | ||
* Returns the display name of the recipe. | ||
* | ||
* @return the display name of the recipe | ||
*/ | ||
@Override | ||
public String getDisplayName() { | ||
return "Add XML declaration to Jelly files"; | ||
} | ||
|
||
/** | ||
* Returns the description of the recipe. | ||
* | ||
* @return the description of the recipe | ||
*/ | ||
@Override | ||
public String getDescription() { | ||
return "Ensure the XML declaration `<?jelly escape-by-default='true'?>` is present in all `.jelly` files."; | ||
} | ||
|
||
/** | ||
* Returns a visitor that adds the XML declaration to Jelly files. | ||
* | ||
* @return a PlainTextVisitor that adds the XML declaration | ||
*/ | ||
@Override | ||
public PlainTextVisitor<ExecutionContext> getVisitor() { | ||
return new PlainTextVisitor<ExecutionContext>() { | ||
|
||
/** | ||
* Visits the text and adds the XML declaration if necessary. | ||
* | ||
* @param text the PlainText object representing the file content | ||
* @param ctx the execution context | ||
*/ | ||
@Override | ||
public PlainText visitText(PlainText text, ExecutionContext ctx) { | ||
if (text.getSourcePath().toString().endsWith(".jelly")) { | ||
String content = text.getText().trim(); | ||
if (content.isEmpty()) { | ||
return text.withText(JELLY_DECLARATION); | ||
} | ||
String lineEnding = content.contains("\r\n") ? "\r\n" : "\n"; | ||
if (content.toLowerCase().matches("^<\\?jelly\\s+[^>]*>") && !content.startsWith(JELLY_DECLARATION)) { | ||
content = content.substring(content.indexOf(lineEnding) + lineEnding.length()); | ||
} | ||
if (!content.startsWith(JELLY_DECLARATION)) { | ||
content = JELLY_DECLARATION + lineEnding + content; | ||
return text.withText(content); | ||
} | ||
} | ||
return text; | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.