Author: cziegeler
Date: Fri Jul  7 13:10:32 2017
New Revision: 1801155

URL: http://svn.apache.org/viewvc?rev=1801155&view=rev
Log:
Refactoring of package layout

Added:
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
   (with props)
    
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
   (with props)

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java?rev=1801155&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
 Fri Jul  7 13:10:32 2017
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import org.apache.sling.feature.Application;
+
+/**
+ * Information about an application.
+ * This is the aggregated information.
+ */
+public interface ApplicationDescriptor extends ContainerDescriptor {
+
+    Application getApplication();
+
+    Descriptor getFrameworkDescriptor();
+}
\ No newline at end of file

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ApplicationDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java?rev=1801155&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
 Fri Jul  7 13:10:32 2017
@@ -0,0 +1,30 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+/**
+ * Information about a container (feature/application).
+ * This is the aggregated information.
+ */
+public interface ContainerDescriptor extends Descriptor {
+
+    Set<BundleDescriptor> getBundleDescriptors();
+
+    Set<ArtifactDescriptor> getArtifactDescriptors();
+}
\ No newline at end of file

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ContainerDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java?rev=1801155&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
 Fri Jul  7 13:10:32 2017
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+import org.apache.sling.feature.Feature;
+
+/**
+ * Information about a feature.
+ * This is the aggregated information.
+ */
+public interface FeatureDescriptor extends ContainerDescriptor {
+
+    Feature getFeature();
+}
\ No newline at end of file

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/FeatureDescriptor.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
URL: 
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java?rev=1801155&view=auto
==============================================================================
--- 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
 (added)
+++ 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
 Fri Jul  7 13:10:32 2017
@@ -0,0 +1,218 @@
+/*
+ * 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.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.sling.feature.Artifact;
+import org.apache.sling.feature.analyser.BundleDescriptor;
+import org.apache.sling.feature.analyser.PackageInfo;
+import org.osgi.framework.Constants;
+
+/**
+ * Information about a bundle
+ */
+public class BundleDescriptorImpl
+    implements BundleDescriptor {
+
+    /** The bundle symbolic name. */
+    private String symbolicName;
+
+    /** The bundle version. */
+    private String bundleVersion;
+
+    /** The start level of this artifact. */
+    private final int startLevel;
+
+    /** Information about exported packages. */
+    private final Set<PackageInfo> exportedPackages = new HashSet<>();
+
+    /** Information about imported packages. */
+    private final Set<PackageInfo> importedPackages = new HashSet<>();
+
+    /** Information about dynamic imported packages. */
+    private final Set<PackageInfo> dynamicImportedPackages = new HashSet<>();
+
+    /** Manifest */
+    private final Manifest manifest;
+
+    /** The physical file for analyzing. */
+    private final File artifactFile;
+
+    /** The corresponding artifact from the feature. */
+    private final Artifact artifact;
+
+    public BundleDescriptorImpl(final Artifact a,
+            final File file,
+            final int startLevel) throws IOException  {
+        this.artifact = a;
+        this.artifactFile = file;
+        this.startLevel = startLevel;
+
+        this.manifest = ManifestUtil.getManifest(file);
+        if ( this.manifest == null ) {
+            throw new IOException("File has no manifest");
+        }
+        this.analyze();
+    }
+
+    public BundleDescriptorImpl(final Artifact artifact,
+            final Set<PackageInfo> pcks) throws IOException {
+        this.artifact = artifact;
+        this.artifactFile = null;
+        this.startLevel = 0;
+
+        this.symbolicName = Constants.SYSTEM_BUNDLE_SYMBOLICNAME;
+        this.bundleVersion = artifact.getId().getOSGiVersion().toString();
+        this.exportedPackages.addAll(pcks);
+        this.manifest = null;
+    }
+
+    /**
+     * Get the bundle symbolic name.
+     * @return The bundle symbolic name
+     */
+    @Override
+    public String getBundleSymbolicName() {
+        return symbolicName;
+    }
+
+    /**
+     * Get the bundle version
+     * @return The bundle version
+     */
+    @Override
+    public String getBundleVersion() {
+        return bundleVersion;
+    }
+
+    /**
+     * Get the start level
+     * @return The start level or {@code 0} for the default.
+     */
+    @Override
+    public int getBundleStartLevel() {
+        return startLevel;
+    }
+
+    @Override
+    public Set<PackageInfo> getExportedPackages() {
+        return Collections.unmodifiableSet(this.exportedPackages);
+    }
+
+    @Override
+    public File getArtifactFile() {
+        return artifactFile;
+    }
+
+    @Override
+    public Artifact getArtifact() {
+        return artifact;
+    }
+
+    @Override
+    public Manifest getManifest() {
+        return this.manifest;
+    }
+
+    @Override
+    public boolean isExportingPackage(final String packageName) {
+        if ( getExportedPackages() != null ) {
+            for(final PackageInfo i : getExportedPackages()) {
+                if ( i.getName().equals(packageName) ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public boolean isExportingPackage(final PackageInfo info) {
+        if ( getExportedPackages() != null ) {
+            for(final PackageInfo i : getExportedPackages()) {
+                if ( i.getName().equals(info.getName())
+                     && (info.getVersion() == null || 
info.getPackageVersionRange().includes(i.getPackageVersion()))) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Set<PackageInfo> getImportedPackages() {
+        return Collections.unmodifiableSet(this.importedPackages);
+    }
+
+    @Override
+    public Set<PackageInfo> getDynamicImportedPackages() {
+        return Collections.unmodifiableSet(this.dynamicImportedPackages);
+    }
+
+    protected void analyze() throws IOException {
+        final String name = 
this.manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+        if ( name != null ) {
+            final String version = 
this.manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
+            if ( version == null ) {
+                throw new IOException("Unable to get bundle version from 
artifact " + getArtifact().getId().toMvnId());
+            }
+            this.symbolicName = name;
+            this.bundleVersion = version;
+            final String newBundleName = 
this.getArtifact().getMetadata().get("bundle:rename-bsn");
+            if (newBundleName != null) {
+                this.symbolicName = newBundleName;
+            }
+
+            
this.exportedPackages.addAll(ManifestUtil.extractExportedPackages(this.manifest));
+            
this.importedPackages.addAll(ManifestUtil.extractImportedPackages(this.manifest));
+            
this.dynamicImportedPackages.addAll(ManifestUtil.extractDynamicImportedPackages(this.manifest));
+
+        } else {
+            throw new IOException("Unable to get bundle symbolic name from 
artifact " + getArtifact().getId().toMvnId());
+        }
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if ( obj instanceof BundleDescriptorImpl ) {
+            return 
this.symbolicName.equals(((BundleDescriptorImpl)obj).symbolicName) && 
this.bundleVersion.equals(((BundleDescriptorImpl)obj).bundleVersion);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return (this.symbolicName + ':' + this.bundleVersion).hashCode();
+
+    }
+
+    @Override
+    public String toString() {
+        return "BundleInfo [symbolicName=" + symbolicName + ", version=" + 
this.bundleVersion + "]";
+    }
+
+    @Override
+    public int compareTo(final BundleDescriptor o) {
+        return (this.symbolicName + ':' + 
this.bundleVersion).compareTo((o.getBundleSymbolicName() + ':' + 
o.getBundleVersion()));
+    }
+}
\ No newline at end of file

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/impl/BundleDescriptorImpl.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url


Reply via email to