This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.paxexam-0.0.4 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-paxexam.git
commit 057e5ed34966786a62dcea27239860fa3d1d09f6 Author: Oliver Lietz <[email protected]> AuthorDate: Sat Mar 4 13:58:36 2017 +0000 SLING-6473 Create a VersionResolver that provides versions from provisioning model files remove VersionResolver until matching Options are also provided by provisioning model git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/org.apache.sling.testing.paxexam@1785487 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 13 -- .../paxexam/ProvisioningModelVersionResolver.java | 136 --------------------- .../ProvisioningModelVersionResolverTest.java | 55 --------- .../testing/paxexam/SlingOptionsTestSupport.java | 2 - src/test/resources/test-dependencies.txt | 25 ---- 5 files changed, 231 deletions(-) diff --git a/pom.xml b/pom.xml index 9bb462e..a5a70a3 100644 --- a/pom.xml +++ b/pom.xml @@ -105,13 +105,6 @@ <artifactId>osgi.cmpn</artifactId> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.provisioning.model</artifactId> - <version>1.0.0</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> <!-- Apache Felix --> <dependency> <groupId>org.apache.felix</groupId> @@ -153,12 +146,6 @@ <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>1.7.13</version> - <scope>test</scope> - </dependency> </dependencies> </project> diff --git a/src/main/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolver.java b/src/main/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolver.java deleted file mode 100644 index 6cc1207..0000000 --- a/src/main/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolver.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.testing.paxexam; - -import org.apache.sling.provisioning.model.Artifact; -import org.apache.sling.provisioning.model.ArtifactGroup; -import org.apache.sling.provisioning.model.Feature; -import org.apache.sling.provisioning.model.Model; -import org.apache.sling.provisioning.model.RunMode; -import org.apache.sling.provisioning.model.io.ModelReader; -import org.ops4j.pax.exam.options.MavenArtifactUrlReference; -import org.ops4j.pax.exam.options.MavenUrlReference.VersionResolver; - -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * VersionResolver that reads version information from a sling provisioning file. - * One use-case is to reference Sling's launchpad, which normally references a - * (recent) set of compatible bundles, in order to allow running test based on - * the versioning information from the Sling launchpad's provisioning model. - */ -public class ProvisioningModelVersionResolver implements VersionResolver { - - private final Model model; - - /** - * Adds classifier "slingfeature" and type "txt" to the provided MavenArtifactUrlReference - * to simplify creation of a VersionResolver based on a slingfeature. - * - * @param reference Maven coordinates of a module that provides a slingfeature. - * @return VersionResolver instance backed by the referenced slingfeature. - */ - public static VersionResolver fromSlingfeature(MavenArtifactUrlReference reference) { - final String url = reference.classifier("slingfeature").type("txt").getURL(); - try { - return new ProvisioningModelVersionResolver(url); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - /** - * Constructor to create a VersionResolver instance backed by a provisioning model referenced - * by the URL represented by the provided String. - * - * @param url The String representation of a URL. - * @throws MalformedURLException If the String representation of the URL is not a valid URL. - */ - public ProvisioningModelVersionResolver(final String url) throws MalformedURLException { - this(toUrl(url)); - } - - /** - * Constructor to create a VersionResolver instance backed by a provisioning model referenced - * by the provided URL object. - * - * @param url The URL pointing the the provisioning model file. - */ - public ProvisioningModelVersionResolver(final URL url) { - InputStream inputStream = null; - try { - inputStream = url.openStream(); - this.model = ModelReader.read(new InputStreamReader(inputStream), url.toExternalForm()); - } catch (IOException e) { - throw new RuntimeException("Failed to read " + url.toExternalForm(), e); - } finally { - if (inputStream != null) { - try { - inputStream.close(); - } catch (IOException e) { - // silent - } - } - } - } - - private static URL toUrl(final String url) throws MalformedURLException { - final boolean hasProtocolHandler = System.getProperty("java.protocol.handler.pkgs") != null; - if (!hasProtocolHandler) { - // enable org.ops4j.pax.url handlers by default, unless the property is already set - System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url"); - } - try { - return new URL(url); - } catch (final MalformedURLException e) { - if ("unknown protocol: mvn".equals(e.getMessage())) { - // best effort: present a helpful message in case the mvn protocol handler is missing - final MalformedURLException exception = new MalformedURLException(e.getMessage() - + " -> Consider a dependency to org.ops4j.pax.url:pax-url-aether"); - exception.initCause(e); - throw exception; - } - throw e; - } finally { - if (!hasProtocolHandler) { - System.clearProperty("java.protocol.handler.pkgs"); - } - } - } - - @Override - public String getVersion(final String groupId, final String artifactId) { - for (final Feature feature : model.getFeatures()) { - for (final RunMode runMode : feature.getRunModes()) { - for (final ArtifactGroup artifacts : runMode.getArtifactGroups()) { - for (final Artifact artifact : artifacts) { - if (groupId.equals(artifact.getGroupId()) && artifactId.equals(artifact.getArtifactId())) { - return artifact.getVersion(); - } - } - } - } - } - return null; - } -} diff --git a/src/test/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolverTest.java b/src/test/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolverTest.java deleted file mode 100644 index 6529c11..0000000 --- a/src/test/java/org/apache/sling/testing/paxexam/ProvisioningModelVersionResolverTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.testing.paxexam; - -import org.junit.Test; -import org.ops4j.pax.exam.options.MavenUrlReference.VersionResolver; - -import static org.apache.sling.testing.paxexam.ProvisioningModelVersionResolver.fromSlingfeature; -import static org.junit.Assert.assertEquals; -import static org.ops4j.pax.exam.CoreOptions.maven; - -public class ProvisioningModelVersionResolverTest { - - @Test - public void getVersionFromClasspathResource() throws Exception { - final VersionResolver versionResolver = - new ProvisioningModelVersionResolver(getClass().getResource("/test-dependencies.txt")); - assertVersion("2.6.4", "org.apache.sling", "org.apache.sling.engine", versionResolver); - assertVersion("2.4.10", "org.apache.sling", "org.apache.sling.servlets.resolver", versionResolver); - assertVersion("2.1.18", "org.apache.sling", "org.apache.sling.servlets.get", versionResolver); - assertVersion("2.3.14", "org.apache.sling", "org.apache.sling.servlets.post", versionResolver); - } - - @Test - public void getVersionFromMavenDependency() throws Exception { - final VersionResolver versionResolver = - fromSlingfeature(maven("org.apache.sling", "org.apache.sling.launchpad", "8")); - assertVersion("2.4.4", "org.apache.sling", "org.apache.sling.engine", versionResolver); - assertVersion("2.3.8", "org.apache.sling", "org.apache.sling.servlets.resolver", versionResolver); - assertVersion("2.1.12", "org.apache.sling", "org.apache.sling.servlets.get", versionResolver); - assertVersion("2.3.8", "org.apache.sling", "org.apache.sling.servlets.post", versionResolver); - } - - private void assertVersion(final String expectedVersion, - final String groupId, final String artifactId, final VersionResolver versionResolver) { - final String actualVersion = versionResolver.getVersion(groupId, artifactId); - assertEquals("Version mismatch for " + groupId + ":" + artifactId, expectedVersion, actualVersion); - } -} \ No newline at end of file diff --git a/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java index 13f8b5a..f3dcff2 100644 --- a/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java +++ b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java @@ -18,13 +18,11 @@ */ package org.apache.sling.testing.paxexam; - import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; import static org.ops4j.pax.exam.CoreOptions.composite; import static org.ops4j.pax.exam.CoreOptions.keepCaches; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; public abstract class SlingOptionsTestSupport extends TestSupport { diff --git a/src/test/resources/test-dependencies.txt b/src/test/resources/test-dependencies.txt deleted file mode 100644 index fa43db7..0000000 --- a/src/test/resources/test-dependencies.txt +++ /dev/null @@ -1,25 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -[feature name=test] -# Dependencies -[artifacts] - org.apache.sling/org.apache.sling.engine/2.6.4 - org.apache.sling/org.apache.sling.servlets.resolver/2.4.10 - org.apache.sling/org.apache.sling.servlets.get/2.1.18 - org.apache.sling/org.apache.sling.servlets.post/2.3.14 -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
