You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2025/02/24 19:17:53 UTC
(sling-org-apache-sling-repoinit-filevault-validator) 02/02: SLING-12670 apply spotless formatting
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch feature/parent-62
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-filevault-validator.git
commit e65afebb022f570cb31f98e4953051f2e04bddbf
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Mon Feb 24 20:17:42 2025 +0100
SLING-12670 apply spotless formatting
---
pom.xml | 29 ++---
.../filevault/validator/RepoInitValidator.java | 130 +++++++++++++--------
.../validator/RepoInitValidatorFactory.java | 27 ++---
3 files changed, 108 insertions(+), 78 deletions(-)
diff --git a/pom.xml b/pom.xml
index 971cca9..74d4c6f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with this
@@ -16,6 +17,12 @@
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>62</version>
+ </parent>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.repoinit.filevault.validator</artifactId>
<version>1.0.1-SNAPSHOT</version>
@@ -23,24 +30,18 @@
<name>Apache Sling Repoinit FileVault Validator</name>
<description>FileVault validator which validates RepoInit OSGi configurations</description>
- <parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>62</version>
- </parent>
+ <scm>
+ <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-filevault-validator.git</connection>
+ <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-filevault-validator.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://github.com/apache/sling-org-apache-sling-repoinit-filevault-validator.git</url>
+ </scm>
<properties>
<sling.java.version>8</sling.java.version>
<project.build.outputTimestamp>2025-02-24T00:00:00Z</project.build.outputTimestamp>
</properties>
- <scm>
- <connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-filevault-validator.git</connection>
- <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-repoinit-filevault-validator.git</developerConnection>
- <url>https://github.com/apache/sling-org-apache-sling-repoinit-filevault-validator.git</url>
- <tag>HEAD</tag>
- </scm>
-
<dependencies>
<dependency>
<groupId>org.apache.jackrabbit.vault</groupId>
@@ -100,7 +101,7 @@
<scope>provided</scope>
</dependency>
</dependencies>
-
+
<build>
<plugins>
<plugin>
@@ -134,4 +135,4 @@
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
diff --git a/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidator.java b/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidator.java
index cdb15d9..e994b8f 100644
--- a/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidator.java
+++ b/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidator.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * 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.
+ * 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.apache.sling.repoinit.filevault.validator;
@@ -57,14 +59,16 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
private static final String SLING_OSGI_CONFIG_NODETYPE = "sling:OsgiConfig";
- private static final String OSGI_CONFIG_NAME = "org\\.apache\\.sling\\.jcr\\.repoinit\\.RepositoryInitializer([~-]).*";
+ private static final String OSGI_CONFIG_NAME =
+ "org\\.apache\\.sling\\.jcr\\.repoinit\\.RepositoryInitializer([~-]).*";
private static final Pattern OSGI_CONFIG_NODE_NAME_PATTERN = Pattern.compile(OSGI_CONFIG_NAME);
/**
* https://sling.apache.org/documentation/bundles/configuration-installer-factory.html#configuration-serialization-formats
*/
- private static final Pattern OSGI_CONFIG_FILE_NAME_PATTERN = Pattern.compile(OSGI_CONFIG_NAME + "\\.(config|cfg\\.json|cfg)");
+ private static final Pattern OSGI_CONFIG_FILE_NAME_PATTERN =
+ Pattern.compile(OSGI_CONFIG_NAME + "\\.(config|cfg\\.json|cfg)");
enum OsgiConfigurationSerialization {
CFG,
@@ -84,15 +88,24 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
}
@Override
- public @Nullable Collection<ValidationMessage> validate(@NotNull DocViewNode2 node, @NotNull NodeContext nodeContext,
- boolean isRoot) {
- if (SLING_OSGI_CONFIG_NODETYPE.equals(node.getPrimaryType().orElse("")) && OSGI_CONFIG_NODE_NAME_PATTERN.matcher(Text.getName(nodeContext.getNodePath())).matches()) {
- Optional<DocViewProperty2> scriptsProperty = node.getProperty(NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "scripts"));
+ public @Nullable Collection<ValidationMessage> validate(
+ @NotNull DocViewNode2 node, @NotNull NodeContext nodeContext, boolean isRoot) {
+ if (SLING_OSGI_CONFIG_NODETYPE.equals(node.getPrimaryType().orElse(""))
+ && OSGI_CONFIG_NODE_NAME_PATTERN
+ .matcher(Text.getName(nodeContext.getNodePath()))
+ .matches()) {
+ Optional<DocViewProperty2> scriptsProperty =
+ node.getProperty(NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "scripts"));
if (scriptsProperty.isPresent()) {
try {
- return validateStatements(scriptsProperty.get().getStringValues(), nodeContext.getFilePath().toString());
+ return validateStatements(
+ scriptsProperty.get().getStringValues(),
+ nodeContext.getFilePath().toString());
} catch (IOException e) {
- return Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "IOException while parsing " + nodeContext.getFilePath() +" : " + e.getMessage(), e));
+ return Collections.singleton(new ValidationMessage(
+ ValidationMessageSeverity.ERROR,
+ "IOException while parsing " + nodeContext.getFilePath() + " : " + e.getMessage(),
+ e));
}
}
}
@@ -101,9 +114,14 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
@Override
@Nullable
- public Collection<ValidationMessage> validateJcrData(@NotNull InputStream input, @NotNull Path filePath, @NotNull Path basePath,
- @NotNull Map<String, Integer> nodePathsAndLineNumbers) throws IOException {
- Map<String, Object> config = deserializeOsgiConfiguration(getType(filePath.getFileName().toString()), input);
+ public Collection<ValidationMessage> validateJcrData(
+ @NotNull InputStream input,
+ @NotNull Path filePath,
+ @NotNull Path basePath,
+ @NotNull Map<String, Integer> nodePathsAndLineNumbers)
+ throws IOException {
+ Map<String, Object> config =
+ deserializeOsgiConfiguration(getType(filePath.getFileName().toString()), input);
return validateConfig(config, filePath.toString());
}
@@ -119,7 +137,8 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
} else if (fileName.endsWith(".cfg")) {
return OsgiConfigurationSerialization.CFG;
} else {
- throw new IllegalArgumentException("Given file name " + fileName + " does not represent a known OSGi configuration serialization");
+ throw new IllegalArgumentException(
+ "Given file name " + fileName + " does not represent a known OSGi configuration serialization");
}
}
@@ -129,41 +148,48 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
return OSGI_CONFIG_FILE_NAME_PATTERN.matcher(fileName).matches();
}
- Map<String, Object> deserializeOsgiConfiguration(@NotNull OsgiConfigurationSerialization serializationType, @NotNull InputStream input) throws IOException {
- switch(serializationType) {
- case CONFIG:
- return convertToMap(org.apache.felix.cm.file.ConfigurationHandler.read(input));
- case CFG:
- Properties properties = new Properties();
- properties.load(input);
- return convertToMap(properties);
- case CFG_JSON:
- Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
- ConfigurationReader configReader = org.apache.felix.cm.json.Configurations.buildReader().build(reader);
- return convertToMap(configReader.readConfiguration());
+ Map<String, Object> deserializeOsgiConfiguration(
+ @NotNull OsgiConfigurationSerialization serializationType, @NotNull InputStream input) throws IOException {
+ switch (serializationType) {
+ case CONFIG:
+ return convertToMap(org.apache.felix.cm.file.ConfigurationHandler.read(input));
+ case CFG:
+ Properties properties = new Properties();
+ properties.load(input);
+ return convertToMap(properties);
+ case CFG_JSON:
+ Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8);
+ ConfigurationReader configReader =
+ org.apache.felix.cm.json.Configurations.buildReader().build(reader);
+ return convertToMap(configReader.readConfiguration());
}
return null;
}
private Collection<ValidationMessage> validateConfig(Map<String, Object> config, String source) throws IOException {
// https://sling.apache.org/documentation/bundles/repository-initialization.html#providing-repoinit-statements-from-osgi-factory-configurations
- // only evaluate scripts for now, references might have unresolvable URLs at the time of building (https://sling.apache.org/documentation/bundles/repository-initialization.html#references-to-urls-providing-raw-repoinit-statements)
+ // only evaluate scripts for now, references might have unresolvable URLs at the time of building
+ // (https://sling.apache.org/documentation/bundles/repository-initialization.html#references-to-urls-providing-raw-repoinit-statements)
Object scripts = config.get("scripts");
if (scripts == null) {
return null;
}
if (scripts instanceof String[]) {
- return validateStatements(Arrays.asList((String[])scripts), source);
+ return validateStatements(Arrays.asList((String[]) scripts), source);
} else if (scripts instanceof String) {
- return validateStatements((String)scripts, source);
+ return validateStatements((String) scripts, source);
} else {
- return Collections.singletonList(new ValidationMessage(ValidationMessageSeverity.ERROR, "OSGi config property 'scripts' must be of type String or String[]"));
+ return Collections.singletonList(new ValidationMessage(
+ ValidationMessageSeverity.ERROR,
+ "OSGi config property 'scripts' must be of type String or String[]"));
}
}
- private Collection<ValidationMessage> validateStatements(Collection<String> scripts, String source) throws IOException {
+ private Collection<ValidationMessage> validateStatements(Collection<String> scripts, String source)
+ throws IOException {
List<ValidationMessage> validationMsgs = new ArrayList<>();
- validationMsgs.add(new ValidationMessage(ValidationMessageSeverity.DEBUG, "Validating repoinit statements from " + source));
+ validationMsgs.add(new ValidationMessage(
+ ValidationMessageSeverity.DEBUG, "Validating repoinit statements from " + source));
for (String statements : scripts) {
validateStatements(statements).ifPresent(validationMsgs::add);
}
@@ -172,7 +198,8 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
private Collection<ValidationMessage> validateStatements(String statements, String source) throws IOException {
List<ValidationMessage> validationMsgs = new ArrayList<>();
- validationMsgs.add(new ValidationMessage(ValidationMessageSeverity.DEBUG, "Validating repoinit statements from " + source));
+ validationMsgs.add(new ValidationMessage(
+ ValidationMessageSeverity.DEBUG, "Validating repoinit statements from " + source));
validateStatements(statements).ifPresent(validationMsgs::add);
return validationMsgs;
}
@@ -181,22 +208,23 @@ public class RepoInitValidator implements DocumentViewXmlValidator, GenericJcrDa
try (Reader reader = new StringReader(statements)) {
parser.parse(reader);
} catch (RepoInitParsingException e) {
- return Optional.of(new ValidationMessage(ValidationMessageSeverity.ERROR, "Invalid repoinit statement(s) detected: " + e.getMessage(), e));
+ return Optional.of(new ValidationMessage(
+ ValidationMessageSeverity.ERROR, "Invalid repoinit statement(s) detected: " + e.getMessage(), e));
}
return Optional.empty();
}
static Map<String, Object> convertToMap(Dictionary<String, ?> dictionary) {
List<String> keys = Collections.list(dictionary.keys());
- return keys.stream().collect(Collectors.toMap(Function.identity(), dictionary::get));
+ return keys.stream().collect(Collectors.toMap(Function.identity(), dictionary::get));
}
static Map<String, Object> convertToMap(Properties properties) {
- return properties.entrySet().stream().collect(
- Collectors.toMap(
- e -> String.valueOf(e.getKey()),
- e -> String.valueOf(e.getValue()),
- (prev, next) -> next, HashMap::new
- ));
+ return properties.entrySet().stream()
+ .collect(Collectors.toMap(
+ e -> String.valueOf(e.getKey()),
+ e -> String.valueOf(e.getValue()),
+ (prev, next) -> next,
+ HashMap::new));
}
}
diff --git a/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidatorFactory.java b/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidatorFactory.java
index f471750..4e23ce2 100644
--- a/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidatorFactory.java
+++ b/src/main/java/org/apache/sling/repoinit/filevault/validator/RepoInitValidatorFactory.java
@@ -1,18 +1,20 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You 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
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ * 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.
+ * 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.apache.sling.repoinit.filevault.validator;
@@ -41,5 +43,4 @@ public class RepoInitValidatorFactory implements ValidatorFactory {
public int getServiceRanking() {
return 0;
}
-
}