FELIX-1461: make local repository updates a bit more atomic
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@810765 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java
index 4f76943..512943b 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrCleanRepo.java
@@ -20,7 +20,6 @@
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
@@ -44,6 +43,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -268,13 +268,14 @@
DOMSource input = new DOMSource( treeToBeWrite );
- File fichier = new File( outputFilename );
+ File fichier = null;
FileOutputStream flux = null;
try
{
+ fichier = File.createTempFile( "repository", ".xml" );
flux = new FileOutputStream( fichier );
}
- catch ( FileNotFoundException e )
+ catch ( IOException e )
{
getLog().error( "Unable to write to file: " + fichier.getName() );
throw new MojoExecutionException( "Unable to write to file: " + fichier.getName() + " : " + e.getMessage() );
@@ -294,6 +295,8 @@
{
flux.flush();
flux.close();
+
+ FileUtils.rename( fichier, new File( outputFilename ) );
}
catch ( IOException e )
{
diff --git a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java
index b30ebcd..51472f4 100644
--- a/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java
+++ b/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUpdate.java
@@ -20,7 +20,6 @@
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
@@ -42,6 +41,7 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -477,18 +477,18 @@
DOMSource input = new DOMSource( treeToBeWrite );
- File fichier = new File( outputFilename );
- fichier.getParentFile().mkdirs();
+ File fichier = null;
FileOutputStream flux = null;
try
{
+ fichier = File.createTempFile( "repository", ".xml" );
flux = new FileOutputStream( fichier );
}
- catch ( FileNotFoundException e )
+ catch ( IOException e )
{
m_logger.error( "Unable to write to file: " + fichier.getName() );
e.printStackTrace();
- throw new MojoExecutionException( "FileNotFoundException" );
+ throw new MojoExecutionException( "Unable to write to file: " + fichier.getName() + " : " + e.getMessage() );
}
Result output = new StreamResult( flux );
try
@@ -505,6 +505,10 @@
{
flux.flush();
flux.close();
+
+ File outputFile = new File( outputFilename );
+ outputFile.getParentFile().mkdirs();
+ FileUtils.rename( fichier, outputFile );
}
catch ( IOException e )
{