FELIX-2032 (and revert of FELIX-2011):  file host.key is not created or copied in the folder etc of the new instance(s)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@906932 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java b/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java
index 631ab86..f6b8eae 100644
--- a/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java
+++ b/karaf/admin/core/src/main/java/org/apache/felix/karaf/admin/internal/AdminServiceImpl.java
@@ -23,7 +23,6 @@
 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;
@@ -152,10 +151,10 @@
         copyResourceToDir(karafBase, "etc/users.properties", true);
 
         HashMap<String, String> props = new HashMap<String, String>();
-        props.put("${karaf.name}", name);
-        props.put("${karaf.home}", System.getProperty("karaf.home"));
-        props.put("${karaf.base}", karafBase.getPath());
-        props.put("${karaf.sshPort}", Integer.toString(sshPort));
+        props.put("${SUBST-KARAF-NAME}", name);
+        props.put("${SUBST-KARAF-HOME}", System.getProperty("karaf.home"));
+        props.put("${SUBST-KARAF-BASE}", karafBase.getPath());
+        props.put("${SUBST-SSH-PORT}", Integer.toString(sshPort));
         copyFilteredResourceToDir(karafBase, "etc/system.properties", props);
         copyFilteredResourceToDir(karafBase, "etc/org.apache.felix.karaf.shell.cfg", props);
         if( System.getProperty("os.name").startsWith("Win") ) {
@@ -226,33 +225,11 @@
         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 = openKarafHomeFiles(resource);
-            if (is == null) {
-            	// copy it from the karaf bundle
-            	is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
-            }
+            InputStream 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.
@@ -292,10 +269,7 @@
         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 = openKarafHomeFiles(resource);
-            if (is == null) {
-            	is = getClass().getClassLoader().getResourceAsStream("org/apache/felix/karaf/admin/" + resource);
-            }
+            InputStream 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));
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf
index 7a97f92..8967cea 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf
@@ -1,4 +1,5 @@
 #!/bin/sh
+################################################################################
 #
 #    Licensed to the Apache Software Foundation (ASF) under one or more
 #    contributor license agreements.  See the NOTICE file distributed with
@@ -15,11 +16,10 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #
-# $Id: karaf 979 2005-11-30 22:50:55Z bsnyder $
-#
+################################################################################
 
-KARAF_HOME=${karaf.home}
-KARAF_BASE=${karaf.base}
+KARAF_HOME=${SUBST-KARAF-HOME}
+KARAF_BASE=${SUBST-KARAF-BASE}
 
 export KARAF_BASE
 exec ${KARAF_HOME}/bin/karaf "$*"
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf.bat b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf.bat
index b54a669..312b66c 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf.bat
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/karaf.bat
@@ -19,7 +19,7 @@
 REM =========================================================================
 
 SETLOCAL
-SET KARAF_BASE=${karaf.base}
-SET KARAF_HOME=${karaf.home}
+SET KARAF_HOME=${SUBST-KARAF-HOME}
+SET KARAF_BASE=${SUBST-KARAF-BASE}
 
 %KARAF_HOME%\bin\karaf.bat %*
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start
index d4552b5..333cba1 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start
@@ -18,7 +18,8 @@
 #
 ################################################################################
 
-KARAF_HOME=${karaf.home}
+KARAF_HOME=${SUBST-KARAF-HOME}
+KARAF_NAME=${SUBST-KARAF-NAME}
 
-exec ${KARAF_HOME}/bin/admin start ${karaf.name} "$@"
+exec ${KARAF_HOME}/bin/admin start ${KARAF_NAME} "$@"
 
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start.bat b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start.bat
index 2da0758..822ed42 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start.bat
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/start.bat
@@ -18,6 +18,7 @@
 REM 
 REM =========================================================================
 
-SET KARAF_HOME=${karaf.home}
+SET KARAF_HOME=${SUBST-KARAF-HOME}
+SET KARAF_NAME=${SUBST-KARAF-NAME}
 
-%KARAF_HOME%\bin\admin.bat start ${karaf.name}
+%KARAF_HOME%\bin\admin.bat start %KARAF_NAME%
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop
index 46f8b01..459a488 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop
@@ -18,7 +18,8 @@
 #
 ################################################################################
 
-KARAF_HOME=${karaf.home}
+KARAF_HOME=${SUBST-KARAF-HOME}
+KARAF_NAME=${SUBST-KARAF-NAME}
 
-exec ${KARAF_HOME}/bin/admin stop ${karaf.name} "$@"
+exec ${KARAF_HOME}/bin/admin stop ${KARAF_NAME} "$@"
 
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop.bat b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop.bat
index fd6279e..31d92cb 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop.bat
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/bin/stop.bat
@@ -18,6 +18,7 @@
 REM 
 REM =========================================================================
 
-SET KARAF_HOME=${karaf.home}
+SET KARAF_HOME=${SUBST-KARAF-HOME}
+SET KARAF_NAME=${SUBST-KARAF-NAME}
 
-%KARAF_HOME%\bin\admin.bat stop ${karaf.name}
+%KARAF_HOME%\bin\admin.bat stop %KARAF_NAME%
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.apache.felix.karaf.shell.cfg b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.apache.felix.karaf.shell.cfg
index 8b83a07..cd3045c 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.apache.felix.karaf.shell.cfg
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.apache.felix.karaf.shell.cfg
@@ -18,6 +18,6 @@
 ################################################################################
 
 #
-startLocalConsole=${karaf.startLocalConsole}
-startRemoteShell=${karaf.startRemoteShell}
-sshPort=${karaf.sshPort}
+sshPort=${SUBST-SSH-PORT}
+sshRealm=karaf
+hostKey=${karaf.base}/etc/host.key
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.ops4j.pax.url.mvn.cfg b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.ops4j.pax.url.mvn.cfg
index 9ae4b8a..87480f2 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.ops4j.pax.url.mvn.cfg
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/org.ops4j.pax.url.mvn.cfg
@@ -55,8 +55,8 @@
 #
 # 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
+org.ops4j.pax.url.mvn.defaultRepositories=file:${karaf.home}/${karaf.default.repository}@snapshots, \
+    file:${karaf.base}/${karaf.default.repository}@snapshots
 
 #
 # Comma separated list of repositories scanned when resolving an artifact.
diff --git a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/system.properties b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/system.properties
index 66bbaef..d5fc11f 100644
--- a/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/system.properties
+++ b/karaf/admin/core/src/main/resources/org/apache/felix/karaf/admin/etc/system.properties
@@ -17,7 +17,45 @@
 #
 ################################################################################
 
+#
+# The properties defined in this file will be made available through system
+# properties at the very beginning of the Karaf's boot process.
+#
+
+
+# Log level when the pax-logging service is not available
+# This level will only be used while the pax-logging service bundle
+# is not fully available.
+# To change log levels, please refer to the org.ops4j.pax.logging.cfg file
+# instead.
 org.ops4j.pax.logging.DefaultServiceLog.level=ERROR
-karaf.name=${karaf.name}
+
+#
+# Name of this karaf instance.
+#
+karaf.name=${SUBST-KARAF-NAME}
+
+#
+# Default repository where bundles will be loaded from before using
+# other maven repositories.  For the full maven configuration, see
+# the org.ops4j.pax.url.mvn.cfg file.
+#
 karaf.default.repository=system
+
+#
+# Location of a shell script that will be run when starting a shell
+# session.  This script can be used to create aliases and define
+# additional commands.
+#
+karaf.shell.init.script=${karaf.home}/etc/shell.init.script
+
+#
+# Set this empty property to avoid errors when validating xml documents.
+#
 xml.catalog.files=
+
+#
+# Suppress the bell in the console when hitting backspace to many times
+# for example
+#
+jline.nobell=true
diff --git a/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java b/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java
index 196a568..89dac42 100644
--- a/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java
+++ b/karaf/admin/core/src/test/java/org/apache/felix/karaf/admin/internal/AdminServiceImplTest.java
@@ -69,11 +69,8 @@
      * //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);
@@ -89,9 +86,6 @@
         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 {
diff --git a/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg b/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg
deleted file mode 100644
index 9ae4b8a..0000000
--- a/karaf/admin/core/src/test/resources/etc/org.ops4j.pax.url.mvn.cfg
+++ /dev/null
@@ -1,80 +0,0 @@
-################################################################################
-#
-#    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
diff --git a/karaf/admin/core/src/test/resources/etc/system.properties b/karaf/admin/core/src/test/resources/etc/system.properties
deleted file mode 100644
index 6596868..0000000
--- a/karaf/admin/core/src/test/resources/etc/system.properties
+++ /dev/null
@@ -1,24 +0,0 @@
-################################################################################
-#
-#    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=