diff options
author | wolframhaussig <13997737+wolframhaussig@users.noreply.github.com> | 2021-06-15 18:57:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 19:57:03 +0300 |
commit | d18706e9d0efec02e6b543a2c3f1110f260ab8ec (patch) | |
tree | 4aec134d74e4349f7c1e1121744e82e7b3963857 | |
parent | 503d7866051e3ee13e74d820550e54e9bdbc8b9c (diff) | |
download | pf4j-d18706e9d0efec02e6b543a2c3f1110f260ab8ec.tar.gz pf4j-d18706e9d0efec02e6b543a2c3f1110f260ab8ec.zip |
Do not rely on version from Manifest (#455)
-rw-r--r-- | pf4j/pom.xml | 12 | ||||
-rw-r--r-- | pf4j/src/main/java-templates/org/pf4j/Pf4jInfo.java | 28 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/AbstractPluginManager.java | 12 | ||||
-rw-r--r-- | pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java | 7 |
4 files changed, 48 insertions, 11 deletions
diff --git a/pf4j/pom.xml b/pf4j/pom.xml index a3fa87f..6ea4f4c 100644 --- a/pf4j/pom.xml +++ b/pf4j/pom.xml @@ -20,6 +20,18 @@ <build> <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>templating-maven-plugin</artifactId> + <executions> + <execution> + <id>filter-src</id> + <goals> + <goal>filter-sources</goal> + </goals> + </execution> + </executions> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> diff --git a/pf4j/src/main/java-templates/org/pf4j/Pf4jInfo.java b/pf4j/src/main/java-templates/org/pf4j/Pf4jInfo.java new file mode 100644 index 0000000..d2616f8 --- /dev/null +++ b/pf4j/src/main/java-templates/org/pf4j/Pf4jInfo.java @@ -0,0 +1,28 @@ +/*
+ * Copyright (C) 2012-present the original author or authors.
+ *
+ * Licensed 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.pf4j;
+
+/**
+ * This class provides access to the current Pf4j version which might otherwise not be possible:
+ * e.g. in Uber-Jars where the Manifest was merged and the Pf4j info was overridden
+ * @author Wolfram Haussig
+ */
+public class Pf4jInfo {
+ /**
+ * the current Pf4j version
+ */
+ public static final String VERSION = "${project.version}";
+}
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 2374b56..d57b12e 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -660,17 +660,7 @@ public abstract class AbstractPluginManager implements PluginManager { } public String getVersion() { - String version = null; - - Package pf4jPackage = PluginManager.class.getPackage(); - if (pf4jPackage != null) { - version = pf4jPackage.getImplementationVersion(); - if (version == null) { - version = pf4jPackage.getSpecificationVersion(); - } - } - - return (version != null) ? version : "0.0.0"; + return Pf4jInfo.VERSION; } protected abstract PluginRepository createPluginRepository(); diff --git a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java index f1824f7..c43bc63 100644 --- a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java +++ b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,5 +46,11 @@ public class AbstractPluginManagerTest { List<TestExtensionPoint> extensions = pluginManager.getExtensions(TestExtensionPoint.class); assertEquals(1, extensions.size()); } + + @Test + public void getVersion() { + AbstractPluginManager pluginManager = mock(AbstractPluginManager.class, CALLS_REAL_METHODS); + assertNotEquals("0.0.0", pluginManager.getVersion()); + } } |