karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r959962 - in /karaf/trunk: assembly/src/main/filtered-resources/etc/ shell/obr/ shell/obr/src/main/java/org/apache/karaf/shell/obr/
Date Fri, 02 Jul 2010 12:27:34 GMT
Author: gnodet
Date: Fri Jul  2 12:27:34 2010
New Revision: 959962

URL: http://svn.apache.org/viewvc?rev=959962&view=rev
Log:
KARAF-100: the list of OBR repositories is not persisted

Modified:
    karaf/trunk/assembly/src/main/filtered-resources/etc/config.properties
    karaf/trunk/shell/obr/pom.xml
    karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/AddUrlCommand.java
    karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ObrCommandSupport.java
    karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java

Modified: karaf/trunk/assembly/src/main/filtered-resources/etc/config.properties
URL: http://svn.apache.org/viewvc/karaf/trunk/assembly/src/main/filtered-resources/etc/config.properties?rev=959962&r1=959961&r2=959962&view=diff
==============================================================================
--- karaf/trunk/assembly/src/main/filtered-resources/etc/config.properties (original)
+++ karaf/trunk/assembly/src/main/filtered-resources/etc/config.properties Fri Jul  2 12:27:34
2010
@@ -74,6 +74,11 @@ felix.fileinstall.noInitialDelay = true
 eclipse.stateSaveDelayInterval = 1000
 
 #
+# OBR Repository list
+#
+obr.repository.url = 
+
+#
 # Java platform package export properties.
 #
 

Modified: karaf/trunk/shell/obr/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/pom.xml?rev=959962&r1=959961&r2=959962&view=diff
==============================================================================
--- karaf/trunk/shell/obr/pom.xml (original)
+++ karaf/trunk/shell/obr/pom.xml Fri Jul  2 12:27:34 2010
@@ -42,6 +42,21 @@
 
     <dependencies>
         <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.5</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/AddUrlCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/AddUrlCommand.java?rev=959962&r1=959961&r2=959962&view=diff
==============================================================================
--- karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/AddUrlCommand.java (original)
+++ karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/AddUrlCommand.java Fri
Jul  2 12:27:34 2010
@@ -32,5 +32,6 @@ public class AddUrlCommand extends ObrCo
         for (String url : urls) {
             admin.addRepository(url);
         }
+        persistRepositoryList(admin);
     }
 }

Modified: karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ObrCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ObrCommandSupport.java?rev=959962&r1=959961&r2=959962&view=diff
==============================================================================
--- karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ObrCommandSupport.java
(original)
+++ karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/ObrCommandSupport.java
Fri Jul  2 12:27:34 2010
@@ -16,10 +16,12 @@
  */
 package org.apache.karaf.shell.obr;
 
-import java.io.PrintStream;
+import java.io.*;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.felix.bundlerepository.Reason;
+import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.RepositoryAdmin;
 import org.apache.felix.bundlerepository.Requirement;
 import org.apache.felix.bundlerepository.Resolver;
@@ -249,4 +251,63 @@ public abstract class ObrCommandSupport 
         return reqs;
     }
 
+    public static final String REPOSITORY_URL_PROP = "obr.repository.url";
+
+    protected void persistRepositoryList(RepositoryAdmin admin) {
+        try {
+            StringBuilder sb = new StringBuilder();
+            for (Repository repo : admin.listRepositories()) {
+                if (sb.length() > 0) {
+                    sb.append(",");
+                }
+                sb.append(repo.getURI());
+            }
+            File base = new File(System.getProperty("karaf.base"));
+            File sys = new File(base, "etc/config.properties");
+            File sysTmp = new File(base, "etc/config.properties.tmp");
+
+            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sysTmp)));
+            boolean modified = false;
+            try {
+                if (sys.exists()) {
+                    BufferedReader reader = new BufferedReader(new InputStreamReader(new
FileInputStream(sys)));
+                    try {
+                        String line = reader.readLine();
+                        while (line != null) {
+                            if (line.matches("obr\\.repository\\.url[:= ].*")) {
+                                modified = true;
+                                line = "obr.repository.url = " + sb.toString();
+                            }
+                            writer.write(line);
+                            writer.newLine();
+                            line = reader.readLine();
+                        }
+                    } finally {
+                        reader.close();
+                    }
+                }
+                if (!modified) {
+                    writer.newLine();
+                    writer.write("# ");
+                    writer.newLine();
+                    writer.write("# OBR Repository list");
+                    writer.newLine();
+                    writer.write("# ");
+                    writer.newLine();
+                    writer.write("obr.repository.url = " + sb.toString());
+                    writer.newLine();
+                    writer.newLine();
+                }
+            } finally {
+                writer.close();
+            }
+
+            sys.delete();
+            sysTmp.renameTo(sys);
+
+        } catch (Exception e) {
+            System.err.println("Error while persisting repository list");
+        }
+    }
+
 }

Modified: karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java?rev=959962&r1=959961&r2=959962&view=diff
==============================================================================
--- karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java (original)
+++ karaf/trunk/shell/obr/src/main/java/org/apache/karaf/shell/obr/RemoveUrlCommand.java Fri
Jul  2 12:27:34 2010
@@ -32,5 +32,6 @@ public class RemoveUrlCommand extends Ob
         for (String url : urls) {
             admin.removeRepository(url);
         }
+        persistRepositoryList(admin);
     }
 }



Mime
View raw message