Search in sources :

Example 1 with CmdLineArgs

use of alma.acs.util.CmdLineArgs in project ACS by ACS-Community.

the class AcsContainerRunner method setOptions.

/**
	 * Parses commandline and property options.
	 * 
	 * @param args		as received by main()
	 */
void setOptions(String[] args) throws AcsJContainerEx {
    // -- prepare arg parser
    CmdLineArgs cmdArgs = new CmdLineArgs();
    // container name
    CmdLineRegisteredOption optContainerName = new CmdLineRegisteredOption("-containerName", 1);
    cmdArgs.registerOption(optContainerName);
    // container port; TODO unify port argument / property with CDB, C++, etc., abstract from ORB option
    CmdLineRegisteredOption optContainerPort = new CmdLineRegisteredOption("-OAPort", "-OAport", 1);
    cmdArgs.registerOption(optContainerPort);
    // CmdLineRegisteredOption optContainerPort2 = new CmdLineRegisteredOption("-OAport", 1);
    // cmdArgs.registerOption(optContainerPort2);
    // manager reference
    CmdLineRegisteredOption optManagerLoc = new CmdLineRegisteredOption("-manager", "-m", 1);
    cmdArgs.registerOption(optManagerLoc);
    // recovery mode
    CmdLineRegisteredOption optRecoveryMode = new CmdLineRegisteredOption("-recovery", "-r", 0);
    cmdArgs.registerOption(optRecoveryMode);
    // no-recovery mode
    CmdLineRegisteredOption optNoRecoveryMode = new CmdLineRegisteredOption("-norecovery", "-nr", 0);
    cmdArgs.registerOption(optNoRecoveryMode);
    // -- parse and set args
    try {
        cmdArgs.parseArgs(args);
        // -- container name
        if (cmdArgs.isSpecified(optContainerName)) {
            m_containerName = cmdArgs.getValues(optContainerName)[0].trim();
        } else {
            m_containerName = System.getProperty(CONTAINER_NAME_PROPERTYNAME);
        }
        // -- container port
        if (cmdArgs.isSpecified(optContainerPort)) {
            m_containerPort = Integer.parseInt(cmdArgs.getValues(optContainerPort)[0]);
        } else {
            // default port -- C++ container uses -ORBEndpoint, default 3 0 5 0
            m_containerPort = OrbConfigurator.ORB_DEFAULT_PORT;
        }
        // -- manager
        if (cmdArgs.isSpecified(optManagerLoc)) {
            m_managerLoc = cmdArgs.getValues(optManagerLoc)[0].trim();
        } else if (System.getProperty(MANAGER_PROPERTYNAME) != null) {
            m_managerLoc = System.getProperty(MANAGER_PROPERTYNAME).trim();
        } else {
            // default = localhost
            m_managerLoc = AcsManagerProxy.getLocalManagerCorbaloc();
        }
        if (cmdArgs.isSpecified(optRecoveryMode)) {
            m_recoveryModeOverride = Boolean.TRUE;
            if (cmdArgs.isSpecified(optNoRecoveryMode)) {
                m_logger.warning("Conflicting command line options for recovery mode: both -r and -nr are specified. Will use -r.");
            }
        } else if (cmdArgs.isSpecified(optNoRecoveryMode)) {
            m_recoveryModeOverride = Boolean.FALSE;
        }
        Integer starttimeDelayMillisProperty = Integer.getInteger(CONTAINER_STARTTIME_DELAY_MILLIS_PROPERTYNAME);
        if (starttimeDelayMillisProperty != null) {
            initialSleeptimeMillis = starttimeDelayMillisProperty.intValue();
        }
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo("incorrect or missing arguments.");
        throw ex;
    }
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Example 2 with CmdLineArgs

use of alma.acs.util.CmdLineArgs in project ACS by ACS-Community.

the class ConfigFileFinder method configureFromArgs.

public void configureFromArgs(String[] args) {
    CmdLineArgs cmdArgs = new CmdLineArgs();
    CmdLineRegisteredOption optBaseDir = new CmdLineRegisteredOption("-baseDir", 1);
    cmdArgs.registerOption(optBaseDir);
    CmdLineRegisteredOption optTargetDir = new CmdLineRegisteredOption("-targetDir", 1);
    cmdArgs.registerOption(optTargetDir);
    CmdLineRegisteredOption optTargetFilesFlat = new CmdLineRegisteredOption("-targetFilesFlat", 0);
    cmdArgs.registerOption(optTargetFilesFlat);
    CmdLineRegisteredOption optFileEndings = new CmdLineRegisteredOption("-fileEndings", 1);
    cmdArgs.registerOption(optFileEndings);
    cmdArgs.parseArgs(args);
    if (cmdArgs.isSpecified(optBaseDir)) {
        String baseDirName = cmdArgs.getValues(optBaseDir)[0].trim();
        setBaseDir(new File(baseDirName));
    }
    if (cmdArgs.isSpecified(optTargetDir)) {
        String targetDirName = cmdArgs.getValues(optTargetDir)[0].trim();
        setTargetDir(new File(targetDirName));
    }
    targetFilesFlat = cmdArgs.isSpecified(optTargetFilesFlat);
    if (cmdArgs.isSpecified(optFileEndings)) {
        addFileEndings(cmdArgs.getValues(optFileEndings));
    }
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs) File(java.io.File)

Example 3 with CmdLineArgs

use of alma.acs.util.CmdLineArgs in project ACS by ACS-Community.

the class PluginBuilder method parseCmdLineArgs.

/**
	 * Parse the command line
	 * 
	 * @param args The command line params
	 * @return <code>true</code> if the user asked for help
	 */
public boolean parseCmdLineArgs(String[] args) {
    CmdLineArgs cmdLineArgs = new CmdLineArgs();
    CmdLineRegisteredOption helpOpt = new CmdLineRegisteredOption("-h", "--help", 0);
    cmdLineArgs.registerOption(helpOpt);
    CmdLineRegisteredOption verboseOpt = new CmdLineRegisteredOption("-v", "--verbose", 0);
    cmdLineArgs.registerOption(verboseOpt);
    CmdLineRegisteredOption includeOpt = new CmdLineRegisteredOption("-i", "--include", 0);
    cmdLineArgs.registerOption(includeOpt);
    CmdLineRegisteredOption linkOpt = new CmdLineRegisteredOption("-l", "--link", 0);
    cmdLineArgs.registerOption(linkOpt);
    CmdLineRegisteredOption dirsOpt = new CmdLineRegisteredOption("-d", "--userDirs", 0);
    cmdLineArgs.registerOption(dirsOpt);
    CmdLineRegisteredOption endorsedOpt = new CmdLineRegisteredOption("-e", "--endorsedDirs", 0);
    cmdLineArgs.registerOption(endorsedOpt);
    CmdLineRegisteredOption requiredOpt = new CmdLineRegisteredOption("-r", "--requiredPlugins", 0);
    cmdLineArgs.registerOption(requiredOpt);
    cmdLineArgs.parseArgs(args);
    // Help
    if (cmdLineArgs.isSpecified(helpOpt)) {
        return true;
    }
    // Verbose mode
    verbose = cmdLineArgs.isSpecified(verboseOpt);
    // Endorsed
    endorsed = cmdLineArgs.isSpecified(endorsedOpt);
    if (cmdLineArgs.isSpecified(requiredOpt)) {
        String temp = cmdLineArgs.getValues(requiredOpt)[0];
        requiredPlugins = temp.split(":");
    } else {
        requiredPlugins = new String[0];
    }
    // Set the wrap mode
    // what follows -i|-l
    String[] mainArgs;
    if (cmdLineArgs.isSpecified(includeOpt) && cmdLineArgs.isSpecified(linkOpt)) {
        System.out.println("Set only one between -i and -l");
        return true;
    }
    if (!cmdLineArgs.isSpecified(includeOpt) && !cmdLineArgs.isSpecified(linkOpt)) {
        System.out.println("Set one between -i and -l");
        return true;
    }
    if (cmdLineArgs.isSpecified(includeOpt)) {
        wrapJars = true;
        mainArgs = cmdLineArgs.getValues(includeOpt);
    } else {
        wrapJars = false;
        mainArgs = cmdLineArgs.getValues(linkOpt);
    }
    if (mainArgs.length < 3) {
        System.err.println("Wrong command line args!");
        return true;
    }
    name = mainArgs[0];
    target = mainArgs[1];
    jars = new String[mainArgs.length - 2];
    for (int t = 2; t < mainArgs.length; t++) {
        jars[t - 2] = mainArgs[t];
    }
    // User defined folders
    if (cmdLineArgs.isSpecified(dirsOpt)) {
        String udirs = cmdLineArgs.getValues(dirsOpt)[0];
        userDirs = udirs.split(":");
    } else {
        userDirs = new String[0];
    }
    return false;
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Example 4 with CmdLineArgs

use of alma.acs.util.CmdLineArgs in project ACS by ACS-Community.

the class ProcessCvs2clOutput method setOptions.

void setOptions(String[] args) throws IOException {
    // -- prepare arg parser
    CmdLineArgs cmdArgs = new CmdLineArgs();
    // optionally subtract other sets of cvs logs
    CmdLineRegisteredOption optSubtract = new CmdLineRegisteredOption("-subtract", 1);
    cmdArgs.registerOption(optSubtract);
    // sort by time or by path (module, file,...) and time
    CmdLineRegisteredOption optSortBy = new CmdLineRegisteredOption("-sortBy", 1);
    cmdArgs.registerOption(optSortBy);
    // sort by time or by path (module, file,...) and time
    CmdLineRegisteredOption optRetainFiles = new CmdLineRegisteredOption("-retainFiles", 1);
    cmdArgs.registerOption(optRetainFiles);
    // -- parse and set args
    cmdArgs.parseArgs(args);
    // -- subtract
    subtractFiles.clear();
    if (cmdArgs.isSpecified(optSubtract)) {
        String subtractFileNames = cmdArgs.getValues(optSubtract)[0].trim();
        for (String fileName : subtractFileNames.split(File.pathSeparator)) {
            File file = new File(fileName);
            if (file.exists() && file.isFile()) {
                subtractFiles.add(file);
            } else {
                System.err.println("Will ignore non-existing subtract file " + file.getAbsolutePath());
            }
        }
    }
    // -- sort by
    if (cmdArgs.isSpecified(optSortBy)) {
        String sortByString = cmdArgs.getValues(optSortBy)[0].trim();
        try {
            sortBy = SortBy.valueOf(sortByString);
        } catch (IllegalArgumentException ex) {
            System.err.println("Will ignore illegal sort option '" + sortByString + "'.");
        }
    } else {
        sortBy = SortBy.time;
    }
    // -- retain files
    if (cmdArgs.isSpecified(optRetainFiles)) {
        File retainFilesFile = new File(cmdArgs.getValues(optRetainFiles)[0].trim());
        if (sortBy != SortBy.file) {
            System.err.println("Ignoring retain-files file '" + retainFilesFile.getAbsolutePath() + "' because 'sortBy' is not set to 'file'.");
        } else if (!retainFilesFile.exists() || !retainFilesFile.isFile()) {
            System.err.println("Ignoring invalid retain-files file '" + retainFilesFile.getAbsolutePath() + "'");
        }
        BufferedReader reader = new BufferedReader(new FileReader(retainFilesFile));
        retainFiles = new HashSet<String>();
        String line = null;
        //			System.out.println("Will only consider the following files given in " + retainFilesFile.getAbsolutePath() + ":");
        while ((line = reader.readLine()) != null) {
            retainFiles.add(line);
        //				System.out.println(line);
        }
        reader.close();
    }
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CmdLineArgs(alma.acs.util.CmdLineArgs) File(java.io.File) EntryFile(alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile)

Example 5 with CmdLineArgs

use of alma.acs.util.CmdLineArgs in project ACS by ACS-Community.

the class ContinuousNcPublisher method main.

/**
	 * @param args
	 */
public static void main(String[] args) {
    String managerLoc = System.getProperty("ACS.manager");
    if (managerLoc == null) {
        System.out.println("Java property 'ACS.manager' must be set to the corbaloc of the ACS manager!");
        System.exit(-1);
    }
    try {
        CmdLineArgs cmdArgs = new CmdLineArgs();
        CmdLineRegisteredOption optChannelName = new CmdLineRegisteredOption("-channelName", 1);
        cmdArgs.registerOption(optChannelName);
        CmdLineRegisteredOption optEventsPerBurst = new CmdLineRegisteredOption("-eventsPerBurst", 1);
        cmdArgs.registerOption(optEventsPerBurst);
        CmdLineRegisteredOption optDelayBurstsMillis = new CmdLineRegisteredOption("-delayBurstsMillis", 1);
        cmdArgs.registerOption(optDelayBurstsMillis);
        CmdLineRegisteredOption optLogAfterBurst = new CmdLineRegisteredOption("-logAfterBurst", 1);
        cmdArgs.registerOption(optLogAfterBurst);
        cmdArgs.parseArgs(args);
        String channelName = null;
        if (cmdArgs.isSpecified(optChannelName)) {
            channelName = cmdArgs.getValues(optChannelName)[0].trim();
        } else {
            throw new IllegalArgumentException("Option " + optChannelName.getName() + " must be specified.");
        }
        int eventsPerBurst = 1;
        if (cmdArgs.isSpecified(optEventsPerBurst)) {
            eventsPerBurst = Integer.parseInt(cmdArgs.getValues(optEventsPerBurst)[0]);
        }
        int delayBurstsMillis = 1000;
        if (cmdArgs.isSpecified(optDelayBurstsMillis)) {
            delayBurstsMillis = Integer.parseInt(cmdArgs.getValues(optDelayBurstsMillis)[0]);
        }
        boolean logAfterBurst = false;
        if (cmdArgs.isSpecified(optLogAfterBurst)) {
            logAfterBurst = Boolean.parseBoolean(cmdArgs.getValues(optLogAfterBurst)[0]);
        }
        new ContinuousNcPublisher(managerLoc).run(channelName, eventsPerBurst, delayBurstsMillis, logAfterBurst);
    } catch (Throwable thr) {
        thr.printStackTrace();
    }
}
Also used : CmdLineRegisteredOption(alma.acs.util.CmdLineRegisteredOption) CmdLineArgs(alma.acs.util.CmdLineArgs)

Aggregations

CmdLineArgs (alma.acs.util.CmdLineArgs)9 CmdLineRegisteredOption (alma.acs.util.CmdLineRegisteredOption)9 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)1 EntryFile (alma.acs.releasedoc.Cvs2clXmlEntry.EntryFile)1 FileReader (java.io.FileReader)1 InputStreamReader (java.io.InputStreamReader)1 ParseException (java.text.ParseException)1