You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2010/01/28 11:11:03 UTC

svn commit: r904025 - in /felix/trunk/karaf/admin/core/src: main/java/org/apache/felix/karaf/admin/internal/ test/java/org/apache/felix/karaf/admin/internal/ test/resources/ test/resources/etc/

Author: gnodet
Date: Thu Jan 28 10:11:03 2010
New Revision: 904025

URL: http://svn.apache.org/viewvc?rev=904025&view=rev
Log:
FELIX-2011: admin:create should use the ${karaf.home}/etc configuration files

Added:
    felix/trunk/karaf/admin/core/src/test/resources/
    felix/trunk/karaf/admin/core/src/test/resources/etc/
    felix/trunk/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg
    felix/trunk/karaf/admin/core/src/test/resources/etc/system.properties
Modified:
    felix/trunk/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java
    felix/trunk/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java

Modified: felix/trunk/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java?rev=904025&r1=904024&r2=904025&view=diff
==============================================================================
--- felix/trunk/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java (original)
+++ felix/trunk/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java Thu Jan 28 10:11:03 2010
@@ -23,6 +23,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
+import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -224,12 +225,34 @@
         }
         saveStorage(storage, new File(storageLocation, STORAGE_FILE), "Admin Service storage");
     }
+    
+    private InputStream openKarafHomeFiles(String resource) {
+    	 String home = System.getProperty("karaf.home");
+    	 if (home == null) {
+    		 return null;
+    	 }
+    	 File karafHome = new File(System.getProperty("karaf.home"));
+         File sourceFile = new File(karafHome, resource);
+         InputStream is = null;
+         if (sourceFile.exists()) {
+         	try {
+				is = sourceFile.toURI().toURL().openStream();
+			} catch (Exception e) {
+				// Do nothing here
+			}	
+         }
+         return is;
+    }
 
     private void copyResourceToDir(File target, String resource, boolean text) throws Exception {
         File outFile = new File(target, resource);
         if( !outFile.exists() ) {
             println(Ansi.ansi().a("Creating file: ").a(Ansi.Attribute.INTENSITY_BOLD).a(outFile.getPath()).a(Ansi.Attribute.RESET).toString());
-            InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
+            InputStream is = openKarafHomeFiles(resource);
+            if (is == null) {
+            	// copy it from the karaf bundle
+            	is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
+            }
             try {
                 if( text ) {
                     // Read it line at a time so that we can use the platform line ending when we write it out.
@@ -269,7 +292,10 @@
         File outFile = new File(target, resource);
         if( !outFile.exists() ) {
             println(Ansi.ansi().a("Creating file: ").a(Ansi.Attribute.INTENSITY_BOLD).a(outFile.getPath()).a(Ansi.Attribute.RESET).toString());
-            InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
+            InputStream is = openKarafHomeFiles(resource);
+            if (is == null) {
+            	is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
+            }
             try {
                 // Read it line at a time so that we can use the platform line ending when we write it out.
                 PrintStream out = new PrintStream(new FileOutputStream(outFile));

Modified: felix/trunk/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java?rev=904025&r1=904024&r2=904025&view=diff
==============================================================================
--- felix/trunk/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java (original)
+++ felix/trunk/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java Thu Jan 28 10:11:03 2010
@@ -69,8 +69,11 @@
      * //TODO: fix this test so it can run in an IDE
      */
     public void testConfigurationFiles() throws Exception {
+    	try {
         AdminServiceImpl service = new AdminServiceImpl();
         service.setStorageLocation(new File("target/instances/" + System.currentTimeMillis()));
+        File karafHome = new File("target/test-classes");
+        System.setProperty("karaf.home", karafHome.getAbsolutePath());
 
         InstanceSettings settings = new InstanceSettings(8122, getName(), null, null);
         Instance instance = service.createInstance(getName(), settings);
@@ -86,6 +89,9 @@
         assertFileExists(instance.getLocation(), "etc/org.apache.felix.karaf.management.cfg");
         assertFileExists(instance.getLocation(), "etc/org.ops4j.pax.logging.cfg");
         assertFileExists(instance.getLocation(), "etc/org.ops4j.pax.url.mvn.cfg");
+    	} finally {
+    		System.clearProperty("karaf.home");
+    	}
     }
 
     private void assertFileExists(String path, String name) throws IOException {

Added: felix/trunk/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg?rev=904025&view=auto
==============================================================================
--- felix/trunk/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg (added)
+++ felix/trunk/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg Thu Jan 28 10:11:03 2010
@@ -0,0 +1,80 @@
+################################################################################
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You 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.
+#
+################################################################################
+
+#
+# If set to true, the following property will not allow any certificate to be used
+# when accessing maven repositories through SSL
+#
+#org.ops4j.pax.url.mvn.certificateCheck=
+
+#
+# Path to the local maven settings file.
+# The repositories defined in this file will be automatically added to the list
+# of default repositories if the 'org.ops4j.pax.url.mvn.repositories' property
+# below is not set.
+# The following locations are checked for the existence of the settings.xml file
+#   * 1. looks for the specified url
+#   * 2. if not found looks for ${user.home}/.m2/settings.xml
+#   * 3. if not found looks for ${maven.home}/conf/settings.xml
+#   * 4. if not found looks for ${M2_HOME}/conf/settings.xml
+#
+#org.ops4j.pax.url.mvn.settings=
+
+#
+# Path to the local maven repository which is used to avoid downloading
+# artifacts when they already exist locally.
+# The value of this property will be extracted from the settings.xml file
+# above, or defaulted to:
+#     System.getProperty( "user.home" ) + "/.m2/repository"
+#
+#org.ops4j.pax.url.mvn.localRepository=
+
+#
+# Comma separated list of repositories scanned when resolving an artifact.
+# Those repositories will be checked before iterating through the
+     below list of repositories and even before the local repository
+# A repository url can be appended with zero or more of the following flags:
+#    @snapshots  : the repository contains snaphots
+#    @noreleases : the repository does not contain any released artifacts
+#
+# The following property value will add the system folder as a repo.
+#
+org.ops4j.pax.url.mvn.defaultRepositories=file:${karaf.home}/system@snapshots, \
+    file:${karaf.base}/system@snapshots
+
+#
+# Comma separated list of repositories scanned when resolving an artifact.
+# The default list includes the following repositories:
+#    http://repo1.maven.org/maven2
+#    http://repository.ops4j.org/maven2
+# To add repositories to the default ones, prepend '+' to the list of repositories
+# to add.
+# A repository url can be appended with zero or more of the following flags:
+#    @snapshots  : the repository contains snaphots
+#    @noreleases : the repository does not contain any released artifacts
+#
+# The following property value will add the system folder as a repo.
+#
+org.ops4j.pax.url.mvn.repositories= \
+    http://repo1.maven.org/maven2, \
+    http://people.apache.org/repo/m2-snapshot-repository@snapshots@noreleases, \
+    http://repository.ops4j.org/maven2, \
+    http://svn.apache.org/repos/asf/servicemix/m2-repo, \
+    http://repository.springsource.com/maven/bundles/release, \
+    http://repository.springsource.com/maven/bundles/external

Added: felix/trunk/karaf/admin/core/src/test/resources/etc/system.properties
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/admin/core/src/test/resources/etc/system.properties?rev=904025&view=auto
==============================================================================
--- felix/trunk/karaf/admin/core/src/test/resources/etc/system.properties (added)
+++ felix/trunk/karaf/admin/core/src/test/resources/etc/system.properties Thu Jan 28 10:11:03 2010
@@ -0,0 +1,24 @@
+################################################################################
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You 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.
+#
+################################################################################
+
+org.ops4j.pax.logging.DefaultServiceLog.level=ERROR
+karaf.name=${karaf.name}
+karaf.default.repository=system
+karaf.customer.key=value
+xml.catalog.files=