This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-paxexam-util.git
commit 8f58cb3d100be454575c95e625007b912ec9cbe9 Author: Bertrand Delacretaz <[email protected]> AuthorDate: Wed Jun 24 20:20:23 2015 +0000 SLING-4832 - SlingPaxOptions.setIgnoredBundles added, with tests git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1687359 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 2 + .../apache/sling/paxexam/util/SlingPaxOptions.java | 33 +++++++++++- .../sling/paxexam/util/IgnoredBundlesTest.java | 63 ++++++++++++++++++++++ .../apache/sling/paxexam/util/SlingSetupTest.java | 11 ++-- 4 files changed, 105 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 6e9b378..af14bac 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,7 @@ <exam.version>3.0.3</exam.version> <url.version>1.5.2</url.version> <pax.exam.log.level>INFO</pax.exam.log.level> + <pax.vm.options>-Xmx256M -XX:MaxPermSize=256m</pax.vm.options> </properties> <scm> @@ -76,6 +77,7 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> + <argLine>${pax.vm.options}</argLine> <systemProperties> <property> <name>pax.exam.log.level</name> diff --git a/src/main/java/org/apache/sling/paxexam/util/SlingPaxOptions.java b/src/main/java/org/apache/sling/paxexam/util/SlingPaxOptions.java index 9b1dcef..5368d71 100644 --- a/src/main/java/org/apache/sling/paxexam/util/SlingPaxOptions.java +++ b/src/main/java/org/apache/sling/paxexam/util/SlingPaxOptions.java @@ -55,6 +55,7 @@ public class SlingPaxOptions { public static final String PROP_TELNET_PORT = "osgi.shell.telnet.port"; public static final String PROP_HTTP_PORT = "org.osgi.service.http.port"; public static final String DEFAULT_RUN_MODES = "jackrabbit"; + private static String [] ignoredBundlePrefixes; private static int getAvailablePort() { int result = Integer.MIN_VALUE; @@ -67,6 +68,16 @@ public class SlingPaxOptions { return result; } + /** When reading bundle lists, ignore bundles which have symbolic names + * starting with one of the supplied prefixes */ + public static void setIgnoredBundles(String ... symbolicNamePrefix) { + if(symbolicNamePrefix == null || symbolicNamePrefix.length == 0) { + ignoredBundlePrefixes = new String[] {}; + } else { + ignoredBundlePrefixes = symbolicNamePrefix; + } + } + /** Get run modes to use for our tests, as set by the sling.run.modes property */ public static Collection<String> getTestRunModes() { final String runModes = System.getProperty("sling.run.modes", DEFAULT_RUN_MODES); @@ -96,6 +107,20 @@ public class SlingPaxOptions { ); } + private static boolean ignore(Bundle b) { + boolean result = false; + if(ignoredBundlePrefixes != null) { + final String sn = b.getArtifactId(); + for(String prefix : ignoredBundlePrefixes) { + if(sn.startsWith(prefix)) { + result = true; + break; + } + } + } + return result; + } + public static CompositeOption slingBundleList(String groupId, String artifactId, String version, String type, String classifier) { final DefaultCompositeOption result = new DefaultCompositeOption(); @@ -121,12 +146,18 @@ public class SlingPaxOptions { tmp = dumpMvnUrlToTmpFile(paxUrl); final BundleList list = BundleListUtils.readBundleList(tmp); int counter = 0; + int ignored = 0; for(StartLevel s : list.getStartLevels()) { // Start level < 0 means bootstrap in our bundle lists final int startLevel = s.getStartLevel() < 0 ? 1 : s.getStartLevel(); for(Bundle b : s.getBundles()) { + if(ignore(b)) { + log.info("Bundle ignored due to setIgnoredBundles: {}", b); + ignored++; + continue; + } counter++; // TODO need better fragment detection @@ -163,7 +194,7 @@ public class SlingPaxOptions { log.info("Bundle added: {}/{}/{}", new Object [] { b.getGroupId(), b.getArtifactId(), b.getVersion()}); } } - log.info("Got {} bundles from {}", counter, paxUrl); + log.info("Got {} bundles ({} ignored) from {}", new Object[] { counter, ignored, paxUrl }); } catch(Exception e) { throw new RuntimeException("Error getting bundle list " + paxUrl, e); } finally { diff --git a/src/test/java/org/apache/sling/paxexam/util/IgnoredBundlesTest.java b/src/test/java/org/apache/sling/paxexam/util/IgnoredBundlesTest.java new file mode 100644 index 0000000..23e8ff1 --- /dev/null +++ b/src/test/java/org/apache/sling/paxexam/util/IgnoredBundlesTest.java @@ -0,0 +1,63 @@ +/* + * 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.paxexam.util; + +import static org.junit.Assert.assertNull; + +import javax.inject.Inject; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.osgi.framework.BundleContext; + +/** Test the bundles ignoring feature */ +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class IgnoredBundlesTest { + /** Use a released launchpad for this example */ + public static final String SLING_LAUNCHPAD_VERSION = "7"; + + public static final String MIME_BUNDLE_SN = "org.apache.sling.commons.mime"; + public static final String JSON_BUNDLE_SN = "org.apache.sling.commons.json"; + + @Inject + private BundleContext bundleContext; + + @org.ops4j.pax.exam.Configuration + public Option[] config() { + SlingPaxOptions.setIgnoredBundles(MIME_BUNDLE_SN, JSON_BUNDLE_SN); + try { + return SlingPaxOptions.defaultLaunchpadOptions(SLING_LAUNCHPAD_VERSION).getOptions(); + } finally { + SlingPaxOptions.setIgnoredBundles(); + } + } + + @Test + public void testMimeBundle() { + assertNull(SlingSetupTest.getBundle(bundleContext, MIME_BUNDLE_SN)); + } + + @Test + public void testJsonBundle() { + assertNull(SlingSetupTest.getBundle(bundleContext, JSON_BUNDLE_SN)); + } + } \ No newline at end of file diff --git a/src/test/java/org/apache/sling/paxexam/util/SlingSetupTest.java b/src/test/java/org/apache/sling/paxexam/util/SlingSetupTest.java index 13e40c2..d3157e1 100644 --- a/src/test/java/org/apache/sling/paxexam/util/SlingSetupTest.java +++ b/src/test/java/org/apache/sling/paxexam/util/SlingSetupTest.java @@ -97,13 +97,18 @@ public class SlingSetupTest { } private Bundle getBundle(String symbolicName) { - for(Bundle b : bundleContext.getBundles()) { + return getBundle(bundleContext, symbolicName); + } + + static Bundle getBundle(BundleContext bc, String symbolicName) { + for(Bundle b : bc.getBundles()) { if(symbolicName.equals(b.getSymbolicName())) { return b; } } return null; } + /** @return bundle state, UNINSTALLED if absent */ private int getBundleState(String symbolicName) { return getBundleState(getBundle(symbolicName)); @@ -177,10 +182,10 @@ public class SlingSetupTest { "org.apache.sling.bundleresource.impl", "org.apache.sling.commons.classloader", "org.apache.sling.commons.compiler", - "org.apache.sling.commons.json", + IgnoredBundlesTest.JSON_BUNDLE_SN, "org.apache.sling.commons.log", "org.apache.sling.commons.logservice", - "org.apache.sling.commons.mime", + IgnoredBundlesTest.MIME_BUNDLE_SN, "org.apache.sling.commons.osgi", "org.apache.sling.commons.scheduler", "org.apache.sling.commons.threads", -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
