You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2017/05/30 08:07:16 UTC
svn commit: r1796767 - in /sling/whiteboard/cziegeler: feature-analyser/
feature-analyser/src/ feature-analyser/src/main/
feature-analyser/src/main/java/ feature-analyser/src/main/java/org/
feature-analyser/src/main/java/org/apache/ feature-analyser/sr...
Author: cziegeler
Date: Tue May 30 08:07:16 2017
New Revision: 1796767
URL: http://svn.apache.org/viewvc?rev=1796767&view=rev
Log:
Move analyser into separate module
Added:
sling/whiteboard/cziegeler/feature-analyser/
sling/whiteboard/cziegeler/feature-analyser/pom.xml (with props)
sling/whiteboard/cziegeler/feature-analyser/src/
sling/whiteboard/cziegeler/feature-analyser/src/main/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java (with props)
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java (with props)
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java (with props)
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java (with props)
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java (with props)
sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java (with props)
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java (with props)
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java (with props)
Modified:
sling/whiteboard/cziegeler/feature/pom.xml
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Bundles.java
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/json/FeatureJSONReader.java
Added: sling/whiteboard/cziegeler/feature-analyser/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/pom.xml?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/pom.xml (added)
+++ sling/whiteboard/cziegeler/feature-analyser/pom.xml Tue May 30 08:07:16 2017
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+ 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.
+ -->
+<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 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>30</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>org.apache.sling.feature.analyser</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Sling Feature Analyser</name>
+ <description>
+ A feature describes an OSGi system
+ </description>
+
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ </properties>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/tooling/support/feature-analyser</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/trunk/tooling/support/feature-analyser</developerConnection>
+ <url>http://svn.apache.org/viewvc/sling/trunk/tooling/support/feature-analyser</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Conditional-Package>
+ org.apache.sling.commons.osgi
+ </Conditional-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.feature</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.osgi</artifactId>
+ <version>2.4.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: sling/whiteboard/cziegeler/feature-analyser/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/pom.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java Tue May 30 08:07:16 2017
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+public interface AnalyserTask {
+
+ String getName();
+
+ void execute(AnalyserTaskContext ctx);
+}
+
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTask.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java Tue May 30 08:07:16 2017
@@ -0,0 +1,40 @@
+/*
+ * 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.List;
+
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.KeyValueMap;
+
+public interface AnalyserTaskContext {
+
+ Application getApplication();
+
+ KeyValueMap<String> getDefaultFrameworkProperties();
+
+ List<PackageInfo> getSystemPackages();
+
+ List<BundleInfo> getBundleInfos();
+
+ List<ArtifactInfo> getArtifactInfos();
+
+ void addWarning(String message);
+
+ void addError(String message);
+}
+
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/AnalyserTaskContext.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java Tue May 30 08:07:16 2017
@@ -0,0 +1,200 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.feature.Artifact;
+import org.osgi.framework.Constants;
+
+/**
+ * Information about an artifact
+ */
+public class ArtifactInfo {
+
+ /** The physical file for analysing. */
+ private final File artifactFile;
+
+ /** The corresponding artifact from the feature. */
+ private final Artifact artifact;
+
+ /** Information about exported packages. */
+ private final List<PackageInfo> exportedPackages = new ArrayList<>();
+
+ /** Information about imported packages. */
+ private final List<PackageInfo> importedPackages = new ArrayList<>();
+
+ /** Information about dynamic imported packages. */
+ private final List<PackageInfo> dynamicImportedPackages = new ArrayList<>();
+
+ public ArtifactInfo(final Artifact a,
+ final File file) throws IOException {
+ this.artifact = a;
+ this.artifactFile = file;
+
+ this.analyze();
+ }
+
+ /**
+ * Get the artifact file
+ * @return The artifact file
+ */
+ public File getArtifactFile() {
+ return artifactFile;
+ }
+
+ /**
+ * Get the artifact
+ * @return The artifact
+ */
+ public Artifact getArtifact() {
+ return artifact;
+ }
+
+ public List<PackageInfo> getExportedPackages() {
+ return Collections.unmodifiableList(this.exportedPackages);
+ }
+
+ public boolean isExportingPackage(final String packageName) {
+ if ( getExportedPackages() != null ) {
+ for(final PackageInfo i : getExportedPackages()) {
+ if ( i.getName().equals(packageName) ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ 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;
+ }
+
+ public List<PackageInfo> getImportedPackages() {
+ return Collections.unmodifiableList(this.importedPackages);
+ }
+
+ public List<PackageInfo> getDynamicImportedPackages() {
+ return Collections.unmodifiableList(this.dynamicImportedPackages);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( obj instanceof ArtifactInfo ) {
+ return this.getArtifact().getId().toMvnId().equals(((ArtifactInfo)obj).getArtifact().getId().toMvnId());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return this.getArtifact().getId().toMvnId().hashCode();
+
+ }
+
+ @Override
+ public String toString() {
+ return "ArtifactInfo [artifact=" + this.getArtifact().getId().toMvnId() + "]";
+ }
+
+ private void analyze() throws IOException {
+ final Manifest m = getManifest(this.artifactFile);
+ if (m != null ) {
+
+ doAnalyze(m);
+
+ } else {
+ throw new IOException("Unable to get manifest from artifact " + getArtifact().getId().toMvnId());
+ }
+ }
+
+ protected void doAnalyze(final Manifest m) throws IOException {
+ extractExportedPackages(m);
+ extractDynamicImportedPackages(m);
+ extractImportedPackages(m);
+ }
+
+ /**
+ * Get the manifest from the artifact.
+ * @param artifact The artifact
+ * @throws IOException If the manifest can't be read
+ */
+ private static Manifest getManifest(final File artifact) throws IOException {
+ try (final JarFile file = new JarFile(artifact) ) {
+ return file.getManifest();
+ }
+ }
+
+ private void extractExportedPackages(final Manifest m) {
+ final String exportedPackages = m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
+ if (exportedPackages != null) {
+ final ManifestHeader header = ManifestHeader.parse(exportedPackages);
+ for(final ManifestHeader.Entry entry : header.getEntries()) {
+ String version = entry.getAttributeValue("version");
+ if ( version == null ) {
+ version = "0.0.0";
+ }
+ final PackageInfo pck = new PackageInfo(entry.getValue(),
+ version,
+ false);
+ this.exportedPackages.add(pck);
+ }
+ }
+ }
+
+ private void extractImportedPackages(final Manifest m) {
+ final String importedPackages = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
+ if (importedPackages != null) {
+ final ManifestHeader header = ManifestHeader.parse(importedPackages);
+ for(final ManifestHeader.Entry entry : header.getEntries()) {
+ final String resolution = entry.getDirectiveValue("resolution");
+ final PackageInfo pck = new PackageInfo(entry.getValue(),
+ entry.getAttributeValue("version"),
+ "optional".equalsIgnoreCase(resolution));
+ this.importedPackages.add(pck);
+ }
+ }
+ }
+
+ private void extractDynamicImportedPackages(final Manifest m) {
+ final String importedPackages = m.getMainAttributes().getValue(Constants.DYNAMICIMPORT_PACKAGE);
+ if (importedPackages != null) {
+ final ManifestHeader header = ManifestHeader.parse(importedPackages);
+ for(final ManifestHeader.Entry entry : header.getEntries()) {
+ final PackageInfo pck = new PackageInfo(entry.getValue(),
+ entry.getAttributeValue("version"),
+ false);
+ this.dynamicImportedPackages.add(pck);
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/ArtifactInfo.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java Tue May 30 08:07:16 2017
@@ -0,0 +1,142 @@
+/*
+ * 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.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.jar.Manifest;
+
+import org.apache.sling.commons.osgi.ManifestHeader;
+import org.apache.sling.feature.Artifact;
+import org.osgi.framework.Constants;
+
+/**
+ * Information about a bundle
+ */
+public class BundleInfo extends ArtifactInfo {
+
+ /** The manifest header to specify initial content to be loaded. */
+ private static final String CONTENT_HEADER = "Sling-Initial-Content";
+
+ /**
+ * The path directive specifying the target node where initial content will
+ * be loaded.
+ */
+ private static final String PATH_DIRECTIVE = "path";
+
+ /** The bundle symbolic name. */
+ private String symbolicName;
+
+ /** The bundle version. */
+ private String bundleVersion;
+
+ /** The start level of this artifact. */
+ private final int startLevel;
+
+ /** Initial content */
+ private final List<String> initialContent = new ArrayList<>();
+
+ public BundleInfo(final Artifact a,
+ final File file,
+ final int startLevel) throws IOException {
+ super(a, file);
+ this.startLevel = startLevel;
+ }
+
+ public String getBundleSymbolicName() {
+ return symbolicName;
+ }
+
+ public String getBundleVersion() {
+ return bundleVersion;
+ }
+
+ /**
+ * Get the start level
+ * @return The start level or {@code 0} for the default.
+ */
+ public int getBundleStartLevel() {
+ return startLevel;
+ }
+
+ public List<String> getInitialContent() {
+ return Collections.unmodifiableList(this.initialContent);
+ }
+
+ @Override
+ protected void doAnalyze(final Manifest m) throws IOException {
+ final String name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
+ if ( name != null ) {
+ final String version = m.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;
+ }
+
+ extractInitialContent(m);
+
+ super.doAnalyze(m);
+ } else {
+ throw new IOException("Unable to get bundle symbolic name from artifact " + getArtifact().getId().toMvnId());
+ }
+ }
+
+ private void extractInitialContent(final Manifest m) {
+ final String root = m.getMainAttributes().getValue(CONTENT_HEADER);
+ if (root != null) {
+ final ManifestHeader header = ManifestHeader.parse(root);
+ for (final ManifestHeader.Entry entry : header.getEntries()) {
+
+ String path = entry.getDirectiveValue(PATH_DIRECTIVE);
+ if (path == null) {
+ path = "/";
+ } else if (!path.startsWith("/")) {
+ // make relative path absolute
+ path = "/" + path;
+ }
+ this.initialContent.add(path);
+ }
+ }
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if ( obj instanceof BundleInfo ) {
+ return this.symbolicName.equals(((BundleInfo)obj).symbolicName) && this.bundleVersion.equals(((BundleInfo)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 + "]";
+ }
+}
\ No newline at end of file
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/BundleInfo.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java Tue May 30 08:07:16 2017
@@ -0,0 +1,58 @@
+/*
+ * 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.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
+
+public class PackageInfo {
+
+ private final boolean optional;
+ private final String name;
+ private final String version;
+
+ public PackageInfo(final String name, final String version, final boolean optional) {
+ this.name = name;
+ this.version = version;
+ this.optional = optional;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public boolean isOptional() {
+ return optional;
+ }
+
+ public Version getPackageVersion() {
+ return new Version(this.version);
+ }
+
+ public VersionRange getPackageVersionRange() {
+ return new VersionRange(this.version);
+ }
+
+ @Override
+ public String toString() {
+ return "Package " + name + ";version=" + version;
+ }
+}
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/PackageInfo.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Added: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java (added)
+++ sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java Tue May 30 08:07:16 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.feature.analyser;
+
+
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature-analyser/src/main/java/org/apache/sling/feature/analyser/package-info.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified: sling/whiteboard/cziegeler/feature/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/pom.xml?rev=1796767&r1=1796766&r2=1796767&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature/pom.xml (original)
+++ sling/whiteboard/cziegeler/feature/pom.xml Tue May 30 08:07:16 2017
@@ -51,7 +51,7 @@
<Conditional-Package>
org.apache.felix.configurator.impl.conversion,
org.apache.felix.configurator.impl.json,
- org.apache.felix.configurator.impl.model
+ org.apache.felix.configurator.impl.model
</Conditional-Package>
</instructions>
</configuration>
Modified: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Bundles.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Bundles.java?rev=1796767&r1=1796766&r2=1796767&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Bundles.java (original)
+++ sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Bundles.java Tue May 30 08:07:16 2017
@@ -71,4 +71,15 @@ public class Bundles {
public void clear() {
this.startLevelMap.clear();
}
+
+ public boolean contains(final ArtifactId id) {
+ for(final Map.Entry<Integer, List<Artifact>> entry : this.startLevelMap.entrySet()) {
+ for(final Artifact artifact : entry.getValue()) {
+ if ( artifact.getId().equals(id)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
Added: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java (added)
+++ sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java Tue May 30 08:07:16 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.feature.analyser;
+
+
Propchange: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/analyser/package-info.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Modified: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/json/FeatureJSONReader.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/json/FeatureJSONReader.java?rev=1796767&r1=1796766&r2=1796767&view=diff
==============================================================================
--- sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/json/FeatureJSONReader.java (original)
+++ sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/json/FeatureJSONReader.java Tue May 30 08:07:16 2017
@@ -44,15 +44,14 @@ import org.apache.sling.feature.Include;
import org.apache.sling.feature.Requirement;
/**
- * This class offers a method to read a model using a {@code Reader} instance.
- *
- * TODO - check for IllegalStateException|IllegalArgumentException
+ * This class offers a method to read a {@code Feature} using a {@code Reader} instance.
*/
public class FeatureJSONReader {
/**
* Read a new feature from the reader
* The reader is not closed. It is up to the caller to close the reader.
+ *
* @param reader The reader for the feature
* @param location Optional location
* @return The read feature
@@ -68,15 +67,21 @@ public class FeatureJSONReader {
contents = out.toString();
}
- final FeatureJSONReader mr = new FeatureJSONReader(location);
- return mr.readFeature(new StringReader(contents));
+ try {
+ final FeatureJSONReader mr = new FeatureJSONReader(location);
+ return mr.readFeature(new StringReader(contents));
+ } catch (final IllegalStateException | IllegalArgumentException e) {
+ throw new IOException(e);
+ }
}
-
+ /** The read feature. */
private Feature feature;
+ /** The optional location. */
private final String location;
+ /** Exception prefix containing the location (if set) */
private final String exceptionPrefix;
/**
@@ -126,7 +131,7 @@ public class FeatureJSONReader {
// TODO - extensions
- // TODO - check duplicates (e.g. bundles, includes...)
+ // check duplicates in configurations, includes, extensions
return feature;
}
@@ -296,6 +301,9 @@ public class FeatureJSONReader {
final List<Artifact> list = new ArrayList<>();
readArtifacts("startLevel", "bundle", list, val);
for(final Artifact a : list) {
+ if ( this.feature.getBundles().contains(a.getId()) ) {
+ throw new IOException(this.exceptionPrefix + "Duplicate bundle " + a.getId().toMvnId());
+ }
this.feature.getBundles().add(startLevel, a);
}
}
Added: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java?rev=1796767&view=auto
==============================================================================
--- sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java (added)
+++ sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java Tue May 30 08:07:16 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+@org.osgi.annotation.versioning.Version("1.0.0")
+package org.apache.sling.feature.process;
+
+
Propchange: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/package-info.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url