001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.system.configuration.cli;
018    
019    import java.io.*;
020    
021    /**
022     * A tool for use by clients who really know what they're doing (such as the
023     * installer).  You point this to a FileConfigurationList file, and give it
024     * a configuration name, and it adds the name to the file.  This should only
025     * be run while the server is down, and will only work if you have previous
026     * knowledge of which PersistentConfigurationList implementation is going to
027     * be used and what file it persists to.  This is NOT a general-purpose
028     * feature for users.
029     *
030     * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
031     */
032    public class AddStartupConfiguration {
033        public static void main(String[] args) {
034            try {
035                String file = args[0];
036                String configuration = args[1].trim();
037                BufferedReader in = new BufferedReader(new FileReader(file));
038                String line;
039                while((line = in.readLine()) != null) {
040                    if(line.trim().equals(configuration)) {
041                        in.close();
042                        System.exit(0);
043                    }
044                }
045                in.close();
046    
047                PrintWriter out = new PrintWriter(new FileWriter(file, true));
048                out.println(configuration);
049                out.close();
050            } catch (IOException e) {
051                e.printStackTrace();
052                System.exit(1);
053            }
054        }
055    }