rombert commented on code in PR #57:
URL: 
https://github.com/apache/sling-org-apache-sling-feature-analyser/pull/57#discussion_r3264873461


##########
src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRepoInitConflicts.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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
+ *
+ * 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.feature.analyser.task.impl;
+
+import java.util.List;
+
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.analyser.task.AnalyserTask;
+import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
+import 
org.apache.sling.feature.analyser.task.impl.repoinitconflicts.RepoInitValidationReport;
+import 
org.apache.sling.feature.analyser.task.impl.repoinitconflicts.RepoInitValidator;
+
+public class CheckRepoInitConflicts implements AnalyserTask {
+
+    @Override
+    public String getId() {
+        return "repoinit-conflict-validation";

Review Comment:
   We already have CheckRepoinit.java . Can this validator task be included in 
that one or does that complicate things?
   
   If it can't be easily included let's set a naming convention, e.g. 
_repoinit-conflicts_ and consistently use it in this PR. Right now the task id 
is 'repoinit-conflict-validation' and therefore the class should be 
CheckRepoinitConflictValidation . Additionally, please see CheckRepoinit.java 
for some text constants you can use instead of hardcoding the values.



##########
src/main/java/org/apache/sling/feature/analyser/task/impl/repoinitconflicts/RepoInitValidator.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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
+ *
+ * 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.feature.analyser.task.impl.repoinitconflicts;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.repoinit.parser.impl.ParseException;
+import org.apache.sling.repoinit.parser.impl.RepoInitParserImpl;
+import org.apache.sling.repoinit.parser.operations.CreatePath;
+import org.apache.sling.repoinit.parser.operations.Operation;
+import org.apache.sling.repoinit.parser.operations.PathSegmentDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SuppressWarnings("java:S1874")
+public class RepoInitValidator {
+    private RepoInitValidator() {}
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(RepoInitValidator.class);
+
+    public static RepoInitValidationReport validateRepoinit(final Feature 
feature) {
+        RepoInitValidationReport report = new RepoInitValidationReport();
+
+        if (feature.getExtensions().getByName("repoinit") == null) {

Review Comment:
   Because there is only one public method in the class I would slightly 
rearrange the checks.
   
   First, get the extension
   
   ```
   final Extension repoinitExtension = 
feature.getExtensions().getByName("repoinit");
   ```
   
   Then, apply the full checks in this method
   
   ```
           if (repoinitExtension == null
                   || repoinitExtension.getText() == null
                   || repoinitExtension.getType() != ExtensionType.TEXT) {
               return report;
           }
   ```
   
   Then access the extension in other methods without any checks since they 
were already done.



##########
src/test/java/org/apache/sling/feature/analyser/task/impl/repoinitconflicts/RepoInitValidatorTest.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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
+ *
+ * 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.feature.analyser.task.impl.repoinitconflicts;
+
+import java.util.List;
+
+import org.apache.sling.feature.Extension;
+import org.apache.sling.feature.ExtensionType;
+import org.apache.sling.feature.Feature;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class RepoInitValidatorTest {
+
+    @Test
+    void shouldReturnNoIssuesWhenFeatureHasNoRepoinit() {
+        Feature feature = mock(Feature.class);
+        
when(feature.getExtensions()).thenReturn(mock(org.apache.sling.feature.Extensions.class));
+        when(feature.getExtensions().getByName("repoinit")).thenReturn(null);
+
+        RepoInitValidationReport report = 
RepoInitValidator.validateRepoinit(feature);
+
+        assertFalse(report.hasConflicts());
+        assertTrue(report.generate().contains("No issues found"));
+    }
+
+    @Test
+    void shouldReturnNoIssuesForCorrectRepoinit() {
+        Extension extension =
+                textExtension("create path (sling:Folder) /apps/a/b\n" + 
"create path (sling:Folder) /apps/a/c\n"
+                        + "create path (sling:Folder) 
/apps/a/c/d(cq:ClientLibraryFolder)");

Review Comment:
   nit: please use a node type available in Sling, e.g. `sling:OrderedFolder`. 
No practical impact, just a bit nicer to read and not wonder why an 'external' 
node type is used.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to