custom plugin loading during deployment problem fixed
MODIFY
common/plugin/src/main/java/io/apiman/common/plugin/PluginClassLoader.java
common/plugin/src/main/java/io/apiman/common/plugin/PluginClassLoader.java
@@ -119,13 +119,17 @@ public class PluginClassLoader extends ClassLoader {
String depFileName = new File(zipEntry.getName()).getName();
File depFile = new File(dependencyWorkDir, depFileName);
if (!depFile.isFile()) {
+ File tmpFile = File.createTempFile("lib", ".tmp", dependencyWorkDir);
+ tmpFile.deleteOnExit();
+
InputStream input = null;
OutputStream output = null;
try {
input = this.pluginArtifactZip.getInputStream(zipEntry);
- output = new FileOutputStream(depFile);
+ output = new FileOutputStream(tmpFile);
IOUtils.copy(input, output);
output.flush();
+ tmpFile.renameTo(depFile);
} catch (IOException e) {
throw e;
} finally {
@@ -151,13 +155,16 @@ public class PluginClassLoader extends ClassLoader {
File resourceFile = new File(resourceWorkDir, zipEntry.getName());
if (!resourceFile.isFile()) {
resourceFile.getParentFile().mkdirs();
+ File tmpFile = File.createTempFile("res", ".tmp", resourceWorkDir);
+ tmpFile.deleteOnExit();
InputStream input = null;
OutputStream output = null;
try {
input = this.pluginArtifactZip.getInputStream(zipEntry);
- output = new FileOutputStream(resourceFile);
+ output = new FileOutputStream(tmpFile);
IOUtils.copy(input, output);
output.flush();
+ tmpFile.renameTo(resourceFile);
} catch (IOException e) {
throw e;
} finally {

MODIFY
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPluginRegistry.java
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/DefaultPluginRegistry.java
@@ -242,7 +242,10 @@ public class DefaultPluginRegistry implements IPluginRegistry {
if (artifactFile.isFile()) {
handled = true;
try {
- FileUtils.copyFile(artifactFile, pluginFile);
+ File tmpFile = File.createTempFile("plugin", ".tmp", pluginDir);
+ tmpFile.deleteOnExit();
+ FileUtils.copyFile(artifactFile, tmpFile);
+ tmpFile.renameTo(pluginFile);
handler.handle(AsyncResultImpl.create(readPluginFile(coordinates, pluginFile)));
} catch (Exception error) {
handler.handle(AsyncResultImpl.<Plugin>create(error));

APIMAN-1347, custom plugin loading during deployment problem fixed (#720)