-
Notifications
You must be signed in to change notification settings - Fork 460
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 subgroup-catch-all
- Loading branch information
Showing
108 changed files
with
3,439 additions
and
289 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
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 |
---|---|---|
|
@@ -121,3 +121,6 @@ nbdist/ | |
nbactions.xml | ||
nb-configuration.xml | ||
.nb-gradle/ | ||
|
||
# MacOS jenv | ||
.java-version |
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
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
2 changes: 1 addition & 1 deletion
2
lib-extra/src/main/java/com/diffplug/spotless/extra/GitRatchet.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
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
97 changes: 97 additions & 0 deletions
97
lib/src/jackson/java/com/diffplug/spotless/glue/yaml/YamlJacksonFormatterFunc.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,97 @@ | ||
/* | ||
* Copyright 2021-2023 DiffPlug | ||
* | ||
* 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 | ||
* | ||
* 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 com.diffplug.spotless.glue.yaml; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
|
||
import com.diffplug.spotless.FormatterFunc; | ||
|
||
public class YamlJacksonFormatterFunc implements FormatterFunc { | ||
private List<String> enabledFeatures; | ||
private List<String> disabledFeatures; | ||
|
||
public YamlJacksonFormatterFunc(List<String> enabledFeatures, List<String> disabledFeatures) { | ||
this.enabledFeatures = enabledFeatures; | ||
this.disabledFeatures = disabledFeatures; | ||
} | ||
|
||
@Override | ||
public String apply(String input) throws Exception { | ||
ObjectMapper objectMapper = makeObjectMapper(); | ||
|
||
return format(objectMapper, input); | ||
} | ||
|
||
protected ObjectMapper makeObjectMapper() { | ||
YAMLFactory yamlFactory = new YAMLFactory(); | ||
ObjectMapper objectMapper = new ObjectMapper(yamlFactory); | ||
|
||
// Configure the ObjectMapper | ||
// https://github.com/FasterXML/jackson-databind#commonly-used-features | ||
for (String rawFeature : enabledFeatures) { | ||
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection | ||
SerializationFeature feature = SerializationFeature.valueOf(rawFeature); | ||
|
||
objectMapper.enable(feature); | ||
} | ||
|
||
for (String rawFeature : disabledFeatures) { | ||
// https://stackoverflow.com/questions/3735927/java-instantiating-an-enum-using-reflection | ||
SerializationFeature feature = SerializationFeature.valueOf(rawFeature); | ||
|
||
objectMapper.disable(feature); | ||
} | ||
return objectMapper; | ||
} | ||
|
||
protected String format(ObjectMapper objectMapper, String input) throws IllegalArgumentException, IOException { | ||
// We may consider adding manually an initial '---' prefix to help management of multiple documents | ||
// if (!input.trim().startsWith("---")) { | ||
// input = "---" + "\n" + input; | ||
// } | ||
|
||
try { | ||
// https://stackoverflow.com/questions/25222327/deserialize-pojos-from-multiple-yaml-documents-in-a-single-file-in-jackson | ||
// https://github.com/FasterXML/jackson-dataformats-text/issues/66#issuecomment-375328648 | ||
// 2023-01: For now, we get 'Cannot deserialize value of type `com.fasterxml.jackson.databind.node.ObjectNode` from Array value' | ||
// JsonParser yamlParser = objectMapper.getFactory().createParser(input); | ||
// List<ObjectNode> docs = objectMapper.readValues(yamlParser, ObjectNode.class).readAll(); | ||
// return objectMapper.writeValueAsString(docs); | ||
|
||
// 2023-01: This returns JSON instead of YAML | ||
// This will transit with a JsonNode | ||
// A JsonNode may keep the comments from the input node | ||
// JsonNode jsonNode = objectMapper.readTree(input); | ||
//Not 'toPrettyString' as one could require no INDENT_OUTPUT | ||
// return jsonNode.toPrettyString(); | ||
ObjectNode objectNode = objectMapper.readValue(input, ObjectNode.class); | ||
return objectMapper.writeValueAsString(objectNode); | ||
} catch (JsonProcessingException e) { | ||
throw new AssertionError("Unable to format YAML. input='" + input + "'", e); | ||
} | ||
} | ||
|
||
// Spotbugs | ||
private static class ObjectNodeTypeReference extends TypeReference<ObjectNode> {} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
lib/src/main/java/com/diffplug/spotless/npm/BaseNpmRestService.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,30 @@ | ||
/* | ||
* Copyright 2016-2023 DiffPlug | ||
* | ||
* 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 | ||
* | ||
* 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 com.diffplug.spotless.npm; | ||
|
||
abstract class BaseNpmRestService { | ||
|
||
protected final SimpleRestClient restClient; | ||
|
||
BaseNpmRestService(String baseUrl) { | ||
this.restClient = SimpleRestClient.forBaseUrl(baseUrl); | ||
} | ||
|
||
public String shutdown() { | ||
return restClient.post("/shutdown"); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
lib/src/main/java/com/diffplug/spotless/npm/EslintConfig.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,72 @@ | ||
/* | ||
* Copyright 2016-2023 DiffPlug | ||
* | ||
* 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 | ||
* | ||
* 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 com.diffplug.spotless.npm; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.diffplug.spotless.FileSignature; | ||
import com.diffplug.spotless.ThrowingEx; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public class EslintConfig implements Serializable { | ||
|
||
private static final long serialVersionUID = -6196834313082791248L; | ||
|
||
@SuppressFBWarnings("SE_TRANSIENT_FIELD_NOT_RESTORED") | ||
@Nullable | ||
private final transient File eslintConfigPath; | ||
|
||
@SuppressWarnings("unused") | ||
private final FileSignature eslintConfigPathSignature; | ||
|
||
private final String eslintConfigJs; | ||
|
||
public EslintConfig(@Nullable File eslintConfigPath, @Nullable String eslintConfigJs) { | ||
try { | ||
this.eslintConfigPath = eslintConfigPath; | ||
this.eslintConfigPathSignature = eslintConfigPath != null ? FileSignature.signAsList(this.eslintConfigPath) : FileSignature.signAsList(); | ||
this.eslintConfigJs = eslintConfigJs; | ||
} catch (IOException e) { | ||
throw ThrowingEx.asRuntime(e); | ||
} | ||
} | ||
|
||
public EslintConfig withEslintConfigPath(@Nullable File eslintConfigPath) { | ||
return new EslintConfig(eslintConfigPath, this.eslintConfigJs); | ||
} | ||
|
||
@Nullable | ||
public File getEslintConfigPath() { | ||
return eslintConfigPath; | ||
} | ||
|
||
@Nullable | ||
public String getEslintConfigJs() { | ||
return eslintConfigJs; | ||
} | ||
|
||
public EslintConfig verify() { | ||
if (eslintConfigPath == null && eslintConfigJs == null) { | ||
throw new IllegalArgumentException("ESLint must be configured using either a configFile or a configJs - but both are null."); | ||
} | ||
return this; | ||
} | ||
} |
Oops, something went wrong.