Skip to content

Commit

Permalink
Merge branch 'main' into xslt-transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Jun 20, 2024
2 parents bb62000 + 22ac272 commit d0cc544
Show file tree
Hide file tree
Showing 57 changed files with 2,087 additions and 233 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/comment-pr.yml
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
68 changes: 68 additions & 0 deletions .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
with:
recipe: 'org.openrewrite.recipes.OpenRewriteBestPracticesSubset'
rewrite_yml: |
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.OpenRewriteBestPracticesSubset
displayName: OpenRewrite best practices
description: Best practices for OpenRewrite recipe development.
recipeList:
- org.openrewrite.recipes.JavaRecipeBestPracticesSubset
- org.openrewrite.recipes.RecipeTestingBestPracticesSubset
- org.openrewrite.recipes.RecipeNullabilityBestPractices
#- org.openrewrite.java.OrderImports
#- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
- org.openrewrite.staticanalysis.InlineVariable
- org.openrewrite.staticanalysis.MissingOverrideAnnotation
- org.openrewrite.staticanalysis.UseDiamondOperator
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.JavaRecipeBestPracticesSubset
displayName: Java Recipe best practices
description: Best practices for Java recipe development.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.Recipe
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.BlankLinesAroundFieldsWithAnnotations
- org.openrewrite.java.recipes.ExecutionContextParameterName
- org.openrewrite.java.recipes.MissingOptionExample
- org.openrewrite.java.recipes.RecipeEqualsAndHashCodeCallSuper
- org.openrewrite.java.recipes.UseTreeRandomId
- org.openrewrite.staticanalysis.NeedBraces
#- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.recipes.RecipeTestingBestPracticesSubset
displayName: Recipe testing best practices
description: Best practices for testing recipes.
preconditions:
- org.openrewrite.java.search.FindTypes:
fullyQualifiedTypeName: org.openrewrite.test.RewriteTest
checkAssignability: true
recipeList:
- org.openrewrite.java.recipes.RewriteTestClassesShouldNotBePublic
#- org.openrewrite.java.recipes.SelectRecipeExamples
- org.openrewrite.java.recipes.SourceSpecTextBlockIndentation
- org.openrewrite.java.testing.cleanup.RemoveTestPrefix
- org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
- org.openrewrite.staticanalysis.NeedBraces
- org.openrewrite.staticanalysis.RemoveSystemOutPrintln
4 changes: 2 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/DataTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public class DataTable<Row> {
private final Class<Row> type;

@Language("markdown")
private final String displayName;
private final @NlsRewrite.DisplayName String displayName;

@Language("markdown")
private final String description;
private final @NlsRewrite.Description String description;

@Setter
private boolean enabled = true;
Expand Down
31 changes: 31 additions & 0 deletions rewrite-core/src/main/java/org/openrewrite/NlsRewrite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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;

import org.jetbrains.annotations.Nls;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class NlsRewrite {
@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface DisplayName {
}

@Target({ElementType.TYPE_USE, ElementType.PARAMETER, ElementType.METHOD})
public @Nls(capitalization = Nls.Capitalization.Sentence) @interface Description {
}
}
8 changes: 6 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Option {
@Language("markdown") String displayName() default "";
@Language("markdown") String description() default "";
@Language("markdown") @NlsRewrite.DisplayName String displayName() default "";

@Language("markdown") @NlsRewrite.Description String description() default "";

String example() default "";

String[] valid() default "";

boolean required() default true;
}
5 changes: 3 additions & 2 deletions rewrite-core/src/main/java/org/openrewrite/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Setter;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.Nls;
import org.openrewrite.config.DataTableDescriptor;
import org.openrewrite.config.OptionDescriptor;
import org.openrewrite.config.RecipeDescriptor;
Expand Down Expand Up @@ -103,7 +104,7 @@ public int maxCycles() {
* @return The display name.
*/
@Language("markdown")
public abstract String getDisplayName();
public abstract @NlsRewrite.DisplayName String getDisplayName();

/**
* A human-readable display name for this recipe instance, including some descriptive
Expand Down Expand Up @@ -179,7 +180,7 @@ public String getInstanceNameSuffix() {
* @return The display name.
*/
@Language("markdown")
public abstract String getDescription();
public abstract @NlsRewrite.Description String getDescription();

/**
* A set of strings used for categorizing related recipes. For example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import lombok.Value;
import lombok.With;
import org.intellij.lang.annotations.Language;
import org.openrewrite.NlsRewrite;

import java.util.Set;

Expand All @@ -29,11 +30,13 @@ public class CategoryDescriptor {
public static final int HIGHEST_PRECEDENCE = Integer.MAX_VALUE;

@Language("markdown")
@NlsRewrite.DisplayName
String displayName;

String packageName;

@Language("markdown")
@NlsRewrite.Description
String description;

Set<String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;
import org.openrewrite.internal.lang.Nullable;

@Value
Expand All @@ -30,8 +31,10 @@ public class ColumnDescriptor {
String type;

@Nullable
@NlsRewrite.DisplayName
String displayName;

@Nullable
@NlsRewrite.Description
String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;

import java.util.List;

Expand All @@ -27,8 +28,10 @@ public class DataTableDescriptor {
@EqualsAndHashCode.Include
String name;

@NlsRewrite.DisplayName
String displayName;

@NlsRewrite.Description
String description;

@EqualsAndHashCode.Include
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public String getDescription() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
TreeVisitor<?, ExecutionContext> p = precondition.get();

@Override
public boolean isAcceptable(SourceFile sourceFile, ExecutionContext ctx) {
return p.isAcceptable(sourceFile, ctx);
Expand Down Expand Up @@ -314,11 +315,17 @@ public void addValidation(Validated<Object> validated) {

@Override
public Validated<Object> validate() {
return Validated.<Object>test("initialization",
"initialize(..) must be called on DeclarativeRecipe prior to use.",
this, r -> initValidation != null)
.and(validation)
.and(initValidation);
Validated<Object> validated = Validated.none();

if (!uninitializedRecipes.isEmpty() && uninitializedRecipes.size() != recipeList.size()) {
validated = validated.and(Validated.invalid("initialization", recipeList, "DeclarativeRecipe must not contain uninitialized recipes. Be sure to call .initialize() on DeclarativeRecipe."));
}
if (!uninitializedPreconditions.isEmpty() && uninitializedPreconditions.size() != preconditions.size()) {
validated = validated.and(Validated.invalid("initialization", preconditions, "DeclarativeRecipe must not contain uninitialized preconditions. Be sure to call .initialize() on DeclarativeRecipe."));
}

return validated.and(validation)
.and(initValidation == null ? Validated.none() : initValidation);
}

@Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.EqualsAndHashCode;
import lombok.Value;
import org.openrewrite.NlsRewrite;
import org.openrewrite.internal.lang.Nullable;

import java.util.List;
Expand All @@ -32,9 +33,11 @@ public class OptionDescriptor {
String type;

@Nullable
@NlsRewrite.DisplayName
String displayName;

@Nullable
@NlsRewrite.Description
String description;

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.With;
import org.openrewrite.Contributor;
import org.openrewrite.Maintainer;
import org.openrewrite.NlsRewrite;
import org.openrewrite.internal.lang.Nullable;

import java.net.URI;
Expand All @@ -33,8 +34,10 @@ public class RecipeDescriptor {
@EqualsAndHashCode.Include
String name;

@NlsRewrite.DisplayName
String displayName;

@NlsRewrite.Description
String description;

Set<String> tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.time.Duration;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.Map;
Expand Down Expand Up @@ -74,12 +75,16 @@ class Request {
private final byte[] entity;
private final Method method;
private final Map<String, String> requestHeaders;
private final Duration connectTimeout;
private final Duration readTimeout;

public Request(URL url, byte[] entity, Method method, Map<String, String> requestHeaders) {
public Request(URL url, byte[] entity, Method method, Map<String, String> requestHeaders, Duration connectTimeout, Duration readTimeout) {
this.url = url;
this.entity = entity;
this.method = method;
this.requestHeaders = requestHeaders;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
}

public URL getUrl() {
Expand All @@ -98,6 +103,14 @@ public Map<String, String> getRequestHeaders() {
return requestHeaders;
}

public Duration getConnectTimeout() {
return connectTimeout;
}

public Duration getReadTimeout() {
return readTimeout;
}

public static Builder build(String uri, HttpSender sender) {
return new Builder(uri, sender);
}
Expand Down Expand Up @@ -125,6 +138,8 @@ public static class Builder {
private URL url;
private byte[] entity = new byte[0];
private Method method;
private Duration connectTimeout;
private Duration readTimeout;

Builder(String url, HttpSender sender) {
try {
Expand Down Expand Up @@ -277,8 +292,9 @@ public final Builder compress() throws IOException {
* @throws IOException If compression fails.
*/
public final Builder compressWhen(Supplier<Boolean> when) throws IOException {
if (when.get())
if (when.get()) {
return compress();
}
return this;
}

Expand Down Expand Up @@ -331,7 +347,17 @@ public Response send() {
}

public Request build() {
return new Request(url, entity, method, requestHeaders);
return new Request(url, entity, method, requestHeaders, connectTimeout, readTimeout);
}

public Builder withConnectTimeout(Duration connectTimeout) {
this.connectTimeout = connectTimeout;
return this;
}

public Builder withReadTimeout(Duration readTimeout) {
this.readTimeout = readTimeout;
return this;
}
}
}
Expand Down
Loading

0 comments on commit d0cc544

Please sign in to comment.