This is an automated email from the ASF dual-hosted git repository.

davidb pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-analyser.git


The following commit(s) were added to refs/heads/master by this push:
     new ef94950  SLING-7717 Create an analyser that can generate initial API 
Controller feature content
ef94950 is described below

commit ef949505dd43ac5207a9b66c4bcd065f6cf6ef20
Author: David Bosschaert <[email protected]>
AuthorDate: Fri Jun 8 15:08:36 2018 +0100

    SLING-7717 Create an analyser that can generate initial API Controller 
feature content
    
    This analyser puts the exported packages of all bundles in the
    application in packages.txt. This text file can then be processed to
    form the initial content for the API Controller.
---
 .../analyser/task/impl/ListExportedPackages.java   | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git 
a/src/main/java/org/apache/sling/feature/analyser/task/impl/ListExportedPackages.java
 
b/src/main/java/org/apache/sling/feature/analyser/task/impl/ListExportedPackages.java
new file mode 100644
index 0000000..6e73d47
--- /dev/null
+++ 
b/src/main/java/org/apache/sling/feature/analyser/task/impl/ListExportedPackages.java
@@ -0,0 +1,56 @@
+/*
+ * 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 org.apache.sling.feature.analyser.task.AnalyserTask;
+import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
+import org.apache.sling.feature.scanner.BundleDescriptor;
+import org.apache.sling.feature.scanner.PackageInfo;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+public class ListExportedPackages implements AnalyserTask {
+
+    @Override
+    public void execute(AnalyserTaskContext ctx) throws Exception {
+        SortedSet<String> packages = new TreeSet<>();
+
+        for (BundleDescriptor bd : ctx.getDescriptor().getBundleDescriptors()) 
{
+            for (PackageInfo p : bd.getExportedPackages()) {
+                packages.add(p.getName());
+            }
+        }
+
+        File f = new File("packages.txt");
+        if (f.exists()) {
+            throw new IOException("File " + f.getAbsolutePath() +
+                    " already exists. This plugin does not overwrite an 
existing file");
+        }
+
+        try (FileWriter fw = new FileWriter(f)) {
+            for (String p : packages) {
+                fw.write(p);
+                fw.write(System.getProperty("line.separator"));
+            }
+        }
+        ctx.reportWarning("Finished writing exported packages to " + 
f.getAbsolutePath());;
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to