<commit_before>/*
 * eXist Open Source Native XML Database
 * Copyright (C) 2005-2009 The eXist Project
 * http://exist-db.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *  
 *  $Id$
 */
package org.exist.izpack;

import com.izforge.izpack.installer.AutomatedInstaller;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

/**
 * @author wolf
 *
 */
public class CommandLineInstaller {

	private final static String HELP_OPT = "-h";
	private final static String PATH_OPT = "-p";
	
	/**
	 * 
	 */
	public CommandLineInstaller() {
	}

	protected void execute(String[] args) throws Exception {
		if (args.length == 0 && !System.getProperty("os.name").startsWith("OpenServer")) {
			System.out.println("\neXist Installation");
			System.out.println("------------------------");
			System.out.println("Using GUI mode ...");
			System.out.println("On a headless system, add parameter -p install-path");
			System.out.println("to install without GUI.");
 			
 			// can't load the GUIInstaller class on headless machines,
 			// so we use Class.forName to force lazy loading.
 			Class.forName("com.izforge.izpack.installer.GUIInstaller").newInstance();
 		} else {
            String installPath = System.getProperty("user.home") + "/eXist";
            for(int i = 0; i < args.length; i++) {
                if (args[i].equals(HELP_OPT)) {
                    printHelp();
                    return;
                } else if (args[i].equals(PATH_OPT)) {
                    if (++i == args.length) {
                        System.out.println("Option -p requires an argument: the path to the directory " +
                                "where you want to have eXist installed.");
                        return;
                    }
                    installPath = args[i];
                }
            }
			System.out.println("Installing into directory: " + installPath);
            
            String filename = File.createTempFile("inst", ".xml").getAbsolutePath();
            Writer w = new FileWriter(filename);
            w.write("<AutomatedInstallation langpack=\"eng\">\n");
			w.write("<com.izforge.izpack.panels.HelloPanel/>\n" +
                "<com.izforge.izpack.panels.PacksPanel>\n" +
                "<pack name=\"core\" index=\"0\" selected=\"true\"/>\n" +
                "<pack name=\"sources\" index=\"1\" selected=\"true\"/>\n" +
                "<pack name=\"javadoc\" index=\"2\" selected=\"true\"/>\n" +
                "</com.izforge.izpack.panels.PacksPanel>");
			w.write("<com.izforge.izpack.panels.TargetPanel>\n" +
					"        <installpath>" + installPath + "</installpath>\n" +
					"    </com.izforge.izpack.panels.TargetPanel>\n");
            w.write("<com.izforge.izpack.panels.UserInputPanel>\n" +
                    "        <userInput>\n" +
                    "            <entry key=\"adminPasswd\" value=\"\"/>\n" +
                    "        </userInput>\n" +
                    "    </com.izforge.izpack.panels.UserInputPanel>");
			w.write("<com.izforge.izpack.panels.InstallPanel />\n" +
                    "  <com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "       <programGroup/>" +
                    "  </com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "  <com.izforge.izpack.panels.ProcessPanel />\n" +
                    "  <com.izforge.izpack.panels.HTMLInfoPanel />\n" +
                    "  <com.izforge.izpack.panels.FinishPanel />");
			w.write("</AutomatedInstallation>");
			w.close();

            EXistAutomatedInstaller installer = new EXistAutomatedInstaller(filename);
            installer.run();

            new File(filename).delete();
 		}
	}
	
	private static void printHelp() {
        System.out.println("Usage: java " + CommandLineInstaller.class.getName() + " [options]");
        System.out.println("Options:");
        System.out.println("    -p install-path");
        System.out.println("        Install eXist with default options and no GUI into directory 'install-path'");
        System.out.println("    -h");
        System.out.println("        Print this help message and exit");
    }

    /**
     * Workaround: AutomatedInstaller.doInstall is protected, so we can't call it
     * directly. Instead we have to create a subclass which calls it.
     */
    private class EXistAutomatedInstaller extends AutomatedInstaller {

        public EXistAutomatedInstaller(String string) throws Exception {
            super(string);
        }

        public void run() throws Exception {
            super.doInstall();<commit_msg>[installer] - fix for cli installer. Use java which was used to start the installer in inst.xml.<commit_after>/*
 * eXist Open Source Native XML Database
 * Copyright (C) 2005-2009 The eXist Project
 * http://exist-db.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *  
 *  $Id$
 */
package org.exist.izpack;

import com.izforge.izpack.installer.AutomatedInstaller;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;

/**
 * @author wolf
 *
 */
public class CommandLineInstaller {

	private final static String HELP_OPT = "-h";
	private final static String PATH_OPT = "-p";
	
	/**
	 * 
	 */
	public CommandLineInstaller() {
	}

	protected void execute(String[] args) throws Exception {
		if (args.length == 0 && !System.getProperty("os.name").startsWith("OpenServer")) {
			System.out.println("\neXist Installation");
			System.out.println("------------------------");
			System.out.println("Using GUI mode ...");
			System.out.println("On a headless system, add parameter -p install-path");
			System.out.println("to install without GUI.");
 			
 			// can't load the GUIInstaller class on headless machines,
 			// so we use Class.forName to force lazy loading.
 			Class.forName("com.izforge.izpack.installer.GUIInstaller").newInstance();
 		} else {
            String installPath = System.getProperty("user.home") + "/eXist";
            for(int i = 0; i < args.length; i++) {
                if (args[i].equals(HELP_OPT)) {
                    printHelp();
                    return;
                } else if (args[i].equals(PATH_OPT)) {
                    if (++i == args.length) {
                        System.out.println("Option -p requires an argument: the path to the directory " +
                                "where you want to have eXist installed.");
                        return;
                    }
                    installPath = args[i];
                }
            }
			System.out.println("Installing into directory: " + installPath);
            
            String filename = File.createTempFile("inst", ".xml").getAbsolutePath();
            Writer w = new FileWriter(filename);
            w.write("<AutomatedInstallation langpack=\"eng\">\n");
			w.write("<com.izforge.izpack.panels.HelloPanel/>\n" +
                "<com.izforge.izpack.panels.JDKPathPanel>\n" +
                    "<JDKPath>" + System.getProperty("java.home") + "</JDKPath>\n" +
                "</com.izforge.izpack.panels.JDKPathPanel>\n" +
                "<com.izforge.izpack.panels.PacksPanel>\n" +
                "<pack name=\"core\" index=\"0\" selected=\"true\"/>\n" +
                "<pack name=\"sources\" index=\"1\" selected=\"true\"/>\n" +
                "<pack name=\"javadoc\" index=\"2\" selected=\"true\"/>\n" +
                "</com.izforge.izpack.panels.PacksPanel>");
			w.write("<com.izforge.izpack.panels.TargetPanel>\n" +
					"        <installpath>" + installPath + "</installpath>\n" +
					"    </com.izforge.izpack.panels.TargetPanel>\n");
            w.write("<com.izforge.izpack.panels.UserInputPanel>\n" +
                    "        <userInput>\n" +
                    "            <entry key=\"adminPasswd\" value=\"\"/>\n" +
                    "        </userInput>\n" +
                    "    </com.izforge.izpack.panels.UserInputPanel>");
			w.write("<com.izforge.izpack.panels.InstallPanel />\n" +
                    "  <com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "       <programGroup/>" +
                    "  </com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "  <com.izforge.izpack.panels.ProcessPanel />\n" +
                    "  <com.izforge.izpack.panels.HTMLInfoPanel />\n" +
                    "  <com.izforge.izpack.panels.FinishPanel />");
			w.write("</AutomatedInstallation>");
			w.close();


            System.out.print("<AutomatedInstallation langpack=\"eng\">\n");
            System.out.print("<com.izforge.izpack.panels.HelloPanel/>\n" +
                    "<com.izforge.izpack.panels.JDKPathPanel>\n" +
                    "<JDKPath>" + System.getProperty("java.home") + "</JDKPath>\n" +
                    "</com.izforge.izpack.panels.JDKPathPanel>\n" +
                    "<com.izforge.izpack.panels.PacksPanel>\n" +
                    "<pack name=\"core\" index=\"0\" selected=\"true\"/>\n" +
                    "<pack name=\"sources\" index=\"1\" selected=\"true\"/>\n" +
                    "<pack name=\"javadoc\" index=\"2\" selected=\"true\"/>\n" +
                    "</com.izforge.izpack.panels.PacksPanel>");
            System.out.print("<com.izforge.izpack.panels.TargetPanel>\n" +
                    "        <installpath>" + installPath + "</installpath>\n" +
                    "    </com.izforge.izpack.panels.TargetPanel>\n");
            System.out.print("<com.izforge.izpack.panels.UserInputPanel>\n" +
                    "        <userInput>\n" +
                    "            <entry key=\"adminPassSystem.out.printd\" value=\"\"/>\n" +
                    "        </userInput>\n" +
                    "    </com.izforge.izpack.panels.UserInputPanel>");
            System.out.print("<com.izforge.izpack.panels.InstallPanel />\n" +
                    "  <com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "       <programGroup/>" +
                    "  </com.izforge.izpack.panels.ShortcutPanel>\n" +
                    "  <com.izforge.izpack.panels.ProcessPanel />\n" +
                    "  <com.izforge.izpack.panels.HTMLInfoPanel />\n" +
                    "  <com.izforge.izpack.panels.FinishPanel />");
            System.out.print("</AutomatedInstallation>");
            
            EXistAutomatedInstaller installer = new EXistAutomatedInstaller(filename);
            installer.run();

            new File(filename).delete();
 		}
	}
	
	private static void printHelp() {
        System.out.println("Usage: java " + CommandLineInstaller.class.getName() + " [options]");
        System.out.println("Options:");
        System.out.println("    -p install-path");
        System.out.println("        Install eXist with default options and no GUI into directory 'install-path'");
        System.out.println("    -h");
        System.out.println("        Print this help message and exit");
    }

    /**
     * Workaround: AutomatedInstaller.doInstall is protected, so we can't call it
     * directly. Instead we have to create a subclass which calls it.
     */
    private class EXistAutomatedInstaller extends AutomatedInstaller {

        public EXistAutomatedInstaller(String string) throws Exception {
            super(string);
        }

        public void run() throws Exception {
            super.doInstall();
{'fraction_non_alphanumeric': 0.14232916568373044, 'fraction_numerical': 0.004167649602893764, 'mean_word_length': 2.0002359046945033, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7148696', 'n_tokens_mistral': 3844, 'n_tokens_neox': 3558, 'n_words': 816}