/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2006-2015 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2015 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.netmgt.newts.cli;

import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.spi.SubCommand;
import org.kohsuke.args4j.spi.SubCommandHandler;
import org.kohsuke.args4j.spi.SubCommands;

public class Newts {

    @Argument(handler=SubCommandHandler.class, required=true)
    @SubCommands({
        @SubCommand(name="init", impl=Init.class),
    })
    Command cmd;

    public static void main(String[] args) throws Exception {
        Newts cli = new Newts();
        CmdLineParser parser = new CmdLineParser(cli);
        try {
            parser.parseArgument(args);
        } catch (CmdLineException e) {
            System.out.println("Usage: $OPENNMS_HOME/bin/newts init");
            return;
        }

        cli.cmd.execute();
    }
}

@@ -1239,16 +1239,215 @@
 s.cli;%0A%0A
+import java.io.File;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.IOException;%0Aimport java.nio.file.Paths;%0Aimport java.util.Map;%0Aimport java.util.Properties;%0A%0A
 import o
@@ -1474,16 +1474,16 @@
 gument;%0A
-
 import o
@@ -1935,16 +1935,201 @@
 ption %7B%0A
+        // NMS-8051: opennms_bootstrap.jar in versions %3C 18.0.0 does not load%0A        // all of the system properties, so we need to do this ourselves%0A        loadOpenNMSProperties();%0A%0A
         
@@ -2403,16 +2403,16 @@
      %7D%0A%0A
-
         
@@ -2435,11 +2435,1014 @@
 );%0A    %7D
+%0A%0A    private static void loadOpenNMSProperties() throws FileNotFoundException, IOException %7B%0A        // Find the opennms.properties file%0A        File props = Paths.get(System.getProperty(%22opennms.home%22), %22etc%22, %22opennms.properties%22).toFile();%0A        if (!props.canRead()) %7B%0A            throw new IOException(%22Cannot read opennms.properties file: %22 + props);%0A        %7D%0A%0A        // Load the properties%0A        try (FileInputStream fis = new FileInputStream(props)) %7B%0A            Properties p = new Properties();%0A            p.load(fis);%0A%0A            for (Map.Entry%3CObject, Object%3E entry : p.entrySet()) %7B%0A                String propertyName = entry.getKey().toString();%0A                Object value = entry.getValue();%0A                // Only set the value of a system property if it is not already set%0A                if (System.getProperty(propertyName) == null && value != null) %7B%0A                    System.setProperty(propertyName, value.toString());%0A                %7D%0A            %7D%0A        %7D%0A    %7D
 %0A%7D%0A

Use the system properties from opennms.properties in the 'newts init' script.