You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2019/06/13 13:02:03 UTC

[GitHub] [sling-org-apache-sling-feature-analyser] karlpauls commented on a change in pull request #16: SLING-8251 - Support checking dependencies for content packages

karlpauls commented on a change in pull request #16: SLING-8251 - Support checking dependencies for content packages
URL: https://github.com/apache/sling-org-apache-sling-feature-analyser/pull/16#discussion_r293364888
 
 

 ##########
 File path: src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependencies.java
 ##########
 @@ -0,0 +1,133 @@
+/*
+ * 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.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Queue;
+import java.util.Set;
+
+import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.apache.jackrabbit.vault.packaging.PackageManager;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.apache.jackrabbit.vault.packaging.impl.PackageManagerImpl;
+import org.apache.sling.feature.analyser.task.AnalyserTask;
+import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
+import org.apache.sling.feature.scanner.ArtifactDescriptor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CheckContentPackagesDependencies implements AnalyserTask {
+
+    private final PackageManager packageManager = new PackageManagerImpl();
+
+    private final Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Override
+    public String getId() {
+        return "content-packages-dependencies";
+    }
+
+    @Override
+    public String getName() {
+        return "Content-packages dependencies checker";
+    }
+
+    @Override
+    public void execute(AnalyserTaskContext ctx) throws Exception {
+        Set<ArtifactDescriptor> descriptors = ctx.getFeatureDescriptor().getArtifactDescriptors();
+        if (descriptors == null || descriptors.isEmpty()) {
+            return;
+        }
+
+        Map<PackageId, Dependency[]> dependenciesMap = new HashMap<>();
+
+        for (ArtifactDescriptor descriptor : descriptors) {
+            onDescriptor(ctx, descriptor, dependenciesMap);
+        }
+
+        for (PackageId contentPackageId : dependenciesMap.keySet()) {
+            verifyDependenciesTree(ctx, contentPackageId, dependenciesMap);
+        }
+    }
+
+    private void onDescriptor(AnalyserTaskContext ctx, ArtifactDescriptor descriptor, Map<PackageId, Dependency[]> dependenciesMap) throws Exception {
+        URL resourceUrl = descriptor.getArtifactFile();
+        String filename = resourceUrl.getFile().replace('/', File.separatorChar);
 
 Review comment:
   @simonetripodi, not sure that is the best approach. You can use o.a.s.feature.io.IOUtils to get the File from the url.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services