Skip to content

Commit 8091ee3

Browse files
committed
Add KarafDistributionOption.systemBundle
https://ops4j1.jira.com/browse/PAXEXAM-800
1 parent 2f9d58d commit 8091ee3

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/DependenciesDeployer.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@
3131
import org.apache.commons.io.FileUtils;
3232
import org.ops4j.pax.exam.ExamSystem;
3333
import org.ops4j.pax.exam.karaf.options.KarafFeaturesOption;
34-
import org.ops4j.pax.exam.options.BootClasspathLibraryOption;
35-
import org.ops4j.pax.exam.options.ProvisionOption;
36-
import org.ops4j.pax.exam.options.UrlReference;
34+
import org.ops4j.pax.exam.karaf.options.SystemBundleOption;
35+
import org.ops4j.pax.exam.options.*;
3736

3837
/**
3938
* Deploys exam and the user specified dependencies and creates the
@@ -69,7 +68,25 @@ public void copyBootClasspathLibraries() throws IOException {
6968
karafHome + "/lib"), new String[] { "jar" }));
7069
}
7170
}
72-
71+
72+
/**
73+
*
74+
* Copies SystemBundleOption entries into the Karaf system folder using the Maven repository folder convention.
75+
*
76+
* @throws IOException if copy fails
77+
*/
78+
public void copySystemLibraries() throws IOException {
79+
SystemBundleOption[] systemBundleOptions = subsystem
80+
.getOptions(SystemBundleOption.class);
81+
for (SystemBundleOption systemBundleOption : systemBundleOptions) {
82+
UrlReference libraryUrl = systemBundleOption.getLibraryUrl();
83+
String destPath = karafHome + "/system" + systemBundleOption.getRepositoryPath();
84+
FileUtils.copyURLToFile(
85+
new URL(libraryUrl.getURL()),
86+
new File(destPath));
87+
}
88+
}
89+
7390
/**
7491
* Copy dependencies specified as ProvisionOption in system to the deploy folder
7592
*/

containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/container/internal/KarafTestContainer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public synchronized TestContainer start() {
156156
DependenciesDeployer deployer = new DependenciesDeployer(subsystem, karafBase,
157157
karafHome);
158158
deployer.copyBootClasspathLibraries();
159+
deployer.copySystemLibraries();
159160

160161
updateLogProperties(karafHome, subsystem);
161162
setupSystemProperties(karafHome, subsystem);

containers/pax-exam-container-karaf/src/main/java/org/ops4j/pax/exam/karaf/options/KarafDistributionOption.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
import org.ops4j.pax.exam.Option;
3131
import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel;
32+
import org.ops4j.pax.exam.options.CompositeOption;
33+
import org.ops4j.pax.exam.options.DefaultCompositeOption;
3234
import org.ops4j.pax.exam.options.UrlReference;
3335
import org.ops4j.pax.exam.options.extra.VMOption;
3436

@@ -109,6 +111,34 @@ public static KarafDistributionConfigurationSecurityOption configureSecurity() {
109111
return new KarafDistributionConfigurationSecurityOption(null);
110112
}
111113

114+
/**
115+
* Returns an option to adding an artifact to the Karaf system directory using the provided file.
116+
* A corresponding (maven) entry will also be placed into the startup.properties configuration.
117+
*
118+
* @return
119+
*/
120+
public static CompositeOption systemBundle(String aGroup, String artifact, String version, File file) {
121+
return new DefaultCompositeOption(
122+
new SystemBundleOption(aGroup, artifact, version, file),
123+
editConfigurationFilePut("etc/startup.properties",
124+
"mvn:" + aGroup + "/" + artifact + "/" + version, "5")
125+
);
126+
}
127+
128+
/**
129+
* Returns an option to adding an artifact to the Karaf system directory using the provided file.
130+
* A corresponding (maven) entry will also be placed into the startup.properties configuration.
131+
*
132+
* @return
133+
*/
134+
public static CompositeOption systemBundle(String aGroup, String artifact, String version) {
135+
return new DefaultCompositeOption(
136+
new SystemBundleOption(aGroup, artifact, version),
137+
editConfigurationFilePut("etc/startup.properties",
138+
"mvn:" + aGroup + "/" + artifact + "/" + version, "5")
139+
);
140+
}
141+
112142
/**
113143
* Configures which distribution options to use. Relevant are the frameworkURL, the
114144
* frameworkName and the Karaf version since all of those params are relevant to decide which
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.ops4j.pax.exam.karaf.options;
18+
19+
import org.ops4j.pax.exam.Option;
20+
import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
21+
import org.ops4j.pax.exam.options.RawUrlReference;
22+
import org.ops4j.pax.exam.options.UrlReference;
23+
24+
import java.io.File;
25+
import java.net.MalformedURLException;
26+
27+
/**
28+
* Copies the specified file into the Karaf system folder. (A Karaf folder that follows the m2 directory structure)
29+
*/
30+
public class SystemBundleOption implements Option {
31+
32+
private String group;
33+
private String artifact;
34+
private String version;
35+
private File file;
36+
37+
38+
public SystemBundleOption(String aGroup, String artifact, String version, File file) {
39+
addSystemBundle(aGroup, artifact, version, file);
40+
}
41+
42+
public SystemBundleOption(String aGroup, String artifact, String version) {
43+
addSystemBundle(aGroup, artifact, version);
44+
}
45+
46+
public String getGroup() {
47+
return group;
48+
}
49+
50+
public String getArtifact() {
51+
return artifact;
52+
}
53+
54+
public String getVersion() {
55+
return version;
56+
}
57+
58+
public SystemBundleOption addSystemBundle(String aGroup, String artifact, String version) {
59+
return addSystemBundle(aGroup, artifact, version, null);
60+
}
61+
62+
public SystemBundleOption addSystemBundle(String aGroup, String artifact, String version, File file) {
63+
this.group = aGroup;
64+
this.artifact = artifact;
65+
this.version = version;
66+
this.file = file;
67+
return this;
68+
}
69+
70+
/**
71+
*
72+
* @return The URL to fetch the artifact
73+
*/
74+
public UrlReference getLibraryUrl() {
75+
if (file != null) {
76+
try {
77+
return new RawUrlReference(file.toURI().toURL().toString());
78+
} catch (MalformedURLException e) {
79+
e.printStackTrace();
80+
return null;
81+
}
82+
} else {
83+
return new MavenArtifactUrlReference().groupId(group).artifactId(artifact).version(version);
84+
}
85+
}
86+
87+
/**
88+
*
89+
* @return The maven repository path to the artifact. Must start with <strong>/</strong>.
90+
* This path should not include the /system prefix.
91+
*/
92+
public String getRepositoryPath() {
93+
String path = "/" + getGroup().replace(".", "/");
94+
path += "/" + getArtifact();
95+
path += "/" + getVersion();
96+
if (file != null) {
97+
path += "/" + file.getName();
98+
} else {
99+
path += "/" + getArtifact() + "-" + getVersion() + ".jar";
100+
}
101+
return path;
102+
}
103+
}

0 commit comments

Comments
 (0)