]> source.dussan.org Git - pf4j.git/commitdiff
Rename org.pf4j.plugin package to org.pf4j.test
authorDecebal Suiu <decebal.suiu@gmail.com>
Wed, 6 Jan 2021 18:34:25 +0000 (20:34 +0200)
committerDecebal Suiu <decebal.suiu@gmail.com>
Wed, 6 Jan 2021 18:34:25 +0000 (20:34 +0200)
37 files changed:
pf4j/pom.xml
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java
pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java
pf4j/src/test/java/org/pf4j/LegacyExtensionFinderTest.java
pf4j/src/test/java/org/pf4j/LoadPluginsFromMultipleRootsTest.java
pf4j/src/test/java/org/pf4j/LoadPluginsTest.java
pf4j/src/test/java/org/pf4j/ManifestPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/PluginClassLoaderTest.java
pf4j/src/test/java/org/pf4j/PropertiesPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/SingletonExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/plugin/AnotherFailTestPlugin.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/ClassDataProvider.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/DefaultClassDataProvider.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/FailTestExtension.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/FailTestPlugin.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/PluginJar.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/PluginZip.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/TestExtension.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/TestExtensionPoint.java [deleted file]
pf4j/src/test/java/org/pf4j/plugin/TestPlugin.java [deleted file]
pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/ClassDataProvider.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/DefaultClassDataProvider.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/FailTestExtension.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/FailTestPlugin.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/PluginJar.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/PluginZip.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/TestExtension.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/TestExtensionPoint.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/test/TestPlugin.java [new file with mode: 0644]
pf4j/src/test/java/org/pf4j/util/FileUtilsTest.java

index 0bcac25f42ab94f8f8880a74019845d42774227e..06f016f6be567b79a4fc4d1e6cfb3e83ed40168c 100644 (file)
@@ -73,7 +73,7 @@
                         </goals>
                         <configuration>
                             <includes>
-                                <inculde>org/pf4j/plugin/*</inculde>
+                                <inculde>org/pf4j/test/*</inculde>
                             </includes>
                         </configuration>
                     </execution>
index e841189604482fe17f95cec0ea718f2d325999f1..f809d6cda0001d4be4423cfeaf59e43832b11691 100644 (file)
@@ -22,8 +22,8 @@ import java.util.Comparator;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.FailTestPlugin;
-import org.pf4j.plugin.TestExtensionPoint;
+import org.pf4j.test.FailTestPlugin;
+import org.pf4j.test.TestExtensionPoint;
 
 import javax.tools.JavaFileObject;
 import java.io.IOException;
index 784d1f9830a3d48dd631409fc255dfe81f3d3daa..f1824f76739274af74ef0cd61a4221662b832c32 100644 (file)
@@ -16,8 +16,8 @@
 package org.pf4j;
 
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.TestExtension;
-import org.pf4j.plugin.TestExtensionPoint;
+import org.pf4j.test.TestExtension;
+import org.pf4j.test.TestExtensionPoint;
 
 import java.util.ArrayList;
 import java.util.List;
index c16839e21c0e121fc90393cdaf3b119cc876d6fa..f80c19e178f6844737f07ae431686ead97cd0626 100644 (file)
@@ -17,9 +17,9 @@ package org.pf4j;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
-import org.pf4j.plugin.PluginZip;
-import org.pf4j.plugin.TestPlugin;
+import org.pf4j.test.PluginJar;
+import org.pf4j.test.PluginZip;
+import org.pf4j.test.TestPlugin;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
index 150828f36103084b909e792d1475c701bb6b9f29..9d73b5e42ce1bc71ea9ab1bf728d7791d4a9fb77 100644 (file)
@@ -18,8 +18,8 @@ package org.pf4j;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.FailTestExtension;
-import org.pf4j.plugin.TestExtension;
+import org.pf4j.test.FailTestExtension;
+import org.pf4j.test.TestExtension;
 
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
index eccfca2f2ea84218d5ede8819bde35aa413584ce..31070839821f2d036fa63ca30c2ab01ba2b4661c 100644 (file)
@@ -16,9 +16,9 @@
 package org.pf4j;
 
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.AnotherFailTestPlugin;
-import org.pf4j.plugin.FailTestPlugin;
-import org.pf4j.plugin.TestPlugin;
+import org.pf4j.test.AnotherFailTestPlugin;
+import org.pf4j.test.FailTestPlugin;
+import org.pf4j.test.TestPlugin;
 
 import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.MatcherAssert.assertThat;
index ae512823f33a9f610cefb84b9a9320e987c42cf8..fab1a02ed7eedb51c711b92e733896c6c58be302 100644 (file)
@@ -19,8 +19,8 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginJar;
+import org.pf4j.test.PluginZip;
 
 import java.io.IOException;
 import java.nio.file.Files;
index b8ffd7c248aec1286cd415b2ac26805d5ebcd839..c11938d44b5c46327784f9708be581aa7478b69b 100644 (file)
@@ -18,7 +18,7 @@ package org.pf4j;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginZip;
 import org.pf4j.util.FileUtils;
 
 import java.io.IOException;
index 4eb28729d2bf66fa09221d47468956804aea58c6..0e16f752e3e929cd5e283c47b438f8f13e08a45c 100644 (file)
@@ -19,10 +19,10 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
-import org.pf4j.plugin.TestExtension;
-import org.pf4j.plugin.TestExtensionPoint;
-import org.pf4j.plugin.TestPlugin;
+import org.pf4j.test.PluginJar;
+import org.pf4j.test.TestExtension;
+import org.pf4j.test.TestExtensionPoint;
+import org.pf4j.test.TestPlugin;
 
 import java.io.IOException;
 import java.nio.file.Path;
index 8f5a72739ddb3006da488a40029e26a05281984f..bde5417f346cd55a38faa1636a9e050fcc175b9e 100644 (file)
@@ -18,9 +18,9 @@ package org.pf4j;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.EnabledOnOs;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
-import org.pf4j.plugin.TestExtension;
-import org.pf4j.plugin.TestPlugin;
+import org.pf4j.test.PluginJar;
+import org.pf4j.test.TestExtension;
+import org.pf4j.test.TestPlugin;
 
 import java.nio.file.Path;
 import java.util.Map;
index 2117a628bd164dfb6ca1bb54240cdd02986eb46b..9396f15bd20bcee4fbaf5c844b32908614533114 100644 (file)
@@ -18,7 +18,7 @@ package org.pf4j;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginZip;
 import org.pf4j.util.FileUtils;
 
 import java.io.IOException;
index ef2376b4ad884366e50b5c29941a6ea0d0167d28..189bd0a2f49609ccb7228c33b565a0463c51e823 100644 (file)
@@ -18,7 +18,7 @@ package org.pf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginZip;
 
 import java.nio.file.Files;
 import java.nio.file.Path;
index 468f2fb555dd844073a5248e8c05ceda5d0ad7ac..079d8e235bc0e4f18cb3931510a0928f2ce55d32 100644 (file)
@@ -18,7 +18,7 @@ package org.pf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginJar;
+import org.pf4j.test.PluginJar;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
index b0316c7cc40718cf32fecc86c531ba619d6dc4d8..fb75f27708ee084a3e56480fdd790346fb1fe0aa 100644 (file)
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginZip;
 import org.pf4j.util.FileUtils;
 
 import java.io.File;
@@ -49,7 +49,7 @@ public class PluginClassLoaderTest {
 
     private PluginClassLoader parentLastPluginClassLoader;
     private PluginClassLoader parentFirstPluginClassLoader;
-    
+
     private PluginClassLoader parentLastPluginDependencyClassLoader;
     private PluginClassLoader parentFirstPluginDependencyClassLoader;
 
@@ -95,7 +95,7 @@ public class PluginClassLoaderTest {
         pluginDependencyDescriptor.setProvider("Me");
         pluginDependencyDescriptor.setRequires("5.0.0");
 
-        
+
         Path pluginDependencyPath = pluginsPath.resolve(pluginDependencyDescriptor.getPluginId() + "-" + pluginDependencyDescriptor.getVersion() + ".zip");
         PluginZip pluginDependencyZip = new PluginZip.Builder(pluginDependencyPath, pluginDependencyDescriptor.getPluginId())
                 .pluginVersion(pluginDependencyDescriptor.getVersion())
@@ -110,11 +110,11 @@ public class PluginClassLoaderTest {
 
         parentLastPluginDependencyClassLoader = new PluginClassLoader(pluginManager, pluginDependencyDescriptor, PluginClassLoaderTest.class.getClassLoader());
         parentFirstPluginDependencyClassLoader = new PluginClassLoader(pluginManagerParentFirst, pluginDependencyDescriptor, PluginClassLoaderTest.class.getClassLoader(), true);
-        
+
         pluginManager.addClassLoader(pluginDependencyDescriptor.getPluginId(), parentLastPluginDependencyClassLoader);
         pluginManagerParentFirst.addClassLoader(pluginDependencyDescriptor.getPluginId(), parentFirstPluginDependencyClassLoader);
-        
-        
+
+
         for (String classesDirectory : pluginDependencyClasspath.getClassesDirectories()) {
             File classesDirectoryFile = pluginDependencyZip.unzippedPath().resolve(classesDirectory).toFile();
             parentLastPluginDependencyClassLoader.addFile(classesDirectoryFile);
@@ -129,7 +129,7 @@ public class PluginClassLoaderTest {
                parentFirstPluginDependencyClassLoader.addFile(jar);
             }
         }
-        
+
         pluginDescriptor = new DefaultPluginDescriptor();
         pluginDescriptor.setPluginId("myPlugin");
         pluginDescriptor.setPluginVersion("1.2.3");
@@ -155,7 +155,7 @@ public class PluginClassLoaderTest {
 
         pluginManager.addClassLoader(pluginDescriptor.getPluginId(), parentLastPluginClassLoader);
         pluginManagerParentFirst.addClassLoader(pluginDescriptor.getPluginId(), parentFirstPluginClassLoader);
-        
+
         for (String classesDirectory : pluginClasspath.getClassesDirectories()) {
             File classesDirectoryFile = pluginZip.unzippedPath().resolve(classesDirectory).toFile();
             parentLastPluginClassLoader.addFile(classesDirectoryFile);
@@ -196,7 +196,7 @@ public class PluginClassLoaderTest {
         URL resource = parentLastPluginClassLoader.getResource("META-INF/file-only-in-parent");
         assertFirstLine("parent", resource);
     }
-    
+
     @Test
     void parentFirstGetResourceExistsInParent() throws IOException, URISyntaxException {
         URL resource = parentFirstPluginClassLoader.getResource("META-INF/file-only-in-parent");
@@ -214,7 +214,7 @@ public class PluginClassLoaderTest {
         URL resource = parentFirstPluginClassLoader.getResource("META-INF/plugin-file");
         assertFirstLine("plugin", resource);
     }
-    
+
     @Test
     void parentLastGetResourceExistsOnlyInDependnecy() throws IOException, URISyntaxException {
         URL resource = parentLastPluginClassLoader.getResource("META-INF/dependency-file");
@@ -238,13 +238,13 @@ public class PluginClassLoaderTest {
         URL resource = parentFirstPluginClassLoader.getResource("META-INF/file-in-both-parent-and-plugin");
         assertFirstLine("parent", resource);
     }
-    
+
     @Test
     void parentLastGetResourceExistsInParentAndDependencyAndPlugin() throws URISyntaxException, IOException {
         URL resource = parentLastPluginClassLoader.getResource("META-INF/file-in-both-parent-and-dependency-and-plugin");
         assertFirstLine("plugin", resource);
     }
-    
+
     @Test
     void parentFirstGetResourceExistsInParentAndDependencyAndPlugin() throws URISyntaxException, IOException {
         URL resource = parentFirstPluginClassLoader.getResource("META-INF/file-in-both-parent-and-dependency-and-plugin");
@@ -284,7 +284,7 @@ public class PluginClassLoaderTest {
         Enumeration<URL> resources = parentFirstPluginClassLoader.getResources("META-INF/dependency-file");
         assertNumberOfResourcesAndFirstLineOfFirstElement(1, "dependency", resources);
     }
-    
+
     @Test
     void parentLastGetResourcesExistsOnlyInPlugin() throws IOException, URISyntaxException {
         Enumeration<URL> resources = parentLastPluginClassLoader.getResources("META-INF/plugin-file");
@@ -308,7 +308,7 @@ public class PluginClassLoaderTest {
         Enumeration<URL> resources = parentFirstPluginClassLoader.getResources("META-INF/file-in-both-parent-and-plugin");
         assertNumberOfResourcesAndFirstLineOfFirstElement(2, "parent", resources);
     }
-    
+
     @Test
     void parentLastGetResourcesExistsInParentAndDependencyAndPlugin() throws URISyntaxException, IOException {
         Enumeration<URL> resources = parentLastPluginClassLoader.getResources("META-INF/file-in-both-parent-and-dependency-and-plugin");
@@ -333,9 +333,9 @@ public class PluginClassLoaderTest {
         URL firstResource = list.get(0);
         assertEquals(expectedFirstLine, Files.readAllLines(Paths.get(firstResource.toURI())).get(0));
     }
-    
+
     class TestPluginManager extends DefaultPluginManager {
-       
+
        public TestPluginManager(Path pluginsPath) {
                        super(pluginsPath);
                }
index bc91a7fa3568ecd2bdca9ce650d16fef20c77f04..4d73a4f3f2e131d6cc17b4ff9d9cd23173aa586a 100644 (file)
@@ -18,8 +18,8 @@ package org.pf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginZip;
-import org.pf4j.plugin.TestPlugin;
+import org.pf4j.test.PluginZip;
+import org.pf4j.test.TestPlugin;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
index ac8a3c5a81160b85e92eab8b0cfcb756d03c44ef..104403407cf2961fb36fcd5bda5b213d660e4259 100644 (file)
@@ -16,8 +16,8 @@
 package org.pf4j;
 
 import org.junit.jupiter.api.Test;
-import org.pf4j.plugin.FailTestExtension;
-import org.pf4j.plugin.TestExtension;
+import org.pf4j.test.FailTestExtension;
+import org.pf4j.test.TestExtension;
 
 import java.io.File;
 import java.net.MalformedURLException;
diff --git a/pf4j/src/test/java/org/pf4j/plugin/AnotherFailTestPlugin.java b/pf4j/src/test/java/org/pf4j/plugin/AnotherFailTestPlugin.java
deleted file mode 100644 (file)
index b45f343..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.Plugin;
-
-/**
- * @author Mario Franco
- */
-public class AnotherFailTestPlugin extends Plugin {
-
-    public AnotherFailTestPlugin() {
-        super(null);
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/ClassDataProvider.java b/pf4j/src/test/java/org/pf4j/plugin/ClassDataProvider.java
deleted file mode 100644 (file)
index ff55967..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.plugin;
-
-/**
- * Defines the interface for classes that know to supply class data for a class name.
- * The idea is to have the possibility to retrieve the data for a class from different sources:
- * <ul>
- * <li>Class path - the class is already loaded by the class loader</li>
- * <li>String - the string (the source code) is compiled dynamically via {@link javax.tools.JavaCompiler}</>
- * <li>Generate the source code programmatically using something like {@code https://github.com/square/javapoet}</li>
- * </ul>
- *
- * @author Decebal Suiu
- */
-public interface ClassDataProvider {
-
-    byte[] getClassData(String className);
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/DefaultClassDataProvider.java b/pf4j/src/test/java/org/pf4j/plugin/DefaultClassDataProvider.java
deleted file mode 100644 (file)
index ef0eaf9..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.plugin;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * Get class data from the class path.
- *
- * @author Decebal Suiu
- */
-public class DefaultClassDataProvider implements ClassDataProvider {
-
-    @Override
-    public byte[] getClassData(String className) {
-        String path = className.replace('.', '/') + ".class";
-        InputStream classDataStream = getClass().getClassLoader().getResourceAsStream(path);
-        if (classDataStream == null) {
-            throw new RuntimeException("Cannot find class data");
-        }
-
-        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
-            copyStream(classDataStream, outputStream);
-            return outputStream.toByteArray();
-        } catch (IOException e) {
-            throw new RuntimeException(e.getMessage(), e);
-        }
-    }
-
-    private void copyStream(InputStream in, OutputStream out) throws IOException {
-        byte[] buffer = new byte[1024];
-
-        int bytesRead;
-        while ((bytesRead = in.read(buffer)) != -1) {
-            out.write(buffer, 0, bytesRead);
-        }
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/FailTestExtension.java b/pf4j/src/test/java/org/pf4j/plugin/FailTestExtension.java
deleted file mode 100644 (file)
index 13b51ee..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.Extension;
-
-/**
- * @author Mario Franco
- */
-@Extension
-public class FailTestExtension implements TestExtensionPoint {
-
-    public FailTestExtension(String name) {
-    }
-
-    @Override
-    public String saySomething() {
-        return "I am a fail test extension";
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/FailTestPlugin.java b/pf4j/src/test/java/org/pf4j/plugin/FailTestPlugin.java
deleted file mode 100644 (file)
index fab11c9..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.plugin;
-
-/**
- * @author Mario Franco
- */
-public class FailTestPlugin {
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java b/pf4j/src/test/java/org/pf4j/plugin/PluginJar.java
deleted file mode 100644 (file)
index 4a08e20..0000000
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.ManifestPluginDescriptorFinder;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.nio.file.Path;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-/**
- * Represents a plugin {@code jar} file.
- * The {@code MANIFEST.MF} file is created on the fly from the information supplied in {@link Builder}.
- *
- * @author Decebal Suiu
- */
-public class PluginJar {
-
-    private final Path path;
-    private final String pluginId;
-    private final String pluginClass;
-    private final String pluginVersion;
-
-    protected PluginJar(Builder builder) {
-        this.path = builder.path;
-        this.pluginId = builder.pluginId;
-        this.pluginClass = builder.pluginClass;
-        this.pluginVersion = builder.pluginVersion;
-    }
-
-    public Path path() {
-        return path;
-    }
-
-    public File file() {
-        return path.toFile();
-    }
-
-    public String pluginClass() {
-        return pluginClass;
-    }
-
-    public String pluginId() {
-        return pluginId;
-    }
-
-    public String pluginVersion() {
-        return pluginVersion;
-    }
-
-    public static Manifest createManifest(Map<String, String> map) {
-        Manifest manifest = new Manifest();
-        Attributes attributes = manifest.getMainAttributes();
-        attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
-        for (Map.Entry<String, String> entry : map.entrySet()) {
-            attributes.put(new Attributes.Name(entry.getKey()), entry.getValue());
-        }
-
-        return manifest;
-    }
-
-    public static class Builder {
-
-        private final Path path;
-        private final String pluginId;
-
-        private String pluginClass;
-        private String pluginVersion;
-        private Map<String, String> manifestAttributes = new LinkedHashMap<>();
-        private Set<String> extensions = new LinkedHashSet<>();
-        private ClassDataProvider classDataProvider = new DefaultClassDataProvider();
-
-        public Builder(Path path, String pluginId) {
-            this.path = path;
-            this.pluginId = pluginId;
-        }
-
-        public Builder pluginClass(String pluginClass) {
-            this.pluginClass = pluginClass;
-
-            return this;
-        }
-
-        public Builder pluginVersion(String pluginVersion) {
-            this.pluginVersion = pluginVersion;
-
-            return this;
-        }
-
-        /**
-         * Add extra attributes to the {@code manifest} file.
-         * As possible attribute name please see {@link ManifestPluginDescriptorFinder}.
-         */
-        public Builder manifestAttributes(Map<String, String> manifestAttributes) {
-            this.manifestAttributes.putAll(manifestAttributes);
-
-            return this;
-        }
-
-        /**
-         * Add extra attribute to the {@code manifest} file.
-         * As possible attribute name please see {@link ManifestPluginDescriptorFinder}.
-         */
-        public Builder manifestAttribute(String name, String value) {
-            manifestAttributes.put(name, value);
-
-            return this;
-        }
-
-        public Builder extension(String extensionClassName) {
-            extensions.add(extensionClassName);
-
-            return this;
-        }
-
-        public Builder classDataProvider(ClassDataProvider classDataProvider) {
-             this.classDataProvider = classDataProvider;
-
-             return this;
-        }
-
-        public PluginJar build() throws IOException {
-            Manifest manifest = createManifest();
-            try (OutputStream outputStream = new FileOutputStream(path.toFile());
-                 JarOutputStream jarOutputStream = new JarOutputStream(outputStream, manifest)) {
-                if (!extensions.isEmpty()) {
-                    // add extensions.idx
-                    JarEntry jarEntry = new JarEntry("META-INF/extensions.idx");
-                    jarOutputStream.putNextEntry(jarEntry);
-                    jarOutputStream.write(extensionsAsByteArray());
-                    jarOutputStream.closeEntry();
-                    // add extensions classes
-                    for (String extension : extensions) {
-                        String extensionPath = extension.replace('.', '/') + ".class";
-                        JarEntry classEntry = new JarEntry(extensionPath);
-                        jarOutputStream.putNextEntry(classEntry);
-                        jarOutputStream.write(classDataProvider.getClassData(extension));
-                        jarOutputStream.closeEntry();
-                    }
-                }
-            }
-
-            return new PluginJar(this);
-        }
-
-        private Manifest createManifest() {
-            Map<String, String> map = new LinkedHashMap<>();
-            map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, pluginId);
-            map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion);
-            if (pluginClass != null) {
-                map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, pluginClass);
-            }
-            if (manifestAttributes != null) {
-                map.putAll(manifestAttributes);
-            }
-
-            return PluginJar.createManifest(map);
-        }
-
-        private byte[] extensionsAsByteArray() throws IOException {
-            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
-                PrintWriter writer = new PrintWriter(outputStream);
-                for (String extension : extensions) {
-                    writer.println(extension);
-                }
-                writer.flush();
-
-                return outputStream.toByteArray();
-            }
-        }
-
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java b/pf4j/src/test/java/org/pf4j/plugin/PluginZip.java
deleted file mode 100644 (file)
index c2da257..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.PropertiesPluginDescriptorFinder;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.file.Path;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * Represents a plugin {@code zip} file.
- * The {@code plugin.properties} file is created on the fly from the information supplied in {@link Builder}.
- *
- * @author Decebal Suiu
- */
-public class PluginZip {
-
-    private final Path path;
-    private final String pluginId;
-    private final String pluginClass;
-    private final String pluginVersion;
-
-    protected PluginZip(Builder builder) {
-        this.path = builder.path;
-        this.pluginId = builder.pluginId;
-        this.pluginClass = builder.pluginClass;
-        this.pluginVersion = builder.pluginVersion;
-    }
-
-    public Path path() {
-        return path;
-    }
-
-    public File file() {
-        return path.toFile();
-    }
-
-    public String pluginId() {
-        return pluginId;
-    }
-
-    public String pluginClass() {
-        return pluginClass;
-    }
-
-    public String pluginVersion() {
-        return pluginVersion;
-    }
-
-    public Path unzippedPath() {
-        Path path = path();
-        String fileName = path.getFileName().toString();
-
-        return path.getParent().resolve(fileName.substring(0, fileName.length() - 4)); // without ".zip" suffix
-    }
-
-    public static Properties createProperties(Map<String, String> map) {
-        Properties properties = new Properties();
-        properties.putAll(map);
-
-        return properties;
-    }
-
-    public static class Builder {
-
-        private final Path path;
-        private final String pluginId;
-
-        private String pluginClass;
-        private String pluginVersion;
-        private Map<String, String> properties = new LinkedHashMap<>();
-        private Map<Path, byte[]> files = new LinkedHashMap<>();
-
-        public Builder(Path path, String pluginId) {
-            this.path = path;
-            this.pluginId = pluginId;
-        }
-
-        public Builder pluginClass(String pluginClass) {
-            this.pluginClass = pluginClass;
-
-            return this;
-        }
-
-        public Builder pluginVersion(String pluginVersion) {
-            this.pluginVersion = pluginVersion;
-
-            return this;
-        }
-
-        /**
-         * Add extra properties to the {@code properties} file.
-         * As possible attribute name please see {@link PropertiesPluginDescriptorFinder}.
-         */
-        public Builder properties(Map<String, String> properties) {
-            this.properties.putAll(properties);
-
-            return this;
-        }
-
-        /**
-         * Add extra property to the {@code properties} file.
-         * As possible property name please see {@link PropertiesPluginDescriptorFinder}.
-         */
-        public Builder property(String name, String value) {
-            properties.put(name, value);
-
-            return this;
-        }
-
-        /**
-         * Adds a file to the archive.
-         *
-         * @param path the relative path of the file
-         * @param content the content of the file
-         */
-        public Builder addFile(Path path, byte[] content) {
-            files.put(path, content.clone());
-
-            return this;
-        }
-
-        /**
-         * Adds a file to the archive.
-         *
-         * @param path the relative path of the file
-         * @param content the content of the file
-         */
-        public Builder addFile(Path path, String content) {
-            files.put(path, content.getBytes());
-
-            return this;
-        }
-
-        public PluginZip build() throws IOException {
-            createPropertiesFile();
-
-            return new PluginZip(this);
-        }
-
-        protected void createPropertiesFile() throws IOException {
-            Map<String, String> map = new LinkedHashMap<>();
-            map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, pluginId);
-            map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion);
-            if (pluginClass != null) {
-                map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, pluginClass);
-            }
-            if (properties != null) {
-                map.putAll(properties);
-            }
-
-            try (ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile()))) {
-                ZipEntry propertiesFile = new ZipEntry(PropertiesPluginDescriptorFinder.DEFAULT_PROPERTIES_FILE_NAME);
-                outputStream.putNextEntry(propertiesFile);
-                createProperties(map).store(outputStream, "");
-                outputStream.closeEntry();
-
-                for (Map.Entry<Path, byte[]> fileEntry : files.entrySet()) {
-                    ZipEntry file = new ZipEntry(fileEntry.getKey().toString());
-                    outputStream.putNextEntry(file);
-                    outputStream.write(fileEntry.getValue());
-                    outputStream.closeEntry();
-                }
-            }
-        }
-
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/TestExtension.java b/pf4j/src/test/java/org/pf4j/plugin/TestExtension.java
deleted file mode 100644 (file)
index 83bc0b5..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.Extension;
-
-/**
- * @author Mario Franco
- */
-@Extension
-public class TestExtension implements TestExtensionPoint {
-
-    @Override
-    public String saySomething() {
-        return "I am a test extension";
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/TestExtensionPoint.java b/pf4j/src/test/java/org/pf4j/plugin/TestExtensionPoint.java
deleted file mode 100644 (file)
index d29a7ab..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.ExtensionPoint;
-
-/**
- * @author Mario Franco
- */
-public interface TestExtensionPoint extends ExtensionPoint {
-
-    String saySomething();
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/plugin/TestPlugin.java b/pf4j/src/test/java/org/pf4j/plugin/TestPlugin.java
deleted file mode 100644 (file)
index f094808..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.plugin;
-
-import org.pf4j.Plugin;
-import org.pf4j.PluginWrapper;
-
-/**
- * @author Mario Franco
- */
-public class TestPlugin extends Plugin {
-
-    public TestPlugin(PluginWrapper wrapper) {
-        super(wrapper);
-    }
-
-}
diff --git a/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java b/pf4j/src/test/java/org/pf4j/test/AnotherFailTestPlugin.java
new file mode 100644 (file)
index 0000000..a32a682
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * 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.test;
+
+import org.pf4j.Plugin;
+
+/**
+ * @author Mario Franco
+ */
+public class AnotherFailTestPlugin extends Plugin {
+
+    public AnotherFailTestPlugin() {
+        super(null);
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/ClassDataProvider.java b/pf4j/src/test/java/org/pf4j/test/ClassDataProvider.java
new file mode 100644 (file)
index 0000000..cc5a984
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.test;
+
+/**
+ * Defines the interface for classes that know to supply class data for a class name.
+ * The idea is to have the possibility to retrieve the data for a class from different sources:
+ * <ul>
+ * <li>Class path - the class is already loaded by the class loader</li>
+ * <li>String - the string (the source code) is compiled dynamically via {@link javax.tools.JavaCompiler}</>
+ * <li>Generate the source code programmatically using something like {@code https://github.com/square/javapoet}</li>
+ * </ul>
+ *
+ * @author Decebal Suiu
+ */
+public interface ClassDataProvider {
+
+    byte[] getClassData(String className);
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/DefaultClassDataProvider.java b/pf4j/src/test/java/org/pf4j/test/DefaultClassDataProvider.java
new file mode 100644 (file)
index 0000000..6a203aa
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * Get class data from the class path.
+ *
+ * @author Decebal Suiu
+ */
+public class DefaultClassDataProvider implements ClassDataProvider {
+
+    @Override
+    public byte[] getClassData(String className) {
+        String path = className.replace('.', '/') + ".class";
+        InputStream classDataStream = getClass().getClassLoader().getResourceAsStream(path);
+        if (classDataStream == null) {
+            throw new RuntimeException("Cannot find class data");
+        }
+
+        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+            copyStream(classDataStream, outputStream);
+            return outputStream.toByteArray();
+        } catch (IOException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    private void copyStream(InputStream in, OutputStream out) throws IOException {
+        byte[] buffer = new byte[1024];
+
+        int bytesRead;
+        while ((bytesRead = in.read(buffer)) != -1) {
+            out.write(buffer, 0, bytesRead);
+        }
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/FailTestExtension.java b/pf4j/src/test/java/org/pf4j/test/FailTestExtension.java
new file mode 100644 (file)
index 0000000..511da42
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.test;
+
+import org.pf4j.Extension;
+
+/**
+ * @author Mario Franco
+ */
+@Extension
+public class FailTestExtension implements TestExtensionPoint {
+
+    public FailTestExtension(String name) {
+    }
+
+    @Override
+    public String saySomething() {
+        return "I am a fail test extension";
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/FailTestPlugin.java b/pf4j/src/test/java/org/pf4j/test/FailTestPlugin.java
new file mode 100644 (file)
index 0000000..7545f6c
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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.test;
+
+/**
+ * @author Mario Franco
+ */
+public class FailTestPlugin {
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/PluginJar.java b/pf4j/src/test/java/org/pf4j/test/PluginJar.java
new file mode 100644 (file)
index 0000000..034b10f
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * 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.test;
+
+import org.pf4j.ManifestPluginDescriptorFinder;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.nio.file.Path;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+/**
+ * Represents a plugin {@code jar} file.
+ * The {@code MANIFEST.MF} file is created on the fly from the information supplied in {@link Builder}.
+ *
+ * @author Decebal Suiu
+ */
+public class PluginJar {
+
+    private final Path path;
+    private final String pluginId;
+    private final String pluginClass;
+    private final String pluginVersion;
+
+    protected PluginJar(Builder builder) {
+        this.path = builder.path;
+        this.pluginId = builder.pluginId;
+        this.pluginClass = builder.pluginClass;
+        this.pluginVersion = builder.pluginVersion;
+    }
+
+    public Path path() {
+        return path;
+    }
+
+    public File file() {
+        return path.toFile();
+    }
+
+    public String pluginClass() {
+        return pluginClass;
+    }
+
+    public String pluginId() {
+        return pluginId;
+    }
+
+    public String pluginVersion() {
+        return pluginVersion;
+    }
+
+    public static Manifest createManifest(Map<String, String> map) {
+        Manifest manifest = new Manifest();
+        Attributes attributes = manifest.getMainAttributes();
+        attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0.0");
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            attributes.put(new Attributes.Name(entry.getKey()), entry.getValue());
+        }
+
+        return manifest;
+    }
+
+    public static class Builder {
+
+        private final Path path;
+        private final String pluginId;
+
+        private String pluginClass;
+        private String pluginVersion;
+        private Map<String, String> manifestAttributes = new LinkedHashMap<>();
+        private Set<String> extensions = new LinkedHashSet<>();
+        private ClassDataProvider classDataProvider = new DefaultClassDataProvider();
+
+        public Builder(Path path, String pluginId) {
+            this.path = path;
+            this.pluginId = pluginId;
+        }
+
+        public Builder pluginClass(String pluginClass) {
+            this.pluginClass = pluginClass;
+
+            return this;
+        }
+
+        public Builder pluginVersion(String pluginVersion) {
+            this.pluginVersion = pluginVersion;
+
+            return this;
+        }
+
+        /**
+         * Add extra attributes to the {@code manifest} file.
+         * As possible attribute name please see {@link ManifestPluginDescriptorFinder}.
+         */
+        public Builder manifestAttributes(Map<String, String> manifestAttributes) {
+            this.manifestAttributes.putAll(manifestAttributes);
+
+            return this;
+        }
+
+        /**
+         * Add extra attribute to the {@code manifest} file.
+         * As possible attribute name please see {@link ManifestPluginDescriptorFinder}.
+         */
+        public Builder manifestAttribute(String name, String value) {
+            manifestAttributes.put(name, value);
+
+            return this;
+        }
+
+        public Builder extension(String extensionClassName) {
+            extensions.add(extensionClassName);
+
+            return this;
+        }
+
+        public Builder classDataProvider(ClassDataProvider classDataProvider) {
+             this.classDataProvider = classDataProvider;
+
+             return this;
+        }
+
+        public PluginJar build() throws IOException {
+            Manifest manifest = createManifest();
+            try (OutputStream outputStream = new FileOutputStream(path.toFile());
+                 JarOutputStream jarOutputStream = new JarOutputStream(outputStream, manifest)) {
+                if (!extensions.isEmpty()) {
+                    // add extensions.idx
+                    JarEntry jarEntry = new JarEntry("META-INF/extensions.idx");
+                    jarOutputStream.putNextEntry(jarEntry);
+                    jarOutputStream.write(extensionsAsByteArray());
+                    jarOutputStream.closeEntry();
+                    // add extensions classes
+                    for (String extension : extensions) {
+                        String extensionPath = extension.replace('.', '/') + ".class";
+                        JarEntry classEntry = new JarEntry(extensionPath);
+                        jarOutputStream.putNextEntry(classEntry);
+                        jarOutputStream.write(classDataProvider.getClassData(extension));
+                        jarOutputStream.closeEntry();
+                    }
+                }
+            }
+
+            return new PluginJar(this);
+        }
+
+        private Manifest createManifest() {
+            Map<String, String> map = new LinkedHashMap<>();
+            map.put(ManifestPluginDescriptorFinder.PLUGIN_ID, pluginId);
+            map.put(ManifestPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion);
+            if (pluginClass != null) {
+                map.put(ManifestPluginDescriptorFinder.PLUGIN_CLASS, pluginClass);
+            }
+            if (manifestAttributes != null) {
+                map.putAll(manifestAttributes);
+            }
+
+            return PluginJar.createManifest(map);
+        }
+
+        private byte[] extensionsAsByteArray() throws IOException {
+            try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+                PrintWriter writer = new PrintWriter(outputStream);
+                for (String extension : extensions) {
+                    writer.println(extension);
+                }
+                writer.flush();
+
+                return outputStream.toByteArray();
+            }
+        }
+
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/PluginZip.java b/pf4j/src/test/java/org/pf4j/test/PluginZip.java
new file mode 100644 (file)
index 0000000..5dd2291
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * 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.test;
+
+import org.pf4j.PropertiesPluginDescriptorFinder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * Represents a plugin {@code zip} file.
+ * The {@code plugin.properties} file is created on the fly from the information supplied in {@link Builder}.
+ *
+ * @author Decebal Suiu
+ */
+public class PluginZip {
+
+    private final Path path;
+    private final String pluginId;
+    private final String pluginClass;
+    private final String pluginVersion;
+
+    protected PluginZip(Builder builder) {
+        this.path = builder.path;
+        this.pluginId = builder.pluginId;
+        this.pluginClass = builder.pluginClass;
+        this.pluginVersion = builder.pluginVersion;
+    }
+
+    public Path path() {
+        return path;
+    }
+
+    public File file() {
+        return path.toFile();
+    }
+
+    public String pluginId() {
+        return pluginId;
+    }
+
+    public String pluginClass() {
+        return pluginClass;
+    }
+
+    public String pluginVersion() {
+        return pluginVersion;
+    }
+
+    public Path unzippedPath() {
+        Path path = path();
+        String fileName = path.getFileName().toString();
+
+        return path.getParent().resolve(fileName.substring(0, fileName.length() - 4)); // without ".zip" suffix
+    }
+
+    public static Properties createProperties(Map<String, String> map) {
+        Properties properties = new Properties();
+        properties.putAll(map);
+
+        return properties;
+    }
+
+    public static class Builder {
+
+        private final Path path;
+        private final String pluginId;
+
+        private String pluginClass;
+        private String pluginVersion;
+        private Map<String, String> properties = new LinkedHashMap<>();
+        private Map<Path, byte[]> files = new LinkedHashMap<>();
+
+        public Builder(Path path, String pluginId) {
+            this.path = path;
+            this.pluginId = pluginId;
+        }
+
+        public Builder pluginClass(String pluginClass) {
+            this.pluginClass = pluginClass;
+
+            return this;
+        }
+
+        public Builder pluginVersion(String pluginVersion) {
+            this.pluginVersion = pluginVersion;
+
+            return this;
+        }
+
+        /**
+         * Add extra properties to the {@code properties} file.
+         * As possible attribute name please see {@link PropertiesPluginDescriptorFinder}.
+         */
+        public Builder properties(Map<String, String> properties) {
+            this.properties.putAll(properties);
+
+            return this;
+        }
+
+        /**
+         * Add extra property to the {@code properties} file.
+         * As possible property name please see {@link PropertiesPluginDescriptorFinder}.
+         */
+        public Builder property(String name, String value) {
+            properties.put(name, value);
+
+            return this;
+        }
+
+        /**
+         * Adds a file to the archive.
+         *
+         * @param path the relative path of the file
+         * @param content the content of the file
+         */
+        public Builder addFile(Path path, byte[] content) {
+            files.put(path, content.clone());
+
+            return this;
+        }
+
+        /**
+         * Adds a file to the archive.
+         *
+         * @param path the relative path of the file
+         * @param content the content of the file
+         */
+        public Builder addFile(Path path, String content) {
+            files.put(path, content.getBytes());
+
+            return this;
+        }
+
+        public PluginZip build() throws IOException {
+            createPropertiesFile();
+
+            return new PluginZip(this);
+        }
+
+        protected void createPropertiesFile() throws IOException {
+            Map<String, String> map = new LinkedHashMap<>();
+            map.put(PropertiesPluginDescriptorFinder.PLUGIN_ID, pluginId);
+            map.put(PropertiesPluginDescriptorFinder.PLUGIN_VERSION, pluginVersion);
+            if (pluginClass != null) {
+                map.put(PropertiesPluginDescriptorFinder.PLUGIN_CLASS, pluginClass);
+            }
+            if (properties != null) {
+                map.putAll(properties);
+            }
+
+            try (ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(path.toFile()))) {
+                ZipEntry propertiesFile = new ZipEntry(PropertiesPluginDescriptorFinder.DEFAULT_PROPERTIES_FILE_NAME);
+                outputStream.putNextEntry(propertiesFile);
+                createProperties(map).store(outputStream, "");
+                outputStream.closeEntry();
+
+                for (Map.Entry<Path, byte[]> fileEntry : files.entrySet()) {
+                    ZipEntry file = new ZipEntry(fileEntry.getKey().toString());
+                    outputStream.putNextEntry(file);
+                    outputStream.write(fileEntry.getValue());
+                    outputStream.closeEntry();
+                }
+            }
+        }
+
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/TestExtension.java b/pf4j/src/test/java/org/pf4j/test/TestExtension.java
new file mode 100644 (file)
index 0000000..45c6282
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.test;
+
+import org.pf4j.Extension;
+
+/**
+ * @author Mario Franco
+ */
+@Extension
+public class TestExtension implements TestExtensionPoint {
+
+    @Override
+    public String saySomething() {
+        return "I am a test extension";
+    }
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/TestExtensionPoint.java b/pf4j/src/test/java/org/pf4j/test/TestExtensionPoint.java
new file mode 100644 (file)
index 0000000..3a282c7
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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.test;
+
+import org.pf4j.ExtensionPoint;
+
+/**
+ * @author Mario Franco
+ */
+public interface TestExtensionPoint extends ExtensionPoint {
+
+    String saySomething();
+
+}
diff --git a/pf4j/src/test/java/org/pf4j/test/TestPlugin.java b/pf4j/src/test/java/org/pf4j/test/TestPlugin.java
new file mode 100644 (file)
index 0000000..46cc5c0
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.test;
+
+import org.pf4j.Plugin;
+import org.pf4j.PluginWrapper;
+
+/**
+ * @author Mario Franco
+ */
+public class TestPlugin extends Plugin {
+
+    public TestPlugin(PluginWrapper wrapper) {
+        super(wrapper);
+    }
+
+}
index 7bf06c6b5ca80e1cab01441199b35fc6c83029cf..050b3f13ea8ee17453fa0c49ffb0905d2014e30b 100644 (file)
@@ -17,7 +17,7 @@ package org.pf4j.util;
 
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
-import org.pf4j.plugin.PluginZip;
+import org.pf4j.test.PluginZip;
 
 import java.nio.file.Files;
 import java.nio.file.Path;