Skip to content

Commit aca95be

Browse files
authored
JCR-4945: Ensure OSGi-enabled Jackrabbit bundles deploy in environments featuring only Slf4j v2 or even Tika v2.9 (#337)
Added tests.
1 parent 6cce9a4 commit aca95be

4 files changed

Lines changed: 309 additions & 1 deletion

File tree

jackrabbit-it-osgi/src/test/java/org/apache/jackrabbit/osgi/OSGiIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public Option[] configuration() throws IOException, URISyntaxException {
6666
mavenBundle("org.apache.felix", "org.apache.felix.fileinstall", "3.2.6"),
6767
mavenBundle("org.slf4j", "slf4j-api", "1.7.36"),
6868
mavenBundle("commons-logging", "commons-logging", "1.2"),
69+
mavenBundle("org.apache.tika", "tika-core", "2.4.1"),
6970
mavenBundle("ch.qos.logback", "logback-core", "1.2.13"),
7071
mavenBundle("ch.qos.logback", "logback-classic", "1.2.13"),
7172
frameworkProperty("repository.home").value("target"),
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.jackrabbit.osgi.slf4j2;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.ops4j.pax.exam.CoreOptions.bundle;
21+
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
22+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
23+
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
24+
import static org.ops4j.pax.exam.CoreOptions.systemProperties;
25+
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
26+
import static org.ops4j.pax.exam.CoreOptions.vmOption;
27+
28+
import java.io.File;
29+
import java.io.IOException;
30+
import java.net.URI;
31+
import java.net.MalformedURLException;
32+
import java.net.URISyntaxException;
33+
34+
import javax.inject.Inject;
35+
36+
import org.junit.Test;
37+
import org.junit.runner.RunWith;
38+
import org.ops4j.pax.exam.Configuration;
39+
import org.ops4j.pax.exam.CoreOptions;
40+
import org.ops4j.pax.exam.Option;
41+
import org.ops4j.pax.exam.junit.PaxExam;
42+
import org.ops4j.pax.exam.options.DefaultCompositeOption;
43+
import org.ops4j.pax.exam.options.SystemPropertyOption;
44+
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
45+
import org.ops4j.pax.exam.spi.reactors.PerClass;
46+
import org.ops4j.pax.exam.util.PathUtils;
47+
import org.osgi.framework.Bundle;
48+
import org.osgi.framework.BundleContext;
49+
import org.osgi.framework.InvalidSyntaxException;
50+
import org.osgi.framework.ServiceReference;
51+
import org.osgi.framework.Version;
52+
53+
@RunWith(PaxExam.class)
54+
@ExamReactorStrategy(PerClass.class)
55+
public class Slf4j_v2_Tika_v2_4_OSGiIT {
56+
57+
@Configuration
58+
public Option[] configuration() throws IOException, URISyntaxException {
59+
return CoreOptions.options(
60+
junitBundles(),
61+
mavenBundle("org.osgi", "org.osgi.service.log", "1.3.0"),
62+
mavenBundle("org.apache.felix", "org.apache.felix.scr", "2.0.12"),
63+
mavenBundle("org.apache.felix", "org.apache.felix.jaas", "1.0.2"),
64+
mavenBundle("org.osgi", "org.osgi.dto", "1.0.0"),
65+
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.16"),
66+
mavenBundle("org.apache.felix", "org.apache.felix.fileinstall", "3.2.6"),
67+
68+
//slf4j-api-2.0.7 requirement:
69+
//[slf4j.api [24](R 24.0)] osgi.extender; (&(osgi.extender=osgi.serviceloader.processor)(version>=1.0.0)(!(version>=2.0.0)))
70+
mavenBundle("org.ow2.asm", "asm", "9.5"),
71+
mavenBundle("org.ow2.asm", "asm-tree", "9.5"),
72+
mavenBundle("org.ow2.asm", "asm-analysis", "9.5"),
73+
mavenBundle("org.ow2.asm", "asm-commons", "9.5"),
74+
mavenBundle("org.ow2.asm", "asm-util", "9.5"),
75+
mavenBundle("org.apache.aries.spifly", "org.apache.aries.spifly.dynamic.bundle", "1.3.6"),
76+
77+
mavenBundle("org.slf4j", "slf4j-api", "2.0.7"),
78+
mavenBundle("ch.qos.logback", "logback-core", "1.3.5"),
79+
mavenBundle("ch.qos.logback", "logback-classic", "1.3.5"),
80+
81+
mavenBundle("commons-logging", "commons-logging", "1.2"),
82+
mavenBundle("org.apache.tika", "tika-core", "2.4.1"),
83+
84+
frameworkProperty("repository.home").value("target"),
85+
systemProperties(
86+
systemProperty("logback.configurationFile")
87+
.value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback-test.xml"),
88+
new SystemPropertyOption("felix.fileinstall.dir").value(getConfigDir())),
89+
jarBundles(),
90+
jpmsOptions());
91+
}
92+
93+
private Option jpmsOptions(){
94+
DefaultCompositeOption composite = new DefaultCompositeOption();
95+
if (Version.parseVersion(System.getProperty("java.specification.version")).getMajor() > 1){
96+
if (java.nio.file.Files.exists(java.nio.file.FileSystems.getFileSystem(URI.create("jrt:/")).getPath("modules", "java.se.ee"))){
97+
composite.add(vmOption("--add-modules=java.se.ee"));
98+
}
99+
composite.add(vmOption("--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED"));
100+
composite.add(vmOption("--add-opens=java.base/java.lang=ALL-UNNAMED"));
101+
composite.add(vmOption("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED"));
102+
composite.add(vmOption("--add-opens=java.base/java.io=ALL-UNNAMED"));
103+
composite.add(vmOption("--add-opens=java.base/java.net=ALL-UNNAMED"));
104+
composite.add(vmOption("--add-opens=java.base/java.nio=ALL-UNNAMED"));
105+
composite.add(vmOption("--add-opens=java.base/java.util=ALL-UNNAMED"));
106+
composite.add(vmOption("--add-opens=java.base/java.util.jar=ALL-UNNAMED"));
107+
composite.add(vmOption("--add-opens=java.base/java.util.regex=ALL-UNNAMED"));
108+
composite.add(vmOption("--add-opens=java.base/java.util.zip=ALL-UNNAMED"));
109+
composite.add(vmOption("--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"));
110+
}
111+
return composite;
112+
}
113+
114+
private String getConfigDir(){
115+
return new File(new File("src", "test"), "config").getAbsolutePath();
116+
}
117+
118+
private Option jarBundles() throws MalformedURLException {
119+
DefaultCompositeOption composite = new DefaultCompositeOption();
120+
for (File bundle : new File("target", "test-bundles").listFiles()) {
121+
if (bundle.getName().endsWith(".jar") && bundle.isFile()) {
122+
composite.add(bundle(bundle.toURI().toURL().toString()));
123+
}
124+
}
125+
return composite;
126+
}
127+
128+
@Inject
129+
private BundleContext context;
130+
131+
@Test
132+
public void bundleStates() {
133+
for (Bundle bundle : context.getBundles()) {
134+
assertEquals(
135+
String.format("Bundle %s not active. have a look at the logs", bundle.toString()),
136+
Bundle.ACTIVE, bundle.getState());
137+
}
138+
}
139+
140+
@Test
141+
public void listBundles() {
142+
for (Bundle bundle : context.getBundles()) {
143+
System.out.println(bundle);
144+
}
145+
}
146+
147+
@Test
148+
public void listServices() throws InvalidSyntaxException {
149+
for (ServiceReference<?> reference
150+
: context.getAllServiceReferences(null, null)) {
151+
System.out.println(reference);
152+
}
153+
}
154+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.jackrabbit.osgi.slf4j2;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.ops4j.pax.exam.CoreOptions.bundle;
21+
import static org.ops4j.pax.exam.CoreOptions.frameworkProperty;
22+
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
23+
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
24+
import static org.ops4j.pax.exam.CoreOptions.systemProperties;
25+
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
26+
import static org.ops4j.pax.exam.CoreOptions.vmOption;
27+
28+
import java.io.File;
29+
import java.io.IOException;
30+
import java.net.URI;
31+
import java.net.MalformedURLException;
32+
import java.net.URISyntaxException;
33+
34+
import javax.inject.Inject;
35+
36+
import org.junit.Test;
37+
import org.junit.runner.RunWith;
38+
import org.ops4j.pax.exam.Configuration;
39+
import org.ops4j.pax.exam.CoreOptions;
40+
import org.ops4j.pax.exam.Option;
41+
import org.ops4j.pax.exam.junit.PaxExam;
42+
import org.ops4j.pax.exam.options.DefaultCompositeOption;
43+
import org.ops4j.pax.exam.options.SystemPropertyOption;
44+
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
45+
import org.ops4j.pax.exam.spi.reactors.PerClass;
46+
import org.ops4j.pax.exam.util.PathUtils;
47+
import org.osgi.framework.Bundle;
48+
import org.osgi.framework.BundleContext;
49+
import org.osgi.framework.InvalidSyntaxException;
50+
import org.osgi.framework.ServiceReference;
51+
import org.osgi.framework.Version;
52+
53+
@RunWith(PaxExam.class)
54+
@ExamReactorStrategy(PerClass.class)
55+
public class Slf4j_v2_Tika_v2_9_OSGiIT {
56+
57+
@Configuration
58+
public Option[] configuration() throws IOException, URISyntaxException {
59+
return CoreOptions.options(
60+
junitBundles(),
61+
mavenBundle("org.osgi", "org.osgi.service.log", "1.3.0"),
62+
mavenBundle("org.apache.felix", "org.apache.felix.scr", "2.0.12"),
63+
mavenBundle("org.apache.felix", "org.apache.felix.jaas", "1.0.2"),
64+
mavenBundle("org.osgi", "org.osgi.dto", "1.0.0"),
65+
mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.8.16"),
66+
mavenBundle("org.apache.felix", "org.apache.felix.fileinstall", "3.2.6"),
67+
68+
//slf4j-api-2.0.7 requirement:
69+
//[slf4j.api [24](R 24.0)] osgi.extender; (&(osgi.extender=osgi.serviceloader.processor)(version>=1.0.0)(!(version>=2.0.0)))
70+
mavenBundle("org.ow2.asm", "asm", "9.5"),
71+
mavenBundle("org.ow2.asm", "asm-tree", "9.5"),
72+
mavenBundle("org.ow2.asm", "asm-analysis", "9.5"),
73+
mavenBundle("org.ow2.asm", "asm-commons", "9.5"),
74+
mavenBundle("org.ow2.asm", "asm-util", "9.5"),
75+
mavenBundle("org.apache.aries.spifly", "org.apache.aries.spifly.dynamic.bundle", "1.3.6"),
76+
77+
mavenBundle("org.slf4j", "slf4j-api", "2.0.7"),
78+
mavenBundle("ch.qos.logback", "logback-core", "1.3.5"),
79+
mavenBundle("ch.qos.logback", "logback-classic", "1.3.5"),
80+
81+
mavenBundle("commons-logging", "commons-logging", "1.2"),
82+
mavenBundle("org.apache.tika", "tika-core", "2.9.4"),
83+
84+
frameworkProperty("repository.home").value("target"),
85+
systemProperties(
86+
systemProperty("logback.configurationFile")
87+
.value("file:" + PathUtils.getBaseDir() + "/src/test/resources/logback-test.xml"),
88+
new SystemPropertyOption("felix.fileinstall.dir").value(getConfigDir())),
89+
jarBundles(),
90+
jpmsOptions());
91+
}
92+
93+
private Option jpmsOptions(){
94+
DefaultCompositeOption composite = new DefaultCompositeOption();
95+
if (Version.parseVersion(System.getProperty("java.specification.version")).getMajor() > 1){
96+
if (java.nio.file.Files.exists(java.nio.file.FileSystems.getFileSystem(URI.create("jrt:/")).getPath("modules", "java.se.ee"))){
97+
composite.add(vmOption("--add-modules=java.se.ee"));
98+
}
99+
composite.add(vmOption("--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED"));
100+
composite.add(vmOption("--add-opens=java.base/java.lang=ALL-UNNAMED"));
101+
composite.add(vmOption("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED"));
102+
composite.add(vmOption("--add-opens=java.base/java.io=ALL-UNNAMED"));
103+
composite.add(vmOption("--add-opens=java.base/java.net=ALL-UNNAMED"));
104+
composite.add(vmOption("--add-opens=java.base/java.nio=ALL-UNNAMED"));
105+
composite.add(vmOption("--add-opens=java.base/java.util=ALL-UNNAMED"));
106+
composite.add(vmOption("--add-opens=java.base/java.util.jar=ALL-UNNAMED"));
107+
composite.add(vmOption("--add-opens=java.base/java.util.regex=ALL-UNNAMED"));
108+
composite.add(vmOption("--add-opens=java.base/java.util.zip=ALL-UNNAMED"));
109+
composite.add(vmOption("--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"));
110+
}
111+
return composite;
112+
}
113+
114+
private String getConfigDir(){
115+
return new File(new File("src", "test"), "config").getAbsolutePath();
116+
}
117+
118+
private Option jarBundles() throws MalformedURLException {
119+
DefaultCompositeOption composite = new DefaultCompositeOption();
120+
for (File bundle : new File("target", "test-bundles").listFiles()) {
121+
if (bundle.getName().endsWith(".jar") && bundle.isFile()) {
122+
composite.add(bundle(bundle.toURI().toURL().toString()));
123+
}
124+
}
125+
return composite;
126+
}
127+
128+
@Inject
129+
private BundleContext context;
130+
131+
@Test
132+
public void bundleStates() {
133+
for (Bundle bundle : context.getBundles()) {
134+
assertEquals(
135+
String.format("Bundle %s not active. have a look at the logs", bundle.toString()),
136+
Bundle.ACTIVE, bundle.getState());
137+
}
138+
}
139+
140+
@Test
141+
public void listBundles() {
142+
for (Bundle bundle : context.getBundles()) {
143+
System.out.println(bundle);
144+
}
145+
}
146+
147+
@Test
148+
public void listServices() throws InvalidSyntaxException {
149+
for (ServiceReference<?> reference
150+
: context.getAllServiceReferences(null, null)) {
151+
System.out.println(reference);
152+
}
153+
}
154+
}

jackrabbit-it-osgi/test-bundles.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
<include>org.apache.jackrabbit:jackrabbit-jcr-commons</include>
3737
<include>org.apache.jackrabbit:jackrabbit-spi</include>
3838
<include>org.apache.jackrabbit:jackrabbit-spi-commons</include>
39-
<include>org.apache.tika:tika-core</include>
4039
<include>org.apache.httpcomponents:httpclient-osgi</include>
4140
<include>org.apache.httpcomponents:httpcore-osgi</include>
4241
<include>org.apache.jackrabbit:jackrabbit-webdav</include>

0 commit comments

Comments
 (0)