--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.odlparent.featuretest;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import org.eclipse.jdt.annotation.NonNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class KarafConstants {
+ private static final Logger LOG = LoggerFactory.getLogger(KarafConstants.class);
+
+ /**
+ * Property file used to store the Karaf distribution version.
+ */
+ private static final String PROPERTIES_FILENAME = "/singlefeaturetest.properties";
+ private static final String KARAF_DISTRO_VERSION_PROP = "karaf.distro.version";
+ private static final String KARAF_RELEASE_VERSION_PROP = "karaf.release.version";
+
+ private static final @NonNull String KARAF_DISTRO_VERSION;
+ private static final @NonNull String KARAF_RELEASE_VERSION;
+
+ static {
+ final InputStream input = KarafConstants.class.getResourceAsStream(PROPERTIES_FILENAME);
+ if (input == null) {
+ throw new IllegalStateException("Failed to open resource \"" + PROPERTIES_FILENAME + "\"");
+ }
+
+ final Properties props = new Properties();
+ try {
+ // We use a properties file to retrieve Karaf's version, instead of .versionAsInProject()
+ // This avoids forcing all users to depend on Karaf in their POMs
+ props.load(input);
+ } catch (IOException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+
+ KARAF_DISTRO_VERSION = nonnullProp(props, KARAF_DISTRO_VERSION_PROP);
+ KARAF_RELEASE_VERSION = nonnullProp(props, KARAF_RELEASE_VERSION_PROP);
+ }
+
+ private KarafConstants() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Return Karaf distribution version. This defaults to this project version, as we use opendaylight-karaf-empty
+ * from this project. It can be overridden via a system property.
+ *
+ * @return Distribution version
+ */
+ static @NonNull String karafDistroVersion() {
+ return systemOrFile(KARAF_DISTRO_VERSION_PROP, KARAF_DISTRO_VERSION);
+ }
+
+ /**
+ * Return Karaf release version. This is upstream karaf release which is contained within the distribution. Note
+ * this is distinct from {@link #karafDistroVersion()}.
+ *
+ * @return Karaf version
+ */
+ static @NonNull String karafReleaseVersion() {
+ return systemOrFile(KARAF_RELEASE_VERSION_PROP, KARAF_RELEASE_VERSION);
+ }
+
+ private static @NonNull String systemOrFile(final String key, final @NonNull String fileVal) {
+ String ret = System.getProperty(key);
+ if (ret == null) {
+ ret = fileVal;
+ LOG.info("Retrieved {} value {} from properties file {}", key, ret, key);
+ } else {
+ LOG.info("Retrieved {} value {} from system properties", key, ret);
+ }
+ return ret;
+ }
+
+ private static @NonNull String nonnullProp(final Properties props, final String key) {
+ final String ret = props.getProperty(requireNonNull(key));
+ if (ret == null) {
+ throw new IllegalStateException("Property \"" + key + "\" not found");
+ }
+ return ret;
+ }
+}
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.EnumSet;
-import java.util.Properties;
import javax.inject.Inject;
import org.apache.karaf.bundle.core.BundleService;
import org.apache.karaf.features.Feature;
/*
* Property names to override defaults for karaf distro artifactId, groupId, version, and type
*/
- private static final String KARAF_DISTRO_VERSION_PROP = "karaf.distro.version";
private static final String KARAF_DISTRO_TYPE_PROP = "karaf.distro.type";
private static final String KARAF_DISTRO_ARTIFACTID_PROP = "karaf.distro.artifactId";
private static final String KARAF_DISTRO_GROUPID_PROP = "karaf.distro.groupId";
- /**
- * Property file used to store the Karaf distribution version.
- */
- private static final String PROPERTIES_FILENAME = "singlefeaturetest.properties";
-
/**
* <p>List of Karaf 4.2.6 default maven repositories with snapshot repositories excluded.</p>
* <p>Unfortunately this must be hard-coded since declarative model which uses Options,
@Inject @NonNull
private FeaturesService featuresService;
- private String karafVersion;
+ private String karafReleaseVersion;
private String karafDistroVersion;
@ProbeBuilder
return baseConfig;
}
- final String version = getKarafVersion();
+ final String version = getKarafReleaseVersion();
return OptionUtils.combine(baseConfig, new VMOption[] {
new VMOption("--add-reads=java.xml=java.logging"),
new VMOption("--add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED"),
return File.createTempFile("SingleFeatureTest-Karaf-JavaFlightRecorder", ".jfr").getAbsolutePath();
}
- private String getKarafVersion() throws IOException {
- if (karafVersion == null) {
- // We use a properties file to retrieve Karaf's version, instead of .versionAsInProject()
- // This avoids forcing all users to depend on Karaf in their POMs
- Properties singleFeatureTestProps = new Properties();
- try (InputStream singleFeatureTestInputStream = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(PROPERTIES_FILENAME)) {
- if (singleFeatureTestInputStream == null) {
- throw new IOException("Resource not found; expected to be present on current thread classloader: "
- + PROPERTIES_FILENAME);
- }
- singleFeatureTestProps.load(singleFeatureTestInputStream);
- }
- karafVersion = singleFeatureTestProps.getProperty(KARAF_DISTRO_VERSION_PROP);
-
- LOG.info("Retrieved karafVersion {} from properties file {}", karafVersion, PROPERTIES_FILENAME);
- } else {
- LOG.info("Retrieved karafVersion {} from system property {}", karafVersion, KARAF_DISTRO_VERSION_PROP);
+ private String getKarafReleaseVersion() throws IOException {
+ if (karafReleaseVersion == null) {
+ karafReleaseVersion = KarafConstants.karafReleaseVersion();
}
-
- return karafVersion;
+ return karafReleaseVersion;
}
- private String getKarafDistroVersion() throws IOException {
+ private String getKarafDistroVersion() {
if (karafDistroVersion == null) {
- karafDistroVersion = System.getProperty(KARAF_DISTRO_VERSION_PROP);
- if (karafDistroVersion == null) {
- karafDistroVersion = getKarafVersion();
- } else {
- LOG.info("Retrieved karafDistroVersion {} from system property {}", karafVersion,
- KARAF_DISTRO_VERSION_PROP);
- }
+ karafDistroVersion = KarafConstants.karafDistroVersion();
}
-
return karafDistroVersion;
}
karaf.distro.version=${project.version}
+karaf.release.version=${karaf.version}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.odlparent.featuretest;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class KarafConstantsTest {
+ @Test
+ public void testKarafVersions() {
+ assertNotNull(KarafConstants.karafDistroVersion());
+ assertNotNull(KarafConstants.karafReleaseVersion());
+ }
+}