You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/11/22 11:41:11 UTC
(sling-org-apache-sling-feature-analyser) 02/03: SLING-12504 - Update Feature Analyser to parent 61
This is an automated email from the ASF dual-hosted git repository.
jsedding pushed a commit to branch update-to-parent-61
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-analyser.git
commit 37f2c1f01f94de13da4f8af5c208f7d6a0d8c36d
Author: Julian Sedding <js...@apache.org>
AuthorDate: Fri Nov 22 11:48:20 2024 +0100
SLING-12504 - Update Feature Analyser to parent 61
- mvn spotless:apply
---
pom.xml | 112 +++++++-------
.../apache/sling/feature/analyser/Analyser.java | 119 +++++++++------
.../sling/feature/analyser/AnalyserResult.java | 76 +++++----
.../extensions/AnalyserMetaDataExtension.java | 84 +++++-----
.../extensions/AnalyserMetaDataHandler.java | 152 +++++++++---------
.../sling/feature/analyser/package-info.java | 2 -
.../sling/feature/analyser/task/AnalyserTask.java | 33 ++--
.../feature/analyser/task/AnalyserTaskContext.java | 35 +++--
.../analyser/task/AnalyzerTaskProvider.java | 11 +-
.../task/impl/CheckApisJarsProperties.java | 139 +++++++++--------
.../task/impl/CheckBundleExportsImports.java | 74 +++++----
.../analyser/task/impl/CheckBundleNativeCode.java | 8 +-
.../task/impl/CheckBundleUnversionedPackages.java | 51 ++++---
.../analyser/task/impl/CheckBundlesForConnect.java | 11 +-
.../task/impl/CheckBundlesForInitialContent.java | 10 +-
.../task/impl/CheckBundlesForResources.java | 8 +-
.../analyser/task/impl/CheckCompareFeatures.java | 62 ++++----
.../analyser/task/impl/CheckConfigurations.java | 7 +-
.../impl/CheckContentPackageForInstallables.java | 59 ++++---
.../analyser/task/impl/CheckContentPackages.java | 100 +++++++-----
.../impl/CheckContentPackagesDependencies.java | 47 +++---
.../task/impl/CheckContentPackagesForPaths.java | 55 +++----
.../task/impl/CheckDuplicateSymbolicName.java | 12 +-
.../feature/analyser/task/impl/CheckFeatureId.java | 27 ++--
.../feature/analyser/task/impl/CheckRepoinit.java | 29 ++--
.../task/impl/CheckRequirementsCapabilities.java | 108 +++++++------
.../task/impl/CheckServiceUserMapping.java | 24 ++-
.../analyser/task/impl/CheckUnusedBundles.java | 43 +++---
.../ArchiveValidationContextImpl.java | 28 ++--
.../task/impl/contentpackage/PackageValidator.java | 55 ++++---
.../sling/feature/analyser/task/package-info.java | 2 -
.../sling/feature/scanner/ArtifactDescriptor.java | 28 ++--
.../sling/feature/scanner/BundleDescriptor.java | 48 +++---
.../sling/feature/scanner/ContainerDescriptor.java | 38 ++---
.../feature/scanner/ContentPackageDescriptor.java | 29 ++--
.../apache/sling/feature/scanner/Descriptor.java | 34 +++--
.../sling/feature/scanner/FeatureDescriptor.java | 28 ++--
.../apache/sling/feature/scanner/PackageInfo.java | 63 ++++----
.../org/apache/sling/feature/scanner/Scanner.java | 90 ++++++-----
.../scanner/impl/ArtifactDescriptorImpl.java | 35 ++---
.../feature/scanner/impl/BundleDescriptorImpl.java | 90 +++++------
.../scanner/impl/ContentPackageDescriptorImpl.java | 33 ++--
.../scanner/impl/ContentPackageScanner.java | 169 ++++++++++++---------
.../impl/ContentPackagesExtensionScanner.java | 51 ++++---
.../scanner/impl/FeatureDescriptorImpl.java | 31 ++--
.../scanner/impl/FelixFrameworkScanner.java | 82 +++++-----
.../scanner/impl/MatchingRequirementImpl.java | 36 +++--
.../feature/scanner/impl/RepoInitScanner.java | 42 ++---
.../scanner/impl/SystemBundleDescriptor.java | 34 +++--
.../impl/fwk/FrameworkPropertiesGatherer.java | 38 ++---
.../apache/sling/feature/scanner/package-info.java | 2 -
.../feature/scanner/spi/ExtensionScanner.java | 35 +++--
.../feature/scanner/spi/FrameworkScanner.java | 41 ++---
.../sling/feature/scanner/spi/package-info.java | 2 -
.../sling/feature/analyser/AnalyserTest.java | 99 +++++++-----
.../extensions/AnalyserMetaDataExtensionTest.java | 61 +++++---
.../extensions/AnalyserMetaDataHandlerTest.java | 137 +++++++++--------
.../task/impl/AnalyserTaskContextImpl.java | 17 +--
.../task/impl/AnalyserTaskProviderTest.java | 18 +--
.../task/impl/CheckApisJarsPropertiesTest.java | 44 +++---
.../task/impl/CheckBundleExportsImportsTest.java | 23 +--
.../task/impl/CheckBundleNativeCodeTest.java | 2 +-
.../impl/CheckBundleUnversionedPackagesTest.java | 29 ++--
.../task/impl/CheckCompareFeaturesTest.java | 51 ++++---
.../task/impl/CheckConfigurationsTest.java | 34 +++--
.../impl/CheckContentPackagesDependenciesTest.java | 76 ++++-----
.../CheckContentPackagesForInstallablesTest.java | 74 ++++++---
.../impl/CheckContentPackagesForPathsTest.java | 60 +++++---
.../task/impl/CheckContentPackagesTest.java | 88 +++++++----
.../task/impl/CheckDuplicateSymbolicNameTest.java | 35 +++--
.../analyser/task/impl/CheckFeatureIdTest.java | 84 ++++++----
.../analyser/task/impl/CheckRepoinitTest.java | 57 ++++---
.../impl/CheckRequirementsCapabilitiesTest.java | 62 ++++----
.../task/impl/CheckServiceUserMappingTest.java | 45 +++---
.../feature/analyser/task/impl/RulesTest.java | 40 ++---
.../scanner/impl/BundleDescriptorImplTest.java | 92 ++++++-----
.../scanner/impl/ContentPackageScannerTest.java | 124 ++++++++++-----
.../scanner/impl/FelixFrameworkScannerTest.java | 82 +++++-----
78 files changed, 2268 insertions(+), 1828 deletions(-)
diff --git a/pom.xml b/pom.xml
index 8b04c37..2b39766 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -31,73 +31,27 @@
<version>2.0.11-SNAPSHOT</version>
<name>Apache Sling Feature Model Analyser</name>
- <description>
- A feature describes an OSGi system
- </description>
-
- <properties>
- <sling.java.version>8</sling.java.version>
- <project.build.outputTimestamp>1723369461</project.build.outputTimestamp>
- </properties>
+ <description>A feature describes an OSGi system</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-analyser.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-analyser.git</developerConnection>
+ <tag>org.apache.sling.feature.analyser-1.6.4</tag>
<url>https://github.com/apache/sling-org-apache-sling-feature-analyser.git</url>
- <tag>org.apache.sling.feature.analyser-1.6.4</tag>
- </scm>
+ </scm>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>readme.md</exclude>
- <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask</exclude>
- <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.spi.ExtensionScanner</exclude>
- <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.spi.FrameworkScanner</exclude>
- <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler</exclude>
- <exclude>src/test/resources/origins/**</exclude>
- <exclude>src/test/resources/test-bundle-src/**</exclude>
- <exclude>src/test/resources/**.xml</exclude>
- </excludes>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <createSourcesJar>true</createSourcesJar>
- <shadeSourcesContent>true</shadeSourcesContent>
- <createDependencyReducedPom>false</createDependencyReducedPom>
- <relocations>
- <relocation>
- <pattern>org.apache.felix</pattern>
- <shadedPattern>org.apache.sling.feature.analyzer.impl.felix</shadedPattern>
- </relocation>
- </relocations>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ <project.build.outputTimestamp>1723369461</project.build.outputTimestamp>
+ </properties>
<dependencies>
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.2</version>
<scope>provided</scope>
- </dependency>
- <dependency>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
<scope>provided</scope>
@@ -208,8 +162,8 @@
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
- <classifier>jakarta</classifier>
<version>1.2.14</version>
+ <classifier>jakarta</classifier>
<scope>test</scope>
</dependency>
<dependency>
@@ -231,4 +185,48 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>readme.md</exclude>
+ <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.analyser.task.AnalyserTask</exclude>
+ <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.spi.ExtensionScanner</exclude>
+ <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.scanner.spi.FrameworkScanner</exclude>
+ <exclude>src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler</exclude>
+ <exclude>src/test/resources/origins/**</exclude>
+ <exclude>src/test/resources/test-bundle-src/**</exclude>
+ <exclude>src/test/resources/**.xml</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <createSourcesJar>true</createSourcesJar>
+ <shadeSourcesContent>true</shadeSourcesContent>
+ <createDependencyReducedPom>false</createDependencyReducedPom>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.felix</pattern>
+ <shadedPattern>org.apache.sling.feature.analyzer.impl.felix</shadedPattern>
+ </relocation>
+ </relocations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/org/apache/sling/feature/analyser/Analyser.java b/src/main/java/org/apache/sling/feature/analyser/Analyser.java
index a2c3ecf..6ccea8f 100644
--- a/src/main/java/org/apache/sling/feature/analyser/Analyser.java
+++ b/src/main/java/org/apache/sling/feature/analyser/Analyser.java
@@ -1,25 +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
+ * 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
+ * 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.
+ * 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 static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasks;
-import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByClassName;
-import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByIds;
-
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -44,6 +42,10 @@ import org.apache.sling.feature.scanner.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasks;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByClassName;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByIds;
+
public class Analyser {
/**
* Configurration key for configuration that applies to all tasks.
@@ -79,8 +81,9 @@ public class Analyser {
* @param tasks The tasks
* @throws IOException If setting up the analyser fails
*/
- public Analyser(final Scanner scanner, final Map<String, Map<String, String>> configurations,
- final AnalyserTask... tasks) throws IOException {
+ public Analyser(
+ final Scanner scanner, final Map<String, Map<String, String>> configurations, final AnalyserTask... tasks)
+ throws IOException {
this.tasks = tasks;
this.configurations = configurations;
this.scanner = scanner;
@@ -106,8 +109,11 @@ public class Analyser {
* @param taskClassNames The task class names
* @throws IOException If setting up the analyser fails
*/
- public Analyser(final Scanner scanner, final Map<String, Map<String, String>> configurations,
- final String... taskClassNames) throws IOException {
+ public Analyser(
+ final Scanner scanner,
+ final Map<String, Map<String, String>> configurations,
+ final String... taskClassNames)
+ throws IOException {
this(scanner, configurations, getTasksByClassName(taskClassNames));
if (this.tasks.length != taskClassNames.length) {
throw new IOException("Couldn't find all tasks " + Arrays.toString(taskClassNames));
@@ -137,8 +143,12 @@ public class Analyser {
* @param excludes The excludes for the task ids - can be {@code null}
* @throws IOException If setting up the analyser fails
*/
- public Analyser(final Scanner scanner, final Map<String, Map<String, String>> configurations,
- final Set<String> includes, final Set<String> excludes) throws IOException {
+ public Analyser(
+ final Scanner scanner,
+ final Map<String, Map<String, String>> configurations,
+ final Set<String> includes,
+ final Set<String> excludes)
+ throws IOException {
this(scanner, configurations, getTasksByIds(includes, excludes));
}
@@ -202,8 +212,8 @@ public class Analyser {
BundleDescriptor bd = null;
ArtifactId framework = fwk;
if (framework == null) {
- final ExecutionEnvironmentExtension ext = ExecutionEnvironmentExtension
- .getExecutionEnvironmentExtension(feature);
+ final ExecutionEnvironmentExtension ext =
+ ExecutionEnvironmentExtension.getExecutionEnvironmentExtension(feature);
if (ext != null && ext.getFramework() != null) {
framework = ext.getFramework().getId();
}
@@ -226,7 +236,8 @@ public class Analyser {
final List<AnalyserResult.ExtensionReport> extensionErrors = new ArrayList<>();
final List<AnalyserResult.ConfigurationReport> configurationErrors = new ArrayList<>();
- AnalyserMetaDataExtension analyserMetaDataExtension = AnalyserMetaDataExtension.getAnalyserMetaDataExtension(feature);
+ AnalyserMetaDataExtension analyserMetaDataExtension =
+ AnalyserMetaDataExtension.getAnalyserMetaDataExtension(feature);
// execute analyser tasks
for (final AnalyserTask task : tasks) {
@@ -239,13 +250,16 @@ public class Analyser {
final boolean strict = Boolean.valueOf(taskConfiguration.getOrDefault("strict", "false"));
task.execute(new AnalyserTaskContext() {
- private final FeatureProvider cachingFeatureProvider = featureProvider != null ? new FeatureProvider() {
- private final ConcurrentHashMap<ArtifactId, Feature> cache = new ConcurrentHashMap<>();
- @Override
- public Feature provide(ArtifactId artifactId) {
- return cache.computeIfAbsent(artifactId, key -> featureProvider.provide(artifactId));
- }
- }: null;
+ private final FeatureProvider cachingFeatureProvider = featureProvider != null
+ ? new FeatureProvider() {
+ private final ConcurrentHashMap<ArtifactId, Feature> cache = new ConcurrentHashMap<>();
+
+ @Override
+ public Feature provide(ArtifactId artifactId) {
+ return cache.computeIfAbsent(artifactId, key -> featureProvider.provide(artifactId));
+ }
+ }
+ : null;
@Override
public Feature getFeature() {
@@ -287,14 +301,18 @@ public class Analyser {
if (strict) {
reportArtifactError(artifactId, message);
}
- if (analyserMetaDataExtension == null || (analyserMetaDataExtension.reportWarning(artifactId) && analyserMetaDataExtension.reportWarning(feature.getId()))) {
+ if (analyserMetaDataExtension == null
+ || (analyserMetaDataExtension.reportWarning(artifactId)
+ && analyserMetaDataExtension.reportWarning(feature.getId()))) {
artifactWarnings.add(new AnalyserResult.ArtifactReport(artifactId, message, task.getId()));
}
}
@Override
public void reportArtifactError(ArtifactId artifactId, String message) {
- if (analyserMetaDataExtension == null || (analyserMetaDataExtension.reportError(artifactId) && analyserMetaDataExtension.reportError(feature.getId()))) {
+ if (analyserMetaDataExtension == null
+ || (analyserMetaDataExtension.reportError(artifactId)
+ && analyserMetaDataExtension.reportError(feature.getId()))) {
artifactErrors.add(new AnalyserResult.ArtifactReport(artifactId, message, task.getId()));
}
}
@@ -341,14 +359,26 @@ public class Analyser {
}
});
if (this.outputTaskDetails) {
- logger.info("- Executed {} [{}] in {}ms", task.getName(), task.getId(), System.currentTimeMillis() - startTask);
+ logger.info(
+ "- Executed {} [{}] in {}ms",
+ task.getName(),
+ task.getId(),
+ System.currentTimeMillis() - startTask);
}
}
- final int allWarnings = globalWarnings.size() + artifactWarnings.size() + extensionWarnings.size() + configurationWarnings.size();
- final int allErrors = globalErrors.size() + artifactErrors.size() + extensionErrors.size() + configurationErrors.size();
- logger.info("Finished analyzing feature '{}' in {}ms : {} warnings, {} errors.",
- feature.getId(), System.currentTimeMillis() - start, allWarnings, allErrors);
+ final int allWarnings = globalWarnings.size()
+ + artifactWarnings.size()
+ + extensionWarnings.size()
+ + configurationWarnings.size();
+ final int allErrors =
+ globalErrors.size() + artifactErrors.size() + extensionErrors.size() + configurationErrors.size();
+ logger.info(
+ "Finished analyzing feature '{}' in {}ms : {} warnings, {} errors.",
+ feature.getId(),
+ System.currentTimeMillis() - start,
+ allWarnings,
+ allErrors);
return new AnalyserResult() {
@Override
@@ -403,17 +433,14 @@ public class Analyser {
};
}
- Map<String,String> getConfiguration(final String id) {
- final Map<String,String> result = new HashMap<>();
+ Map<String, String> getConfiguration(final String id) {
+ final Map<String, String> result = new HashMap<>();
Map<String, String> globalCfg = this.configurations.get(ALL_TASKS_KEY);
- if (globalCfg != null)
- result.putAll(globalCfg);
-
+ if (globalCfg != null) result.putAll(globalCfg);
Map<String, String> specificCfg = this.configurations.get(id);
- if (specificCfg != null)
- result.putAll(specificCfg);
+ if (specificCfg != null) result.putAll(specificCfg);
return result;
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/AnalyserResult.java b/src/main/java/org/apache/sling/feature/analyser/AnalyserResult.java
index fe7ef59..889a445 100644
--- a/src/main/java/org/apache/sling/feature/analyser/AnalyserResult.java
+++ b/src/main/java/org/apache/sling/feature/analyser/AnalyserResult.java
@@ -1,32 +1,34 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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 java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.scanner.BundleDescriptor;
import org.apache.sling.feature.scanner.FeatureDescriptor;
import org.osgi.annotation.versioning.ProviderType;
-import java.util.List;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
/**
* The result returned by the {@code Analyser}.
* A result of an analyser run might contain warnings and or errors.
@@ -55,7 +57,7 @@ public interface AnalyserResult {
public T getKey() {
return key;
}
-
+
/**
* The message
* @return The message
@@ -63,7 +65,7 @@ public interface AnalyserResult {
public String getValue() {
return value;
}
-
+
/**
* Return the task id of the analyser task issuing this report
* @return The task id
@@ -75,7 +77,12 @@ public interface AnalyserResult {
@Override
public String toString() {
- return "[".concat(this.getTaskId()).concat("] ").concat(this.getKey().toString()).concat(": ").concat(this.getValue());
+ return "["
+ .concat(this.getTaskId())
+ .concat("] ")
+ .concat(this.getKey().toString())
+ .concat(": ")
+ .concat(this.getValue());
}
}
@@ -90,7 +97,12 @@ public interface AnalyserResult {
@Override
public String toString() {
- return "[".concat(this.getTaskId()).concat("] Configuration ").concat(this.getKey().getPid()).concat(": ").concat(this.getValue());
+ return "["
+ .concat(this.getTaskId())
+ .concat("] Configuration ")
+ .concat(this.getKey().getPid())
+ .concat(": ")
+ .concat(this.getValue());
}
}
@@ -130,15 +142,16 @@ public interface AnalyserResult {
/**
* List of warnings. Warnings can be used to improve the feature.
* This method returns all warnings, if more detailed information about the warnings is desired,
- * use {@link #getGlobalWarnings()}, {@link #getArtifactWarnings()}, {@link #getExtensionWarnings()},
+ * use {@link #getGlobalWarnings()}, {@link #getArtifactWarnings()}, {@link #getExtensionWarnings()},
* and {@link #getConfigurationWarnings()} instead.
* @return A list of warnings, might be empty.
*/
default List<String> getWarnings() {
- return Stream.of(getGlobalWarnings().stream().map(GlobalReport::toString),
- getArtifactWarnings().stream().map(Report::toString),
- getExtensionWarnings().stream().map(Report::toString),
- getConfigurationWarnings().stream().map(Report::toString))
+ return Stream.of(
+ getGlobalWarnings().stream().map(GlobalReport::toString),
+ getArtifactWarnings().stream().map(Report::toString),
+ getExtensionWarnings().stream().map(Report::toString),
+ getConfigurationWarnings().stream().map(Report::toString))
.flatMap(Function.identity())
.collect(Collectors.toList());
}
@@ -171,15 +184,16 @@ public interface AnalyserResult {
/**
* List of errors. Errors should be fixed in the feature
* This method returns all errors, if more detailed information about the errors is desired,
- * use {@link #getGlobalErrors()}, {@link #getArtifactErrors()}, {@link #getExtensionErrors ()},
+ * use {@link #getGlobalErrors()}, {@link #getArtifactErrors()}, {@link #getExtensionErrors ()},
* and {@link #getConfigurationErrors()} instead.
* @return A list of errors, might be empty.
*/
default List<String> getErrors() {
- return Stream.of(getGlobalErrors().stream().map(Report::toString),
- getArtifactErrors().stream().map(Report::toString),
- getExtensionErrors().stream().map(Report::toString),
- getConfigurationErrors().stream().map(Report::toString))
+ return Stream.of(
+ getGlobalErrors().stream().map(Report::toString),
+ getArtifactErrors().stream().map(Report::toString),
+ getExtensionErrors().stream().map(Report::toString),
+ getConfigurationErrors().stream().map(Report::toString))
.flatMap(Function.identity())
.collect(Collectors.toList());
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtension.java b/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtension.java
index 8435e3b..38f412e 100644
--- a/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtension.java
+++ b/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtension.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.extensions;
@@ -21,6 +23,10 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Stream;
+import jakarta.json.Json;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonValue;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionType;
@@ -28,31 +34,26 @@ import org.apache.sling.feature.Feature;
import org.apache.sling.feature.scanner.BundleDescriptor;
import org.osgi.framework.Constants;
-import jakarta.json.Json;
-import jakarta.json.JsonObject;
-import jakarta.json.JsonObjectBuilder;
-import jakarta.json.JsonValue;
-
public class AnalyserMetaDataExtension {
public static final String EXTENSION_NAME = "analyser-metadata";
// use ArtifactId.fromMvnId to ensure the string form can be parsed back to an ArtifactId
- static final String SYSTEM_BUNDLE_KEY = ArtifactId.fromMvnId("extra-metadata:" + Constants.SYSTEM_BUNDLE_SYMBOLICNAME + ":0").toString();
+ static final String SYSTEM_BUNDLE_KEY = ArtifactId.fromMvnId(
+ "extra-metadata:" + Constants.SYSTEM_BUNDLE_SYMBOLICNAME + ":0")
+ .toString();
static final String MANIFEST_KEY = "manifest";
static final String REPORT_KEY = "report";
static final String WARNING_KEY = "warning";
static final String ERROR_KEY = "error";
static final String ARTIFACT_ID_KEY = "artifactId";
static final String SCANNER_CACHE_KEY = "scannerCacheKey";
-
+
private final Map<ArtifactId, Map<String, String>> manifests = new HashMap<>();
private final Map<ArtifactId, Boolean> reportWarnings = new HashMap<>();
private final Map<ArtifactId, Boolean> reportErrors = new HashMap<>();
private SystemBundle systemBundle;
-
-
public static AnalyserMetaDataExtension getAnalyserMetaDataExtension(Feature feature) {
Extension ext = feature == null ? null : feature.getExtensions().getByName(EXTENSION_NAME);
return getAnalyserMetaDataExtension(ext);
@@ -71,20 +72,22 @@ public class AnalyserMetaDataExtension {
private AnalyserMetaDataExtension(JsonObject json) {
for (Map.Entry<String, JsonValue> entry : json.entrySet()) {
-
+
// handle system bundle separately
- if ( entry.getKey().equals(SYSTEM_BUNDLE_KEY) ) {
+ if (entry.getKey().equals(SYSTEM_BUNDLE_KEY)) {
JsonObject systemBundleConfig = entry.getValue().asJsonObject();
JsonObject manifestObj = systemBundleConfig.getJsonObject(MANIFEST_KEY);
- String artifactId = systemBundleConfig.getJsonString(ARTIFACT_ID_KEY).getString();
- String scannerCacheKey = systemBundleConfig.getJsonString(SCANNER_CACHE_KEY).getString();
-
+ String artifactId =
+ systemBundleConfig.getJsonString(ARTIFACT_ID_KEY).getString();
+ String scannerCacheKey =
+ systemBundleConfig.getJsonString(SCANNER_CACHE_KEY).getString();
+
Map<String, String> manifest = new HashMap<>();
for (String key : manifestObj.keySet()) {
manifest.put(key, manifestObj.getString(key));
}
systemBundle = new SystemBundle(manifest, ArtifactId.fromMvnId(artifactId), scannerCacheKey);
-
+
continue;
}
@@ -117,7 +120,7 @@ public class AnalyserMetaDataExtension {
public Map<String, String> getManifest(final ArtifactId artifactId) {
return this.manifests.get(artifactId);
}
-
+
public SystemBundle getSystemBundle() {
return systemBundle;
}
@@ -132,9 +135,13 @@ public class AnalyserMetaDataExtension {
public Extension toExtension(Extension extension) {
if (isAnalyserMetaDataExtension(extension)) {
- JsonObjectBuilder builder = Json.createObjectBuilder(extension.getJSONStructure().asJsonObject());
- Stream.concat(Stream.concat(manifests.keySet().stream(), reportErrors.keySet().stream()), reportWarnings.keySet().stream()).distinct().forEachOrdered(
- id -> {
+ JsonObjectBuilder builder =
+ Json.createObjectBuilder(extension.getJSONStructure().asJsonObject());
+ Stream.concat(
+ Stream.concat(manifests.keySet().stream(), reportErrors.keySet().stream()),
+ reportWarnings.keySet().stream())
+ .distinct()
+ .forEachOrdered(id -> {
JsonObjectBuilder metadata = Json.createObjectBuilder();
if (manifests.containsKey(id)) {
JsonObjectBuilder manifest = Json.createObjectBuilder();
@@ -152,8 +159,7 @@ public class AnalyserMetaDataExtension {
metadata.add(REPORT_KEY, report);
}
builder.add(id.toMvnId(), metadata);
- }
- );
+ });
extension.setJSONStructure(builder.build());
}
return extension;
@@ -176,27 +182,27 @@ public class AnalyserMetaDataExtension {
public void setReportErrors(ArtifactId id, boolean enabled) {
reportErrors.put(id, enabled);
}
-
+
public static class SystemBundle {
-
+
private Map<String, String> manifest = new HashMap<>();
private ArtifactId artifactId;
private String scannerCacheKey;
-
+
public SystemBundle(Map<String, String> manifest, ArtifactId artifactId, String scannerCacheKey) {
this.manifest = manifest;
this.artifactId = artifactId;
this.scannerCacheKey = scannerCacheKey;
}
-
+
public ArtifactId getArtifactId() {
return artifactId;
}
-
+
public Map<String, String> getManifest() {
return manifest;
}
-
+
public String getScannerCacheKey() {
return scannerCacheKey;
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandler.java b/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandler.java
index 65cda8d..434c69c 100644
--- a/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandler.java
+++ b/src/main/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandler.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.extensions;
@@ -28,6 +30,10 @@ import java.util.Set;
import java.util.StringJoiner;
import java.util.jar.JarFile;
+import jakarta.json.Json;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonObjectBuilder;
+import jakarta.json.JsonValue;
import org.apache.commons.lang3.SystemUtils;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.ExecutionEnvironmentExtension;
@@ -49,14 +55,9 @@ import org.osgi.resource.Capability;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import jakarta.json.Json;
-import jakarta.json.JsonObject;
-import jakarta.json.JsonObjectBuilder;
-import jakarta.json.JsonValue;
-
public class AnalyserMetaDataHandler implements PostProcessHandler {
private static final Logger LOG = LoggerFactory.getLogger(AnalyserMetaDataHandler.class);
-
+
@Override
public void postProcess(HandlerContext handlerContext, Feature feature, Extension extension) {
@@ -67,65 +68,68 @@ public class AnalyserMetaDataHandler implements PostProcessHandler {
Map<String, JsonValue> directEntries = new HashMap<>();
Map<String, JsonValue> wildcardEntries = new LinkedHashMap<>();
JsonObject[] systemBundleHolder = new JsonObject[1];
- extensionJSONStructure.entrySet().forEach(
- entry -> {
- if (entry.getKey().contains("*")) {
- wildcardEntries.put(entry.getKey(), entry.getValue());
- } else if (entry.getKey().equals(AnalyserMetaDataExtension.SYSTEM_BUNDLE_KEY)) {
- systemBundleHolder[0] = entry.getValue().asJsonObject();
+ extensionJSONStructure.entrySet().forEach(entry -> {
+ if (entry.getKey().contains("*")) {
+ wildcardEntries.put(entry.getKey(), entry.getValue());
+ } else if (entry.getKey().equals(AnalyserMetaDataExtension.SYSTEM_BUNDLE_KEY)) {
+ systemBundleHolder[0] = entry.getValue().asJsonObject();
+ } else {
+ directEntries.put(entry.getKey(), entry.getValue());
+ }
+ });
+
+ feature.getBundles().stream().forEach(bundle -> findFirst(directEntries, wildcardEntries, bundle.getId())
+ .ifPresent(json -> {
+ if (nullManifest(json)) {
+ JsonObjectBuilder wrapper = Json.createObjectBuilder(json);
+ wrapper.remove(AnalyserMetaDataExtension.MANIFEST_KEY);
+ result.add(bundle.getId().toMvnId(), wrapper);
+ } else if (noManifest(json)) {
+ JsonObjectBuilder wrapper = Json.createObjectBuilder(json);
+ getManifest(handlerContext, bundle.getId())
+ .ifPresent(
+ manifest -> wrapper.add(AnalyserMetaDataExtension.MANIFEST_KEY, manifest));
+ result.add(bundle.getId().toMvnId(), wrapper);
} else {
- directEntries.put(entry.getKey(), entry.getValue());
+ result.add(bundle.getId().toMvnId(), json);
}
- }
- );
-
- feature.getBundles().stream().forEach(
- bundle ->
- findFirst(directEntries, wildcardEntries, bundle.getId()).ifPresent(
- json -> {
- if (nullManifest(json)) {
- JsonObjectBuilder wrapper = Json.createObjectBuilder(json);
- wrapper.remove(AnalyserMetaDataExtension.MANIFEST_KEY);
- result.add(bundle.getId().toMvnId(), wrapper);
- } else if (noManifest(json)) {
- JsonObjectBuilder wrapper = Json.createObjectBuilder(json);
- getManifest(handlerContext, bundle.getId()).ifPresent(manifest ->
- wrapper.add(AnalyserMetaDataExtension.MANIFEST_KEY, manifest));
- result.add(bundle.getId().toMvnId(), wrapper);
- } else {
- result.add(bundle.getId().toMvnId(), json);
- }
- }
- )
- );
-
+ }));
+
// only process if we have an empty system bundle definition
- if (JsonValue.EMPTY_JSON_OBJECT.equals(systemBundleHolder[0]) ) {
+ if (JsonValue.EMPTY_JSON_OBJECT.equals(systemBundleHolder[0])) {
JsonObject systemBundle = systemBundleHolder[0];
try {
- ExecutionEnvironmentExtension executionEnv = ExecutionEnvironmentExtension.getExecutionEnvironmentExtension(feature);
- if ( executionEnv != null ) {
+ ExecutionEnvironmentExtension executionEnv =
+ ExecutionEnvironmentExtension.getExecutionEnvironmentExtension(feature);
+ if (executionEnv != null) {
ArtifactId frameworkId = executionEnv.getFramework().getId();
- if ( executionEnv.getJavaVersion() == null ) {
- LOG.warn("No java version set in execution environment extension, skipping version validation");
+ if (executionEnv.getJavaVersion() == null) {
+ LOG.warn(
+ "No java version set in execution environment extension, skipping version validation");
} else {
Version requiredJavaVersion = executionEnv.getJavaVersion();
Version currentJavaVersion = new Version(SystemUtils.JAVA_VERSION);
-
- if ( requiredJavaVersion.getMajor() != currentJavaVersion.getMajor() )
- throw new IllegalStateException("Execution environment requires Java " + requiredJavaVersion.getMajor() + ", but running on " + currentJavaVersion.getMajor() + ". Aborting.");
-
+
+ if (requiredJavaVersion.getMajor() != currentJavaVersion.getMajor())
+ throw new IllegalStateException(
+ "Execution environment requires Java " + requiredJavaVersion.getMajor()
+ + ", but running on " + currentJavaVersion.getMajor() + ". Aborting.");
}
- FrameworkScanner scanner = ServiceLoader.load(FrameworkScanner.class).iterator().next();
-
- BundleDescriptor fw = scanner.scan(frameworkId, feature.getFrameworkProperties(), handlerContext.getArtifactProvider());
+ FrameworkScanner scanner = ServiceLoader.load(FrameworkScanner.class)
+ .iterator()
+ .next();
+
+ BundleDescriptor fw = scanner.scan(
+ frameworkId, feature.getFrameworkProperties(), handlerContext.getArtifactProvider());
JsonObjectBuilder wrapper = Json.createObjectBuilder(systemBundle);
JsonObjectBuilder manifest = Json.createObjectBuilder();
manifest.add(Constants.PROVIDE_CAPABILITY, capabilitiesToString(fw.getCapabilities()));
manifest.add(Constants.EXPORT_PACKAGE, exportedPackagesToString(fw.getExportedPackages()));
wrapper.add(AnalyserMetaDataExtension.MANIFEST_KEY, manifest);
wrapper.add(AnalyserMetaDataExtension.ARTIFACT_ID_KEY, frameworkId.toMvnId());
- wrapper.add(AnalyserMetaDataExtension.SCANNER_CACHE_KEY, SystemBundleDescriptor.createCacheKey(frameworkId, feature.getFrameworkProperties()));
+ wrapper.add(
+ AnalyserMetaDataExtension.SCANNER_CACHE_KEY,
+ SystemBundleDescriptor.createCacheKey(frameworkId, feature.getFrameworkProperties()));
result.add(AnalyserMetaDataExtension.SYSTEM_BUNDLE_KEY, wrapper);
} else {
LOG.warn("No execution environment found, not creating framework capabilities");
@@ -138,7 +142,6 @@ public class AnalyserMetaDataHandler implements PostProcessHandler {
result.add(AnalyserMetaDataExtension.SYSTEM_BUNDLE_KEY, systemBundleHolder[0]);
}
-
feature.getExtensions().remove(extension);
// Mark the extension as optional now that we've processed it.
@@ -157,12 +160,12 @@ public class AnalyserMetaDataHandler implements PostProcessHandler {
}
private static String capabilitiesToString(Set<Capability> capabilities) {
-
+
StringJoiner joiner = new StringJoiner(",");
for (Capability c : capabilities) {
joiner.add(ResourceUtils.toString(null, c.getNamespace(), c.getAttributes(), c.getDirectives()));
}
-
+
return joiner.toString();
}
@@ -178,7 +181,8 @@ public class AnalyserMetaDataHandler implements PostProcessHandler {
return object.get(AnalyserMetaDataExtension.MANIFEST_KEY) == match;
}
- private Optional<JsonObject> findFirst(Map<String, JsonValue> directValues, Map<String, JsonValue> wildcardValues, ArtifactId bundle) {
+ private Optional<JsonObject> findFirst(
+ Map<String, JsonValue> directValues, Map<String, JsonValue> wildcardValues, ArtifactId bundle) {
JsonValue direct = directValues.get(bundle.toMvnId());
if (direct != null && direct != JsonValue.NULL) {
return Optional.of(direct.asJsonObject());
@@ -193,17 +197,17 @@ public class AnalyserMetaDataHandler implements PostProcessHandler {
private Optional<JsonObject> getManifest(HandlerContext handlerContext, ArtifactId bundle) {
URL url = handlerContext.getArtifactProvider().provide(bundle);
try (JarFile jarFile = IOUtils.getJarFileFromURL(url, false, null)) {
- return Optional.ofNullable(jarFile.getManifest())
- .map(manifest -> {
- JsonObjectBuilder manifestBuilder = Json.createObjectBuilder();
- manifest.getMainAttributes().entrySet().stream()
- .forEachOrdered(entry -> manifestBuilder.add(entry.getKey().toString(), (String) entry.getValue()));
-
- return manifestBuilder.build();
- });
+ return Optional.ofNullable(jarFile.getManifest()).map(manifest -> {
+ JsonObjectBuilder manifestBuilder = Json.createObjectBuilder();
+ manifest.getMainAttributes().entrySet().stream()
+ .forEachOrdered(
+ entry -> manifestBuilder.add(entry.getKey().toString(), (String) entry.getValue()));
+
+ return manifestBuilder.build();
+ });
} catch (IOException ex) {
LOG.error("Unable to parse manifest of: " + bundle, ex);
throw new UncheckedIOException(ex);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/analyser/package-info.java b/src/main/java/org/apache/sling/feature/analyser/package-info.java
index 7356714..c71d6fb 100644
--- a/src/main/java/org/apache/sling/feature/analyser/package-info.java
+++ b/src/main/java/org/apache/sling/feature/analyser/package-info.java
@@ -19,5 +19,3 @@
@org.osgi.annotation.versioning.Version("1.6.0")
package org.apache.sling.feature.analyser;
-
-
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTask.java b/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTask.java
index d72b15f..0841a41 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTask.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTask.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -30,14 +32,16 @@ public interface AnalyserTask {
*/
default String getId() {
return getClass().getName();
- };
+ }
+ ;
/** A human readable name to identify the task.
* @return the task name.
*/
default String getName() {
return getClass().getSimpleName();
- };
+ }
+ ;
/** Execute the task.
* @param ctx the task context.
@@ -45,4 +49,3 @@ public interface AnalyserTask {
*/
void execute(AnalyserTaskContext ctx) throws Exception;
}
-
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTaskContext.java b/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTaskContext.java
index 24718df..f00f02b 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTaskContext.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/AnalyserTaskContext.java
@@ -1,21 +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
+ * 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
+ * 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.
+ * 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;
+import java.util.Map;
+
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.Feature;
@@ -24,8 +28,6 @@ import org.apache.sling.feature.scanner.BundleDescriptor;
import org.apache.sling.feature.scanner.FeatureDescriptor;
import org.osgi.annotation.versioning.ProviderType;
-import java.util.Map;
-
@ProviderType
public interface AnalyserTaskContext {
@@ -59,7 +61,7 @@ public interface AnalyserTaskContext {
*
* @return The configuration map for the analyser task
*/
- Map<String,String> getConfiguration();
+ Map<String, String> getConfiguration();
/**
* This method is invoked by a {@link AnalyserTask} to report
@@ -124,7 +126,4 @@ public interface AnalyserTaskContext {
* @param message The message.
*/
void reportError(String message);
-
-
}
-
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/AnalyzerTaskProvider.java b/src/main/java/org/apache/sling/feature/analyser/task/AnalyzerTaskProvider.java
index 2b626ca..f8b3ebe 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/AnalyzerTaskProvider.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/AnalyzerTaskProvider.java
@@ -53,13 +53,12 @@ public final class AnalyzerTaskProvider {
* @throws IllegalStateException If an included task is not found
*/
public static AnalyserTask[] getTasksByIds(Set<String> includes, Set<String> excludes) {
- if (excludes == null)
- excludes = Collections.emptySet();
+ if (excludes == null) excludes = Collections.emptySet();
final ServiceLoader<AnalyserTask> loader = ServiceLoader.load(AnalyserTask.class);
final Set<String> foundTasks = new HashSet<>();
final List<AnalyserTask> list = new ArrayList<>();
- for(final AnalyserTask task : loader) {
+ for (final AnalyserTask task : loader) {
boolean included = includes != null ? includes.contains(task.getId()) : true;
boolean excluded = excludes.contains(task.getId());
@@ -86,7 +85,7 @@ public final class AnalyzerTaskProvider {
* @return The analyser tasks, array is never {@code null} but might be empty
* @throws IOException If class names is null or loading fails
*/
- public static AnalyserTask[] getTasksByClassName(String...taskClassNames) throws IOException {
+ public static AnalyserTask[] getTasksByClassName(String... taskClassNames) throws IOException {
if (taskClassNames == null) {
throw new IOException("Impossible to load Tasks from a null string array");
}
@@ -94,7 +93,8 @@ public final class AnalyzerTaskProvider {
List<AnalyserTask> list = new ArrayList<>();
for (String cls : taskClassNames) {
try {
- AnalyserTask task = (AnalyserTask) Analyser.class.getClassLoader().loadClass(cls).newInstance();
+ AnalyserTask task = (AnalyserTask)
+ Analyser.class.getClassLoader().loadClass(cls).newInstance();
list.add(task);
} catch (Exception e) {
throw new IOException(e);
@@ -102,5 +102,4 @@ public final class AnalyzerTaskProvider {
}
return list.toArray(new AnalyserTask[list.size()]);
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsProperties.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsProperties.java
index 6f0f233..4875131 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsProperties.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsProperties.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -23,7 +25,6 @@ import java.util.Arrays;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import jakarta.json.JsonValue.ValueType;
-
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Extension;
@@ -55,7 +56,6 @@ public class CheckApisJarsProperties implements AnalyserTask {
/** Alternative classifier for the source artifact. */
private static final String SCM_CLASSIFIER = "source-classifier";
-
/** Links for javadocs. */
private static final String JAVADOC_LINKS = "javadoc-links";
@@ -106,7 +106,7 @@ public class CheckApisJarsProperties implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) throws Exception {
- for(final Artifact artifact : ctx.getFeature().getBundles()) {
+ for (final Artifact artifact : ctx.getFeature().getBundles()) {
validateSourceInfo(ctx, artifact);
checkIdValidity(ctx, artifact, SCM_IDS);
checkIdValidity(ctx, artifact, API_IDS);
@@ -118,9 +118,9 @@ public class CheckApisJarsProperties implements AnalyserTask {
private void checkExtension(final AnalyserTaskContext ctx) {
final Extension ext = ctx.getFeature().getExtensions().getByName(EXTENSION_NAME);
- if ( ext != null ) {
- if ( ext.getType() != ExtensionType.JSON ) {
- ctx.reportExtensionError(EXTENSION_NAME,"is not of type JSON");
+ if (ext != null) {
+ if (ext.getType() != ExtensionType.JSON) {
+ ctx.reportExtensionError(EXTENSION_NAME, "is not of type JSON");
} else {
final JsonObject obj = ext.getJSONStructure().asJsonObject();
checkStringType(ctx, obj, PROP_API_VERSION);
@@ -143,56 +143,62 @@ public class CheckApisJarsProperties implements AnalyserTask {
}
private void checkStringType(final AnalyserTaskContext ctx, final JsonObject obj, final String propName) {
- if ( obj.containsKey(propName) ) {
+ if (obj.containsKey(propName)) {
final JsonValue val = obj.get(propName);
- if ( val.getValueType() != ValueType.STRING ) {
- ctx.reportExtensionError(EXTENSION_NAME,"property ".concat(propName).concat(" is not of type String"));
+ if (val.getValueType() != ValueType.STRING) {
+ ctx.reportExtensionError(
+ EXTENSION_NAME, "property ".concat(propName).concat(" is not of type String"));
}
}
}
private void checkStringArrayType(final AnalyserTaskContext ctx, final JsonObject obj, final String propName) {
- if ( obj.containsKey(propName) ) {
+ if (obj.containsKey(propName)) {
final JsonValue val = obj.get(propName);
- if ( val.getValueType() != ValueType.ARRAY ) {
- ctx.reportExtensionError(EXTENSION_NAME,"property ".concat(propName).concat(" is not of type Array"));
+ if (val.getValueType() != ValueType.ARRAY) {
+ ctx.reportExtensionError(
+ EXTENSION_NAME, "property ".concat(propName).concat(" is not of type Array"));
} else {
boolean hasNonStringValue = false;
- for(final JsonValue v : val.asJsonArray()) {
- if ( v.getValueType() != ValueType.STRING ) {
+ for (final JsonValue v : val.asJsonArray()) {
+ if (v.getValueType() != ValueType.STRING) {
hasNonStringValue = true;
}
}
- if ( hasNonStringValue ) {
- ctx.reportExtensionError(EXTENSION_NAME,"array ".concat(propName).concat(" contains non string values"));
+ if (hasNonStringValue) {
+ ctx.reportExtensionError(
+ EXTENSION_NAME, "array ".concat(propName).concat(" contains non string values"));
}
}
}
}
- private void checkStringOrStringArrayType(final AnalyserTaskContext ctx, final JsonObject obj, final String propName) {
- if ( obj.containsKey(propName) ) {
+ private void checkStringOrStringArrayType(
+ final AnalyserTaskContext ctx, final JsonObject obj, final String propName) {
+ if (obj.containsKey(propName)) {
final JsonValue val = obj.get(propName);
- if ( val.getValueType() != ValueType.STRING ) {
+ if (val.getValueType() != ValueType.STRING) {
checkStringArrayType(ctx, obj, propName);
}
}
}
private void checkStringMapType(final AnalyserTaskContext ctx, final JsonObject obj, final String propName) {
- if ( obj.containsKey(propName) ) {
+ if (obj.containsKey(propName)) {
final JsonValue val = obj.get(propName);
- if ( val.getValueType() != ValueType.OBJECT ) {
- ctx.reportExtensionError(EXTENSION_NAME,"property ".concat(propName).concat(" is not of type Object"));
+ if (val.getValueType() != ValueType.OBJECT) {
+ ctx.reportExtensionError(
+ EXTENSION_NAME, "property ".concat(propName).concat(" is not of type Object"));
} else {
boolean hasNonStringValue = false;
- for(final JsonValue v : val.asJsonObject().values()) {
- if ( v.getValueType() != ValueType.STRING ) {
+ for (final JsonValue v : val.asJsonObject().values()) {
+ if (v.getValueType() != ValueType.STRING) {
hasNonStringValue = true;
- }
+ }
}
- if ( hasNonStringValue ) {
- ctx.reportExtensionError(EXTENSION_NAME,"object ".concat(propName).concat(" contains non string values"));
+ if (hasNonStringValue) {
+ ctx.reportExtensionError(
+ EXTENSION_NAME, "object ".concat(propName).concat(" contains non string values"));
}
}
}
@@ -200,32 +206,34 @@ public class CheckApisJarsProperties implements AnalyserTask {
private void checkIdValidity(final AnalyserTaskContext ctx, final Artifact a, final String propName) {
final String sourceId = a.getMetadata().get(propName);
- if ( sourceId != null ) {
+ if (sourceId != null) {
Arrays.stream(sourceId.split(","))
- .map( String::trim )
- .filter( el -> el.length() > 0)
- .forEach( el -> {
- try {
- // at the moment we can not validate the availability of the artifact since there is no access to Maven APIs
- ArtifactId.parse(el);
- } catch ( IllegalArgumentException e) {
- ctx.reportArtifactError(a.getId()," has invalid " + propName + " entry '" + el + "' : " + e.getMessage());
- }
- });
+ .map(String::trim)
+ .filter(el -> el.length() > 0)
+ .forEach(el -> {
+ try {
+ // at the moment we can not validate the availability of the artifact since there is no
+ // access to Maven APIs
+ ArtifactId.parse(el);
+ } catch (IllegalArgumentException e) {
+ ctx.reportArtifactError(
+ a.getId(), " has invalid " + propName + " entry '" + el + "' : " + e.getMessage());
+ }
+ });
}
}
private void checkJavadocLinks(final AnalyserTaskContext ctx, final Artifact a) {
final String value = a.getMetadata().get(JAVADOC_LINKS);
- if ( value != null ) {
- for(String v : value.split(",") ) {
- if ( v.endsWith("/") ) {
+ if (value != null) {
+ for (String v : value.split(",")) {
+ if (v.endsWith("/")) {
v = v.substring(0, v.length() - 1);
}
try {
new URL(v);
- } catch ( final MalformedURLException mue) {
- ctx.reportArtifactError(a.getId(),"has invalid javadoc links URL : " + v);
+ } catch (final MalformedURLException mue) {
+ ctx.reportArtifactError(a.getId(), "has invalid javadoc links URL : " + v);
}
}
}
@@ -236,20 +244,25 @@ public class CheckApisJarsProperties implements AnalyserTask {
*/
private void validateSourceInfo(final AnalyserTaskContext ctx, final Artifact artifact) {
int count = 0;
- if ( artifact.getMetadata().get(SCM_LOCATION) != null ) {
+ if (artifact.getMetadata().get(SCM_LOCATION) != null) {
count++;
}
- if ( artifact.getMetadata().get(SCM_CLASSIFIER) != null ) {
+ if (artifact.getMetadata().get(SCM_CLASSIFIER) != null) {
count++;
}
- if ( artifact.getMetadata().get(SCM_IDS) != null ) {
+ if (artifact.getMetadata().get(SCM_IDS) != null) {
count++;
}
- if ( count > 1 ) {
- ctx.reportArtifactError(artifact.getId(),
- "should either define ".concat(SCM_LOCATION).concat(", ")
- .concat(SCM_CLASSIFIER).concat(", or")
- .concat(SCM_IDS).concat(" - but only one of them."));
+ if (count > 1) {
+ ctx.reportArtifactError(
+ artifact.getId(),
+ "should either define "
+ .concat(SCM_LOCATION)
+ .concat(", ")
+ .concat(SCM_CLASSIFIER)
+ .concat(", or")
+ .concat(SCM_IDS)
+ .concat(" - but only one of them."));
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
index 0aaac9d..efe13ff 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImports.java
@@ -64,29 +64,31 @@ public class CheckBundleExportsImports implements AnalyserTask {
final Map<BundleDescriptor, Report> reports = new HashMap<>();
final SortedMap<Integer, List<BundleDescriptor>> bundlesMap = new TreeMap<>();
- for(final BundleDescriptor bi : ctx.getFeatureDescriptor().getBundleDescriptors()) {
- bundlesMap.computeIfAbsent(bi.getArtifact().getStartOrder(), key -> new ArrayList<>()).add(bi);
+ for (final BundleDescriptor bi : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ bundlesMap
+ .computeIfAbsent(bi.getArtifact().getStartOrder(), key -> new ArrayList<>())
+ .add(bi);
}
// add all system packages
final List<BundleDescriptor> exportingBundles = new ArrayList<>();
- if ( ctx.getFrameworkDescriptor() != null ) {
+ if (ctx.getFrameworkDescriptor() != null) {
exportingBundles.add(ctx.getFrameworkDescriptor());
}
- for(final Map.Entry<Integer, List<BundleDescriptor>> entry : bundlesMap.entrySet()) {
+ for (final Map.Entry<Integer, List<BundleDescriptor>> entry : bundlesMap.entrySet()) {
// first add all exporting bundles
- for(final BundleDescriptor info : entry.getValue()) {
- if ( !info.getExportedPackages().isEmpty() ) {
+ for (final BundleDescriptor info : entry.getValue()) {
+ if (!info.getExportedPackages().isEmpty()) {
exportingBundles.add(info);
}
}
// check importing bundles
- for(final BundleDescriptor info : entry.getValue()) {
- for(final PackageInfo pck : info.getImportedPackages() ) {
+ for (final BundleDescriptor info : entry.getValue()) {
+ for (final PackageInfo pck : info.getImportedPackages()) {
final List<BundleDescriptor> candidates = getCandidates(exportingBundles, pck);
- if ( candidates.isEmpty() ) {
- if ( pck.isOptional() ) {
+ if (candidates.isEmpty()) {
+ if (pck.isOptional()) {
getReport(reports, info).missingExportsForOptional.add(pck);
} else {
getReport(reports, info).missingExports.add(pck);
@@ -98,13 +100,17 @@ public class CheckBundleExportsImports implements AnalyserTask {
matchingCandidates.add(i);
}
}
- if ( matchingCandidates.isEmpty() ) {
- if ( pck.isOptional() ) {
- getReport(reports, info).missingExportsForOptional.add(pck);
+ if (matchingCandidates.isEmpty()) {
+ if (pck.isOptional()) {
+ getReport(reports, info)
+ .missingExportsForOptional
+ .add(pck);
} else {
- getReport(reports, info).missingExportsWithVersion.add(pck);
+ getReport(reports, info)
+ .missingExportsWithVersion
+ .add(pck);
}
- } else if ( matchingCandidates.size() > 1 ) {
+ } else if (matchingCandidates.size() > 1) {
getReport(reports, info).exportMatchingSeveral.add(pck);
}
}
@@ -113,18 +119,24 @@ public class CheckBundleExportsImports implements AnalyserTask {
}
boolean errorReported = false;
- for(final Map.Entry<BundleDescriptor, Report> entry : reports.entrySet()) {
- if ( !entry.getValue().missingExports.isEmpty() ) {
- ctx.reportArtifactError(entry.getKey().getArtifact().getId(), "Bundle is importing " + getPackageInfo(entry.getValue().missingExports, false) + " with start order " +
- String.valueOf(entry.getKey().getArtifact().getStartOrder())
- + " but no bundle is exporting these for that start order.");
+ for (final Map.Entry<BundleDescriptor, Report> entry : reports.entrySet()) {
+ if (!entry.getValue().missingExports.isEmpty()) {
+ ctx.reportArtifactError(
+ entry.getKey().getArtifact().getId(),
+ "Bundle is importing " + getPackageInfo(entry.getValue().missingExports, false)
+ + " with start order "
+ + String.valueOf(entry.getKey().getArtifact().getStartOrder())
+ + " but no bundle is exporting these for that start order.");
errorReported = true;
}
- if ( !entry.getValue().missingExportsWithVersion.isEmpty() ) {
- ctx.reportArtifactError(entry.getKey().getArtifact().getId(), "Bundle is importing "
- + getPackageInfo(entry.getValue().missingExportsWithVersion, true) + " with start order "
- + String.valueOf(entry.getKey().getArtifact().getStartOrder())
- + " but no bundle is exporting these for that start order in the required version range.");
+ if (!entry.getValue().missingExportsWithVersion.isEmpty()) {
+ ctx.reportArtifactError(
+ entry.getKey().getArtifact().getId(),
+ "Bundle is importing "
+ + getPackageInfo(entry.getValue().missingExportsWithVersion, true)
+ + " with start order "
+ + String.valueOf(entry.getKey().getArtifact().getStartOrder())
+ + " but no bundle is exporting these for that start order in the required version range.");
errorReported = true;
}
}
@@ -134,7 +146,7 @@ public class CheckBundleExportsImports implements AnalyserTask {
}
private String getPackageInfo(final List<PackageInfo> pcks, final boolean includeVersion) {
- if ( pcks.size() == 1 ) {
+ if (pcks.size() == 1) {
final StringBuilder sb = new StringBuilder("package ");
sb.append(pcks.get(0).getName());
if (includeVersion) {
@@ -146,8 +158,8 @@ public class CheckBundleExportsImports implements AnalyserTask {
final StringBuilder sb = new StringBuilder("packages ");
boolean first = true;
sb.append('[');
- for(final PackageInfo info : pcks) {
- if ( first ) {
+ for (final PackageInfo info : pcks) {
+ if (first) {
first = false;
} else {
sb.append(", ");
@@ -164,11 +176,11 @@ public class CheckBundleExportsImports implements AnalyserTask {
private List<BundleDescriptor> getCandidates(final List<BundleDescriptor> exportingBundles, final PackageInfo pck) {
final List<BundleDescriptor> candidates = new ArrayList<>();
- for(final BundleDescriptor info : exportingBundles) {
- if ( info.isExportingPackage(pck.getName()) ) {
+ for (final BundleDescriptor info : exportingBundles) {
+ if (info.isExportingPackage(pck.getName())) {
candidates.add(info);
}
}
return candidates;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCode.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCode.java
index ec232e3..d8a34a4 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCode.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCode.java
@@ -39,12 +39,14 @@ public class CheckBundleNativeCode implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) {
- for(final BundleDescriptor descriptor : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor descriptor : ctx.getFeatureDescriptor().getBundleDescriptors()) {
final Manifest mf = descriptor.getManifest();
final String nativeCode = mf.getMainAttributes().getValue(Constants.BUNDLE_NATIVECODE);
- if ( nativeCode != null ) {
- ctx.reportArtifactError(descriptor.getArtifact().getId(), "Found native code instruction in bundle: ".concat(nativeCode) );
+ if (nativeCode != null) {
+ ctx.reportArtifactError(
+ descriptor.getArtifact().getId(),
+ "Found native code instruction in bundle: ".concat(nativeCode));
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackages.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackages.java
index c325350..50bb5a3 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackages.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackages.java
@@ -28,11 +28,11 @@ import org.apache.sling.feature.scanner.BundleDescriptor;
import org.apache.sling.feature.scanner.PackageInfo;
import org.osgi.framework.Version;
-
public class CheckBundleUnversionedPackages implements AnalyserTask {
/** Ignore JDK packages */
- private static final List<String> IGNORED_IMPORT_PREFIXES = Arrays.asList("java.", "javax.", "org.w3c.", "org.xml.");
+ private static final List<String> IGNORED_IMPORT_PREFIXES =
+ Arrays.asList("java.", "javax.", "org.w3c.", "org.xml.");
@Override
public String getName() {
@@ -45,55 +45,62 @@ public class CheckBundleUnversionedPackages implements AnalyserTask {
}
private boolean ignoreImportPackage(final String name) {
- for(final String prefix : IGNORED_IMPORT_PREFIXES) {
- if ( name.startsWith(prefix) ) {
+ for (final String prefix : IGNORED_IMPORT_PREFIXES) {
+ if (name.startsWith(prefix)) {
return true;
}
}
return false;
}
-
+
@Override
public void execute(final AnalyserTaskContext ctx) throws Exception {
- for(final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
-
final List<PackageInfo> exportWithoutVersion = new ArrayList<>();
- for(final PackageInfo i : info.getExportedPackages()) {
- if ( i.getPackageVersion().compareTo(Version.emptyVersion) == 0 ) {
+ for (final PackageInfo i : info.getExportedPackages()) {
+ if (i.getPackageVersion().compareTo(Version.emptyVersion) == 0) {
exportWithoutVersion.add(i);
}
}
final List<PackageInfo> importWithoutVersion = new ArrayList<>();
- for(final PackageInfo i : info.getImportedPackages()) {
- if ( i.getVersion() == null && !ignoreImportPackage(i.getName()) ) {
+ for (final PackageInfo i : info.getImportedPackages()) {
+ if (i.getVersion() == null && !ignoreImportPackage(i.getName())) {
importWithoutVersion.add(i);
}
}
- final String key = "Bundle ".concat(info.getArtifact().getId().getArtifactId())
- .concat(":").concat(info.getArtifact().getId().getVersion());
+ final String key = "Bundle "
+ .concat(info.getArtifact().getId().getArtifactId())
+ .concat(":")
+ .concat(info.getArtifact().getId().getVersion());
- if ( !importWithoutVersion.isEmpty() ) {
- ctx.reportArtifactWarning(info.getArtifact().getId(),
- key.concat(" is importing ").concat(getPackageInfo(importWithoutVersion)).concat(" without specifying a version range."));
+ if (!importWithoutVersion.isEmpty()) {
+ ctx.reportArtifactWarning(
+ info.getArtifact().getId(),
+ key.concat(" is importing ")
+ .concat(getPackageInfo(importWithoutVersion))
+ .concat(" without specifying a version range."));
}
- if ( !exportWithoutVersion.isEmpty() ) {
- ctx.reportArtifactWarning(info.getArtifact().getId(),
- key.concat(" is exporting ").concat(getPackageInfo(exportWithoutVersion)).concat(" without a version."));
+ if (!exportWithoutVersion.isEmpty()) {
+ ctx.reportArtifactWarning(
+ info.getArtifact().getId(),
+ key.concat(" is exporting ")
+ .concat(getPackageInfo(exportWithoutVersion))
+ .concat(" without a version."));
}
}
}
private String getPackageInfo(final List<PackageInfo> pcks) {
- if ( pcks.size() == 1 ) {
+ if (pcks.size() == 1) {
return "package ".concat(pcks.get(0).getName());
}
final StringBuilder sb = new StringBuilder("packages ");
boolean first = true;
sb.append('[');
- for(final PackageInfo info : pcks) {
- if ( first ) {
+ for (final PackageInfo info : pcks) {
+ if (first) {
first = false;
} else {
sb.append(", ");
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForConnect.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForConnect.java
index 799c243..dc587b0 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForConnect.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForConnect.java
@@ -59,13 +59,15 @@ public class CheckBundlesForConnect implements AnalyserTask {
}
final Set<String> packages = new HashSet<>();
- try (final JarInputStream jis = new JarInputStream(bd.getArtifactFile().openStream())) {
+ try (final JarInputStream jis =
+ new JarInputStream(bd.getArtifactFile().openStream())) {
JarEntry entry;
while ((entry = jis.getNextJarEntry()) != null) {
if (entry.getName().endsWith(".class")) {
final int lastPos = entry.getName().lastIndexOf('/');
if (lastPos == -1) {
- ctx.reportArtifactError(bd.getArtifact().getId(),"Bundle contains classes in the default package");
+ ctx.reportArtifactError(
+ bd.getArtifact().getId(), "Bundle contains classes in the default package");
} else {
packages.add(entry.getName().substring(0, lastPos));
}
@@ -78,7 +80,8 @@ public class CheckBundlesForConnect implements AnalyserTask {
if (inner.getName().endsWith(".class")) {
final int lastPos = inner.getName().lastIndexOf('/');
if (lastPos == -1) {
- ctx.reportArtifactError(bd.getArtifact().getId(),
+ ctx.reportArtifactError(
+ bd.getArtifact().getId(),
"Bundle contains (embedded) classes in the default package");
} else {
packages.add(inner.getName().substring(0, lastPos));
@@ -92,7 +95,7 @@ public class CheckBundlesForConnect implements AnalyserTask {
jis.closeEntry();
}
} catch (final IOException ioe) {
- ctx.reportArtifactError(bd.getArtifact().getId(),"Unable to scan bundle: " + ioe.getMessage());
+ ctx.reportArtifactError(bd.getArtifact().getId(), "Unable to scan bundle: " + ioe.getMessage());
}
for (final String p : packages) {
List<Artifact> list = packageMap.get(p);
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
index 7ddb3d8..56072ca 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForInitialContent.java
@@ -52,10 +52,10 @@ public class CheckBundlesForInitialContent implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) {
// check for initial content
- for(final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
final List<String> initialContent = extractInitialContent(info.getManifest());
- if ( !initialContent.isEmpty() ) {
+ if (!initialContent.isEmpty()) {
ctx.reportArtifactWarning(info.getArtifact().getId(), "Found initial content : " + initialContent);
}
}
@@ -63,11 +63,11 @@ public class CheckBundlesForInitialContent implements AnalyserTask {
private List<String> extractInitialContent(final Manifest m) {
final List<String> initialContent = new ArrayList<>();
- if ( m != null ) {
- final String root = m.getMainAttributes().getValue(CONTENT_HEADER);
+ if (m != null) {
+ final String root = m.getMainAttributes().getValue(CONTENT_HEADER);
if (root != null) {
Clause[] clauses = Parser.parseHeader(root);
- for (final Clause entry :clauses) {
+ for (final Clause entry : clauses) {
String path = entry.getDirective(PATH_DIRECTIVE);
if (path == null) {
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
index 044fe53..51e24d0 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckBundlesForResources.java
@@ -52,9 +52,9 @@ public class CheckBundlesForResources implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) {
// check for initial content
- for(final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
final List<String> bundleResources = extractBundleResources(info.getManifest());
- if ( !bundleResources.isEmpty() ) {
+ if (!bundleResources.isEmpty()) {
ctx.reportArtifactWarning(info.getArtifact().getId(), "Found bundle resources : " + bundleResources);
}
}
@@ -62,8 +62,8 @@ public class CheckBundlesForResources implements AnalyserTask {
private List<String> extractBundleResources(final Manifest m) {
final List<String> bundleResources = new ArrayList<>();
- if ( m != null ) {
- final String root = m.getMainAttributes().getValue(BUNDLE_RESOURCE_ROOTS);
+ if (m != null) {
+ final String root = m.getMainAttributes().getValue(BUNDLE_RESOURCE_ROOTS);
if (root != null) {
Clause[] clauses = Parser.parseHeader(root);
for (final Clause entry : clauses) {
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeatures.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeatures.java
index 8f09cb9..d200166 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeatures.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeatures.java
@@ -1,21 +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
+ * 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
+ * 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.
+ * 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.Map;
+
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Artifacts;
@@ -26,8 +30,6 @@ import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
import org.apache.sling.feature.builder.FeatureProvider;
-import java.util.Map;
-
public class CheckCompareFeatures implements AnalyserTask {
@Override
@@ -63,27 +65,26 @@ public class CheckCompareFeatures implements AnalyserTask {
}
Feature feat = featureProvider.provide(ArtifactId.fromMvnId(aid));
- if (feat == null)
- throw new Exception("Feature not found: " + aid);
+ if (feat == null) throw new Exception("Feature not found: " + aid);
Artifacts mainArts = getArtifactsToCompare(feat, ext);
Artifacts compArts = getArtifactsToCompare(ctx.getFeature(), ext);
String violationMessage = null;
switch (mode) {
- case "SAME":
- violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
- break;
- case "DIFFERENT":
- violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
- if (violationMessage == null) {
- violationMessage = "Artifacts are not different";
- } else {
- violationMessage = null;
- }
- break;
- default:
- throw new Exception("Unknown comparison mode: " + mode);
+ case "SAME":
+ violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
+ break;
+ case "DIFFERENT":
+ violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
+ if (violationMessage == null) {
+ violationMessage = "Artifacts are not different";
+ } else {
+ violationMessage = null;
+ }
+ break;
+ default:
+ throw new Exception("Unknown comparison mode: " + mode);
}
if (violationMessage != null) {
@@ -123,8 +124,7 @@ public class CheckCompareFeatures implements AnalyserTask {
private static Artifact findArtifact(Artifacts list, ArtifactId artifactId) {
for (Artifact a : list) {
- if (a.getId().equals(artifactId))
- return a;
+ if (a.getId().equals(artifactId)) return a;
}
return null;
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurations.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurations.java
index 9768406..3437161 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurations.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurations.java
@@ -37,11 +37,12 @@ public class CheckConfigurations implements AnalyserTask {
@Override
public void execute(AnalyserTaskContext ctx) throws Exception {
- for(final Configuration cfg : ctx.getFeature().getConfigurations()) {
+ for (final Configuration cfg : ctx.getFeature().getConfigurations()) {
// check that service ranking is of type integer
final Object val = cfg.getProperties().get(Constants.SERVICE_RANKING);
- if ( val != null && !(val instanceof Integer) ) {
- ctx.reportConfigurationError(cfg, "Service.ranking is not of type Integer. Use 'service.ranking:Integer' as the key.");
+ if (val != null && !(val instanceof Integer)) {
+ ctx.reportConfigurationError(
+ cfg, "Service.ranking is not of type Integer. Use 'service.ranking:Integer' as the key.");
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackageForInstallables.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackageForInstallables.java
index 69e2e99..c3fda07 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackageForInstallables.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackageForInstallables.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -38,27 +40,34 @@ public class CheckContentPackageForInstallables implements AnalyserTask {
}
@Override
- public void execute(final AnalyserTaskContext ctx)
- throws Exception {
- final boolean checkPcks = Boolean.parseBoolean(ctx.getConfiguration().getOrDefault(CFG_CHECK_PACKAGES, "false"));
+ public void execute(final AnalyserTaskContext ctx) throws Exception {
+ final boolean checkPcks =
+ Boolean.parseBoolean(ctx.getConfiguration().getOrDefault(CFG_CHECK_PACKAGES, "false"));
- for (final ContentPackageDescriptor cp : ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
- if (cp.getArtifactFile() == null) {
- ctx.reportArtifactError(cp.getArtifact().getId(), "Content package " + cp.getName() + " is not resolved and can not be checked.");
+ for (final ContentPackageDescriptor cp :
+ ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
+ if (cp.getArtifactFile() == null) {
+ ctx.reportArtifactError(
+ cp.getArtifact().getId(),
+ "Content package " + cp.getName() + " is not resolved and can not be checked.");
continue;
}
- if ( checkPcks && cp.isEmbeddedInContentPackage() ) {
- ctx.reportArtifactError(cp.getParentContentPackage().getArtifact().getId(), "Content package " + cp.getParentContentPackage().getArtifact().getId() +
- " embedds content package " + cp.getName());
+ if (checkPcks && cp.isEmbeddedInContentPackage()) {
+ ctx.reportArtifactError(
+ cp.getParentContentPackage().getArtifact().getId(),
+ "Content package "
+ + cp.getParentContentPackage().getArtifact().getId() + " embedds content package "
+ + cp.getName());
}
if (!cp.hasEmbeddedArtifacts() || cp.isEmbeddedInContentPackage()) {
continue;
}
- ctx.reportArtifactError(cp.getArtifact().getId(), "Content package " + cp.getName() +
- " contains " + String.valueOf(cp.getBundles().size()) + " bundles and "
- + String.valueOf(cp.getConfigurations().size()) + " configurations.");
-
+ ctx.reportArtifactError(
+ cp.getArtifact().getId(),
+ "Content package " + cp.getName() + " contains "
+ + String.valueOf(cp.getBundles().size()) + " bundles and "
+ + String.valueOf(cp.getConfigurations().size()) + " configurations.");
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackages.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackages.java
index 7fb03f4..39be3da 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackages.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackages.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -52,7 +54,7 @@ public class CheckContentPackages implements AnalyserTask {
static final String ENABLED_VALIDATORS = "enabled-validators";
static final String MAX_REPORT_LEVEL = "max-report-level";
private Logger log = LoggerFactory.getLogger(this.getClass());
-
+
@Override
public String getName() {
return "Content Package validation";
@@ -68,11 +70,16 @@ public class CheckContentPackages implements AnalyserTask {
String enabledValidators = ctx.getConfiguration().get(ENABLED_VALIDATORS);
Map<String, ValidatorSettings> validatorSettings = enableValidators(enabledValidators);
String maxReportLevelSt = ctx.getConfiguration().get(MAX_REPORT_LEVEL);
- ValidationMessageSeverity maxReportLevel = maxReportLevelSt == null ? ValidationMessageSeverity.WARN : ValidationMessageSeverity.valueOf(maxReportLevelSt);
- for (final ContentPackageDescriptor cp : ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
+ ValidationMessageSeverity maxReportLevel = maxReportLevelSt == null
+ ? ValidationMessageSeverity.WARN
+ : ValidationMessageSeverity.valueOf(maxReportLevelSt);
+ for (final ContentPackageDescriptor cp :
+ ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
URL artifactFile = cp.getArtifactFile();
- if (artifactFile == null) {
- ctx.reportArtifactError(cp.getArtifact().getId(), "Content package " + cp.getName() + " is not resolved and can not be checked.");
+ if (artifactFile == null) {
+ ctx.reportArtifactError(
+ cp.getArtifact().getId(),
+ "Content package " + cp.getName() + " is not resolved and can not be checked.");
} else {
validatePackage(ctx, cp, artifactFile, validatorSettings, maxReportLevel);
}
@@ -80,7 +87,8 @@ public class CheckContentPackages implements AnalyserTask {
}
private Map<String, ValidatorSettings> enableValidators(String enabledValidators) {
- ServiceLoader<ValidatorFactory> validatorFactories = ServiceLoader.load(ValidatorFactory.class, PackageValidator.class.getClassLoader());
+ ServiceLoader<ValidatorFactory> validatorFactories =
+ ServiceLoader.load(ValidatorFactory.class, PackageValidator.class.getClassLoader());
Map<String, ValidatorSettings> validatorSettings = new HashMap<>();
Set<String> enabledValidatorsSet = split(enabledValidators);
@@ -101,10 +109,13 @@ public class CheckContentPackages implements AnalyserTask {
return enabled;
}
- private void validatePackage(final AnalyserTaskContext ctx,
+ private void validatePackage(
+ final AnalyserTaskContext ctx,
final ContentPackageDescriptor cp,
- URL artifactFile, Map<String, ValidatorSettings> validatorSettings,
- ValidationMessageSeverity maxReportLevel) throws URISyntaxException, IOException {
+ URL artifactFile,
+ Map<String, ValidatorSettings> validatorSettings,
+ ValidationMessageSeverity maxReportLevel)
+ throws URISyntaxException, IOException {
URI artifactURI = artifactFile.toURI();
Path artifactPath = Paths.get(artifactURI);
PackageValidator validator = new PackageValidator(artifactURI, validatorSettings);
@@ -112,8 +123,12 @@ public class CheckContentPackages implements AnalyserTask {
reportViolations(ctx, cp, violations, artifactPath, maxReportLevel);
}
- private void reportViolations(AnalyserTaskContext ctx, ContentPackageDescriptor cp,
- Collection<ValidationViolation> violations, Path artifactPath, ValidationMessageSeverity maxReportLevel) {
+ private void reportViolations(
+ AnalyserTaskContext ctx,
+ ContentPackageDescriptor cp,
+ Collection<ValidationViolation> violations,
+ Path artifactPath,
+ ValidationMessageSeverity maxReportLevel) {
for (ValidationViolation violation : violations) {
ValidationMessageSeverity severity = getMin(maxReportLevel, violation.getSeverity());
reportViolation(ctx, cp, violation, artifactPath, severity);
@@ -124,25 +139,29 @@ public class CheckContentPackages implements AnalyserTask {
return a.compareTo(b) < 0 ? a : b;
}
- private void reportViolation(AnalyserTaskContext ctx, ContentPackageDescriptor cp, ValidationViolation violation,
- Path artifactPath, ValidationMessageSeverity severity) {
+ private void reportViolation(
+ AnalyserTaskContext ctx,
+ ContentPackageDescriptor cp,
+ ValidationViolation violation,
+ Path artifactPath,
+ ValidationMessageSeverity severity) {
String msg = getDetailMessage(violation, artifactPath);
ArtifactId id = cp.getArtifact().getId();
switch (severity) {
- case ERROR:
- log.error(msg);
- ctx.reportArtifactError(id, msg);
- break;
- case WARN:
- log.warn(msg);
- ctx.reportArtifactWarning(id, msg);
- break;
- case INFO:
- log.info(msg);
- break;
- default:
- log.debug(msg);
- break;
+ case ERROR:
+ log.error(msg);
+ ctx.reportArtifactError(id, msg);
+ break;
+ case WARN:
+ log.warn(msg);
+ ctx.reportArtifactWarning(id, msg);
+ break;
+ case INFO:
+ log.info(msg);
+ break;
+ default:
+ log.debug(msg);
+ break;
}
}
@@ -162,7 +181,7 @@ public class CheckContentPackages implements AnalyserTask {
}
return message.toString();
}
-
+
private static String getMessage(ValidationViolation violation) {
StringBuilder message = new StringBuilder();
if (violation.getValidatorId() != null) {
@@ -171,5 +190,4 @@ public class CheckContentPackages implements AnalyserTask {
message.append(violation.getMessage());
return message.toString();
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependencies.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependencies.java
index 81d2911..b096d54 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependencies.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependencies.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -59,7 +61,8 @@ public class CheckContentPackagesDependencies implements AnalyserTask {
public void execute(AnalyserTaskContext ctx) throws Exception {
Map<PackageId, Dependency[]> dependenciesMap = new HashMap<>();
- for (ArtifactDescriptor descriptor : ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
+ for (ArtifactDescriptor descriptor :
+ ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
onDescriptor(ctx, descriptor, dependenciesMap);
}
@@ -68,12 +71,16 @@ public class CheckContentPackagesDependencies implements AnalyserTask {
}
}
- private void onDescriptor(AnalyserTaskContext ctx, ArtifactDescriptor descriptor, Map<PackageId, Dependency[]> dependenciesMap) throws Exception {
+ private void onDescriptor(
+ AnalyserTaskContext ctx, ArtifactDescriptor descriptor, Map<PackageId, Dependency[]> dependenciesMap)
+ throws Exception {
URL resourceUrl = descriptor.getArtifactFile();
if (resourceUrl != null) {
File artifactFile = IOUtils.getFileFromURL(resourceUrl, true, null);
if (!artifactFile.exists() || !artifactFile.isFile()) {
- ctx.reportArtifactError(descriptor.getArtifact().getId(), "Artifact file " + artifactFile + " does not exist or it is not a file");
+ ctx.reportArtifactError(
+ descriptor.getArtifact().getId(),
+ "Artifact file " + artifactFile + " does not exist or it is not a file");
return;
}
@@ -87,11 +94,14 @@ public class CheckContentPackagesDependencies implements AnalyserTask {
logger.debug(packageId + " dependencies collected.");
}
} else {
- ctx.reportArtifactError(descriptor.getArtifact().getId(), "Ignoring " + descriptor.getName() + " as file could not be found");
+ ctx.reportArtifactError(
+ descriptor.getArtifact().getId(),
+ "Ignoring " + descriptor.getName() + " as file could not be found");
}
}
- private void verifyDependenciesTree(AnalyserTaskContext ctx, PackageId root, Map<PackageId, Dependency[]> dependenciesMap) {
+ private void verifyDependenciesTree(
+ AnalyserTaskContext ctx, PackageId root, Map<PackageId, Dependency[]> dependenciesMap) {
logger.debug("Verifying " + root + " transitive dependencies...");
Queue<Dependency> toBeVisited = new LinkedList<>();
@@ -120,7 +130,7 @@ public class CheckContentPackagesDependencies implements AnalyserTask {
}
}
- private static void enqueue(Queue<Dependency> target, Dependency...dependencies) {
+ private static void enqueue(Queue<Dependency> target, Dependency... dependencies) {
if (dependencies == null) {
return;
}
@@ -129,5 +139,4 @@ public class CheckContentPackagesDependencies implements AnalyserTask {
target.offer(dependency);
}
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPaths.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPaths.java
index 230bb5b..a818895 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPaths.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPaths.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -43,23 +45,23 @@ public class CheckContentPackagesForPaths implements AnalyserTask {
}
@Override
- public void execute(final AnalyserTaskContext ctx)
- throws Exception {
+ public void execute(final AnalyserTaskContext ctx) throws Exception {
final Rules rules = new Rules(ctx);
if (!rules.isConfigured()) {
ctx.reportError("Configuration for task " + getId() + " is missing.");
return;
}
-
- for (final ContentPackageDescriptor d : ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
+
+ for (final ContentPackageDescriptor d :
+ ctx.getFeatureDescriptor().getDescriptors(ContentPackageDescriptor.class)) {
checkPackage(ctx, d, rules);
}
}
void checkPackage(final AnalyserTaskContext ctx, final ContentPackageDescriptor desc, final Rules rules) {
desc.getContentPaths().stream()
- .filter(rules::isDisAllowed)
- .forEach(path -> ctx.reportArtifactError(desc.getArtifact().getId(), "Content not allowed: " + path));
+ .filter(rules::isDisAllowed)
+ .forEach(path -> ctx.reportArtifactError(desc.getArtifact().getId(), "Content not allowed: " + path));
}
static final class Rules {
@@ -72,12 +74,12 @@ public class CheckContentPackagesForPaths implements AnalyserTask {
includes = splitAndTrim(inc);
excludes = splitAndTrim(exc);
}
-
+
private String[] splitAndTrim(String property) {
if (property == null) {
return new String[] {};
}
-
+
return Stream.of(property.split(","))
.map(String::trim)
.collect(Collectors.toList())
@@ -95,18 +97,18 @@ public class CheckContentPackagesForPaths implements AnalyserTask {
boolean isAllowed(String path) {
boolean isAllowed = includes.length == 0;
int matchLength = 0;
- if ( !isAllowed ) {
- for(final String i : includes) {
- if ( path.equals(i) || path.startsWith(i.concat("/")) ) {
+ if (!isAllowed) {
+ for (final String i : includes) {
+ if (path.equals(i) || path.startsWith(i.concat("/"))) {
isAllowed = true;
matchLength = i.length();
break;
}
}
}
- if ( isAllowed && excludes.length > 0 ) {
- for(final String i : excludes) {
- if ( path.equals(i) || path.startsWith(i.concat("/")) && i.length() > matchLength ) {
+ if (isAllowed && excludes.length > 0) {
+ for (final String i : excludes) {
+ if (path.equals(i) || path.startsWith(i.concat("/")) && i.length() > matchLength) {
isAllowed = false;
break;
}
@@ -115,5 +117,4 @@ public class CheckContentPackagesForPaths implements AnalyserTask {
return isAllowed;
}
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicName.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicName.java
index 5c5987d..64dbd64 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicName.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicName.java
@@ -29,7 +29,6 @@ import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
import org.apache.sling.feature.scanner.BundleDescriptor;
-
public class CheckDuplicateSymbolicName implements AnalyserTask {
@Override
@@ -46,7 +45,7 @@ public class CheckDuplicateSymbolicName implements AnalyserTask {
// build a map of bundles by symbolic name
final SortedMap<String, Set<ArtifactId>> bundleMap = new TreeMap<>();
- for(final BundleDescriptor desc : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor desc : ctx.getFeatureDescriptor().getBundleDescriptors()) {
final String key = desc.getBundleSymbolicName();
final Set<ArtifactId> set = bundleMap.computeIfAbsent(key, id -> new HashSet<>());
set.add(desc.getArtifact().getId());
@@ -58,15 +57,16 @@ public class CheckDuplicateSymbolicName implements AnalyserTask {
public void execute(final AnalyserTaskContext ctx) throws Exception {
final SortedMap<String, Set<ArtifactId>> bundleMap = createBundleMap(ctx);
- for(final Map.Entry<String, Set<ArtifactId>> entry : bundleMap.entrySet()) {
- if ( entry.getValue().size() > 1 ) {
+ for (final Map.Entry<String, Set<ArtifactId>> entry : bundleMap.entrySet()) {
+ if (entry.getValue().size() > 1) {
final StringBuilder sb = new StringBuilder();
sb.append("Duplicate symbolic name ");
sb.append(entry.getKey());
sb.append(" : ");
boolean first = true;
- for(final ArtifactId id : entry.getValue()) {
- if ( first ) first = false; else sb.append(", ");
+ for (final ArtifactId id : entry.getValue()) {
+ if (first) first = false;
+ else sb.append(", ");
sb.append(id.toMvnId());
}
ctx.reportError(sb.toString());
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureId.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureId.java
index 638f524..d21c0b0 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureId.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureId.java
@@ -45,7 +45,7 @@ public class CheckFeatureId implements AnalyserTask {
Map<String, String> cfg = ctx.getConfiguration();
String acceptedFeatureIds = cfg.get(CONFIG_KEY_ACCEPTED_FEATURE_IDS);
if (acceptedFeatureIds == null) {
- // this is a comma-separated list of accepted
+ // this is a comma-separated list of accepted
throw new IllegalArgumentException("Missing 'accepted-feature-ids' configuration for feature-id analyser.");
}
Collection<ArtifactId> acceptedArtifactIds = new ArrayList<>();
@@ -53,7 +53,11 @@ public class CheckFeatureId implements AnalyserTask {
try {
acceptedArtifactIds.add(ArtifactId.fromMvnId(acceptedFeatureId));
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException("Invalid 'accepted-feature-ids' configuration for feature-id analyser, element '" + acceptedFeatureId + "' is not a valid maven coordinate string in format 'groupId:artifactId[:packaging[:classifier]]:version'", e);
+ throw new IllegalArgumentException(
+ "Invalid 'accepted-feature-ids' configuration for feature-id analyser, element '"
+ + acceptedFeatureId
+ + "' is not a valid maven coordinate string in format 'groupId:artifactId[:packaging[:classifier]]:version'",
+ e);
}
}
if (!matchesAnyOf(ctx.getFeature().getId(), acceptedArtifactIds)) {
@@ -71,24 +75,29 @@ public class CheckFeatureId implements AnalyserTask {
}
static boolean matches(ArtifactId artifactId, ArtifactId expectedArtifactId) {
- if (!expectedArtifactId.getGroupId().equals(artifactId.getGroupId()) && !expectedArtifactId.getGroupId().equals("*")) {
+ if (!expectedArtifactId.getGroupId().equals(artifactId.getGroupId())
+ && !expectedArtifactId.getGroupId().equals("*")) {
return false;
}
- if (!expectedArtifactId.getArtifactId().equals(artifactId.getArtifactId()) && !expectedArtifactId.getArtifactId().equals("*")) {
+ if (!expectedArtifactId.getArtifactId().equals(artifactId.getArtifactId())
+ && !expectedArtifactId.getArtifactId().equals("*")) {
return false;
}
- if (!expectedArtifactId.getVersion().equals(artifactId.getVersion()) && !expectedArtifactId.getVersion().equals("*")) {
+ if (!expectedArtifactId.getVersion().equals(artifactId.getVersion())
+ && !expectedArtifactId.getVersion().equals("*")) {
return false;
}
- if (!expectedArtifactId.getType().equals(artifactId.getType()) && !expectedArtifactId.getType().equals("*")) {
+ if (!expectedArtifactId.getType().equals(artifactId.getType())
+ && !expectedArtifactId.getType().equals("*")) {
return false;
}
// classifier is optional
- if ( (expectedArtifactId.getClassifier() == null && artifactId.getClassifier() != null) ||
- (expectedArtifactId.getClassifier() != null && !expectedArtifactId.getClassifier().equals(artifactId.getClassifier()) && !expectedArtifactId.getClassifier().equals("*"))) {
+ if ((expectedArtifactId.getClassifier() == null && artifactId.getClassifier() != null)
+ || (expectedArtifactId.getClassifier() != null
+ && !expectedArtifactId.getClassifier().equals(artifactId.getClassifier())
+ && !expectedArtifactId.getClassifier().equals("*"))) {
return false;
}
return true;
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinit.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinit.java
index ce649ef..c2f5f97 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinit.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinit.java
@@ -35,6 +35,7 @@ public class CheckRepoinit implements AnalyserTask {
public static final String PID = "org.apache.sling.jcr.repoinit.impl.RepositoryInitializer";
public static final String FACTORY_PID = "org.apache.sling.jcr.repoinit.RepositoryInitializer";
+
@Override
public String getName() {
return "Repoinit Check";
@@ -49,34 +50,34 @@ public class CheckRepoinit implements AnalyserTask {
public void execute(final AnalyserTaskContext ctx) {
// check extension
final Extension ext = ctx.getFeature().getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT);
- if ( ext != null ) {
- if ( ext.getType() != ExtensionType.TEXT ) {
+ if (ext != null) {
+ if (ext.getType() != ExtensionType.TEXT) {
ctx.reportExtensionError(Extension.EXTENSION_NAME_REPOINIT, "Repoinit extension must be of type TEXT");
- } else {
+ } else {
check(ctx, "extension", ext.getText());
}
}
// configuration
final Configuration cfg = ctx.getFeature().getConfigurations().getConfiguration(PID);
- if ( cfg != null ) {
+ if (cfg != null) {
check(ctx, cfg, false);
}
- for(final Configuration c : ctx.getFeature().getConfigurations()) {
- if ( FACTORY_PID.equals(c.getFactoryPid()) ) {
+ for (final Configuration c : ctx.getFeature().getConfigurations()) {
+ if (FACTORY_PID.equals(c.getFactoryPid())) {
check(ctx, c, true);
}
}
-
}
private void check(final AnalyserTaskContext ctx, final Configuration cfg, final boolean supportsScripts) {
// for now we only check scripts
- if ( supportsScripts ) {
+ if (supportsScripts) {
final Object val = cfg.getProperties().get("scripts");
- if ( val != null ) {
- final String[] scripts = Converters.standardConverter().convert(val).to(String[].class);
- for(final String contents : scripts) {
+ if (val != null) {
+ final String[] scripts =
+ Converters.standardConverter().convert(val).to(String[].class);
+ for (final String contents : scripts) {
check(ctx, "configuration ".concat(cfg.getPid()), contents);
}
}
@@ -88,8 +89,10 @@ public class CheckRepoinit implements AnalyserTask {
try {
parser.parse(new StringReader(contents));
- } catch ( RepoInitParsingException e) {
- ctx.reportExtensionError(Extension.EXTENSION_NAME_REPOINIT, "Parsing error in repoinit from ".concat(id).concat(" : ").concat(e.getMessage()));
+ } catch (RepoInitParsingException e) {
+ ctx.reportExtensionError(
+ Extension.EXTENSION_NAME_REPOINIT,
+ "Parsing error in repoinit from ".concat(id).concat(" : ").concat(e.getMessage()));
}
}
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
index 0979f69..b3a52bb 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilities.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -50,7 +52,7 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
@Override
public void execute(AnalyserTaskContext ctx) throws Exception {
final SortedMap<Integer, List<Descriptor>> artifactsMap = new TreeMap<>();
- for(final BundleDescriptor bi : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor bi : ctx.getFeatureDescriptor().getBundleDescriptors()) {
List<Descriptor> list = getDescriptorList(bi.getArtifact().getStartOrder(), artifactsMap);
list.add(bi);
}
@@ -58,8 +60,7 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
if (!ctx.getFeatureDescriptor().getArtifactDescriptors().isEmpty()) {
artifactsMap.put(
(artifactsMap.isEmpty() ? 0 : artifactsMap.lastKey()) + 1,
- new ArrayList<>(ctx.getFeatureDescriptor().getArtifactDescriptors())
- );
+ new ArrayList<>(ctx.getFeatureDescriptor().getArtifactDescriptors()));
}
String featureMavenID = ctx.getFeature().getId().toMvnId();
@@ -77,12 +78,12 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
// add system artifact
final List<Descriptor> artifacts = new ArrayList<>();
- if ( ctx.getFrameworkDescriptor() != null ) {
+ if (ctx.getFrameworkDescriptor() != null) {
artifacts.add(ctx.getFrameworkDescriptor());
}
boolean errorReported = false;
- for(final Map.Entry<Integer, List<Descriptor>> entry : artifactsMap.entrySet()) {
+ for (final Map.Entry<Integer, List<Descriptor>> entry : artifactsMap.entrySet()) {
// first add all providing artifacts
for (final Descriptor info : entry.getValue()) {
if (info.getCapabilities() != null) {
@@ -91,44 +92,65 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
}
// check requiring artifacts
for (final Descriptor info : entry.getValue()) {
- if (info.getRequirements() != null)
- {
+ if (info.getRequirements() != null) {
for (Requirement requirement : info.getRequirements()) {
String ns = requirement.getNamespace();
// Package namespace is handled by the CheckBundleExportsImports analyzer.
// Service namespace is special - we don't provide errors or warnings in this case
- if (!BundleRevision.PACKAGE_NAMESPACE.equals(ns) && !ServiceNamespace.SERVICE_NAMESPACE.equals(ns))
- {
+ if (!BundleRevision.PACKAGE_NAMESPACE.equals(ns)
+ && !ServiceNamespace.SERVICE_NAMESPACE.equals(ns)) {
List<Descriptor> candidates = getCandidates(artifacts, requirement);
- if (candidates.isEmpty())
- {
- if (!RequirementImpl.isOptional(requirement))
- {
- String message = String.format(format, info.getName(), requirement.toString(), entry.getKey(), "no artifact is providing a matching capability in this start level.");
+ if (candidates.isEmpty()) {
+ if (!RequirementImpl.isOptional(requirement)) {
+ String message = String.format(
+ format,
+ info.getName(),
+ requirement.toString(),
+ entry.getKey(),
+ "no artifact is providing a matching capability in this start level.");
if (info instanceof ArtifactDescriptor) {
- ctx.reportArtifactError(((ArtifactDescriptor) info).getArtifact().getId(), message);
+ ctx.reportArtifactError(
+ ((ArtifactDescriptor) info)
+ .getArtifact()
+ .getId(),
+ message);
} else {
ctx.reportError(message);
}
errorReported = true;
- }
- else
- {
- String message = String.format(format, info.getName(), requirement.toString(), entry.getKey(), "while the requirement is optional no artifact is providing a matching capability in this start level.");
+ } else {
+ String message = String.format(
+ format,
+ info.getName(),
+ requirement.toString(),
+ entry.getKey(),
+ "while the requirement is optional no artifact is providing a matching capability in this start level.");
if (info instanceof ArtifactDescriptor) {
- ctx.reportArtifactWarning(((ArtifactDescriptor) info).getArtifact().getId(), message);
+ ctx.reportArtifactWarning(
+ ((ArtifactDescriptor) info)
+ .getArtifact()
+ .getId(),
+ message);
} else {
ctx.reportWarning(message);
}
}
- }
- else if (candidates.size() > 1)
- {
- String message = String.format(format, info.getName(), requirement.toString(), entry.getKey(), "there is more than one matching capability in this start level: " + candidates);
+ } else if (candidates.size() > 1) {
+ String message = String.format(
+ format,
+ info.getName(),
+ requirement.toString(),
+ entry.getKey(),
+ "there is more than one matching capability in this start level: "
+ + candidates);
if (info instanceof ArtifactDescriptor) {
- ctx.reportArtifactWarning(((ArtifactDescriptor) info).getArtifact().getId(), message);
+ ctx.reportArtifactWarning(
+ ((ArtifactDescriptor) info)
+ .getArtifact()
+ .getId(),
+ message);
} else {
ctx.reportWarning(message);
}
@@ -139,13 +161,14 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
}
}
if (errorReported && ctx.getFeature().isComplete()) {
- ctx.reportError(ctx.getFeature().getId().toMvnId() + " is marked as 'complete' but has unsatisfied requirements.");
+ ctx.reportError(
+ ctx.getFeature().getId().toMvnId() + " is marked as 'complete' but has unsatisfied requirements.");
}
}
private List<Descriptor> getDescriptorList(int sl, SortedMap<Integer, List<Descriptor>> artifactsMap) {
List<Descriptor> list = artifactsMap.get(sl);
- if ( list == null ) {
+ if (list == null) {
list = new ArrayList<>();
artifactsMap.put(sl, list);
}
@@ -155,9 +178,8 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
private List<Descriptor> getCandidates(List<Descriptor> artifactDescriptors, Requirement requirement) {
return artifactDescriptors.stream()
.filter(artifactDescriptor -> artifactDescriptor.getCapabilities() != null)
- .filter(artifactDescriptor -> artifactDescriptor.getCapabilities().stream().anyMatch(
- capability -> CapabilitySet.matches(capability, requirement))
- )
+ .filter(artifactDescriptor -> artifactDescriptor.getCapabilities().stream()
+ .anyMatch(capability -> CapabilitySet.matches(capability, requirement)))
.collect(Collectors.toList());
}
@@ -166,4 +188,4 @@ public class CheckRequirementsCapabilities implements AnalyserTask {
super(name);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMapping.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMapping.java
index 7be354a..f84bdf5 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMapping.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMapping.java
@@ -36,7 +36,7 @@ public class CheckServiceUserMapping implements AnalyserTask {
static final String CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS = "warnOnlyForDeprecatedMappings";
static final String CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT = Boolean.FALSE.toString();
-
+
@Override
public String getName() {
return "Service User Mapping Check";
@@ -49,7 +49,8 @@ public class CheckServiceUserMapping implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) {
- final boolean warnOnlyForDeprecation = Boolean.parseBoolean(ctx.getConfiguration().getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT));
+ final boolean warnOnlyForDeprecation = Boolean.parseBoolean(ctx.getConfiguration()
+ .getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT));
// configuration
Configurations configurations = ctx.getFeature().getConfigurations();
@@ -62,17 +63,23 @@ public class CheckServiceUserMapping implements AnalyserTask {
}
}
- private static void check(final AnalyserTaskContext ctx, final Configuration cfg, final boolean warnOnlyForDeprecation) {
+ private static void check(
+ final AnalyserTaskContext ctx, final Configuration cfg, final boolean warnOnlyForDeprecation) {
final Object val = cfg.getConfigurationProperties().get(USER_MAPPING);
if (val != null) {
- final String[] mappings = Converters.standardConverter().convert(val).to(String[].class);
+ final String[] mappings =
+ Converters.standardConverter().convert(val).to(String[].class);
for (final String spec : mappings) {
check(ctx, cfg, spec, warnOnlyForDeprecation);
}
}
}
- private static void check(final @NotNull AnalyserTaskContext ctx, final @NotNull Configuration cfg, final @Nullable String spec, final boolean warnOnlyForDeprecation) {
+ private static void check(
+ final @NotNull AnalyserTaskContext ctx,
+ final @NotNull Configuration cfg,
+ final @Nullable String spec,
+ final boolean warnOnlyForDeprecation) {
final String id = cfg.getPid();
if (spec == null || spec.trim().isEmpty()) {
ctx.reportConfigurationWarning(cfg, "Ignoring empty mapping in " + id);
@@ -99,7 +106,8 @@ public class CheckServiceUserMapping implements AnalyserTask {
private final boolean isDeprecated;
- private static @Nullable Mapping parse(@NotNull final String spec, @NotNull final AnalyserTaskContext ctx, @NotNull final Configuration cfg) {
+ private static @Nullable Mapping parse(
+ @NotNull final String spec, @NotNull final AnalyserTaskContext ctx, @NotNull final Configuration cfg) {
final int colon = spec.indexOf(':');
final int equals = spec.indexOf('=');
@@ -107,7 +115,8 @@ public class CheckServiceUserMapping implements AnalyserTask {
ctx.reportConfigurationWarning(cfg, "Invalid service user mapping: serviceName is required");
return null;
} else if (equals == spec.length() - 1) {
- ctx.reportConfigurationWarning(cfg, "Invalid service user mapping: userName or principalNames is required");
+ ctx.reportConfigurationWarning(
+ cfg, "Invalid service user mapping: userName or principalNames is required");
return null;
} else if (colon + 1 == equals) {
ctx.reportConfigurationWarning(cfg, "Invalid service user mapping: serviceInfo must not be empty");
@@ -133,4 +142,3 @@ public class CheckServiceUserMapping implements AnalyserTask {
}
}
}
-
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
index e2289dc..3b4ca9f 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/CheckUnusedBundles.java
@@ -43,30 +43,31 @@ public class CheckUnusedBundles implements AnalyserTask {
@Override
public void execute(final AnalyserTaskContext ctx) throws IOException {
// iterate over all bundles
- for(final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ for (final BundleDescriptor info : ctx.getFeatureDescriptor().getBundleDescriptors()) {
- if ( !info.getExportedPackages().isEmpty() ) {
+ if (!info.getExportedPackages().isEmpty()) {
final Set<PackageInfo> exports = new HashSet<>(info.getExportedPackages());
-
+
final Set<String> optionalImports = new HashSet<>();
// find importing bundle
- for(final BundleDescriptor inner : ctx.getFeatureDescriptor().getBundleDescriptors()) {
- if ( inner == info ) {
+ for (final BundleDescriptor inner : ctx.getFeatureDescriptor().getBundleDescriptors()) {
+ if (inner == info) {
continue;
}
final Iterator<PackageInfo> iter = exports.iterator();
- while ( iter.hasNext() ) {
+ while (iter.hasNext()) {
final PackageInfo expPck = iter.next();
boolean found = false;
- for(final PackageInfo impPck : inner.getImportedPackages()) {
-
- if ( expPck.getName().equals(impPck.getName())) {
- if ( impPck.getVersion() == null || impPck.getPackageVersionRange().includes(expPck.getPackageVersion()) ) {
- if ( impPck.isOptional() ) {
+ for (final PackageInfo impPck : inner.getImportedPackages()) {
+
+ if (expPck.getName().equals(impPck.getName())) {
+ if (impPck.getVersion() == null
+ || impPck.getPackageVersionRange().includes(expPck.getPackageVersion())) {
+ if (impPck.isOptional()) {
optionalImports.add(impPck.getName());
} else {
found = true;
@@ -76,26 +77,28 @@ public class CheckUnusedBundles implements AnalyserTask {
}
}
- if ( found ) {
+ if (found) {
iter.remove();
}
-
}
- if ( exports.isEmpty() ) {
+ if (exports.isEmpty()) {
break;
}
}
- if ( exports.size() == info.getExportedPackages().size() ) {
- if ( !optionalImports.isEmpty() ) {
- ctx.reportArtifactWarning(info.getArtifact().getId(), "Exports from bundle are only imported optionally by other bundles.");
+ if (exports.size() == info.getExportedPackages().size()) {
+ if (!optionalImports.isEmpty()) {
+ ctx.reportArtifactWarning(
+ info.getArtifact().getId(),
+ "Exports from bundle are only imported optionally by other bundles.");
} else {
- ctx.reportArtifactWarning(info.getArtifact().getId(), "Exports from bundle are not imported by any other bundle.");
+ ctx.reportArtifactWarning(
+ info.getArtifact().getId(),
+ "Exports from bundle are not imported by any other bundle.");
}
}
-
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/ArchiveValidationContextImpl.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/ArchiveValidationContextImpl.java
index 66f30ef..04e168d 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/ArchiveValidationContextImpl.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/ArchiveValidationContextImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.contentpackage;
@@ -26,7 +28,6 @@ import org.apache.jackrabbit.vault.packaging.PackageInfo;
import org.apache.jackrabbit.vault.packaging.PackageProperties;
import org.apache.jackrabbit.vault.validation.spi.ValidationContext;
-
/**
* Implements a validation context based on a given {@link Archive}.
*/
@@ -68,5 +69,4 @@ public class ArchiveValidationContextImpl implements ValidationContext {
public Collection<PackageInfo> getDependenciesPackageInfo() {
return Collections.emptyList();
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/PackageValidator.java b/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/PackageValidator.java
index 2e93b55..f96c535 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/PackageValidator.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/impl/contentpackage/PackageValidator.java
@@ -47,11 +47,11 @@ import org.slf4j.LoggerFactory;
/**
* Validate a package using filevault validation API.
- * This class contains code from filevault package maven plugin.
+ * This class contains code from filevault package maven plugin.
*/
public class PackageValidator {
private Logger log = LoggerFactory.getLogger(this.getClass());
-
+
private final ValidationExecutorFactory validationExecutorFactory;
private final URI artifactURI;
@@ -63,12 +63,12 @@ public class PackageValidator {
private ValidationExecutor executor;
private Map<String, ? extends ValidatorSettings> validatorSettings;
-
+
public PackageValidator(URI artifactURI, Map<String, ? extends ValidatorSettings> validatorSettings) {
this.artifactURI = artifactURI;
this.validatorSettings = validatorSettings;
- validationExecutorFactory = new ValidationExecutorFactory(
- this.getClass().getClassLoader());
+ validationExecutorFactory =
+ new ValidationExecutorFactory(this.getClass().getClassLoader());
messages = new LinkedList<>();
}
@@ -89,17 +89,18 @@ public class PackageValidator {
}
return messages;
}
-
+
private void validateArchive(Archive archive, Path path) throws IOException {
validateEntry(archive, archive.getRoot(), Paths.get(""), path);
messages.addAll(executor.done());
}
-
- private void validateEntry(Archive archive, Archive.Entry entry, Path entryPath, Path packagePath) throws IOException {
+
+ private void validateEntry(Archive archive, Archive.Entry entry, Path entryPath, Path packagePath)
+ throws IOException {
// sort children to make sure that .content.xml comes first!
List<Archive.Entry> sortedEntryList = new ArrayList<>(entry.getChildren());
sortedEntryList.sort(Comparator.comparing(Archive.Entry::getName, new DotContentXmlFirstComparator()));
-
+
for (Archive.Entry childEntry : sortedEntryList) {
if (childEntry.isDirectory()) {
validateInputStream(null, entryPath.resolve(childEntry.getName()), packagePath);
@@ -111,21 +112,35 @@ public class PackageValidator {
}
}
}
-
+
private void validateInputStream(InputStream inputStream, Path entryPath, Path packagePath) throws IOException {
if (entryPath.startsWith(Constants.META_INF)) {
- messages.addAll(executor.validateMetaInf(inputStream, Paths.get(Constants.META_INF).relativize(entryPath), packagePath.resolve(Constants.META_INF)));
+ messages.addAll(executor.validateMetaInf(
+ inputStream,
+ Paths.get(Constants.META_INF).relativize(entryPath),
+ packagePath.resolve(Constants.META_INF)));
} else if (entryPath.startsWith(Constants.ROOT_DIR)) {
// strip off jcr_root
Path relativeJcrPath = Paths.get(Constants.ROOT_DIR).relativize(entryPath);
- messages.addAll(executor.validateJcrRoot(inputStream, relativeJcrPath, packagePath.resolve(Constants.ROOT_DIR)));
+ messages.addAll(
+ executor.validateJcrRoot(inputStream, relativeJcrPath, packagePath.resolve(Constants.ROOT_DIR)));
} else {
- messages.add(new ValidationViolation(ValidationMessageSeverity.WARN, "Found unexpected file outside of " + Constants.ROOT_DIR + " and " + Constants.META_INF, entryPath, packagePath, null, 0,0, null));
+ messages.add(new ValidationViolation(
+ ValidationMessageSeverity.WARN,
+ "Found unexpected file outside of " + Constants.ROOT_DIR + " and " + Constants.META_INF,
+ entryPath,
+ packagePath,
+ null,
+ 0,
+ 0,
+ null));
}
}
-
+
private void printUsedValidators(boolean printUnusedValidators) {
- String packageType = context.getProperties().getPackageType() != null ? context.getProperties().getPackageType().toString() : "unknown";
+ String packageType = context.getProperties().getPackageType() != null
+ ? context.getProperties().getPackageType().toString()
+ : "unknown";
int numValidators = executor.getAllValidatorsById().entrySet().size();
log.info("Using {} validators for package of type {}: {}", numValidators, packageType, getValidatorNames());
if (printUnusedValidators) {
@@ -136,20 +151,20 @@ public class PackageValidator {
}
}
}
-
+
private String getValidatorNames() {
return executor.getAllValidatorsById().entrySet().stream()
.map(this::describeValidator)
.collect(Collectors.joining(", "));
}
-
+
private String describeValidator(Map.Entry<String, Validator> validatorById) {
String validatorClassName = validatorById.getValue().getClass().getName();
return validatorById.getKey() + " (" + validatorClassName + ")";
}
-
- /**
- * Comparator on file names (excluding paths) which makes sure that the files named {@code .content.xml} come first. Other file names are ordered lexicographically.
+
+ /**
+ * Comparator on file names (excluding paths) which makes sure that the files named {@code .content.xml} come first. Other file names are ordered lexicographically.
*/
static final class DotContentXmlFirstComparator implements Comparator<String> {
@Override
diff --git a/src/main/java/org/apache/sling/feature/analyser/task/package-info.java b/src/main/java/org/apache/sling/feature/analyser/task/package-info.java
index 0ab2231..b89be44 100644
--- a/src/main/java/org/apache/sling/feature/analyser/task/package-info.java
+++ b/src/main/java/org/apache/sling/feature/analyser/task/package-info.java
@@ -19,5 +19,3 @@
@org.osgi.annotation.versioning.Version("1.3.0")
package org.apache.sling.feature.analyser.task;
-
-
diff --git a/src/main/java/org/apache/sling/feature/scanner/ArtifactDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/ArtifactDescriptor.java
index 18c7612..e2a5935 100644
--- a/src/main/java/org/apache/sling/feature/scanner/ArtifactDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/ArtifactDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -60,4 +62,4 @@ public abstract class ArtifactDescriptor extends Descriptor {
* @return The artifact
*/
public abstract Artifact getArtifact();
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/BundleDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/BundleDescriptor.java
index 1333262..e28c76c 100644
--- a/src/main/java/org/apache/sling/feature/scanner/BundleDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/BundleDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -64,8 +66,8 @@ public abstract class BundleDescriptor extends ArtifactDescriptor implements Com
* @return {@code true} if that package is exported.
*/
public boolean isExportingPackage(final String packageName) {
- for(final PackageInfo i : getExportedPackages()) {
- if ( i.getName().equals(packageName) ) {
+ for (final PackageInfo i : getExportedPackages()) {
+ if (i.getName().equals(packageName)) {
return true;
}
}
@@ -78,9 +80,10 @@ public abstract class BundleDescriptor extends ArtifactDescriptor implements Com
* @return {@code true} if that package is exported.
*/
public boolean isExportingPackage(final PackageInfo info) {
- for(final PackageInfo i : getExportedPackages()) {
- if ( i.getName().equals(info.getName())
- && (info.getVersion() == null || info.getPackageVersionRange().includes(i.getPackageVersion()))) {
+ for (final PackageInfo i : getExportedPackages()) {
+ if (i.getName().equals(info.getName())
+ && (info.getVersion() == null
+ || info.getPackageVersionRange().includes(i.getPackageVersion()))) {
return true;
}
}
@@ -89,8 +92,9 @@ public abstract class BundleDescriptor extends ArtifactDescriptor implements Com
@Override
public boolean equals(Object obj) {
- if ( obj instanceof BundleDescriptorImpl ) {
- return this.getBundleSymbolicName().equals(((BundleDescriptorImpl)obj).getBundleSymbolicName()) && this.getBundleVersion().equals(((BundleDescriptorImpl)obj).getBundleVersion());
+ if (obj instanceof BundleDescriptorImpl) {
+ return this.getBundleSymbolicName().equals(((BundleDescriptorImpl) obj).getBundleSymbolicName())
+ && this.getBundleVersion().equals(((BundleDescriptorImpl) obj).getBundleVersion());
}
return false;
}
@@ -98,7 +102,6 @@ public abstract class BundleDescriptor extends ArtifactDescriptor implements Com
@Override
public int hashCode() {
return (this.getBundleSymbolicName() + ':' + this.getBundleVersion()).hashCode();
-
}
@Override
@@ -108,6 +111,7 @@ public abstract class BundleDescriptor extends ArtifactDescriptor implements Com
@Override
public int compareTo(final BundleDescriptor o) {
- return (this.getBundleSymbolicName() + ':' + this.getBundleVersion()).compareTo((o.getBundleSymbolicName() + ':' + o.getBundleVersion()));
+ return (this.getBundleSymbolicName() + ':' + this.getBundleVersion())
+ .compareTo((o.getBundleSymbolicName() + ':' + o.getBundleVersion()));
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/ContainerDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/ContainerDescriptor.java
index 3c1c72f..ba401aa 100644
--- a/src/main/java/org/apache/sling/feature/scanner/ContainerDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/ContainerDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -75,8 +77,8 @@ public abstract class ContainerDescriptor extends Descriptor {
*/
public <T extends ArtifactDescriptor> Set<T> getDescriptors(final Class<T> type) {
final Set<T> result = new HashSet<>();
- for(final ArtifactDescriptor desc : this.getArtifactDescriptors()) {
- if ( type.isInstance(desc) ) {
+ for (final ArtifactDescriptor desc : this.getArtifactDescriptors()) {
+ if (type.isInstance(desc)) {
result.add(type.cast(desc));
}
}
@@ -85,15 +87,15 @@ public abstract class ContainerDescriptor extends Descriptor {
@Override
public void lock() {
- if ( this.isLocked() ) {
+ if (this.isLocked()) {
return;
}
- for(final BundleDescriptor bd : this.bundles) {
+ for (final BundleDescriptor bd : this.bundles) {
this.aggregate(bd);
}
- for(final ArtifactDescriptor d : this.artifacts) {
+ for (final ArtifactDescriptor d : this.artifacts) {
this.aggregate(d);
}
super.lock();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/ContentPackageDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/ContentPackageDescriptor.java
index afa5554..8c79a39 100644
--- a/src/main/java/org/apache/sling/feature/scanner/ContentPackageDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/ContentPackageDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -87,10 +89,9 @@ public abstract class ContentPackageDescriptor extends ArtifactDescriptor {
* @return The package properties
*/
public abstract Properties getPackageProperties();
-
+
@Override
public String toString() {
return "ContentPackage [" + getName() + "]";
}
}
-
diff --git a/src/main/java/org/apache/sling/feature/scanner/Descriptor.java b/src/main/java/org/apache/sling/feature/scanner/Descriptor.java
index ceb5066..efcaf74 100644
--- a/src/main/java/org/apache/sling/feature/scanner/Descriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/Descriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -31,7 +33,7 @@ import org.osgi.resource.Capability;
* descriptor structurally, it must be synchronized externally. However, once a
* descriptor is locked, it is safe to access it concurrently.
*/
-public abstract class Descriptor {
+public abstract class Descriptor {
private final String name;
@@ -54,7 +56,7 @@ public abstract class Descriptor {
*/
protected Descriptor(final String name) {
this.name = name;
- if ( name == null ) {
+ if (name == null) {
throw new IllegalArgumentException("name must not be null");
}
}
@@ -141,11 +143,11 @@ public abstract class Descriptor {
* @return The list of capabilities. The list might be empty.
*/
public final Set<Capability> getCapabilities() {
- return locked ? Collections.unmodifiableSet(caps) : caps;
+ return locked ? Collections.unmodifiableSet(caps) : caps;
}
@Override
public String toString() {
return name;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/FeatureDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/FeatureDescriptor.java
index 654c952..8407a4e 100644
--- a/src/main/java/org/apache/sling/feature/scanner/FeatureDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/FeatureDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -53,4 +55,4 @@ public abstract class FeatureDescriptor extends ContainerDescriptor {
public Feature getFeature() {
return feature;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java b/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
index d8207e1..6c57c9d 100644
--- a/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
+++ b/src/main/java/org/apache/sling/feature/scanner/PackageInfo.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -94,8 +96,7 @@ public class PackageInfo implements Comparable<PackageInfo> {
* @throws IllegalArgumentException If the version is not well formed.
*/
public Version getPackageVersion() {
- if (this.version == null)
- return null;
+ if (this.version == null) return null;
return new Version(this.version);
}
@@ -109,8 +110,7 @@ public class PackageInfo implements Comparable<PackageInfo> {
* @throws IllegalArgumentException If the range is not well formed.
*/
public VersionRange getPackageVersionRange() {
- if (this.version == null)
- return null;
+ if (this.version == null) return null;
return new VersionRange(this.version);
}
@@ -125,15 +125,13 @@ public class PackageInfo implements Comparable<PackageInfo> {
@Override
public String toString() {
- return "Package " + name
- + ";version=" + version
- + (this.optional ? " (optional)" : "");
+ return "Package " + name + ";version=" + version + (this.optional ? " (optional)" : "");
}
@Override
public int compareTo(final PackageInfo o) {
int result = this.name.compareTo(o.name);
- if ( result == 0 ) {
+ if (result == 0) {
result = this.version.compareTo(o.version);
}
return result;
@@ -151,26 +149,17 @@ public class PackageInfo implements Comparable<PackageInfo> {
@Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
PackageInfo other = (PackageInfo) obj;
if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- if (optional != other.optional)
- return false;
+ if (other.name != null) return false;
+ } else if (!name.equals(other.name)) return false;
+ if (optional != other.optional) return false;
if (version == null) {
- if (other.version != null)
- return false;
- } else if (!version.equals(other.version))
- return false;
+ if (other.version != null) return false;
+ } else if (!version.equals(other.version)) return false;
return true;
}
-
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/Scanner.java b/src/main/java/org/apache/sling/feature/scanner/Scanner.java
index 9973736..76d2566 100644
--- a/src/main/java/org/apache/sling/feature/scanner/Scanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/Scanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner;
@@ -81,10 +83,11 @@ public class Scanner {
* @param frameworkScanners A list of framework scanners
* @throws IOException If something goes wrong
*/
- public Scanner(final ArtifactProvider artifactProvider,
+ public Scanner(
+ final ArtifactProvider artifactProvider,
final List<ExtensionScanner> extensionScanners,
final List<FrameworkScanner> frameworkScanners)
- throws IOException {
+ throws IOException {
this.artifactProvider = artifactProvider;
this.extensionScanners = extensionScanners == null ? getServices(ExtensionScanner.class) : extensionScanners;
this.frameworkScanners = frameworkScanners == null ? getServices(FrameworkScanner.class) : frameworkScanners;
@@ -96,8 +99,7 @@ public class Scanner {
* @param artifactProvider The artifact provider
* @throws IOException If something goes wrong
*/
- public Scanner(final ArtifactProvider artifactProvider)
- throws IOException {
+ public Scanner(final ArtifactProvider artifactProvider) throws IOException {
this(artifactProvider, null, null);
}
@@ -110,7 +112,7 @@ public class Scanner {
private static <T> List<T> getServices(final Class<T> clazz) {
final ServiceLoader<T> loader = ServiceLoader.load(clazz);
final List<T> list = new ArrayList<>();
- for(final T task : loader) {
+ for (final T task : loader) {
list.add(task);
}
return list;
@@ -129,9 +131,14 @@ public class Scanner {
}
private BundleDescriptor doScan(final Artifact bundle, final int startLevel) throws IOException {
- final String key = bundle.getId().toMvnId().concat(":")
- .concat(String.valueOf(startLevel)).concat(":")
- .concat(Stream.of(bundle.getFeatureOrigins()).map(ArtifactId::toMvnId).collect(Collectors.joining(",")));
+ final String key = bundle.getId()
+ .toMvnId()
+ .concat(":")
+ .concat(String.valueOf(startLevel))
+ .concat(":")
+ .concat(Stream.of(bundle.getFeatureOrigins())
+ .map(ArtifactId::toMvnId)
+ .collect(Collectors.joining(",")));
BundleDescriptor desc = (BundleDescriptor) this.cache.get(key);
if (desc == null) {
final URL file = artifactProvider.provide(bundle.getId());
@@ -152,8 +159,7 @@ public class Scanner {
* @param desc The container descriptor
* @throws IOException If something goes wrong or no suitable scanner is found.
*/
- private void getBundleInfos(final Bundles bundles, final ContainerDescriptor desc)
- throws IOException {
+ private void getBundleInfos(final Bundles bundles, final ContainerDescriptor desc) throws IOException {
for (final Artifact bundle : bundles) {
final BundleDescriptor bundleDesc = scanBundle(bundle);
desc.getBundleDescriptors().add(bundleDesc);
@@ -167,20 +173,19 @@ public class Scanner {
* @param desc The container descriptor
* @throws IOException If something goes wrong or no suitable scanner is found.
*/
- private void scanExtensions(final Feature f, final ContainerDescriptor desc)
- throws IOException {
+ private void scanExtensions(final Feature f, final ContainerDescriptor desc) throws IOException {
for (final Extension ext : f.getExtensions()) {
if (AnalyserMetaDataExtension.isAnalyserMetaDataExtension(ext)) {
continue;
}
ContainerDescriptor extDesc = null;
- for(final ExtensionScanner scanner : this.extensionScanners) {
+ for (final ExtensionScanner scanner : this.extensionScanners) {
extDesc = scanner.scan(f, ext, this.artifactProvider);
- if ( extDesc != null ) {
+ if (extDesc != null) {
break;
}
}
- if ( extDesc != null ) {
+ if (extDesc != null) {
desc.getRequirements().addAll(extDesc.getRequirements());
desc.getCapabilities().addAll(extDesc.getCapabilities());
desc.getExportedPackages().addAll(extDesc.getExportedPackages());
@@ -242,9 +247,13 @@ public class Scanner {
if (extension != null) {
for (Artifact bundle : feature.getBundles()) {
ArtifactId id = bundle.getId();
- final String key = id.toMvnId().concat(":")
- .concat(String.valueOf(bundle.getStartOrder())).concat(":")
- .concat(Stream.of(bundle.getFeatureOrigins()).map(ArtifactId::toMvnId).collect(Collectors.joining(",")));
+ final String key = id.toMvnId()
+ .concat(":")
+ .concat(String.valueOf(bundle.getStartOrder()))
+ .concat(":")
+ .concat(Stream.of(bundle.getFeatureOrigins())
+ .map(ArtifactId::toMvnId)
+ .collect(Collectors.joining(",")));
if (this.cache.get(key) == null) {
Map<String, String> headers = extension.getManifest(id);
if (headers != null) {
@@ -255,18 +264,18 @@ public class Scanner {
}
}
}
-
+
SystemBundle systemBundle = extension.getSystemBundle();
- if ( systemBundle != null ) {
+ if (systemBundle != null) {
URL artifactUrl = artifactProvider.provide(systemBundle.getArtifactId());
if (artifactUrl == null) {
throw new IOException("Unable to find file for " + systemBundle.getArtifactId());
}
-
+
BundleDescriptor desc = new SystemBundleDescriptor(systemBundle.getArtifactId(), artifactUrl);
-
+
String capabilities = systemBundle.getManifest().get(Constants.PROVIDE_CAPABILITY);
- if ( capabilities != null ) {
+ if (capabilities != null) {
try {
List<Capability> parsedCapabilities = ResourceBuilder.parseCapability(null, capabilities);
desc.getCapabilities().addAll(parsedCapabilities);
@@ -274,9 +283,9 @@ public class Scanner {
throw new IOException("Failed to parse capabilites for the system bundle", e);
}
}
-
+
String exports = systemBundle.getManifest().get(Constants.EXPORT_PACKAGE);
- if ( exports != null ) {
+ if (exports != null) {
Clause[] pcks = Parser.parseHeader(exports);
for (final Clause pck : pcks) {
String version = pck.getAttribute("version");
@@ -285,11 +294,10 @@ public class Scanner {
}
}
desc.lock();
-
+
String key = systemBundle.getScannerCacheKey();
-
+
this.cache.put(key, desc);
-
}
}
}
@@ -302,7 +310,7 @@ public class Scanner {
* @return The framework descriptor
* @throws IOException If something goes wrong or a scanner is missing
*/
- public BundleDescriptor scan(final ArtifactId framework, final Map<String,String> props) throws IOException {
+ public BundleDescriptor scan(final ArtifactId framework, final Map<String, String> props) throws IOException {
final String key = SystemBundleDescriptor.createCacheKey(framework, props);
BundleDescriptor desc = (BundleDescriptor) this.cache.get(key);
if (desc == null) {
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/ArtifactDescriptorImpl.java b/src/main/java/org/apache/sling/feature/scanner/impl/ArtifactDescriptorImpl.java
index 6d0956c..a7376ff 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/ArtifactDescriptorImpl.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/ArtifactDescriptorImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -25,8 +27,7 @@ import org.apache.sling.feature.scanner.ArtifactDescriptor;
/**
* Information about an artifact.
*/
-public class ArtifactDescriptorImpl
- extends ArtifactDescriptor {
+public class ArtifactDescriptorImpl extends ArtifactDescriptor {
/** Manifest */
private final Manifest manifest;
@@ -45,11 +46,7 @@ public class ArtifactDescriptorImpl
* @param Manifest manifest (optional)
* @throws NullPointerException If artifact is {@code null}
*/
- public ArtifactDescriptorImpl(
- final String name,
- final Artifact artifact,
- final URL url,
- final Manifest manifest) {
+ public ArtifactDescriptorImpl(final String name, final Artifact artifact, final URL url, final Manifest manifest) {
super(name != null ? name : artifact.getId().toMvnId());
this.artifact = artifact;
this.artifact.getId(); // throw NPE if artifact is null
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java b/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
index 8bd4c06..e2074d1 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -50,8 +52,7 @@ import org.slf4j.LoggerFactory;
/**
* Information about a bundle
*/
-public class BundleDescriptorImpl
- extends BundleDescriptor {
+public class BundleDescriptorImpl extends BundleDescriptor {
private static final Logger logger = LoggerFactory.getLogger(BundleDescriptorImpl.class);
@@ -70,7 +71,6 @@ public class BundleDescriptorImpl
/** The physical file for analyzing. */
private URL artifactFile;
-
/** The corresponding artifact from the feature. */
private final Artifact artifact;
@@ -88,7 +88,7 @@ public class BundleDescriptorImpl
} else {
try (JarFile jarFile = IOUtils.getJarFileFromURL(file, true, null)) {
manifest = jarFile.getManifest();
- } catch ( final IOException ioe) {
+ } catch (final IOException ioe) {
// rethrow with more info
throw new IOException(file + " : " + ioe.getMessage(), ioe);
}
@@ -106,8 +106,7 @@ public class BundleDescriptorImpl
* @throws IOException If the manifest can't be get
* @throws NullPointerException If artifact is {@code null}
*/
- public BundleDescriptorImpl(final Artifact artifact,
- final URL url) throws IOException {
+ public BundleDescriptorImpl(final Artifact artifact, final URL url) throws IOException {
this(artifact, url, null, getManifest(url));
}
@@ -119,9 +118,8 @@ public class BundleDescriptorImpl
* @throws IOException If the manifest can't be get
* @throws NullPointerException If artifact is {@code null}
*/
- public BundleDescriptorImpl(final Artifact artifact,
- final ArtifactProvider provider,
- final Manifest manifest) throws IOException {
+ public BundleDescriptorImpl(final Artifact artifact, final ArtifactProvider provider, final Manifest manifest)
+ throws IOException {
this(artifact, null, provider, manifest);
}
@@ -134,15 +132,14 @@ public class BundleDescriptorImpl
* @throws IOException If the manifest can't be get
* @throws NullPointerException If artifact is {@code null}
*/
- public BundleDescriptorImpl(final Artifact artifact,
- final URL url,
- final ArtifactProvider provider,
- final Manifest manifest) throws IOException {
+ public BundleDescriptorImpl(
+ final Artifact artifact, final URL url, final ArtifactProvider provider, final Manifest manifest)
+ throws IOException {
super(artifact.getId().toMvnId());
this.artifact = artifact;
this.artifactFile = url;
this.artifactProvider = provider;
- if ( manifest == null ) {
+ if (manifest == null) {
throw new IOException("File has no manifest");
}
this.manifest = new Manifest(manifest);
@@ -194,10 +191,11 @@ public class BundleDescriptorImpl
private void analyze() throws IOException {
final String name = this.manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
- if ( name != null ) {
+ 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());
+ if (version == null) {
+ throw new IOException("Unable to get bundle version from artifact "
+ + getArtifact().getId().toMvnId());
}
this.symbolicName = name;
this.bundleVersion = version;
@@ -210,39 +208,44 @@ public class BundleDescriptorImpl
this.getImportedPackages().addAll(extractImportedPackages(this.manifest));
this.getDynamicImportedPackages().addAll(extractDynamicImportedPackages(this.manifest));
try {
- ResourceImpl resource = ResourceBuilder.build(this.artifact.getId().toMvnUrl(), this.manifest.getMainAttributes().entrySet().stream()
- .collect(Collectors.toMap(entry -> entry.getKey().toString(), entry -> entry.getValue().toString())));
+ ResourceImpl resource = ResourceBuilder.build(
+ this.artifact.getId().toMvnUrl(),
+ this.manifest.getMainAttributes().entrySet().stream()
+ .collect(
+ Collectors.toMap(entry -> entry.getKey().toString(), entry -> entry.getValue()
+ .toString())));
this.getCapabilities().addAll(resource.getCapabilities(null));
- this.getRequirements().addAll(resource.getRequirements(null).stream()
- .map(entry -> new MatchingRequirementImpl(entry)).collect(Collectors.toList()));
+ this.getRequirements()
+ .addAll(resource.getRequirements(null).stream()
+ .map(entry -> new MatchingRequirementImpl(entry))
+ .collect(Collectors.toList()));
} catch (Exception ex) {
throw new IOException(ex);
}
} else {
- throw new IOException("Unable to get bundle symbolic name from artifact " + getArtifact().getId().toMvnId());
+ throw new IOException("Unable to get bundle symbolic name from artifact "
+ + getArtifact().getId().toMvnId());
}
}
- private static List<PackageInfo> extractPackages(final Manifest m,
- final String headerName,
- final String defaultVersion,
- final boolean checkOptional) {
+ private static List<PackageInfo> extractPackages(
+ final Manifest m, final String headerName, final String defaultVersion, final boolean checkOptional) {
final String pckInfo = m.getMainAttributes().getValue(headerName);
if (pckInfo != null) {
final Clause[] clauses = Parser.parseHeader(pckInfo);
final List<PackageInfo> pcks = new ArrayList<>();
- for(final Clause entry : clauses) {
+ for (final Clause entry : clauses) {
Object versionObj = entry.getAttribute("version");
final String version;
- if ( versionObj == null ) {
+ if (versionObj == null) {
version = defaultVersion;
} else {
version = versionObj.toString();
}
boolean optional = false;
- if ( checkOptional ) {
+ if (checkOptional) {
final String resolution = entry.getDirective("resolution");
optional = "optional".equalsIgnoreCase(resolution);
}
@@ -257,10 +260,7 @@ public class BundleDescriptorImpl
}
}
- final PackageInfo pck = new PackageInfo(entry.getName(),
- version,
- optional,
- uses);
+ final PackageInfo pck = new PackageInfo(entry.getName(), version, optional, uses);
pcks.add(pck);
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptorImpl.java b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptorImpl.java
index 7533a3b..2f8b715 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptorImpl.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageDescriptorImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -63,10 +65,10 @@ public class ContentPackageDescriptorImpl extends ContentPackageDescriptor {
/** The physical file for analyzing. */
private final URL artifactFile;
-
+
/** The corresponding artifact from the feature. */
private final Artifact artifact;
-
+
/** The package properties */
private final Properties packageProperties;
@@ -82,7 +84,8 @@ public class ContentPackageDescriptorImpl extends ContentPackageDescriptor {
* @param properties Package properties
* @throws NullPointerException If artifact is {@code null}
*/
- public ContentPackageDescriptorImpl(final String name,
+ public ContentPackageDescriptorImpl(
+ final String name,
final Artifact artifact,
final URL url,
final Manifest manifest,
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
index 44383d2..c12bb9c 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackageScanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -75,7 +77,7 @@ public class ContentPackageScanner {
final String path = url.getPath();
final int lastDotInUrl = path.lastIndexOf(".");
final String name = path.substring(path.lastIndexOf("/") + 1, lastDotInUrl);
- extractContentPackage(null, null, artifact, name, url, contentPackages);
+ extractContentPackage(null, null, artifact, name, url, contentPackages);
}
return contentPackages;
@@ -132,33 +134,35 @@ public class ContentPackageScanner {
fileType = FileType.PACKAGE;
} else {
- for(final String ext : CFG_EXTENSIONS) {
- if ( contentPath.endsWith(ext) ) {
+ for (final String ext : CFG_EXTENSIONS) {
+ if (contentPath.endsWith(ext)) {
fileType = FileType.CONFIG;
break;
}
}
}
}
- } else if ( contentPath.startsWith("/etc/packages/") && contentPath.endsWith(".zip")) {
+ } else if (contentPath.startsWith("/etc/packages/") && contentPath.endsWith(".zip")) {
// embedded content package
fileType = FileType.PACKAGE;
}
return fileType;
}
- private ContentPackageDescriptorImpl extractContentPackage(final ContentPackageDescriptorImpl parentPackage,
+ private ContentPackageDescriptorImpl extractContentPackage(
+ final ContentPackageDescriptorImpl parentPackage,
final String parentContentPath,
final Artifact packageArtifact,
final String name,
final URL archiveUrl,
final Set<ContentPackageDescriptorImpl> infos)
- throws IOException {
+ throws IOException {
logger.debug("Analyzing Content Package {}", archiveUrl);
final File tempDir = Files.createTempDirectory(null).toFile();
try {
- final File toDir = new File(tempDir, archiveUrl.getPath().substring(archiveUrl.getPath().lastIndexOf("/") + 1));
+ final File toDir = new File(
+ tempDir, archiveUrl.getPath().substring(archiveUrl.getPath().lastIndexOf("/") + 1));
toDir.mkdirs();
Manifest manifest = null;
@@ -175,13 +179,13 @@ public class ContentPackageScanner {
final String entryName = entry.getName();
// skip dirs
- if ( entryName.endsWith("/") ) {
+ if (entryName.endsWith("/")) {
continue;
}
logger.debug("Content package entry {}", entryName);
- if ( entryName.startsWith("jcr_root/") ) {
+ if (entryName.startsWith("jcr_root/")) {
final String contentPath = entryName.substring(8);
contentPaths.add(contentPath);
@@ -191,10 +195,8 @@ public class ContentPackageScanner {
final File newFile = new File(toDir, entryName.replace('/', File.separatorChar));
newFile.getParentFile().mkdirs();
- try (
- final FileOutputStream fos = new FileOutputStream(newFile);
- final InputStream zis = zipFile.getInputStream(entry);
- ) {
+ try (final FileOutputStream fos = new FileOutputStream(newFile);
+ final InputStream zis = zipFile.getInputStream(entry); ) {
int len;
while ((len = zis.read(buffer)) > -1) {
fos.write(buffer, 0, len);
@@ -212,18 +214,23 @@ public class ContentPackageScanner {
// ignore
}
- final Artifact bundle = new Artifact(extractArtifactId(packageArtifact.getId(), newFile));
+ final Artifact bundle =
+ new Artifact(extractArtifactId(packageArtifact.getId(), newFile));
bundle.setStartOrder(startLevel);
- final BundleDescriptor info = new BundleDescriptorImpl(bundle, newFile.toURI().toURL());
- bundle.getMetadata().put(ContentPackageDescriptorImpl.METADATA_PACKAGE,
- packageArtifact.getId().toMvnId());
+ final BundleDescriptor info = new BundleDescriptorImpl(
+ bundle, newFile.toURI().toURL());
+ bundle.getMetadata()
+ .put(
+ ContentPackageDescriptorImpl.METADATA_PACKAGE,
+ packageArtifact.getId().toMvnId());
bundle.getMetadata().put(ContentPackageDescriptorImpl.METADATA_PATH, contentPath);
bundles.add(info);
} else if (fileType == FileType.CONFIG) {
- final Configuration configEntry = this.processConfiguration(newFile, packageArtifact.getId(), contentPath);
+ final Configuration configEntry =
+ this.processConfiguration(newFile, packageArtifact.getId(), contentPath);
if (configEntry != null) {
configs.add(configEntry);
}
@@ -232,34 +239,41 @@ public class ContentPackageScanner {
toProcess.add(newFile);
}
}
- } else if ( FILE_MANIFEST.equals(entry.getName()) ) {
- try ( final InputStream zis = zipFile.getInputStream(entry)) {
+ } else if (FILE_MANIFEST.equals(entry.getName())) {
+ try (final InputStream zis = zipFile.getInputStream(entry)) {
manifest = new Manifest(zis);
- } catch ( final IOException ignore ) {
- logger.warn("Failure reading manifest from {} : {}", packageArtifact.getId(), ignore.getMessage());
+ } catch (final IOException ignore) {
+ logger.warn(
+ "Failure reading manifest from {} : {}",
+ packageArtifact.getId(),
+ ignore.getMessage());
}
- } else if ( FILE_PACKAGE_PROPS.equals(entry.getName()) ) {
- try ( final InputStream zis = zipFile.getInputStream(entry)) {
+ } else if (FILE_PACKAGE_PROPS.equals(entry.getName())) {
+ try (final InputStream zis = zipFile.getInputStream(entry)) {
packageProps.loadFromXML(zis);
}
}
}
- final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(name, packageArtifact, archiveUrl, manifest,
- bundles, contentPaths, configs, packageProps);
- if ( parentPackage != null ) {
+ final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(
+ name, packageArtifact, archiveUrl, manifest, bundles, contentPaths, configs, packageProps);
+ if (parentPackage != null) {
desc.setParentContentPackageInfo(parentPackage, parentContentPath);
}
for (final File f : toProcess) {
final int lastDot = f.getName().lastIndexOf(".");
final String subName = f.getName().substring(0, lastDot);
- final String contentPath = f.getAbsolutePath().substring(toDir.getAbsolutePath().length()).replace(File.separatorChar, '/');
+ final String contentPath = f.getAbsolutePath()
+ .substring(toDir.getAbsolutePath().length())
+ .replace(File.separatorChar, '/');
// create synthetic artifact with a synthetic id containing the file name
- final Artifact subArtifact = new Artifact(packageArtifact.getId().changeClassifier(subName));
+ final Artifact subArtifact =
+ new Artifact(packageArtifact.getId().changeClassifier(subName));
- extractContentPackage(desc, contentPath, subArtifact, subName, f.toURI().toURL(), infos);
+ extractContentPackage(
+ desc, contentPath, subArtifact, subName, f.toURI().toURL(), infos);
}
infos.add(desc);
@@ -283,18 +297,20 @@ public class ContentPackageScanner {
}
}
- final List<Properties> getInitialCandidates(final File bundleFile) throws IOException{
+ final List<Properties> getInitialCandidates(final File bundleFile) throws IOException {
logger.debug("Extracting Bundle {}", bundleFile.getName());
final List<Properties> candidates = new ArrayList<>();
try (final JarFile zipFile = new JarFile(bundleFile)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
- while ( entries.hasMoreElements() ) {
+ while (entries.hasMoreElements()) {
final ZipEntry entry = entries.nextElement();
final String entryName = entry.getName();
- if ( !entryName.endsWith("/") && entryName.startsWith("META-INF/maven/") && entryName.endsWith("/pom.properties")) {
+ if (!entryName.endsWith("/")
+ && entryName.startsWith("META-INF/maven/")
+ && entryName.endsWith("/pom.properties")) {
logger.debug("- extracting : {}", entryName);
final Properties props = new Properties();
@@ -310,7 +326,7 @@ public class ContentPackageScanner {
private String adjustVersion(final String version) {
final String parts[] = version.split("\\.");
- if ( parts.length == 4 ) {
+ if (parts.length == 4) {
final int lastDot = version.lastIndexOf('.');
return version.substring(0, lastDot) + '-' + version.substring(lastDot + 1);
}
@@ -320,30 +336,29 @@ public class ContentPackageScanner {
private ArtifactId adjustClassifier(ArtifactId id, final String bundleFileName) {
// check for classifier
final int versionStart = bundleFileName.indexOf(id.getVersion());
- if ( versionStart != -1 ) {
+ if (versionStart != -1) {
// capture classifier
final int versionEnd = versionStart + id.getVersion().length();
- if ( bundleFileName.length() > versionEnd && bundleFileName.charAt(versionEnd) == '-') {
+ if (bundleFileName.length() > versionEnd && bundleFileName.charAt(versionEnd) == '-') {
id = id.changeClassifier(bundleFileName.substring(versionEnd + 1, bundleFileName.lastIndexOf('.')));
}
}
return id;
}
- private ArtifactId extractArtifactId(final ArtifactId packageArtifactId, final File bundleFile)
- throws IOException {
+ private ArtifactId extractArtifactId(final ArtifactId packageArtifactId, final File bundleFile) throws IOException {
final List<Properties> candidates = this.getInitialCandidates(bundleFile);
return extractArtifactId(candidates, bundleFile.getName(), packageArtifactId);
}
private List<ArtifactId> getArtifactIds(final List<Properties> candidates) {
final List<ArtifactId> idCandidates = new ArrayList<>();
- for(final Properties props : candidates) {
+ for (final Properties props : candidates) {
final String version = props.getProperty("version");
final String groupId = props.getProperty("groupId");
final String artifactId = props.getProperty("artifactId");
- if ( version != null && groupId != null && artifactId != null ) {
+ if (version != null && groupId != null && artifactId != null) {
idCandidates.add(new ArtifactId(groupId, artifactId, adjustVersion(version), null, null));
}
}
@@ -352,24 +367,25 @@ public class ContentPackageScanner {
private List<ArtifactId> filterCandidatesByVersion(final List<ArtifactId> ids, final String bundleFileName) {
final List<ArtifactId> idCandidates = new ArrayList<>();
- for(final ArtifactId id : ids) {
+ for (final ArtifactId id : ids) {
final int versionStart = bundleFileName.indexOf(id.getVersion());
- if ( versionStart != -1 ) {
+ if (versionStart != -1) {
idCandidates.add(id);
}
}
return idCandidates;
}
- ArtifactId extractArtifactId(final List<Properties> candidates, final String bundleFileName, final ArtifactId packageArtifactId)
- throws IOException {
+ ArtifactId extractArtifactId(
+ final List<Properties> candidates, final String bundleFileName, final ArtifactId packageArtifactId)
+ throws IOException {
logger.debug("Properties candidates for {} : {}", bundleFileName, candidates);
final List<ArtifactId> idCandidates = getArtifactIds(candidates);
logger.debug("Artifact candidates for {} : {}", bundleFileName, candidates);
// single candidate? return
- if ( idCandidates.size() == 1 ) {
+ if (idCandidates.size() == 1) {
final ArtifactId result = adjustClassifier(idCandidates.get(0), bundleFileName);
logger.debug("Found single candidate : {}", result);
return result;
@@ -377,21 +393,21 @@ public class ContentPackageScanner {
// more than one candidate, find matching version
final List<ArtifactId> versionIds = filterCandidatesByVersion(idCandidates, bundleFileName);
- if ( versionIds.size() == 1 ) {
+ if (versionIds.size() == 1) {
final ArtifactId result = adjustClassifier(versionIds.get(0), bundleFileName);
logger.debug("Found single candidate matching version : {}", result);
return result;
}
// check parent group id
- for(final ArtifactId id : versionIds.isEmpty() ? idCandidates : versionIds) {
- if ( id.getGroupId().equals(packageArtifactId.getGroupId()) ) {
+ for (final ArtifactId id : versionIds.isEmpty() ? idCandidates : versionIds) {
+ if (id.getGroupId().equals(packageArtifactId.getGroupId())) {
final ArtifactId result = adjustClassifier(id, bundleFileName);
- logger.debug("Found candidate with parent group id {} : {}",packageArtifactId.getGroupId(), result);
+ logger.debug("Found candidate with parent group id {} : {}", packageArtifactId.getGroupId(), result);
return result;
}
}
// randomly pick one
- if ( idCandidates.size() > 0 ) {
+ if (idCandidates.size() > 0) {
final ArtifactId result = adjustClassifier(idCandidates.get(0), bundleFileName);
logger.debug("Picking random candidate : {}", result);
return result;
@@ -400,30 +416,28 @@ public class ContentPackageScanner {
throw new IOException(bundleFileName + " has no maven coordinates!");
}
- Configuration processConfiguration(final File configFile,
- final ArtifactId packageArtifactId,
- final String contentPath)
- throws IOException {
+ Configuration processConfiguration(
+ final File configFile, final ArtifactId packageArtifactId, final String contentPath) throws IOException {
boolean isConfig = true;
- if ( contentPath.endsWith(".xml") ) {
+ if (contentPath.endsWith(".xml")) {
final String contents = Files.readAllLines(configFile.toPath()).toString();
- if ( contents.indexOf("jcr:primaryType=\"sling:OsgiConfig\"") == -1 ) {
+ if (contents.indexOf("jcr:primaryType=\"sling:OsgiConfig\"") == -1) {
isConfig = false;
}
}
- if ( isConfig ) {
+ if (isConfig) {
final String id;
- if ( contentPath.endsWith("/.content.xml") ) {
+ if (contentPath.endsWith("/.content.xml")) {
final int lastSlash = contentPath.lastIndexOf('/');
final int previousSlash = contentPath.lastIndexOf('/', lastSlash - 1);
id = contentPath.substring(previousSlash + 1, lastSlash);
} else {
String name = contentPath;
final int lastSlash = contentPath.lastIndexOf('/');
- for(final String ext : CFG_EXTENSIONS) {
- if ( name.endsWith(ext) ) {
+ for (final String ext : CFG_EXTENSIONS) {
+ if (name.endsWith(ext)) {
name = name.substring(lastSlash + 1, name.length() - ext.length());
}
}
@@ -432,16 +446,19 @@ public class ContentPackageScanner {
final String pid;
final int slashPos = id.indexOf('-');
- if ( slashPos == -1 ) {
+ if (slashPos == -1) {
pid = id;
} else {
pid = id.substring(0, slashPos) + '~' + id.substring(slashPos + 1);
}
final Configuration cfg = new Configuration(pid);
- cfg.getProperties().put(Configuration.PROP_PREFIX + ContentPackageDescriptorImpl.METADATA_PATH, contentPath);
- cfg.getProperties().put(Configuration.PROP_PREFIX + ContentPackageDescriptorImpl.METADATA_PACKAGE,
- packageArtifactId.toMvnId());
+ cfg.getProperties()
+ .put(Configuration.PROP_PREFIX + ContentPackageDescriptorImpl.METADATA_PATH, contentPath);
+ cfg.getProperties()
+ .put(
+ Configuration.PROP_PREFIX + ContentPackageDescriptorImpl.METADATA_PACKAGE,
+ packageArtifactId.toMvnId());
return cfg;
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
index 077f12d..e596fd2 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/ContentPackagesExtensionScanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -37,6 +39,7 @@ import org.slf4j.LoggerFactory;
public class ContentPackagesExtensionScanner implements ExtensionScanner {
private static final Logger logger = LoggerFactory.getLogger(ContentPackageScanner.class);
+
@Override
public String getId() {
return Extension.EXTENSION_NAME_CONTENT_PACKAGES;
@@ -48,21 +51,19 @@ public class ContentPackagesExtensionScanner implements ExtensionScanner {
}
@Override
- public ContainerDescriptor scan(final Feature feature,
- final Extension extension,
- final ArtifactProvider provider)
- throws IOException {
+ public ContainerDescriptor scan(final Feature feature, final Extension extension, final ArtifactProvider provider)
+ throws IOException {
if (!Extension.EXTENSION_NAME_CONTENT_PACKAGES.equals(extension.getName())) {
return null;
}
- if ( extension.getType() != ExtensionType.ARTIFACTS ) {
+ if (extension.getType() != ExtensionType.ARTIFACTS) {
return null;
}
final ContentPackageScanner scanner = new ContentPackageScanner();
final ContainerDescriptor cd = new ContainerDescriptor(feature.getId().toMvnId() + "(" + getId() + ")") {};
- for(final Artifact a : extension.getArtifacts()) {
+ for (final Artifact a : extension.getArtifacts()) {
URL url = null;
try {
url = provider.provide(a.getId());
@@ -76,11 +77,17 @@ public class ContentPackagesExtensionScanner implements ExtensionScanner {
cd.getArtifactDescriptors().add(desc);
cd.getBundleDescriptors().addAll(desc.getBundles());
}
- }
- else {
+ } else {
final int lastDot = a.getId().toMvnPath().lastIndexOf(".");
- ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(a.getId().toMvnPath().substring(a.getId().toMvnPath().lastIndexOf("/") + 1, lastDot),
- a, url, null, null, null, null, new Properties());
+ ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(
+ a.getId().toMvnPath().substring(a.getId().toMvnPath().lastIndexOf("/") + 1, lastDot),
+ a,
+ url,
+ null,
+ null,
+ null,
+ null,
+ new Properties());
desc.lock();
cd.getArtifactDescriptors().add(desc);
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/FeatureDescriptorImpl.java b/src/main/java/org/apache/sling/feature/scanner/impl/FeatureDescriptorImpl.java
index af90e49..ca51b57 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/FeatureDescriptorImpl.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/FeatureDescriptorImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -23,8 +25,7 @@ import org.apache.sling.feature.scanner.FeatureDescriptor;
* Information about a feature.
* This is the aggregated information.
*/
-public class FeatureDescriptorImpl
- extends FeatureDescriptor {
+public class FeatureDescriptorImpl extends FeatureDescriptor {
/**
* Constructor for the feature descriptor
@@ -33,4 +34,4 @@ public class FeatureDescriptorImpl
public FeatureDescriptorImpl(final Feature feature) {
super(feature);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java b/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
index d4cab4e..1f60be0 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -56,16 +58,15 @@ import org.osgi.resource.Capability;
public class FelixFrameworkScanner implements FrameworkScanner {
@Override
- public BundleDescriptor scan(final ArtifactId framework,
- final Map<String,String> frameworkProps,
- final ArtifactProvider provider)
- throws IOException {
+ public BundleDescriptor scan(
+ final ArtifactId framework, final Map<String, String> frameworkProps, final ArtifactProvider provider)
+ throws IOException {
final URL platformFile = provider.provide(framework);
- if ( platformFile == null ) {
+ if (platformFile == null) {
throw new IOException("Unable to find file for " + framework.toMvnId());
}
- final Map<String,String> fwkProps = getFrameworkProperties(frameworkProps, platformFile);
- if ( fwkProps == null ) {
+ final Map<String, String> fwkProps = getFrameworkProperties(frameworkProps, platformFile);
+ if (fwkProps == null) {
return null;
}
final Set<PackageInfo> pcks = calculateSystemPackages(fwkProps);
@@ -78,36 +79,35 @@ public class FelixFrameworkScanner implements FrameworkScanner {
return d;
}
- private List<Capability> calculateSystemCapabilities(final Map<String,String> fwkProps) throws IOException {
+ private List<Capability> calculateSystemCapabilities(final Map<String, String> fwkProps) throws IOException {
Map<String, String> mf = new HashMap<>();
mf.put(Constants.PROVIDE_CAPABILITY, fwkProps.get(Constants.FRAMEWORK_SYSTEMCAPABILITIES));
mf.put(Constants.BUNDLE_SYMBOLICNAME, Constants.SYSTEM_BUNDLE_SYMBOLICNAME);
mf.put(Constants.BUNDLE_MANIFESTVERSION, "2");
- try
- {
+ try {
return ResourceBuilder.build(null, mf).getCapabilities(null);
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
throw new IOException(ex);
}
}
- private Set<PackageInfo> calculateSystemPackages(final Map<String,String> fwkProps) {
- return Stream.of(
- Parser.parseHeader(fwkProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES)))
- .map(
- clause -> new PackageInfo(clause.getName(), clause.getAttribute("version") != null ? clause.getAttribute("version") : "0.0.0", false))
- .collect(Collectors.toSet());
+ private Set<PackageInfo> calculateSystemPackages(final Map<String, String> fwkProps) {
+ return Stream.of(Parser.parseHeader(fwkProps.get(Constants.FRAMEWORK_SYSTEMPACKAGES)))
+ .map(clause -> new PackageInfo(
+ clause.getName(),
+ clause.getAttribute("version") != null ? clause.getAttribute("version") : "0.0.0",
+ false))
+ .collect(Collectors.toSet());
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
- Map<String,String> getFrameworkProperties(final Map<String,String> appProps, final URL framework)
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ Map<String, String> getFrameworkProperties(final Map<String, String> appProps, final URL framework)
throws IOException {
Path appPropsFile = Files.createTempFile("appProps", ".properties");
Properties appPropsProperties = new Properties();
- for (Map.Entry<String,String> entry : appProps.entrySet()) {
+ for (Map.Entry<String, String> entry : appProps.entrySet()) {
appPropsProperties.put(entry.getKey(), entry.getValue().replace("{dollar}", "$"));
}
@@ -145,9 +145,7 @@ public class FelixFrameworkScanner implements FrameworkScanner {
Files.delete(outFile);
try (Stream<Path> fileStream = Files.walk(runDir)) {
- fileStream.sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
+ fileStream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
}
return (Map) gatheredProps;
@@ -172,19 +170,17 @@ public class FelixFrameworkScanner implements FrameworkScanner {
return new File(new URL(fileURL).getFile());
}
- private static void runJava(List<String> commandLine, Path execDir)
- throws IOException, InterruptedException {
+ private static void runJava(List<String> commandLine, Path execDir) throws IOException, InterruptedException {
String java = System.getProperty("java.home") + "/bin/java";
commandLine.add(0, java);
runCommand(commandLine, execDir);
}
- private static void runCommand(List<String> commandLine, Path execDir)
- throws IOException, InterruptedException {
+ private static void runCommand(List<String> commandLine, Path execDir) throws IOException, InterruptedException {
Process process = new ProcessBuilder(commandLine)
- .directory(execDir.toFile())
- .inheritIO()
- .start();
+ .directory(execDir.toFile())
+ .inheritIO()
+ .start();
int res = process.waitFor();
if (res != 0) {
throw new IOException("Process returned with a failure: " + res);
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/MatchingRequirementImpl.java b/src/main/java/org/apache/sling/feature/scanner/impl/MatchingRequirementImpl.java
index d43ed31..bddab07 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/MatchingRequirementImpl.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/MatchingRequirementImpl.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -30,8 +32,8 @@ class MatchingRequirementImpl extends RequirementImpl implements MatchingRequire
super(req.getResource(), req.getNamespace(), req.getDirectives(), req.getAttributes());
}
- public MatchingRequirementImpl(final Resource res, final String ns, final Map<String, String> dirs,
- final Map<String, Object> attrs) {
+ public MatchingRequirementImpl(
+ final Resource res, final String ns, final Map<String, String> dirs, final Map<String, Object> attrs) {
super(res, ns, dirs, attrs);
}
@@ -44,7 +46,9 @@ class MatchingRequirementImpl extends RequirementImpl implements MatchingRequire
return false;
}
final RequirementImpl that = (RequirementImpl) o;
- return Objects.equals(resource, that.getResource()) && Objects.equals(namespace, that.getNamespace())
- && Objects.equals(attributes, that.getAttributes()) && Objects.equals(directives, that.getDirectives());
+ return Objects.equals(resource, that.getResource())
+ && Objects.equals(namespace, that.getNamespace())
+ && Objects.equals(attributes, that.getAttributes())
+ && Objects.equals(directives, that.getDirectives());
}
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/RepoInitScanner.java b/src/main/java/org/apache/sling/feature/scanner/impl/RepoInitScanner.java
index 716909a..35a46e6 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/RepoInitScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/RepoInitScanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -31,10 +33,12 @@ import org.apache.sling.feature.scanner.spi.ExtensionScanner;
* A scanner for repo init instructions
*/
public class RepoInitScanner implements ExtensionScanner {
- private static final MatchingRequirement REQUIREMENT_REPOINIT = new MatchingRequirementImpl(null,
+ private static final MatchingRequirement REQUIREMENT_REPOINIT = new MatchingRequirementImpl(
+ null,
"osgi.implementation",
- Collections.singletonMap("filter", "(&(osgi.implementation=org.apache.sling.jcr.repoinit)(version>=1.0)(!(version>=2.0)))"),
- null);
+ Collections.singletonMap(
+ "filter", "(&(osgi.implementation=org.apache.sling.jcr.repoinit)(version>=1.0)(!(version>=2.0)))"),
+ null);
@Override
public String getId() {
@@ -47,14 +51,12 @@ public class RepoInitScanner implements ExtensionScanner {
}
@Override
- public ContainerDescriptor scan(final Feature feature,
- final Extension extension,
- final ArtifactProvider provider)
- throws IOException {
+ public ContainerDescriptor scan(final Feature feature, final Extension extension, final ArtifactProvider provider)
+ throws IOException {
if (!Extension.EXTENSION_NAME_REPOINIT.equals(extension.getName())) {
return null;
}
- if ( extension.getType() != ExtensionType.TEXT ) {
+ if (extension.getType() != ExtensionType.TEXT) {
return null;
}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/SystemBundleDescriptor.java b/src/main/java/org/apache/sling/feature/scanner/impl/SystemBundleDescriptor.java
index 3972042..0cb0dbe 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/SystemBundleDescriptor.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/SystemBundleDescriptor.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.impl;
@@ -28,11 +30,11 @@ import org.osgi.framework.Constants;
/**
* Bundle descriptor that describes the system bundle
- *
+ *
* <p>It is based on an existing artifact id and the associated platform file.</p>
*/
public final class SystemBundleDescriptor extends BundleDescriptor {
-
+
public static String createCacheKey(final ArtifactId framework, final Map<String, String> props) {
final StringBuilder sb = new StringBuilder();
sb.append(framework.toMvnId());
@@ -44,7 +46,7 @@ public final class SystemBundleDescriptor extends BundleDescriptor {
}
return sb.toString();
}
-
+
private final URL platformFile;
private final ArtifactId framework;
@@ -78,4 +80,4 @@ public final class SystemBundleDescriptor extends BundleDescriptor {
public Manifest getManifest() {
return new Manifest();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/impl/fwk/FrameworkPropertiesGatherer.java b/src/main/java/org/apache/sling/feature/scanner/impl/fwk/FrameworkPropertiesGatherer.java
index 2cc6318..604a5d6 100644
--- a/src/main/java/org/apache/sling/feature/scanner/impl/fwk/FrameworkPropertiesGatherer.java
+++ b/src/main/java/org/apache/sling/feature/scanner/impl/fwk/FrameworkPropertiesGatherer.java
@@ -1,25 +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
+ * 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
+ * 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.
+ * 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.scanner.impl.fwk;
-import org.osgi.framework.Constants;
-import org.osgi.framework.launch.Framework;
-import org.osgi.framework.launch.FrameworkFactory;
-
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
@@ -29,6 +27,10 @@ import java.util.Map;
import java.util.Properties;
import java.util.ServiceLoader;
+import org.osgi.framework.Constants;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
+
/**
* This class launches an OSGi framework and obtains the system packages and capabilities provided by it.
* It takes 2 arguments: <ul>
@@ -39,7 +41,7 @@ import java.util.ServiceLoader;
* </ul>After obtaining the values, the launched framework is stopped.
*/
public class FrameworkPropertiesGatherer {
- public static void main(String [] args) throws Exception {
+ public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.print("usage: FrameworkPropertiesGatherer <in props filename> <out props filename>");
System.exit(1);
@@ -53,7 +55,7 @@ public class FrameworkPropertiesGatherer {
ServiceLoader<FrameworkFactory> ldr = ServiceLoader.load(FrameworkFactory.class);
FrameworkFactory ff = ldr.iterator().next();
- @SuppressWarnings({ "unchecked", "rawtypes" })
+ @SuppressWarnings({"unchecked", "rawtypes"})
Framework fwk = ff.newFramework((Map) inProps);
fwk.init();
diff --git a/src/main/java/org/apache/sling/feature/scanner/package-info.java b/src/main/java/org/apache/sling/feature/scanner/package-info.java
index 8fdbfc7..b534a4f 100644
--- a/src/main/java/org/apache/sling/feature/scanner/package-info.java
+++ b/src/main/java/org/apache/sling/feature/scanner/package-info.java
@@ -19,5 +19,3 @@
@org.osgi.annotation.versioning.Version("3.0.0")
package org.apache.sling.feature.scanner;
-
-
diff --git a/src/main/java/org/apache/sling/feature/scanner/spi/ExtensionScanner.java b/src/main/java/org/apache/sling/feature/scanner/spi/ExtensionScanner.java
index 35e7c5c..6b638c0 100644
--- a/src/main/java/org/apache/sling/feature/scanner/spi/ExtensionScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/spi/ExtensionScanner.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.spi;
@@ -28,7 +30,7 @@ import org.osgi.annotation.versioning.ConsumerType;
* The extension scanner scans an extension.
*/
@ConsumerType
-public interface ExtensionScanner {
+public interface ExtensionScanner {
/** A unique (short) ID.
* @return the ID.
@@ -49,8 +51,5 @@ public interface ExtensionScanner {
* @return The descriptor or {@code null} if the scanner does not know the extension
* @throws IOException If an error occurs while scanning the extension or the extension is invalid
*/
- ContainerDescriptor scan(
- Feature feature,
- Extension extension,
- ArtifactProvider provider) throws IOException;
-}
\ No newline at end of file
+ ContainerDescriptor scan(Feature feature, Extension extension, ArtifactProvider provider) throws IOException;
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/spi/FrameworkScanner.java b/src/main/java/org/apache/sling/feature/scanner/spi/FrameworkScanner.java
index fbdb5a5..e256645 100644
--- a/src/main/java/org/apache/sling/feature/scanner/spi/FrameworkScanner.java
+++ b/src/main/java/org/apache/sling/feature/scanner/spi/FrameworkScanner.java
@@ -1,34 +1,36 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.scanner.spi;
+import java.io.IOException;
+import java.util.Map;
+
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.builder.ArtifactProvider;
import org.apache.sling.feature.scanner.BundleDescriptor;
import org.osgi.annotation.versioning.ConsumerType;
-import java.io.IOException;
-import java.util.Map;
-
/**
* The framework scanner scans the framework
*/
@ConsumerType
-public interface FrameworkScanner {
+public interface FrameworkScanner {
/**
* Try to scan the artifact
@@ -38,7 +40,6 @@ public interface FrameworkScanner {
* @return A descriptor or {@code null}
* @throws IOException If an error occurs while scanning the platform or the artifact is invalid
*/
- BundleDescriptor scan(ArtifactId framework,
- Map<String,String> frameworkProps,
- ArtifactProvider provider) throws IOException;
-}
\ No newline at end of file
+ BundleDescriptor scan(ArtifactId framework, Map<String, String> frameworkProps, ArtifactProvider provider)
+ throws IOException;
+}
diff --git a/src/main/java/org/apache/sling/feature/scanner/spi/package-info.java b/src/main/java/org/apache/sling/feature/scanner/spi/package-info.java
index 3ecb9cb..c8c56df 100644
--- a/src/main/java/org/apache/sling/feature/scanner/spi/package-info.java
+++ b/src/main/java/org/apache/sling/feature/scanner/spi/package-info.java
@@ -19,5 +19,3 @@
@org.osgi.annotation.versioning.Version("1.0.0")
package org.apache.sling.feature.scanner.spi;
-
-
diff --git a/src/test/java/org/apache/sling/feature/analyser/AnalyserTest.java b/src/test/java/org/apache/sling/feature/analyser/AnalyserTest.java
index 9a7cad3..d1b8330 100644
--- a/src/test/java/org/apache/sling/feature/analyser/AnalyserTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/AnalyserTest.java
@@ -1,21 +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
+ * 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
+ * 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.
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Configuration;
@@ -25,11 +32,6 @@ import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
import org.apache.sling.feature.scanner.Scanner;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -37,12 +39,12 @@ import static org.junit.Assert.assertNull;
public class AnalyserTest {
@Test
public void testConfiguration() throws Exception {
- Map<String, Map<String,String>> cfgs = new HashMap<String, Map<String,String>>();
+ Map<String, Map<String, String>> cfgs = new HashMap<String, Map<String, String>>();
cfgs.put("all", Collections.singletonMap("aa", "bb"));
cfgs.put("an-analyser", Collections.singletonMap("cc", "dd"));
cfgs.put("another-analyser", Collections.singletonMap("ee", "ff"));
- Analyser a = new Analyser(null, cfgs, new String [] {});
+ Analyser a = new Analyser(null, cfgs, new String[] {});
Map<String, String> cfg = a.getConfiguration("an-analyser");
assertEquals(2, cfg.size());
@@ -52,22 +54,23 @@ public class AnalyserTest {
@Test
public void testConfiguration1() throws Exception {
- Map<String, Map<String,String>> cfgs = new HashMap<String, Map<String,String>>();
+ Map<String, Map<String, String>> cfgs = new HashMap<String, Map<String, String>>();
cfgs.put("another-analyser", Collections.singletonMap("ee", "ff"));
- Analyser a = new Analyser(null, cfgs, new AnalyserTask [] {});
+ Analyser a = new Analyser(null, cfgs, new AnalyserTask[] {});
Map<String, String> cfg = a.getConfiguration("an-analyser");
assertEquals(0, cfg.size());
}
- @Test public void testResult() throws Exception {
+ @Test
+ public void testResult() throws Exception {
final Feature f = new Feature(ArtifactId.parse("g:a:1"));
final Configuration c = new Configuration("config.pid");
final Artifact bundle = new Artifact(ArtifactId.parse("g:b:1"));
final Scanner scanner = new Scanner(null);
- final Analyser a = new Analyser(scanner, new AnalyserTask(){
+ final Analyser a = new Analyser(scanner, new AnalyserTask() {
public String getId() {
return "mytask";
@@ -82,22 +85,28 @@ public class AnalyserTest {
ctx.reportConfigurationError(c, "config-error");
ctx.reportConfigurationWarning(c, "config-warn");
ctx.reportError("global-error");
- ctx.reportWarning("global-warn");
- }
+ ctx.reportWarning("global-warn");
+ }
});
final AnalyserResult result = a.analyse(f);
assertNotNull(result);
assertEquals(4, result.getErrors().size());
- assertEquals(Arrays.asList("[mytask] global-error",
- "[mytask] " + bundle.getId().toString()+": artifact-error",
- "[mytask] name: extension-error",
- "[mytask] Configuration " + c.getPid() + ": config-error"), result.getErrors());
+ assertEquals(
+ Arrays.asList(
+ "[mytask] global-error",
+ "[mytask] " + bundle.getId().toString() + ": artifact-error",
+ "[mytask] name: extension-error",
+ "[mytask] Configuration " + c.getPid() + ": config-error"),
+ result.getErrors());
assertEquals(4, result.getWarnings().size());
- assertEquals(Arrays.asList("[mytask] global-warn",
- "[mytask] " + bundle.getId().toString()+": artifact-warn",
- "[mytask] name: extension-warn",
- "[mytask] Configuration " + c.getPid() + ": config-warn"), result.getWarnings());
+ assertEquals(
+ Arrays.asList(
+ "[mytask] global-warn",
+ "[mytask] " + bundle.getId().toString() + ": artifact-warn",
+ "[mytask] name: extension-warn",
+ "[mytask] Configuration " + c.getPid() + ": config-warn"),
+ result.getWarnings());
assertEquals(1, result.getGlobalErrors().size());
assertEquals("[mytask] global-error", result.getGlobalErrors().get(0).toString());
@@ -112,37 +121,49 @@ public class AnalyserTest {
assertNull(result.getGlobalWarnings().get(0).getKey());
assertEquals(1, result.getArtifactErrors().size());
- assertEquals("[mytask] " + bundle.getId().toString()+": artifact-error", result.getArtifactErrors().get(0).toString());
+ assertEquals(
+ "[mytask] " + bundle.getId().toString() + ": artifact-error",
+ result.getArtifactErrors().get(0).toString());
assertEquals("artifact-error", result.getArtifactErrors().get(0).getValue());
assertEquals("mytask", result.getArtifactErrors().get(0).getTaskId());
assertEquals(bundle.getId(), result.getArtifactErrors().get(0).getKey());
assertEquals(1, result.getArtifactWarnings().size());
- assertEquals("[mytask] " + bundle.getId().toString()+": artifact-warn", result.getArtifactWarnings().get(0).toString());
+ assertEquals(
+ "[mytask] " + bundle.getId().toString() + ": artifact-warn",
+ result.getArtifactWarnings().get(0).toString());
assertEquals("artifact-warn", result.getArtifactWarnings().get(0).getValue());
assertEquals("mytask", result.getArtifactWarnings().get(0).getTaskId());
assertEquals(bundle.getId(), result.getArtifactWarnings().get(0).getKey());
assertEquals(1, result.getExtensionErrors().size());
- assertEquals("[mytask] name: extension-error", result.getExtensionErrors().get(0).toString());
+ assertEquals(
+ "[mytask] name: extension-error",
+ result.getExtensionErrors().get(0).toString());
assertEquals("extension-error", result.getExtensionErrors().get(0).getValue());
assertEquals("mytask", result.getExtensionErrors().get(0).getTaskId());
assertEquals("name", result.getExtensionErrors().get(0).getKey());
assertEquals(1, result.getExtensionWarnings().size());
- assertEquals("[mytask] name: extension-warn", result.getExtensionWarnings().get(0).toString());
+ assertEquals(
+ "[mytask] name: extension-warn",
+ result.getExtensionWarnings().get(0).toString());
assertEquals("extension-warn", result.getExtensionWarnings().get(0).getValue());
assertEquals("mytask", result.getExtensionWarnings().get(0).getTaskId());
assertEquals("name", result.getExtensionWarnings().get(0).getKey());
assertEquals(1, result.getConfigurationErrors().size());
- assertEquals("[mytask] Configuration " + c.getPid() + ": config-error", result.getConfigurationErrors().get(0).toString());
+ assertEquals(
+ "[mytask] Configuration " + c.getPid() + ": config-error",
+ result.getConfigurationErrors().get(0).toString());
assertEquals("config-error", result.getConfigurationErrors().get(0).getValue());
assertEquals("mytask", result.getConfigurationErrors().get(0).getTaskId());
assertEquals(c, result.getConfigurationErrors().get(0).getKey());
assertEquals(1, result.getConfigurationWarnings().size());
- assertEquals("[mytask] Configuration " + c.getPid() + ": config-warn", result.getConfigurationWarnings().get(0).toString());
+ assertEquals(
+ "[mytask] Configuration " + c.getPid() + ": config-warn",
+ result.getConfigurationWarnings().get(0).toString());
assertEquals("config-warn", result.getConfigurationWarnings().get(0).getValue());
assertEquals("mytask", result.getConfigurationWarnings().get(0).getTaskId());
assertEquals(c, result.getConfigurationWarnings().get(0).getKey());
diff --git a/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtensionTest.java b/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtensionTest.java
index d417aa8..589c63e 100644
--- a/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtensionTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataExtensionTest.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.feature.analyser.extensions;
-import static org.assertj.core.api.Assertions.assertThat;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -39,12 +37,16 @@ import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
+import static org.assertj.core.api.Assertions.assertThat;
+
public class AnalyserMetaDataExtensionTest {
@Test
public void testAnalyserMetaDataExtension() throws Exception {
- Extension extension = new Extension(ExtensionType.JSON, AnalyserMetaDataExtension.EXTENSION_NAME, ExtensionState.REQUIRED);
+ Extension extension =
+ new Extension(ExtensionType.JSON, AnalyserMetaDataExtension.EXTENSION_NAME, ExtensionState.REQUIRED);
extension.setJSON("{}");
- AnalyserMetaDataExtension analyserMetaDataExtension = AnalyserMetaDataExtension.getAnalyserMetaDataExtension(extension);
+ AnalyserMetaDataExtension analyserMetaDataExtension =
+ AnalyserMetaDataExtension.getAnalyserMetaDataExtension(extension);
Assert.assertNotNull(analyserMetaDataExtension);
Manifest manifest = new Manifest();
@@ -58,40 +60,51 @@ public class AnalyserMetaDataExtensionTest {
analyserMetaDataExtension.toExtension(extension);
- Extension testExtension = new Extension(ExtensionType.JSON, AnalyserMetaDataExtension.EXTENSION_NAME, ExtensionState.REQUIRED);
+ Extension testExtension =
+ new Extension(ExtensionType.JSON, AnalyserMetaDataExtension.EXTENSION_NAME, ExtensionState.REQUIRED);
testExtension.setJSON(extension.getJSON());
Assert.assertTrue(AnalyserMetaDataExtension.isAnalyserMetaDataExtension(testExtension));
- AnalyserMetaDataExtension testAnalyserMetaDataExtension = AnalyserMetaDataExtension.getAnalyserMetaDataExtension(testExtension);
+ AnalyserMetaDataExtension testAnalyserMetaDataExtension =
+ AnalyserMetaDataExtension.getAnalyserMetaDataExtension(testExtension);
Assert.assertNotNull(testAnalyserMetaDataExtension.getManifest(artifact.getId()));
- Assert.assertEquals("bar", testAnalyserMetaDataExtension.getManifest(artifact.getId()).get("foo"));
+ Assert.assertEquals(
+ "bar",
+ testAnalyserMetaDataExtension.getManifest(artifact.getId()).get("foo"));
Assert.assertFalse(testAnalyserMetaDataExtension.reportError(artifact.getId()));
-
}
-
+
@Test
public void readSystemBundleInformation() throws IOException {
- InputStream featureStream = Objects.requireNonNull(getClass().getResourceAsStream("/analyse-metadata/feature-output-system-bundle.json"), "Unable to locate feature file");
+ InputStream featureStream = Objects.requireNonNull(
+ getClass().getResourceAsStream("/analyse-metadata/feature-output-system-bundle.json"),
+ "Unable to locate feature file");
Feature feature = FeatureJSONReader.read(new InputStreamReader(featureStream), null);
-
- Extension extension = Objects.requireNonNull(feature.getExtensions().getByName(AnalyserMetaDataExtension.EXTENSION_NAME), "Failed to load analyser-metadata extension");
- AnalyserMetaDataExtension analyserMetaDataExtension = AnalyserMetaDataExtension.getAnalyserMetaDataExtension(extension);
+ Extension extension = Objects.requireNonNull(
+ feature.getExtensions().getByName(AnalyserMetaDataExtension.EXTENSION_NAME),
+ "Failed to load analyser-metadata extension");
+
+ AnalyserMetaDataExtension analyserMetaDataExtension =
+ AnalyserMetaDataExtension.getAnalyserMetaDataExtension(extension);
assertThat(analyserMetaDataExtension).as("metadata extension").isNotNull();
-
+
SystemBundle systemBundle = analyserMetaDataExtension.getSystemBundle();
- assertThat(systemBundle).as("system bundle")
- .isNotNull()
- .extracting(SystemBundle::getArtifactId)
- .isEqualTo(ArtifactId.fromMvnId("org.apache.felix:org.apache.felix.framework:7.0.5"));
-
- assertThat(systemBundle.getScannerCacheKey()).as("system bundle scanner cache key")
- .isNotBlank();
-
- assertThat(systemBundle.getManifest()).as("system bundle manifest")
- .containsKeys("Export-Package", "Provide-Capability");
+ assertThat(systemBundle)
+ .as("system bundle")
+ .isNotNull()
+ .extracting(SystemBundle::getArtifactId)
+ .isEqualTo(ArtifactId.fromMvnId("org.apache.felix:org.apache.felix.framework:7.0.5"));
+
+ assertThat(systemBundle.getScannerCacheKey())
+ .as("system bundle scanner cache key")
+ .isNotBlank();
+
+ assertThat(systemBundle.getManifest())
+ .as("system bundle manifest")
+ .containsKeys("Export-Package", "Provide-Capability");
}
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandlerTest.java b/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandlerTest.java
index 846a620..1875629 100644
--- a/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/extensions/AnalyserMetaDataHandlerTest.java
@@ -1,24 +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
+ * 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
+ * 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.
+ * 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.extensions;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
-
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
@@ -31,6 +30,9 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
+import jakarta.json.JsonObject;
+import jakarta.json.JsonString;
+import jakarta.json.JsonValue;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Parser;
import org.apache.sling.feature.ArtifactId;
@@ -42,9 +44,8 @@ import org.apache.sling.feature.io.json.FeatureJSONWriter;
import org.junit.Test;
import org.mockito.Mockito;
-import jakarta.json.JsonObject;
-import jakarta.json.JsonString;
-import jakarta.json.JsonValue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.InstanceOfAssertFactories.MAP;
public class AnalyserMetaDataHandlerTest {
@@ -68,83 +69,99 @@ public class AnalyserMetaDataHandlerTest {
assertThat(expectedWriter.toString()).isEqualTo(featureWriter.toString());
}
-
+
@Test
public void testMetadataHandlerSystemBundle() throws IOException {
Feature feature = postProcessFeature("/analyse-metadata/feature-input-system-bundle.json");
-
- JsonObject metadata = feature.getExtensions().getByName("analyser-metadata").getJSONStructure().asJsonObject();
+
+ JsonObject metadata = feature.getExtensions()
+ .getByName("analyser-metadata")
+ .getJSONStructure()
+ .asJsonObject();
assertThat(metadata).as("analyser-metadata extension").isNotNull();
-
+
JsonValue systemBundle = metadata.get("extra-metadata:system.bundle:0");
- assertThat(systemBundle).as("system.bundle property of the metadata extension").isNotNull();
-
+ assertThat(systemBundle)
+ .as("system.bundle property of the metadata extension")
+ .isNotNull();
+
// ensure the artifactId is recorded and correctly formed
JsonValue artifactId = systemBundle.asJsonObject().get("artifactId");
assertThat(artifactId).as("artifactId of the system bundle").isNotNull();
ArtifactId.fromMvnId(artifactId.toString());
-
+
JsonValue manifest = systemBundle.asJsonObject().get("manifest");
assertThat(manifest).as("manifest of the system bundle").isNotNull();
JsonString systemBundleCapabilities = manifest.asJsonObject().getJsonString("Provide-Capability");
- assertThat(systemBundleCapabilities).as("capabilities for the system bundle").isNotNull();
+ assertThat(systemBundleCapabilities)
+ .as("capabilities for the system bundle")
+ .isNotNull();
String capabilities = systemBundleCapabilities.getString();
-
+
// validate that the capabilities header is correctly formed
Clause[] clauses = Parser.parseHeader(capabilities);
-
- // validate that we have exactly one osgi.ee clause with the value "JavaSE"
+
+ // validate that we have exactly one osgi.ee clause with the value "JavaSE"
List<Clause> javaSeEeClauses = Arrays.stream(clauses)
- .filter( c -> c.getName().equals("osgi.ee") )
- .filter( c -> c.getAttribute("osgi.ee").equals("JavaSE") )
- .collect(Collectors.toList());
-
- assertThat(javaSeEeClauses).as("osgi.ee=JavaSE capabilities")
- .hasSize(1)
- .element(0).extracting( c -> c.getAttribute("version:List<Version>") )
- .asString().contains("1.8");
-
+ .filter(c -> c.getName().equals("osgi.ee"))
+ .filter(c -> c.getAttribute("osgi.ee").equals("JavaSE"))
+ .collect(Collectors.toList());
+
+ assertThat(javaSeEeClauses)
+ .as("osgi.ee=JavaSE capabilities")
+ .hasSize(1)
+ .element(0)
+ .extracting(c -> c.getAttribute("version:List<Version>"))
+ .asString()
+ .contains("1.8");
+
JsonString systemBundleExports = manifest.asJsonObject().getJsonString("Export-Package");
assertThat(systemBundleExports).as("exports for the system bundle").isNotNull();
String exports = systemBundleExports.getString();
-
+
// validate that the exports header is correctly formed
Clause[] exportClauses = Parser.parseHeader(exports);
List<Clause> javaUtilExports = Arrays.stream(exportClauses)
- .filter( c -> c.getName().equals("java.util") )
- .collect(Collectors.toList());
+ .filter(c -> c.getName().equals("java.util"))
+ .collect(Collectors.toList());
// validate that the java.util.function export is present
- assertThat(javaUtilExports).as("java.util package exports")
- .hasSize(1)
- .element(0).extracting( c -> c.getAttribute("version") )
- .isNotNull();
+ assertThat(javaUtilExports)
+ .as("java.util package exports")
+ .hasSize(1)
+ .element(0)
+ .extracting(c -> c.getAttribute("version"))
+ .isNotNull();
}
-
+
@Test
public void testMetadataHandlerSystemBundleAlreadyProcessed() throws IOException {
-
+
// the minimal feature used in this test would not be processed successfully, as it does not
// have an execution-environment extension . This test guarantees that processing is skipped and the
// information preserved
Feature feature = postProcessFeature("/analyse-metadata/feature-output-system-bundle.json");
-
- JsonObject metadata = feature.getExtensions().getByName("analyser-metadata").getJSONStructure().asJsonObject();
+
+ JsonObject metadata = feature.getExtensions()
+ .getByName("analyser-metadata")
+ .getJSONStructure()
+ .asJsonObject();
assertThat(metadata).as("analyser-metadata extension").isNotNull();
-
+
JsonValue systemBundle = metadata.get("extra-metadata:system.bundle:0");
- assertThat(systemBundle).as("system.bundle property of the metadata extension")
- .isNotNull()
- .extracting(JsonValue::asJsonObject)
- .asInstanceOf(MAP)
- .containsKeys("manifest", "artifactId", "scannerCacheKey");
+ assertThat(systemBundle)
+ .as("system.bundle property of the metadata extension")
+ .isNotNull()
+ .extracting(JsonValue::asJsonObject)
+ .asInstanceOf(MAP)
+ .containsKeys("manifest", "artifactId", "scannerCacheKey");
}
-
+
private Feature postProcessFeature(String featureLocation) throws IOException {
URL url = getClass().getResource(featureLocation);
-
+
Objects.requireNonNull(url, "Failed to load feature file from " + featureLocation);
Feature feature;
@@ -165,9 +182,9 @@ public class AnalyserMetaDataHandlerTest {
Mockito.when(ctx.getArtifactProvider()).thenReturn(provider);
- new AnalyserMetaDataHandler().postProcess(ctx, feature, feature.getExtensions().getByName("analyser-metadata"));
-
+ new AnalyserMetaDataHandler()
+ .postProcess(ctx, feature, feature.getExtensions().getByName("analyser-metadata"));
+
return feature;
}
-
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskContextImpl.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskContextImpl.java
index 3a5d343..dfa75e7 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskContextImpl.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskContextImpl.java
@@ -82,13 +82,10 @@ public class AnalyserTaskContextImpl implements AnalyserTaskContext {
}
@Override
- public void reportWarning(String message) {
- }
+ public void reportWarning(String message) {}
@Override
- public void reportArtifactWarning(ArtifactId artifactId, String message) {
-
- }
+ public void reportArtifactWarning(ArtifactId artifactId, String message) {}
@Override
public void reportArtifactError(ArtifactId artifactId, String message) {
@@ -96,9 +93,7 @@ public class AnalyserTaskContextImpl implements AnalyserTaskContext {
}
@Override
- public void reportExtensionWarning(String extension, String message) {
-
- }
+ public void reportExtensionWarning(String extension, String message) {}
@Override
public void reportExtensionError(String extension, String message) {
@@ -120,7 +115,5 @@ public class AnalyserTaskContextImpl implements AnalyserTaskContext {
}
@Override
- public void reportConfigurationWarning(Configuration cfg, String message) {
-
- }
-}
\ No newline at end of file
+ public void reportConfigurationWarning(Configuration cfg, String message) {}
+}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskProviderTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskProviderTest.java
index ded11e6..63c3b44 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskProviderTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/AnalyserTaskProviderTest.java
@@ -18,11 +18,6 @@
*/
package org.apache.sling.feature.analyser.task.impl;
-import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasks;
-import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByClassName;
-import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByIds;
-import static org.junit.Assert.assertEquals;
-
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
@@ -31,6 +26,11 @@ import java.util.ServiceLoader;
import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.junit.Test;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasks;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByClassName;
+import static org.apache.sling.feature.analyser.task.AnalyzerTaskProvider.getTasksByIds;
+import static org.junit.Assert.assertEquals;
+
public final class AnalyserTaskProviderTest {
private static int allTasks() {
@@ -55,18 +55,18 @@ public final class AnalyserTaskProviderTest {
@Test(expected = IOException.class)
public void failOnLoadingFromNull() throws Exception {
- getTasksByClassName((String[])null);
+ getTasksByClassName((String[]) null);
}
@Test
public void doesNotincludeAnything() throws Exception {
int expected = 0;
- int actual = getTasksByIds(Collections.singleton("bundle-packages"),
- Collections.singleton("bundle-packages")).length;
+ int actual = getTasksByIds(Collections.singleton("bundle-packages"), Collections.singleton("bundle-packages"))
+ .length;
assertEquals(expected, actual);
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected = IllegalStateException.class)
public void testFailOnAnalyzerNotFound() throws Exception {
getTasksByIds(Collections.singleton("not-found"), null);
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsPropertiesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsPropertiesTest.java
index 23d3dad..5e6fcb2 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsPropertiesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckApisJarsPropertiesTest.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.feature.analyser.task.impl;
-import static org.junit.Assert.assertEquals;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -35,6 +33,8 @@ import org.apache.sling.feature.scanner.BundleDescriptor;
import org.apache.sling.feature.scanner.FeatureDescriptor;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
public class CheckApisJarsPropertiesTest {
private static class SpyAnalyserTaskContext implements AnalyserTaskContext {
@@ -101,7 +101,7 @@ public class CheckApisJarsPropertiesTest {
public Map<String, String> getConfiguration() {
return Collections.emptyMap();
}
-
+
@Override
public FeatureProvider getFeatureProvider() {
return null;
@@ -110,7 +110,7 @@ public class CheckApisJarsPropertiesTest {
public List<String> getErrors() {
return errors;
}
-
+
public List<String> getWarnings() {
return warnings;
}
@@ -127,42 +127,43 @@ public class CheckApisJarsPropertiesTest {
warnings.add(message);
}
}
-
+
static class FeatureStub extends Feature {
public FeatureStub() {
- super(ArtifactId.fromMvnId("org.apache.sling:org.apache.sling.feature.analyser.test:slingosgifeature:validSourceIds:1.0"));
-
+ super(ArtifactId.fromMvnId(
+ "org.apache.sling:org.apache.sling.feature.analyser.test:slingosgifeature:validSourceIds:1.0"));
+
setComplete(true);
}
-
+
public void addArtifactWithSourceId(String artifactId, String sourceId) {
Artifact artifact = new Artifact(ArtifactId.parse(artifactId));
- if ( sourceId != null )
- artifact.getMetadata().put("source-ids", sourceId);
-
+ if (sourceId != null) artifact.getMetadata().put("source-ids", sourceId);
+
getBundles().add(artifact);
}
-
+
public void addArtifact(String artifactId) {
addArtifactWithSourceId(artifactId, null);
}
-
}
@Test
public void validSourceIds() throws Exception {
CheckApisJarsProperties check = new CheckApisJarsProperties();
-
+
FeatureStub f = new FeatureStub();
// 1 entry with CSV sourceId
- f.addArtifactWithSourceId("org.apache.aries.transaction:org.apache.aries.transaction.manager:1.2.0",
+ f.addArtifactWithSourceId(
+ "org.apache.aries.transaction:org.apache.aries.transaction.manager:1.2.0",
"org.apache.aries.transaction:org.apache.aries.transaction.manager:jar:sources:1.2.0,javax.transaction:javax.transaction-api:jar:sources:1.2,org.apache.geronimo.components:geronimo-transaction:jar:sources:3.1.2");
// 1 entry with simple sourceId
- f.addArtifactWithSourceId("org.apache.sling:org.apache.sling.scripting.jsp-api:1.0.0",
+ f.addArtifactWithSourceId(
+ "org.apache.sling:org.apache.sling.scripting.jsp-api:1.0.0",
"org.apache.tomcat:tomcat-jsp-api:jar:sources:7.0.96");
-
+
// 1 entry with no sourceId
f.addArtifact("org.apache.sling:org.apache.sling.engine:2.6.20");
@@ -171,19 +172,18 @@ public class CheckApisJarsPropertiesTest {
assertEquals("errors.size", 0, context.getErrors().size());
assertEquals("warnings.size", 0, context.getWarnings().size());
}
-
+
@Test
public void invalidSourceId() throws Exception {
CheckApisJarsProperties check = new CheckApisJarsProperties();
-
+
FeatureStub f = new FeatureStub();
// 1 entry with invalid sourceId
- f.addArtifactWithSourceId("org.apache.sling:org.apache.sling.scripting.jsp-api:1.0.0",
- "invalid-source-id");
+ f.addArtifactWithSourceId("org.apache.sling:org.apache.sling.scripting.jsp-api:1.0.0", "invalid-source-id");
SpyAnalyserTaskContext context = new SpyAnalyserTaskContext(f);
check.execute(context);
assertEquals("errors.size", 1, context.getErrors().size());
- assertEquals("warnings.size", 0, context.getWarnings().size());
+ assertEquals("warnings.size", 0, context.getWarnings().size());
}
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImportsTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImportsTest.java
index dc16885..7a068d5 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImportsTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleExportsImportsTest.java
@@ -18,8 +18,6 @@
*/
package org.apache.sling.feature.analyser.task.impl;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.io.IOException;
import java.util.Collections;
@@ -39,20 +37,22 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
+import static org.junit.Assert.assertEquals;
+
public class CheckBundleExportsImportsTest {
private static File resourceRoot;
@BeforeClass
public static void setupClass() {
- resourceRoot =
- new File(CheckBundleExportsImportsTest.class.
- getResource("/test-content.zip").getFile()).getParentFile();
+ resourceRoot = new File(CheckBundleExportsImportsTest.class
+ .getResource("/test-content.zip")
+ .getFile())
+ .getParentFile();
}
@Test
public void testId() {
- assertEquals("bundle-packages",
- new CheckBundleExportsImports().getId());
+ assertEquals("bundle-packages", new CheckBundleExportsImports().getId());
}
@Test
@@ -148,9 +148,9 @@ public class CheckBundleExportsImportsTest {
AnalyserTaskContext ctx = Mockito.mock(AnalyserTaskContext.class);
Mockito.when(ctx.getFeature()).thenReturn(f);
Mockito.when(ctx.getFeatureDescriptor()).thenReturn(fd);
- Mockito.when(ctx.getConfiguration()).thenReturn(
- Collections.singletonMap("fileStorage",
- resourceRoot + "/origins/testImportFromOtherBundleInSameFeature"));
+ Mockito.when(ctx.getConfiguration())
+ .thenReturn(Collections.singletonMap(
+ "fileStorage", resourceRoot + "/origins/testImportFromOtherBundleInSameFeature"));
t.execute(ctx);
Mockito.verify(ctx, Mockito.never()).reportError(Mockito.anyString());
@@ -159,7 +159,8 @@ public class CheckBundleExportsImportsTest {
private void fdAddBundle(FeatureDescriptor fd, String id, String file) throws IOException {
BundleDescriptor bd1 = new BundleDescriptorImpl(
- new Artifact(ArtifactId.fromMvnId(id)), new File(resourceRoot, file).toURI().toURL());
+ new Artifact(ArtifactId.fromMvnId(id)),
+ new File(resourceRoot, file).toURI().toURL());
fd.getBundleDescriptors().add(bd1);
}
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCodeTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCodeTest.java
index d8a48d4..b07d4c6 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCodeTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleNativeCodeTest.java
@@ -78,7 +78,7 @@ public class CheckBundleNativeCodeTest {
final Artifact a = new Artifact(aId);
Mockito.when(bd.getArtifact()).thenReturn(a);
final Manifest mf = new Manifest();
- if ( header != null ) {
+ if (header != null) {
mf.getMainAttributes().putValue(Constants.BUNDLE_NATIVECODE, header);
}
Mockito.when(bd.getManifest()).thenReturn(mf);
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackagesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackagesTest.java
index 0757b6c..a0d63dd 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackagesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckBundleUnversionedPackagesTest.java
@@ -18,6 +18,10 @@
*/
package org.apache.sling.feature.analyser.task.impl;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Feature;
@@ -30,10 +34,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
-
import static org.junit.Assert.assertEquals;
public class CheckBundleUnversionedPackagesTest {
@@ -41,9 +41,10 @@ public class CheckBundleUnversionedPackagesTest {
@BeforeClass
public static void setupClass() {
- resourceRoot =
- new File(CheckBundleExportsImportsTest.class.
- getResource("/test-content.zip").getFile()).getParentFile();
+ resourceRoot = new File(CheckBundleExportsImportsTest.class
+ .getResource("/test-content.zip")
+ .getFile())
+ .getParentFile();
}
@Test
@@ -68,16 +69,14 @@ public class CheckBundleUnversionedPackagesTest {
Mockito.verify(ctx, Mockito.times(2)).reportArtifactWarning(Mockito.any(), Mockito.anyString());
- Mockito.verify(ctx).reportArtifactWarning(
- Mockito.eq(ArtifactId.fromMvnId("g:b1:1")),
- Mockito.contains("org.foo.i"));
- Mockito.verify(ctx).reportArtifactWarning(
- Mockito.eq(ArtifactId.fromMvnId("g:b1:1")),
- Mockito.contains("org.foo.e"));
+ Mockito.verify(ctx)
+ .reportArtifactWarning(Mockito.eq(ArtifactId.fromMvnId("g:b1:1")), Mockito.contains("org.foo.i"));
+ Mockito.verify(ctx)
+ .reportArtifactWarning(Mockito.eq(ArtifactId.fromMvnId("g:b1:1")), Mockito.contains("org.foo.e"));
}
-
- private void fdAddBundle(FeatureDescriptor fd, String id, String file, ArtifactId... origins) throws URISyntaxException, IOException {
+ private void fdAddBundle(FeatureDescriptor fd, String id, String file, ArtifactId... origins)
+ throws URISyntaxException, IOException {
Artifact artifact = new Artifact(ArtifactId.fromMvnId(id));
artifact.setFeatureOrigins(origins);
BundleDescriptor bd1 = new BundleDescriptorImpl(
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeaturesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeaturesTest.java
index 825fd30..f73bbbb 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeaturesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeaturesTest.java
@@ -1,21 +1,27 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.AbstractMap;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Artifacts;
@@ -28,10 +34,6 @@ import org.apache.sling.feature.builder.FeatureProvider;
import org.junit.Test;
import org.mockito.Mockito;
-import java.util.AbstractMap;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -210,13 +212,13 @@ public class CheckCompareFeaturesTest {
fc.getBundles().add(art2);
@SuppressWarnings("unchecked")
- AnalyserTaskContext ctx = testExecute("DIFFERENT", f, fc, null,
- new AbstractMap.SimpleEntry<>("compare-metadata", "false"));
+ AnalyserTaskContext ctx =
+ testExecute("DIFFERENT", f, fc, null, new AbstractMap.SimpleEntry<>("compare-metadata", "false"));
Mockito.verify(ctx).reportError(Mockito.anyString());
@SuppressWarnings("unchecked")
- AnalyserTaskContext ctx2 = testExecute("DIFFERENT", f, fc, null,
- new AbstractMap.SimpleEntry<>("compare-metadata", "true"));
+ AnalyserTaskContext ctx2 =
+ testExecute("DIFFERENT", f, fc, null, new AbstractMap.SimpleEntry<>("compare-metadata", "true"));
Mockito.verify(ctx2, Mockito.never()).reportError(Mockito.anyString());
}
@@ -237,8 +239,13 @@ public class CheckCompareFeaturesTest {
return testExecute(mode, f, fc, extension, new Map.Entry[0]);
}
- private AnalyserTaskContext testExecute(String mode, Feature f, Feature fc, String extension,
- @SuppressWarnings("unchecked") Map.Entry<String, String> ... cfgEntries) throws Exception {
+ private AnalyserTaskContext testExecute(
+ String mode,
+ Feature f,
+ Feature fc,
+ String extension,
+ @SuppressWarnings("unchecked") Map.Entry<String, String>... cfgEntries)
+ throws Exception {
Map<String, String> cfg = new HashMap<>();
cfg.put("compare-with", f.getId().toMvnId());
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurationsTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurationsTest.java
index ab903af..7ca0cd4 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurationsTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckConfigurationsTest.java
@@ -1,32 +1,34 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.junit.Before;
import org.junit.Test;
import org.osgi.framework.Constants;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class CheckConfigurationsTest {
-
+
private AnalyserTaskContextImpl ctx;
private AnalyserTask task;
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependenciesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependenciesTest.java
index a5289f0..20f5b30 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependenciesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesDependenciesTest.java
@@ -1,29 +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
+ * 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
+ * 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.
+ * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -40,6 +34,14 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class CheckContentPackagesDependenciesTest {
private AnalyserTask task;
@@ -62,26 +64,22 @@ public class CheckContentPackagesDependenciesTest {
Iterator<String> errorsIterator = errors.iterator();
assertEquals("Missing my_packages:test_b dependency for my_packages:test_a:1.0", errorsIterator.next());
- assertEquals("Missing my_packages:test_c:[1.0,2.0) dependency for my_packages:test_a:1.0", errorsIterator.next());
+ assertEquals(
+ "Missing my_packages:test_c:[1.0,2.0) dependency for my_packages:test_a:1.0", errorsIterator.next());
}
@Test
public void dependenciesResolved() throws Exception {
- List<String> errors = execute("test_a-1.0.zip",
- "test_b-1.0.zip",
- "test_c-1.0.zip",
- "test_d-1.0.zip",
- "test_e-1.0.zip");
+ List<String> errors =
+ execute("test_a-1.0.zip", "test_b-1.0.zip", "test_c-1.0.zip", "test_d-1.0.zip", "test_e-1.0.zip");
assertTrue(errors.isEmpty());
}
- private List<String> execute(String...resources) throws Exception {
+ private List<String> execute(String... resources) throws Exception {
Feature feature = mock(Feature.class);
- when(feature.getId()).thenReturn(new ArtifactId("org.apache.sling.testing",
- "org.apache.sling.testing.contentpackages",
- "1.0.0",
- null,
- null));
+ when(feature.getId())
+ .thenReturn(new ArtifactId(
+ "org.apache.sling.testing", "org.apache.sling.testing.contentpackages", "1.0.0", null, null));
FeatureDescriptor featureDescriptor = new FeatureDescriptorImpl(feature);
for (String resource : resources) {
@@ -91,7 +89,8 @@ public class CheckContentPackagesDependenciesTest {
ContentPackageDescriptor descriptor = mock(ContentPackageDescriptor.class);
when(descriptor.getArtifact()).thenReturn(artifact);
- when(descriptor.getArtifactFile()).thenReturn(getClass().getClassLoader().getResource(resource));
+ when(descriptor.getArtifactFile())
+ .thenReturn(getClass().getClassLoader().getResource(resource));
featureDescriptor.getArtifactDescriptors().add(descriptor);
}
@@ -103,14 +102,15 @@ public class CheckContentPackagesDependenciesTest {
List<String> errors = new LinkedList<>();
doAnswer(invocation -> {
- String error = invocation.getArgument(0);
- errors.add(error);
- return null;
- }).when(ctx).reportError(anyString());
+ String error = invocation.getArgument(0);
+ errors.add(error);
+ return null;
+ })
+ .when(ctx)
+ .reportError(anyString());
task.execute(ctx);
return errors;
}
-
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForInstallablesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForInstallablesTest.java
index a0c2b16..3fd3371 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForInstallablesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForInstallablesTest.java
@@ -1,24 +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
+ * 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
+ * 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.
+ * 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 static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.net.URL;
import java.util.Properties;
@@ -29,9 +28,13 @@ import org.apache.sling.feature.scanner.impl.ContentPackageDescriptorImpl;
import org.apache.sling.feature.scanner.impl.FeatureDescriptorImpl;
import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class CheckContentPackagesForInstallablesTest {
- @Test public void testEmptyDescriptor() throws Exception {
+ @Test
+ public void testEmptyDescriptor() throws Exception {
final CheckContentPackageForInstallables analyser = new CheckContentPackageForInstallables();
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
@@ -42,15 +45,23 @@ public class CheckContentPackagesForInstallablesTest {
assertTrue(ctx.getErrors().isEmpty());
}
- @Test public void testEmptyContentPackage() throws Exception {
+ @Test
+ public void testEmptyContentPackage() throws Exception {
final CheckContentPackageForInstallables analyser = new CheckContentPackageForInstallables();
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final FeatureDescriptor fd = new FeatureDescriptorImpl(ctx.getFeature());
ctx.setFeatureDescriptor(fd);
- final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl("content", new Artifact(ArtifactId.parse("g:c:1")), new URL("file:/foo"),
- null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl(
+ "content",
+ new Artifact(ArtifactId.parse("g:c:1")),
+ new URL("file:/foo"),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
fd.getArtifactDescriptors().add(cpd);
analyser.execute(ctx);
@@ -61,19 +72,34 @@ public class CheckContentPackagesForInstallablesTest {
assertTrue(ctx.getErrors().toString(), ctx.getErrors().isEmpty());
}
- @Test public void testEmbeddedContentPackage() throws Exception {
+ @Test
+ public void testEmbeddedContentPackage() throws Exception {
final CheckContentPackageForInstallables analyser = new CheckContentPackageForInstallables();
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final FeatureDescriptor fd = new FeatureDescriptorImpl(ctx.getFeature());
ctx.setFeatureDescriptor(fd);
- final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl("content", new Artifact(ArtifactId.parse("g:c:1")), new URL("file:/foo"),
- null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl(
+ "content",
+ new Artifact(ArtifactId.parse("g:c:1")),
+ new URL("file:/foo"),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
fd.getArtifactDescriptors().add(cpd);
- final ContentPackageDescriptorImpl embedded = new ContentPackageDescriptorImpl("embedded", new Artifact(ArtifactId.parse("g:e:1")),
- new URL("file:/foo"), null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl embedded = new ContentPackageDescriptorImpl(
+ "embedded",
+ new Artifact(ArtifactId.parse("g:e:1")),
+ new URL("file:/foo"),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
embedded.setParentContentPackageInfo(cpd, "/path");
fd.getArtifactDescriptors().add(embedded);
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPathsTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPathsTest.java
index 2866566..fee32c9 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPathsTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesForPathsTest.java
@@ -1,24 +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
+ * 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
+ * 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.
+ * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
@@ -29,17 +28,28 @@ import org.apache.sling.feature.analyser.task.impl.CheckContentPackagesForPaths.
import org.apache.sling.feature.scanner.impl.ContentPackageDescriptorImpl;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class CheckContentPackagesForPathsTest {
- @Test public void testPathsCheck() throws IOException {
+ @Test
+ public void testPathsCheck() throws IOException {
final CheckContentPackagesForPaths analyser = new CheckContentPackagesForPaths();
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
ctx.getConfiguration().put("excludes", "/a");
ctx.getConfiguration().put("includes", "/ab,/b");
final Rules r = new Rules(ctx);
- final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl("name", new Artifact(ArtifactId.parse("g:a:1")),
- new URL("https://sling.apache.org"), null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(
+ "name",
+ new Artifact(ArtifactId.parse("g:a:1")),
+ new URL("https://sling.apache.org"),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
desc.getContentPaths().add("/b/foo");
desc.getContentPaths().add("/a");
desc.getContentPaths().add("/a/foo");
@@ -55,15 +65,23 @@ public class CheckContentPackagesForPathsTest {
assertTrue(ctx.getErrors().get(2), ctx.getErrors().get(2).endsWith(" /c"));
}
- @Test public void testPathsCheckLongestMatching() throws IOException {
+ @Test
+ public void testPathsCheckLongestMatching() throws IOException {
final CheckContentPackagesForPaths analyser = new CheckContentPackagesForPaths();
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
ctx.getConfiguration().put("excludes", "/a");
ctx.getConfiguration().put("includes", "/a/foo");
final Rules r = new Rules(ctx);
- final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl("name", new Artifact(ArtifactId.parse("g:a:1")),
- new URL("https://sling.apache.org"), null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl desc = new ContentPackageDescriptorImpl(
+ "name",
+ new Artifact(ArtifactId.parse("g:a:1")),
+ new URL("https://sling.apache.org"),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
desc.getContentPaths().add("/a/foo");
desc.getContentPaths().add("/a/bar");
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesTest.java
index 8df0c50..ca4eb66 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckContentPackagesTest.java
@@ -1,24 +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
+ * 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
+ * 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.
+ * 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 static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-
import java.io.File;
import java.util.List;
import java.util.Properties;
@@ -30,8 +29,11 @@ import org.apache.sling.feature.scanner.impl.ContentPackageDescriptorImpl;
import org.apache.sling.feature.scanner.impl.FeatureDescriptorImpl;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
public class CheckContentPackagesTest {
-
+
private final CheckContentPackages analyser;
private final AnalyserTaskContextImpl ctx;
private final FeatureDescriptor fd;
@@ -42,13 +44,23 @@ public class CheckContentPackagesTest {
fd = new FeatureDescriptorImpl(ctx.getFeature());
ctx.setFeatureDescriptor(fd);
}
-
- @Test
+
+ @Test
public void testContentPackageWithInvalidXMLOnLowReportLevelShouldNotBeReported() throws Exception {
ctx.getConfiguration().put(CheckContentPackages.MAX_REPORT_LEVEL, "WARN");
- final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl("content", new Artifact(ArtifactId.parse("g:c:1")),
- getClass().getClassLoader().getResource("test-invalid-xml.zip").toURI().toURL(),
- null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl(
+ "content",
+ new Artifact(ArtifactId.parse("g:c:1")),
+ getClass()
+ .getClassLoader()
+ .getResource("test-invalid-xml.zip")
+ .toURI()
+ .toURL(),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
fd.getArtifactDescriptors().add(cpd);
analyser.execute(ctx);
@@ -56,32 +68,46 @@ public class CheckContentPackagesTest {
assertThat(errors.size(), equalTo(0));
}
- @Test
+ @Test
public void testContentPackageWithInvalidXMLShouldBeReported() throws Exception {
ctx.getConfiguration().put(CheckContentPackages.ENABLED_VALIDATORS, "jackrabbit-docviewparser");
ctx.getConfiguration().put(CheckContentPackages.MAX_REPORT_LEVEL, "ERROR");
- final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl("content", new Artifact(ArtifactId.parse("g:c:1")),
- getClass().getClassLoader().getResource("test-invalid-xml.zip").toURI().toURL(),
- null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl(
+ "content",
+ new Artifact(ArtifactId.parse("g:c:1")),
+ getClass()
+ .getClassLoader()
+ .getResource("test-invalid-xml.zip")
+ .toURI()
+ .toURL(),
+ null,
+ null,
+ null,
+ null,
+ new Properties());
fd.getArtifactDescriptors().add(cpd);
analyser.execute(ctx);
List<String> errors = ctx.getErrors();
assertThat(errors.size(), equalTo(1));
- assertThat(errors.get(0), equalTo(String.format("ValidationViolation: \"jackrabbit-docviewparser: Invalid XML found: The reference to entity \"se\" must end with the ';' delimiter.\", filePath=%s, nodePath=/apps/cschneidervalidation/configs/com.adobe.test.Invalid", "jcr_root/apps/cschneidervalidation/configs/com.adobe.test.Invalid.xml".replace('/', File.separatorChar))));
+ assertThat(
+ errors.get(0),
+ equalTo(String.format(
+ "ValidationViolation: \"jackrabbit-docviewparser: Invalid XML found: The reference to entity \"se\" must end with the ';' delimiter.\", filePath=%s, nodePath=/apps/cschneidervalidation/configs/com.adobe.test.Invalid",
+ "jcr_root/apps/cschneidervalidation/configs/com.adobe.test.Invalid.xml"
+ .replace('/', File.separatorChar))));
}
-
+
@Test
public void testInfo() throws Exception {
assertThat(analyser.getId(), equalTo("content-packages-validation"));
assertThat(analyser.getName(), equalTo("Content Package validation"));
}
-
+
@Test
public void testNoContentPackageURLIsReported() throws Exception {
- final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl("content", new Artifact(ArtifactId.parse("g:c:1")),
- null,
- null, null, null, null, new Properties());
+ final ContentPackageDescriptorImpl cpd = new ContentPackageDescriptorImpl(
+ "content", new Artifact(ArtifactId.parse("g:c:1")), null, null, null, null, null, new Properties());
fd.getArtifactDescriptors().add(cpd);
analyser.execute(ctx);
List<String> errors = ctx.getErrors();
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicNameTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicNameTest.java
index 9ffe513..138338a 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicNameTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckDuplicateSymbolicNameTest.java
@@ -18,13 +18,6 @@
*/
package org.apache.sling.feature.analyser.task.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
import java.util.LinkedList;
import java.util.List;
@@ -39,14 +32,21 @@ import org.apache.sling.feature.scanner.impl.FeatureDescriptorImpl;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
-public class CheckDuplicateSymbolicNameTest {
+public class CheckDuplicateSymbolicNameTest {
private List<String> errors = new LinkedList<>();
private AnalyserTaskContext ctx;
- @Before public void setup() {
+ @Before
+ public void setup() {
ctx = mock(AnalyserTaskContext.class);
final Feature feature = new Feature(ArtifactId.parse("g:a:1"));
@@ -55,10 +55,12 @@ public class CheckDuplicateSymbolicNameTest {
when(ctx.getFeatureDescriptor()).thenReturn(featureDescriptor);
doAnswer(invocation -> {
- String error = invocation.getArgument(0);
- errors.add(error);
- return null;
- }).when(ctx).reportError(anyString());
+ String error = invocation.getArgument(0);
+ errors.add(error);
+ return null;
+ })
+ .when(ctx)
+ .reportError(anyString());
}
private BundleDescriptor newDescriptor(final ArtifactId id, final String symbolicName) {
@@ -69,7 +71,8 @@ public class CheckDuplicateSymbolicNameTest {
return desc;
}
- @Test public void testNoDuplicates() throws Exception {
+ @Test
+ public void testNoDuplicates() throws Exception {
final AnalyserTask task = new CheckDuplicateSymbolicName();
ctx.getFeatureDescriptor().getBundleDescriptors().add(newDescriptor(ArtifactId.parse("g:b1:1"), "b1"));
@@ -79,7 +82,8 @@ public class CheckDuplicateSymbolicNameTest {
assertTrue(errors.isEmpty());
}
- @Test public void testDuplicates() throws Exception {
+ @Test
+ public void testDuplicates() throws Exception {
final AnalyserTask task = new CheckDuplicateSymbolicName();
ctx.getFeatureDescriptor().getBundleDescriptors().add(newDescriptor(ArtifactId.parse("g:b1:1"), "b1"));
@@ -90,5 +94,4 @@ public class CheckDuplicateSymbolicNameTest {
task.execute(ctx);
assertEquals(2, errors.size());
}
-
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureIdTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureIdTest.java
index 38a946c..cb33b4d 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureIdTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckFeatureIdTest.java
@@ -18,15 +18,15 @@
*/
package org.apache.sling.feature.analyser.task.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.junit.Before;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class CheckFeatureIdTest {
private AnalyserTaskContextImpl ctx;
@@ -51,41 +51,73 @@ public class CheckFeatureIdTest {
@Test
public void testValidFeatureId() throws Exception {
- ctx.getConfiguration().put(CheckFeatureId.CONFIG_KEY_ACCEPTED_FEATURE_IDS, "myGroupId:*:jar:myFirstClassifier:1.0.0,myGroupId:*:jar:myClassifier:1.0.0");
+ ctx.getConfiguration()
+ .put(
+ CheckFeatureId.CONFIG_KEY_ACCEPTED_FEATURE_IDS,
+ "myGroupId:*:jar:myFirstClassifier:1.0.0,myGroupId:*:jar:myClassifier:1.0.0");
task.execute(ctx);
assertTrue(ctx.getErrors().isEmpty());
}
@Test
public void testInValidFeatureId() throws Exception {
- ctx.getConfiguration().put(CheckFeatureId.CONFIG_KEY_ACCEPTED_FEATURE_IDS, "myGroupId:*:jar:myOtherClassifier:1.0.0");
+ ctx.getConfiguration()
+ .put(CheckFeatureId.CONFIG_KEY_ACCEPTED_FEATURE_IDS, "myGroupId:*:jar:myOtherClassifier:1.0.0");
task.execute(ctx);
assertEquals(1, ctx.getErrors().size());
}
@Test
public void checkMatches() {
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("*:myArtifactId:1.0.0")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:*:1.0.0")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:*")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar:*")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:*:1.0.0")));
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar:*:1.0.0")));
-
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("*:myOtherArtifactId:1.0.0")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myOtherGroupId:*:1.0.0")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myOtherArtifactId:*")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:someothertype:*")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar:*:1.1.0")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:*:*:1.1.0")));
-
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("*:myArtifactId:1.0.0")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:*:1.0.0")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:*")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar:*")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:*:1.0.0")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar:*:1.0.0")));
+
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("*:myOtherArtifactId:1.0.0")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"), ArtifactId.parse("myOtherGroupId:*:1.0.0")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myOtherArtifactId:*")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:someothertype:*")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar:*:1.1.0")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:*:*:1.1.0")));
+
// enforce no classifier
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:jar:invalidClassifier:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0")));
-
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:jar:invalidClassifier:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:jar::1.0.0")));
+
// enforce default type
- assertTrue(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:1.0.0")));
- assertFalse(CheckFeatureId.matches(ArtifactId.parse("myGroupId:myArtifactId:othertype:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:1.0.0")));
+ assertTrue(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:1.0.0"), ArtifactId.parse("myGroupId:myArtifactId:1.0.0")));
+ assertFalse(CheckFeatureId.matches(
+ ArtifactId.parse("myGroupId:myArtifactId:othertype:1.0.0"),
+ ArtifactId.parse("myGroupId:myArtifactId:1.0.0")));
}
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinitTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinitTest.java
index e5168ab..3c84f69 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinitTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRepoinitTest.java
@@ -1,25 +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
+ * 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
+ * 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.
+ * 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.Extension;
import org.apache.sling.feature.ExtensionState;
@@ -27,12 +25,16 @@ import org.apache.sling.feature.ExtensionType;
import org.apache.sling.feature.analyser.task.AnalyserTask;
import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class CheckRepoinitTest {
public static final String VALID_STATEMENT = "create path /acltest/A/B \n delete ACL for testing";
public static final String INVALID_STATEMENT = "create spaceship";
- @Test public void testValidExtension() throws Exception {
+ @Test
+ public void testValidExtension() throws Exception {
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final AnalyserTask task = new CheckRepoinit();
@@ -41,7 +43,8 @@ public class CheckRepoinitTest {
assertTrue(ctx.getErrors().isEmpty());
// create valid extension
- final Extension ext = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
+ final Extension ext =
+ new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
ctx.getFeature().getExtensions().add(ext);
ext.setText(VALID_STATEMENT);
@@ -49,24 +52,28 @@ public class CheckRepoinitTest {
assertTrue(ctx.getErrors().isEmpty());
}
- @Test public void testInvalidExtension() throws Exception {
+ @Test
+ public void testInvalidExtension() throws Exception {
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final AnalyserTask task = new CheckRepoinit();
// wrong type
- final Extension ext = new Extension(ExtensionType.JSON, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
+ final Extension ext =
+ new Extension(ExtensionType.JSON, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
ctx.getFeature().getExtensions().add(ext);
task.execute(ctx);
assertEquals(1, ctx.getErrors().size());
}
- @Test public void testInvalidExtensionRepoinit() throws Exception {
+ @Test
+ public void testInvalidExtensionRepoinit() throws Exception {
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final AnalyserTask task = new CheckRepoinit();
// invalid repoinit
- final Extension ext = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
+ final Extension ext =
+ new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.OPTIONAL);
ext.setText(INVALID_STATEMENT);
ctx.getFeature().getExtensions().add(ext);
@@ -74,7 +81,8 @@ public class CheckRepoinitTest {
assertEquals(1, ctx.getErrors().size());
}
- @Test public void testValidFactoryConfig() throws Exception {
+ @Test
+ public void testValidFactoryConfig() throws Exception {
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final AnalyserTask task = new CheckRepoinit();
@@ -86,7 +94,8 @@ public class CheckRepoinitTest {
assertTrue(ctx.getErrors().isEmpty());
}
- @Test public void testInvalidFactoryConfig() throws Exception {
+ @Test
+ public void testInvalidFactoryConfig() throws Exception {
final AnalyserTaskContextImpl ctx = new AnalyserTaskContextImpl();
final AnalyserTask task = new CheckRepoinit();
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilitiesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilitiesTest.java
index 2142c64..abf08fc 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilitiesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckRequirementsCapabilitiesTest.java
@@ -1,18 +1,20 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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;
@@ -37,26 +39,21 @@ import org.mockito.Mockito;
import org.osgi.resource.Capability;
import org.osgi.resource.Resource;
-
public class CheckRequirementsCapabilitiesTest {
@Test
public void testCheckRequirementsCapabilitiesAllOk() throws Exception {
File f = new File(getClass().getResource("/test-bundle5.jar").getFile());
BundleDescriptor bd1 = new BundleDescriptorImpl(
- new Artifact(ArtifactId.fromMvnId("g:b1:1.2.0")),
- f.toURI().toURL());
+ new Artifact(ArtifactId.fromMvnId("g:b1:1.2.0")), f.toURI().toURL());
Feature feature = new Feature(ArtifactId.fromMvnId("a:b:1"));
- Capability cap1 = new CapabilityImpl(null,
- "org.foo.blah", Collections.emptyMap(),
- Collections.singletonMap("abc", "def"));
- Capability cap2 = new CapabilityImpl(null,
- "org.foo.bar", Collections.emptyMap(),
- Collections.singletonMap("abc", "def"));
- MatchingRequirement req = new MatchingRequirementImpl(null,
- "org.zzz", "(&(zzz=aaa)(qqq=123))");
+ Capability cap1 = new CapabilityImpl(
+ null, "org.foo.blah", Collections.emptyMap(), Collections.singletonMap("abc", "def"));
+ Capability cap2 =
+ new CapabilityImpl(null, "org.foo.bar", Collections.emptyMap(), Collections.singletonMap("abc", "def"));
+ MatchingRequirement req = new MatchingRequirementImpl(null, "org.zzz", "(&(zzz=aaa)(qqq=123))");
feature.getCapabilities().addAll(Arrays.asList(cap1, cap2));
feature.getRequirements().add(req);
@@ -79,8 +76,7 @@ public class CheckRequirementsCapabilitiesTest {
File f = new File(getClass().getResource("/test-bundle5.jar").getFile());
BundleDescriptor bd1 = new BundleDescriptorImpl(
- new Artifact(ArtifactId.fromMvnId("g:b1:1.2.0")),
- f.toURI().toURL());
+ new Artifact(ArtifactId.fromMvnId("g:b1:1.2.0")), f.toURI().toURL());
Feature feature = new Feature(ArtifactId.fromMvnId("a:b:1"));
FeatureDescriptor fd = new FeatureDescriptorImpl(feature);
@@ -100,14 +96,11 @@ public class CheckRequirementsCapabilitiesTest {
public void testCheckRequirementsCapabilitiesMissingFromFeature() throws Exception {
Feature feature = new Feature(ArtifactId.fromMvnId("a:b:1"));
- Capability cap1 = new CapabilityImpl(null,
- "org.foo.blah", Collections.emptyMap(),
- Collections.singletonMap("abc", "def"));
- Capability cap2 = new CapabilityImpl(null,
- "org.foo.bar", Collections.emptyMap(),
- Collections.singletonMap("abc", "def"));
- MatchingRequirement req = new MatchingRequirementImpl(null,
- "org.zzz", "(&(zzz=aaa)(qqq=123))");
+ Capability cap1 = new CapabilityImpl(
+ null, "org.foo.blah", Collections.emptyMap(), Collections.singletonMap("abc", "def"));
+ Capability cap2 =
+ new CapabilityImpl(null, "org.foo.bar", Collections.emptyMap(), Collections.singletonMap("abc", "def"));
+ MatchingRequirement req = new MatchingRequirementImpl(null, "org.zzz", "(&(zzz=aaa)(qqq=123))");
feature.getCapabilities().addAll(Arrays.asList(cap1, cap2));
feature.getRequirements().add(req);
@@ -139,7 +132,8 @@ public class CheckRequirementsCapabilitiesTest {
return false;
}
final RequirementImpl that = (RequirementImpl) o;
- return Objects.equals(resource, that.getResource()) && Objects.equals(namespace, that.getNamespace())
+ return Objects.equals(resource, that.getResource())
+ && Objects.equals(namespace, that.getNamespace())
&& Objects.equals(attributes, that.getAttributes())
&& Objects.equals(directives, that.getDirectives());
}
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMappingTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMappingTest.java
index 3e4bfb8..070090d 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMappingTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/CheckServiceUserMappingTest.java
@@ -33,19 +33,22 @@ import static org.junit.Assert.assertTrue;
public class CheckServiceUserMappingTest {
public static final String[] DEPRECATED_STATEMENTS = {
- "org.apache.sling.test_service:sub_service=sling-reader-service",
- "org.apache.sling.test_service=sling-reader-service"};
+ "org.apache.sling.test_service:sub_service=sling-reader-service",
+ "org.apache.sling.test_service=sling-reader-service"
+ };
public static final String[] VALID_STATEMENTS = {
- "org.apache.sling.test_service:sub_service=[sling-reader-service]",
- "org.apache.sling.test_service=[sling-reader-service, sling-writer-service],\n" +
- "org.apache.sling.test_service:sub_service=[sling-reader-service]"};
+ "org.apache.sling.test_service:sub_service=[sling-reader-service]",
+ "org.apache.sling.test_service=[sling-reader-service, sling-writer-service],\n"
+ + "org.apache.sling.test_service:sub_service=[sling-reader-service]"
+ };
public static final String[] INVALID_STATEMENTS = {
- ":subservice=[sling-reader-service]",
- "=[sling-reader-service]",
- "org.apache.sling.test_service:sub_service=",
- "org.apache.sling.test_service:=[sling-reader-service]",
- "org.apache.sling.test_service",
- ":=[sling-reader-service]"};
+ ":subservice=[sling-reader-service]",
+ "=[sling-reader-service]",
+ "org.apache.sling.test_service:sub_service=",
+ "org.apache.sling.test_service:=[sling-reader-service]",
+ "org.apache.sling.test_service",
+ ":=[sling-reader-service]"
+ };
private AnalyserTaskContextImpl ctx;
private AnalyserTask task;
@@ -57,17 +60,17 @@ public class CheckServiceUserMappingTest {
task.execute(ctx);
assertTrue(ctx.getErrors().isEmpty());
}
-
+
@Test
public void testId() {
assertEquals("serviceusermapping", task.getId());
}
-
+
@Test
public void testName() {
assertEquals("Service User Mapping Check", task.getName());
}
-
+
@Test
public void testValidConfiguration() throws Exception {
// create valid configuration
@@ -103,8 +106,8 @@ public class CheckServiceUserMappingTest {
task.execute(ctx);
assertTrue(ctx.getErrors().isEmpty());
}
-
- @Test
+
+ @Test
public void testInvalidConfiguration() throws Exception {
for (String statement : INVALID_STATEMENTS) {
final Configuration cfg = new Configuration(CheckServiceUserMapping.FACTORY_PID.concat("~name"));
@@ -118,8 +121,9 @@ public class CheckServiceUserMappingTest {
@Test
public void testDeprecatedMappingInvalied() throws Exception {
- assertFalse(Boolean.parseBoolean(ctx.getConfiguration().getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT)));
-
+ assertFalse(Boolean.parseBoolean(ctx.getConfiguration()
+ .getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT)));
+
for (String statement : DEPRECATED_STATEMENTS) {
final Configuration cfg = new Configuration(CheckServiceUserMapping.FACTORY_PID.concat("~name"));
cfg.getProperties().put(USER_MAPPING, statement);
@@ -130,11 +134,12 @@ public class CheckServiceUserMappingTest {
assertEquals(2, ctx.getErrors().size());
}
- @Test
+ @Test
public void testDeprecatedMappingWarnOnly() throws Exception {
ctx.putConfigurationValue(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, Boolean.TRUE.toString());
- assertTrue(Boolean.parseBoolean(ctx.getConfiguration().getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT)));
+ assertTrue(Boolean.parseBoolean(ctx.getConfiguration()
+ .getOrDefault(CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS, CFG_WARN_ONLY_FOR_DEPRECATED_MAPPINGS_DEFAULT)));
for (String statement : DEPRECATED_STATEMENTS) {
final Configuration cfg = new Configuration(CheckServiceUserMapping.FACTORY_PID.concat("~name"));
cfg.getProperties().put(USER_MAPPING, statement);
diff --git a/src/test/java/org/apache/sling/feature/analyser/task/impl/RulesTest.java b/src/test/java/org/apache/sling/feature/analyser/task/impl/RulesTest.java
index a795a23..d30174c 100644
--- a/src/test/java/org/apache/sling/feature/analyser/task/impl/RulesTest.java
+++ b/src/test/java/org/apache/sling/feature/analyser/task/impl/RulesTest.java
@@ -1,37 +1,39 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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 static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-
import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
import org.apache.sling.feature.analyser.task.impl.CheckContentPackagesForPaths.Rules;
import org.junit.Test;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+
public class RulesTest {
- @Test
+ @Test
public void testNoRulesConfiguration() {
final AnalyserTaskContext ctx = new AnalyserTaskContextImpl();
assertThat(new Rules(ctx).isConfigured(), equalTo(false));
}
- @Test
+ @Test
public void testIncludesRulesConfiguration() {
final AnalyserTaskContext ctx = new AnalyserTaskContextImpl();
ctx.getConfiguration().put("includes", "/a, /b");
@@ -43,7 +45,7 @@ public class RulesTest {
assertEquals("/b", r.includes[1]);
}
- @Test
+ @Test
public void testExcludesRulesConfiguration() {
final AnalyserTaskContext ctx = new AnalyserTaskContextImpl();
ctx.getConfiguration().put("excludes", "/a, /b");
diff --git a/src/test/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImplTest.java b/src/test/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImplTest.java
index 1fa26b7..46b7bb7 100644
--- a/src/test/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImplTest.java
+++ b/src/test/java/org/apache/sling/feature/scanner/impl/BundleDescriptorImplTest.java
@@ -1,25 +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
+ * 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
+ * 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.
+ * 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.scanner.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -43,47 +41,58 @@ import org.apache.sling.feature.scanner.Scanner;
import org.junit.Test;
import org.osgi.framework.Version;
-public class BundleDescriptorImplTest
-{
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+public class BundleDescriptorImplTest {
private void assertPackageInfo(Set<PackageInfo> infos, final String name, final Version version) {
- for (PackageInfo info : infos)
- {
- if (name.equals(info.getName()) && version.equals(info.getPackageVersion()))
- {
+ for (PackageInfo info : infos) {
+ if (name.equals(info.getName()) && version.equals(info.getPackageVersion())) {
return;
}
}
fail();
}
- @Test public void testExportPackage() throws Exception {
+ @Test
+ public void testExportPackage() throws Exception {
String bmf = "Bundle-SymbolicName: pkg.bundle\n"
- + "Bundle-Version: 1\n"
- + "Bundle-ManifestVersion: 2\n"
- + "Export-Package: org.apache.sling;version=1.0,org.apache.felix;version=2.0\n";
+ + "Bundle-Version: 1\n"
+ + "Bundle-ManifestVersion: 2\n"
+ + "Export-Package: org.apache.sling;version=1.0,org.apache.felix;version=2.0\n";
URL f = new URL("jar:" + createBundle(bmf).toURI().toURL() + "!/");
- BundleDescriptorImpl bdf = new BundleDescriptorImpl(new Artifact(new ArtifactId("foo", "bar", "1.0", "bla", "bundle")), f);
+ BundleDescriptorImpl bdf =
+ new BundleDescriptorImpl(new Artifact(new ArtifactId("foo", "bar", "1.0", "bla", "bundle")), f);
final Set<PackageInfo> infos = bdf.getExportedPackages();
assertEquals(2, infos.size());
- assertPackageInfo(infos ,"org.apache.sling", Version.parseVersion("1.0"));
- assertPackageInfo(infos,"org.apache.felix", Version.parseVersion("2.0"));
+ assertPackageInfo(infos, "org.apache.sling", Version.parseVersion("1.0"));
+ assertPackageInfo(infos, "org.apache.felix", Version.parseVersion("2.0"));
}
@Test
public void testBundleManifest() throws Exception {
- Feature feature = FeatureJSONReader.read(new InputStreamReader(getClass().getResourceAsStream("/metadata-feature.json")), null);
+ Feature feature = FeatureJSONReader.read(
+ new InputStreamReader(getClass().getResourceAsStream("/metadata-feature.json")), null);
Scanner scanner = new Scanner(artifactId -> null);
FeatureDescriptor descriptor = scanner.scan(feature);
- assertEquals(feature.getBundles().size(), descriptor.getBundleDescriptors().size());
+ assertEquals(
+ feature.getBundles().size(), descriptor.getBundleDescriptors().size());
assertNull(descriptor.getBundleDescriptors().iterator().next().getArtifactFile());
- assertEquals("2.0", descriptor.getBundleDescriptors().stream()
- .filter(b -> b.getBundleSymbolicName().equals("log4j.over.slf4j")).findFirst().get()
- .getManifest().getMainAttributes().getValue("Manifest-Version"));
+ assertEquals(
+ "2.0",
+ descriptor.getBundleDescriptors().stream()
+ .filter(b -> b.getBundleSymbolicName().equals("log4j.over.slf4j"))
+ .findFirst()
+ .get()
+ .getManifest()
+ .getMainAttributes()
+ .getValue("Manifest-Version"));
}
/**
- * for SLING-10182
+ * for SLING-10182
*/
@Test
public void testBundleManifestForFolder() throws Exception {
@@ -94,11 +103,12 @@ public class BundleDescriptorImplTest
File dir = createBundleFolder(bmf);
try {
URL f = dir.toURI().toURL();
- BundleDescriptorImpl bdf = new BundleDescriptorImpl(new Artifact(new ArtifactId("foo", "bar", "1.0", "bla", "bundle")), f);
+ BundleDescriptorImpl bdf =
+ new BundleDescriptorImpl(new Artifact(new ArtifactId("foo", "bar", "1.0", "bla", "bundle")), f);
final Set<PackageInfo> infos = bdf.getExportedPackages();
assertEquals(2, infos.size());
- assertPackageInfo(infos ,"org.apache.sling", Version.parseVersion("1.0"));
- assertPackageInfo(infos,"org.apache.felix", Version.parseVersion("2.0"));
+ assertPackageInfo(infos, "org.apache.sling", Version.parseVersion("1.0"));
+ assertPackageInfo(infos, "org.apache.felix", Version.parseVersion("2.0"));
} finally {
Path tempDir = dir.toPath();
Files.walk(tempDir)
@@ -108,8 +118,7 @@ public class BundleDescriptorImplTest
}
}
- private File createBundle(String manifest) throws IOException
- {
+ private File createBundle(String manifest) throws IOException {
File f = Files.createTempFile("bundle", ".jar").toFile();
f.deleteOnExit();
Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("UTF-8")));
@@ -119,8 +128,7 @@ public class BundleDescriptorImplTest
return f;
}
- private File createBundleFolder(String manifest) throws IOException
- {
+ private File createBundleFolder(String manifest) throws IOException {
File f = Files.createTempDirectory("bundle.folder").toFile();
Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("UTF-8")));
mf.getMainAttributes().putValue("Manifest-Version", "1.0");
diff --git a/src/test/java/org/apache/sling/feature/scanner/impl/ContentPackageScannerTest.java b/src/test/java/org/apache/sling/feature/scanner/impl/ContentPackageScannerTest.java
index dcbc26d..4d7e3d7 100644
--- a/src/test/java/org/apache/sling/feature/scanner/impl/ContentPackageScannerTest.java
+++ b/src/test/java/org/apache/sling/feature/scanner/impl/ContentPackageScannerTest.java
@@ -1,27 +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
+ * 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
+ * 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.
+ * 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.scanner.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -37,8 +33,13 @@ import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Configuration;
import org.junit.Test;
-public class ContentPackageScannerTest {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+public class ContentPackageScannerTest {
@Test
public void testScan() throws URISyntaxException, IOException {
@@ -48,18 +49,23 @@ public class ContentPackageScannerTest {
final ArtifactId TEST_PACKAGE_AID_A_10 = ArtifactId.fromMvnId(COORDINATES_TEST_PACKAGE_A_10);
ContentPackageScanner scanner = new ContentPackageScanner();
- Set<ContentPackageDescriptorImpl> descriptors = scanner.scan(new Artifact(TEST_PACKAGE_AID_A_10), file.toURI().toURL());
+ Set<ContentPackageDescriptorImpl> descriptors =
+ scanner.scan(new Artifact(TEST_PACKAGE_AID_A_10), file.toURI().toURL());
assertEquals(2, descriptors.size());
- for(ContentPackageDescriptorImpl desc : descriptors) {
+ for (ContentPackageDescriptorImpl desc : descriptors) {
if (desc.getName().equals("test-content")) {
- assetDescriptor(desc, "test-content", TEST_PACKAGE_AID_A_10, file.toURI().toURL());
+ assetDescriptor(
+ desc,
+ "test-content",
+ TEST_PACKAGE_AID_A_10,
+ file.toURI().toURL());
} else {
assertEquals(desc.getName(), "sub-content");
}
assertNotNull(desc.getManifest());
}
}
-
+
@Test
public void testMultipleMavenPropertyDirectoryPicking() throws URISyntaxException, IOException {
// this test case is to cover where we have multiple pom.properties files present in our package.
@@ -69,13 +75,15 @@ public class ContentPackageScannerTest {
final ArtifactId TEST_PACKAGE_AID_A_10 = ArtifactId.fromMvnId(COORDINATES_TEST_PACKAGE_A_10);
ContentPackageScanner scanner = new ContentPackageScanner();
- Set<ContentPackageDescriptorImpl> descriptors = scanner.scan(new Artifact(TEST_PACKAGE_AID_A_10), file.toURI().toURL());
-
- for(ContentPackageDescriptorImpl descriptor: descriptors){
- if(descriptor.getName().equals("test-content-felix-bundle-multi-maven-properties")){
- assertEquals("org.apache.felix:org.apache.felix.framework:6.0.1", descriptor.getBundles().get(0).getName());
+ Set<ContentPackageDescriptorImpl> descriptors =
+ scanner.scan(new Artifact(TEST_PACKAGE_AID_A_10), file.toURI().toURL());
+
+ for (ContentPackageDescriptorImpl descriptor : descriptors) {
+ if (descriptor.getName().equals("test-content-felix-bundle-multi-maven-properties")) {
+ assertEquals(
+ "org.apache.felix:org.apache.felix.framework:6.0.1",
+ descriptor.getBundles().get(0).getName());
}
-
}
}
@@ -93,7 +101,11 @@ public class ContentPackageScannerTest {
acs.put("artifactId", "acs-aem-commons-bundle");
acs.put("version", "5.3.7");
candidates.add(acs);
- final ArtifactId id = scanner.extractArtifactId(candidates, "acs-aem-commons-bundle-5.3.4.jar", ArtifactId.parse("com.adobe.acs:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
+ final ArtifactId id = scanner.extractArtifactId(
+ candidates,
+ "acs-aem-commons-bundle-5.3.4.jar",
+ ArtifactId.parse("com.adobe.acs:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting
+ // com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
assertEquals(ArtifactId.parse("com.adobe.acs:acs-aem-commons-bundle:5.3.7"), id);
}
@@ -106,7 +118,11 @@ public class ContentPackageScannerTest {
acs.put("artifactId", "acs-aem-commons-bundle");
acs.put("version", "5.3.4");
candidates.add(acs);
- final ArtifactId id = scanner.extractArtifactId(candidates, "acs-aem-commons-bundle-5.3.4-test.jar", ArtifactId.parse("com.adobe.acs:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
+ final ArtifactId id = scanner.extractArtifactId(
+ candidates,
+ "acs-aem-commons-bundle-5.3.4-test.jar",
+ ArtifactId.parse("com.adobe.acs:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting
+ // com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
assertEquals(ArtifactId.parse("com.adobe.acs:acs-aem-commons-bundle:jar:test:5.3.4"), id);
}
@@ -124,7 +140,11 @@ public class ContentPackageScannerTest {
acs.put("artifactId", "acs-aem-commons-bundle");
acs.put("version", "5.3.4");
candidates.add(acs);
- final ArtifactId id = scanner.extractArtifactId(candidates, "acs-aem-commons-bundle-5.3.4.jar", ArtifactId.parse("something:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
+ final ArtifactId id = scanner.extractArtifactId(
+ candidates,
+ "acs-aem-commons-bundle-5.3.4.jar",
+ ArtifactId.parse("something:acs-aem-commons-content:zip:5.4.3.zip")); // xample we are extracting
+ // com.acs.aem.acs-aem-commons-content-5.4.3.zip > acs-aem-commons-bundle-5.3.4.jar
assertEquals(ArtifactId.parse("com.adobe.acs:acs-aem-commons-bundle:5.3.4"), id);
}
@@ -132,15 +152,21 @@ public class ContentPackageScannerTest {
return new File(getClass().getResource(path).toURI());
}
- private void assetDescriptor(ContentPackageDescriptorImpl desc, String descName, final ArtifactId descArtifactId, final URL descUrl) {
+ private void assetDescriptor(
+ ContentPackageDescriptorImpl desc, String descName, final ArtifactId descArtifactId, final URL descUrl) {
assertEquals(descName, desc.getName());
assertEquals(descArtifactId, desc.getArtifact().getId());
assertEquals(descUrl, desc.getArtifactFile());
assertEquals(1, desc.getBundles().size());
- assertEquals(desc.getBundles().get(0).getArtifact().getId(), ArtifactId.parse("org.apache.felix:org.apache.felix.framework:6.0.1"));
- assertEquals("artifact start order",20, desc.getBundles().get(0).getArtifact().getStartOrder());
+ assertEquals(
+ desc.getBundles().get(0).getArtifact().getId(),
+ ArtifactId.parse("org.apache.felix:org.apache.felix.framework:6.0.1"));
+ assertEquals(
+ "artifact start order",
+ 20,
+ desc.getBundles().get(0).getArtifact().getStartOrder());
assertEquals(1, desc.getConfigurations().size());
assertConfiguration(desc.getConfigurations().get(0));
@@ -167,15 +193,27 @@ public class ContentPackageScannerTest {
final ContentPackageScanner scanner = new ContentPackageScanner();
// content packages need to be below /libs, /apps or /etc/packages/
- assertEquals(ContentPackageScanner.FileType.PACKAGE, scanner.detectContentFileType("/etc/packages/a/b/my-package.zip"));
- assertEquals(ContentPackageScanner.FileType.PACKAGE, scanner.detectContentFileType("/libs/app/install/component.zip"));
+ assertEquals(
+ ContentPackageScanner.FileType.PACKAGE,
+ scanner.detectContentFileType("/etc/packages/a/b/my-package.zip"));
+ assertEquals(
+ ContentPackageScanner.FileType.PACKAGE,
+ scanner.detectContentFileType("/libs/app/install/component.zip"));
assertNull(scanner.detectContentFileType("/content/app/install/component.zip"));
// configs need to be below /libs, /apps in install or config folders
- assertEquals(ContentPackageScanner.FileType.CONFIG, scanner.detectContentFileType("/libs/app/install/component.cfg"));
- assertEquals(ContentPackageScanner.FileType.CONFIG, scanner.detectContentFileType("/libs/app/install/component.config"));
- assertEquals(ContentPackageScanner.FileType.CONFIG, scanner.detectContentFileType("/libs/app/install/component.xml"));
- assertEquals(ContentPackageScanner.FileType.CONFIG, scanner.detectContentFileType("/libs/app/install/component.cfg.json"));
+ assertEquals(
+ ContentPackageScanner.FileType.CONFIG,
+ scanner.detectContentFileType("/libs/app/install/component.cfg"));
+ assertEquals(
+ ContentPackageScanner.FileType.CONFIG,
+ scanner.detectContentFileType("/libs/app/install/component.config"));
+ assertEquals(
+ ContentPackageScanner.FileType.CONFIG,
+ scanner.detectContentFileType("/libs/app/install/component.xml"));
+ assertEquals(
+ ContentPackageScanner.FileType.CONFIG,
+ scanner.detectContentFileType("/libs/app/install/component.cfg.json"));
assertNull(scanner.detectContentFileType("/libs/app/install/component.txt"));
assertNull(scanner.detectContentFileType("/content/app/install/component.cfg"));
assertNull(scanner.detectContentFileType("/content/app/install/component.config"));
@@ -183,7 +221,9 @@ public class ContentPackageScannerTest {
assertNull(scanner.detectContentFileType("/content/app/install/component.cfg.json"));
// bundles need to be below /libs, /apps in install orfolders
- assertEquals(ContentPackageScanner.FileType.BUNDLE, scanner.detectContentFileType("/libs/app/install/component.jar"));
+ assertEquals(
+ ContentPackageScanner.FileType.BUNDLE,
+ scanner.detectContentFileType("/libs/app/install/component.jar"));
assertNull(scanner.detectContentFileType("/content/app/install/component.jar"));
}
diff --git a/src/test/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScannerTest.java b/src/test/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScannerTest.java
index 730e512..6574256 100644
--- a/src/test/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScannerTest.java
+++ b/src/test/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScannerTest.java
@@ -1,21 +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
+ * 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
+ * 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.
+ * 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.scanner.impl;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.felix.framework.Felix;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.builder.ArtifactProvider;
@@ -25,13 +34,6 @@ import org.junit.Test;
import org.osgi.framework.Constants;
import org.osgi.resource.Capability;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -46,27 +48,28 @@ public class FelixFrameworkScannerTest {
String additionalVersions = getAdditionalVersionNumbers();
- Map<String,String> kvmap = new HashMap<>();
- Map<String,String> props = ffs.getFrameworkProperties(kvmap, fwFile.toURI().toURL());
+ Map<String, String> kvmap = new HashMap<>();
+ Map<String, String> props =
+ ffs.getFrameworkProperties(kvmap, fwFile.toURI().toURL());
String expected = "osgi.service; objectClass:List<String>=org.osgi.service.resolver.Resolver; "
- + "uses:=org.osgi.service.resolver, "
+ + "uses:=org.osgi.service.resolver, "
+ "osgi.service; objectClass:List<String>=org.osgi.service.startlevel.StartLevel; "
- + "uses:=org.osgi.service.startlevel, "
+ + "uses:=org.osgi.service.startlevel, "
+ "osgi.service; objectClass:List<String>=org.osgi.service.packageadmin.PackageAdmin; "
- + "uses:=org.osgi.service.packageadmin , "
+ + "uses:=org.osgi.service.packageadmin , "
+ "osgi.ee; osgi.ee=\"OSGi/Minimum\"; version:List<Version>=\"1.0,1.1,1.2\", "
+ "osgi.ee; osgi.ee=\"JavaSE\"; version:List<Version>=\"1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8"
- + additionalVersions + "\", "
+ + additionalVersions + "\", "
+ "osgi.ee; osgi.ee=\"JavaSE/compact1\"; version:List<Version>=\"1.8"
- + additionalVersions + "\", "
+ + additionalVersions + "\", "
+ "osgi.ee; osgi.ee=\"JavaSE/compact2\"; version:List<Version>=\"1.8"
- + additionalVersions + "\", "
+ + additionalVersions + "\", "
+ "osgi.ee; osgi.ee=\"JavaSE/compact3\"; version:List<Version>=\"1.8"
- + additionalVersions + "\"";
+ + additionalVersions + "\"";
String actual = props.get("org.osgi.framework.system.capabilities");
// Remove spaces
- assertEquals(expected.replaceAll("\\s",""), actual.replaceAll("\\s",""));
+ assertEquals(expected.replaceAll("\\s", ""), actual.replaceAll("\\s", ""));
}
private String getAdditionalVersionNumbers() {
@@ -76,7 +79,7 @@ public class FelixFrameworkScannerTest {
if (!javaVersion.startsWith("1.")) {
int curVersion = Integer.parseInt(javaVersion);
- for (int i=9; i<=curVersion; i++) {
+ for (int i = 9; i <= curVersion; i++) {
sb.append(',');
sb.append(i);
}
@@ -90,15 +93,18 @@ public class FelixFrameworkScannerTest {
URL fwFile = getFelixFrameworkJar();
FelixFrameworkScanner ffs = new FelixFrameworkScanner();
- Map<String,String> kvmap = new HashMap<>();
- kvmap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.foo.bar;version=\"{dollar}{java.specification.version}\","
- + "org.zaa.zaa;version=\"{dollar}{java.class.version}\"");
+ Map<String, String> kvmap = new HashMap<>();
+ kvmap.put(
+ Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
+ "org.foo.bar;version=\"{dollar}{java.specification.version}\","
+ + "org.zaa.zaa;version=\"{dollar}{java.class.version}\"");
kvmap.put(Constants.FRAMEWORK_SYSTEMCAPABILITIES_EXTRA, "ding.dong;ding.dong=\"yeah!\"");
kvmap.put("felix.systempackages.substitution", "true");
- BundleDescriptor bundleDescriptor = ffs.scan(new ArtifactId("org.apache.felix",
- "org.apache.felix.framework",
- "6.0.1", null, null), kvmap, new ArtifactProvider() {
+ BundleDescriptor bundleDescriptor = ffs.scan(
+ new ArtifactId("org.apache.felix", "org.apache.felix.framework", "6.0.1", null, null),
+ kvmap,
+ new ArtifactProvider() {
@Override
public URL provide(ArtifactId id) {
@@ -133,8 +139,8 @@ public class FelixFrameworkScannerTest {
assertFalse(providedCaps.isEmpty());
boolean foundDingDong = false;
for (Capability cap : providedCaps) {
- if (cap.getNamespace().equals("ding.dong") && "yeah!".equals(cap.getAttributes().get("ding.dong")))
- foundDingDong = true;
+ if (cap.getNamespace().equals("ding.dong")
+ && "yeah!".equals(cap.getAttributes().get("ding.dong"))) foundDingDong = true;
}
assertTrue(foundDingDong);
}