felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1750620 - in /felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl: Configurator.java TypeConverter.java model/Config.java yaml/YAMLUtil.java
Date Wed, 29 Jun 2016 11:48:21 GMT
Author: cziegeler
Date: Wed Jun 29 11:48:21 2016
New Revision: 1750620

URL: http://svn.apache.org/viewvc?rev=1750620&view=rev
Log:
Binary handling

Modified:
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/model/Config.java
    felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/yaml/YAMLUtil.java

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java?rev=1750620&r1=1750619&r2=1750620&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/Configurator.java
Wed Jun 29 11:48:21 2016
@@ -362,6 +362,11 @@ public class Configurator {
         while ( iter.hasNext() ) {
             final Config cfg = iter.next();
             if ( cfg.getState() == ConfigState.UNINSTALL || cfg.getState() == ConfigState.UNINSTALLED
) {
+                if ( cfg.getFiles() != null ) {
+                    for(final File f : cfg.getFiles()) {
+                        f.delete();
+                    }
+                }
                 iter.remove();
             } else if ( cfg.getState() == ConfigState.INSTALLED ) {
                 if ( foundInstalled ) {

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java?rev=1750620&r1=1750619&r2=1750620&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/TypeConverter.java
Wed Jun 29 11:48:21 2016
@@ -20,6 +20,7 @@ package org.apache.felix.configurator.im
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.felix.converter.impl.ConverterService;
@@ -33,6 +34,10 @@ public class TypeConverter {
         return new ConverterService(); // TODO use OSGi service
     }
 
+    private final List<File> allFiles = new ArrayList<File>();
+
+    private final List<File> files = new ArrayList<File>();
+
     private final Bundle bundle;
 
     /**
@@ -84,7 +89,6 @@ public class TypeConverter {
         }
 
         // binary
-        // TODO - keep track of files and delete them when configuration is UNINSTALLED/removed
         if ( "binary".equals(typeInfo) ) {
             if ( bundle == null ) {
                 throw new IOException("Binary files only allowed within a bundle");
@@ -97,6 +101,8 @@ public class TypeConverter {
             if ( filePath == null ) {
                 throw new IOException("Invalid path for binary property: " + value);
             }
+            files.add(filePath);
+            allFiles.add(filePath);
             return filePath.getAbsolutePath();
 
         } else if ( "binary[]".equals(typeInfo) ) {
@@ -114,6 +120,8 @@ public class TypeConverter {
                 if ( filePath == null ) {
                     throw new IOException("Invalid path for binary property: " + value);
                 }
+                files.add(filePath);
+                allFiles.add(filePath);
                 filePaths[i] = filePath.getAbsolutePath();
                 i++;
             }
@@ -237,6 +245,18 @@ public class TypeConverter {
     }
 
     public void cleanupFiles() {
-        // TODO
+        for(final File f : allFiles) {
+            f.delete();
+        }
+    }
+
+    public List<File> flushFiles() {
+        if ( this.files.isEmpty() ) {
+            return null;
+        } else {
+            final List<File> result = new ArrayList<>(this.files);
+            this.files.clear();
+            return result;
+        }
     }
 }

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/model/Config.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/model/Config.java?rev=1750620&r1=1750619&r2=1750620&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/model/Config.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/model/Config.java
Wed Jun 29 11:48:21 2016
@@ -18,9 +18,11 @@
  */
 package org.apache.felix.configurator.impl.model;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.Serializable;
 import java.util.Dictionary;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.felix.configurator.impl.Util;
@@ -56,6 +58,8 @@ public class Config implements Serializa
     /** The configuration state. */
     private volatile ConfigState state = ConfigState.INSTALL;
 
+    private volatile List<File> files;
+
     public Config(final String pid,
             final Set<String> environments,
             final Dictionary<String, Object> properties,
@@ -88,6 +92,7 @@ public class Config implements Serializa
         out.writeInt(ranking);
         out.writeInt(index);
         out.writeObject(state.name());
+        out.writeObject(files);
     }
 
     /**
@@ -95,6 +100,7 @@ public class Config implements Serializa
      * - read version id
      * - deserialize fields
      */
+    @SuppressWarnings("unchecked")
     private void readObject(final java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException {
         final int version = in.readInt();
@@ -109,6 +115,7 @@ public class Config implements Serializa
         Util.setField(this, "ranking", in.readInt());
         this.index = in.readInt();
         this.state = ConfigState.valueOf((String)in.readObject());
+        this.files = (List<File>) in.readObject();
     }
 
     /**
@@ -192,6 +199,14 @@ public class Config implements Serializa
         return this.environments;
     }
 
+    public void setFiles(final List<File> f) {
+        this.files = f;
+    }
+
+    public List<File> getFiles() {
+        return this.files;
+    }
+
     /**
      * A configuration is active if
      * - it has no environments specified

Modified: felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/yaml/YAMLUtil.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/yaml/YAMLUtil.java?rev=1750620&r1=1750619&r2=1750620&view=diff
==============================================================================
--- felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/yaml/YAMLUtil.java
(original)
+++ felix/sandbox/cziegeler/configurator/src/main/java/org/apache/felix/configurator/impl/yaml/YAMLUtil.java
Wed Jun 29 11:48:21 2016
@@ -207,6 +207,7 @@ public class YAMLUtil {
 
                             if ( valid ) {
                                 final Config c = new Config(pid, environments, properties,
bundleId, ranking, policy);
+                                c.setFiles(converter.flushFiles());
                                 configurations.add(c);
                             }
                         }



Mime
View raw message