]> source.dussan.org Git - pf4j.git/commitdiff
Do not rely on version from Manifest (#455)
authorwolframhaussig <13997737+wolframhaussig@users.noreply.github.com>
Tue, 15 Jun 2021 16:57:03 +0000 (18:57 +0200)
committerGitHub <noreply@github.com>
Tue, 15 Jun 2021 16:57:03 +0000 (19:57 +0300)
pf4j/pom.xml
pf4j/src/main/java-templates/org/pf4j/Pf4jInfo.java [new file with mode: 0644]
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java

index a3fa87f52d398df041d89aad5329386c0feb5f38..6ea4f4cbd9c6fcbf5527698b6557370105c0039a 100644 (file)
 
     <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 (file)
index 0000000..d2616f8
--- /dev/null
@@ -0,0 +1,28 @@
+/*\r
+ * Copyright (C) 2012-present the original author or authors.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package org.pf4j;\r
+\r
+/**\r
+ * This class provides access to the current Pf4j version which might otherwise not be possible:\r
+ * e.g. in Uber-Jars where the Manifest was merged and the Pf4j info was overridden\r
+ * @author Wolfram Haussig\r
+ */\r
+public class Pf4jInfo {\r
+    /**\r
+     * the current Pf4j version\r
+     */\r
+    public static final String VERSION = "${project.version}";\r
+}\r
index 2374b56e5affc928e0046917e7175e23d334c92b..d57b12e9195d50dbd75f52ec52b53b6e9d5be793 100644 (file)
@@ -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();
index f1824f76739274af74ef0cd61a4221662b832c32..c43bc635b9bd982d694b990669c7612b8dd6e5d0 100644 (file)
@@ -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());
+    }
 
 }