Example usage for java.util Properties remove

List of usage examples for java.util Properties remove

Introduction

In this page you can find the example usage for java.util Properties remove.

Prototype

@Override
    public synchronized Object remove(Object key) 

Source Link

Usage

From source file:er.extensions.foundation.ERXProperties.java

/**
 * <div class="en">//  w ww  .java2s .  co  m
 * For each property in originalProperties, process the keys and values with
 * the registered property operators and stores the converted value into
 * destinationProperties.
 * </div>
 * 
 * <div class="ja">
 * ???????????
 * ?????????
 *  ERXSystem? 
 * </div>
 * 
 * @param originalProperties <div class="en">the properties to convert</div>
 *                           <div class="ja"></div>
 * @param destinationProperties <div class="en">the properties to copy into</div>
 *                              <div class="ja">???</div>
 */
public static void evaluatePropertyOperators(Properties originalProperties, Properties destinationProperties) {
    NSArray<String> operatorKeys = ERXProperties.operators.allKeys();
    for (Object keyObj : new TreeSet<Object>(originalProperties.keySet())) {
        String key = (String) keyObj;
        if (key != null && key.length() > 0) {
            String value = originalProperties.getProperty(key);
            if (operatorKeys.count() > 0 && key.indexOf(".@") != -1) {
                ERXProperties.Operator operator = null;
                NSDictionary<String, String> computedProperties = null;
                for (String operatorKey : operatorKeys) {
                    String operatorKeyWithAt = ".@" + operatorKey;
                    if (key.endsWith(operatorKeyWithAt)) {
                        operator = ERXProperties.operators.objectForKey(operatorKey);
                        computedProperties = operator.compute(
                                key.substring(0, key.length() - operatorKeyWithAt.length()), value, null);
                        break;
                    }
                    int keyIndex = key.indexOf(operatorKeyWithAt + ".");
                    if (keyIndex != -1) {
                        operator = ERXProperties.operators.objectForKey(operatorKey);
                        computedProperties = operator.compute(key.substring(0, keyIndex), value,
                                key.substring(keyIndex + operatorKeyWithAt.length() + 1));
                        break;
                    }
                }

                if (computedProperties == null) {
                    destinationProperties.put(key, value);
                } else {
                    originalProperties.remove(key);

                    // If the key exists in the System properties' defaults with a different value, we must reinsert
                    // the property so it doesn't get overwritten with the default value when we evaluate again.
                    // This happens because ERXConfigurationManager processes the properties after a configuration
                    // change in multiple passes and each calls this method.
                    if (System.getProperty(key) != null && !System.getProperty(key).equals(value)) {
                        originalProperties.put(key, value);
                    }

                    for (String computedKey : computedProperties.allKeys()) {
                        destinationProperties.put(computedKey, computedProperties.objectForKey(computedKey));
                    }
                }
            } else {
                destinationProperties.put(key, value);
            }
        }
    }
}

From source file:org.olat.core.util.i18n.I18nManager.java

/**
 * Save the given value for the given i18nItem
 * /*  w  ww .ja  v  a  2 s  .c om*/
 * @param i18nItem
 * @param value
 */
public void saveOrUpdateI18nItem(I18nItem i18nItem, String value) {
    Properties properties = getPropertiesWithoutResolvingRecursively(i18nItem.getLocale(),
            i18nItem.getBundleName());
    // Add logging block to find bogus save issues
    if (isLogDebugEnabled()) {
        String itemIdent = i18nItem.getLocale() + ":"
                + buildI18nItemIdentifyer(i18nItem.getBundleName(), i18nItem.getKey());
        if (properties.containsKey(i18nItem.getKey())) {
            if (StringHelper.containsNonWhitespace(value)) {
                logDebug("Updating i18n item::" + itemIdent + " with new value::" + value, null);
            } else {
                logDebug("Deleting i18n item::" + itemIdent + " because new value is emty", null);
            }
        } else {
            if (StringHelper.containsNonWhitespace(value)) {
                logDebug("Creating i18n item::" + itemIdent + " with new value::" + value, null);
            }
        }
    }
    //
    if (StringHelper.containsNonWhitespace(value)) {
        properties.setProperty(i18nItem.getKey(), value);
    } else if (properties.containsKey(i18nItem.getKey())) {
        properties.remove(i18nItem.getKey());
    }
    if (properties.size() == 0) {
        // delete empty files
        deleteProperties(i18nItem.getLocale(), i18nItem.getBundleName());
    } else {
        // update
        saveOrUpdateProperties(properties, i18nItem.getLocale(), i18nItem.getBundleName());
    }
    // remove all properties files from cache that contain references to
    // this i18n item, rebuild them lazy on next demand.
    if (cachingEnabled) {
        String identifyer = buildI18nItemIdentifyer(i18nItem.getBundleName(), i18nItem.getKey());
        Deque<String> referencingBundles = referencingBundlesIndex.get(identifyer);
        if (referencingBundles != null) {
            // remove from index
            referencingBundlesIndex.remove(identifyer);
            // remove from bundles cache
            for (String bundleName : referencingBundles) {
                cachedBundles.remove(bundleName);
            }
        }
    }

}

From source file:org.apache.axis2.clustering.tribes.TribesClusteringAgent.java

private void setMemberInfo() throws ClusteringFault {
    Properties memberInfo = new Properties();
    AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
    TransportInDescription httpTransport = axisConfig.getTransportIn("http");
    int portOffset = 0;
    Parameter param = getParameter(ClusteringConstants.Parameters.AVOID_INITIATION);
    if (param != null && !JavaUtils.isTrueExplicitly(param.getValue())) {
        //AvoidInitialization = false, Hence we set the portOffset
        if (System.getProperty("portOffset") != null) {
            portOffset = Integer.parseInt(System.getProperty("portOffset"));
        }//  w  w w  . j  a va2  s.c  o m
    }

    if (httpTransport != null) {
        Parameter port = httpTransport.getParameter("port");
        if (port != null) {
            memberInfo.put("httpPort", String.valueOf(Integer.valueOf((String) port.getValue()) + portOffset));
        }
    }
    TransportInDescription httpsTransport = axisConfig.getTransportIn("https");
    if (httpsTransport != null) {
        Parameter port = httpsTransport.getParameter("port");
        if (port != null) {
            memberInfo.put("httpsPort", String.valueOf(Integer.valueOf((String) port.getValue()) + portOffset));
        }
    }
    Parameter isActiveParam = getParameter(ClusteringConstants.Parameters.IS_ACTIVE);
    if (isActiveParam != null) {
        memberInfo.setProperty(ClusteringConstants.Parameters.IS_ACTIVE, (String) isActiveParam.getValue());
    }

    memberInfo.setProperty("hostName",
            TribesUtil.getLocalHost(getParameter(TribesConstants.LOCAL_MEMBER_HOST)));

    Parameter propsParam = getParameter("properties");
    if (propsParam != null) {
        OMElement paramEle = propsParam.getParameterElement();
        for (Iterator iter = paramEle.getChildrenWithLocalName("property"); iter.hasNext();) {
            OMElement propEle = (OMElement) iter.next();
            OMAttribute nameAttrib = propEle.getAttribute(new QName("name"));
            if (nameAttrib != null) {
                String attribName = nameAttrib.getAttributeValue();
                attribName = replaceProperty(attribName, memberInfo);

                OMAttribute valueAttrib = propEle.getAttribute(new QName("value"));
                if (valueAttrib != null) {
                    String attribVal = valueAttrib.getAttributeValue();
                    attribVal = replaceProperty(attribVal, memberInfo);
                    memberInfo.setProperty(attribName, attribVal);
                }
            }
        }
    }

    memberInfo.remove("hostName"); // this was needed only to populate other properties. No need to send it.

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try {
        memberInfo.store(bout, "");
    } catch (IOException e) {
        String msg = "Cannot store member transport properties in the ByteArrayOutputStream";
        log.error(msg, e);
        throw new ClusteringFault(msg, e);
    }
    channel.getMembershipService().setPayload(bout.toByteArray());
}

From source file:org.voltdb.utils.CatalogUtil.java

private static Properties checkExportProcessorConfiguration(ExportConfigurationType exportConfiguration) {
    // on-server export always uses the guest processor
    String exportClientClassName = null;

    switch (exportConfiguration.getType()) {
    case FILE://w w w.j a v a  2s .  co  m
        exportClientClassName = "org.voltdb.exportclient.ExportToFileClient";
        break;
    case JDBC:
        exportClientClassName = "org.voltdb.exportclient.JDBCExportClient";
        break;
    case KAFKA:
        exportClientClassName = "org.voltdb.exportclient.KafkaExportClient";
        break;
    case RABBITMQ:
        exportClientClassName = "org.voltdb.exportclient.RabbitMQExportClient";
        break;
    case HTTP:
        exportClientClassName = "org.voltdb.exportclient.HttpExportClient";
        break;
    //Validate that we can load the class.
    case CUSTOM:
        exportClientClassName = exportConfiguration.getExportconnectorclass();
        if (exportConfiguration.isEnabled()) {
            try {
                CatalogUtil.class.getClassLoader().loadClass(exportClientClassName);
            } catch (ClassNotFoundException ex) {
                String msg = "Custom Export failed to configure, failed to load" + " export plugin class: "
                        + exportConfiguration.getExportconnectorclass() + " Disabling export.";
                hostLog.error(msg);
                throw new DeploymentCheckException(msg);
            }
        }
        break;
    }

    Properties processorProperties = new Properties();

    if (exportClientClassName != null && exportClientClassName.trim().length() > 0) {
        String dexportClientClassName = System.getProperty(ExportDataProcessor.EXPORT_TO_TYPE,
                exportClientClassName);
        //Override for tests
        if (dexportClientClassName != null && dexportClientClassName.trim().length() > 0
                && exportConfiguration.getType().equals(ServerExportEnum.CUSTOM)) {
            processorProperties.setProperty(ExportDataProcessor.EXPORT_TO_TYPE, dexportClientClassName);
        } else {
            processorProperties.setProperty(ExportDataProcessor.EXPORT_TO_TYPE, exportClientClassName);
        }
    }

    if (exportConfiguration != null) {
        List<PropertyType> configProperties = exportConfiguration.getProperty();
        if (configProperties != null && !configProperties.isEmpty()) {

            for (PropertyType configProp : configProperties) {
                String key = configProp.getName();
                String value = configProp.getValue();
                if (!key.toLowerCase().contains("passw")) {
                    processorProperties.setProperty(key, value.trim());
                } else {
                    //Dont trim passwords
                    processorProperties.setProperty(key, value);
                }
            }
        }
    }

    if (!exportConfiguration.isEnabled()) {
        return processorProperties;
    }

    // Instantiate the Guest Processor
    Class<?> processorClazz = null;
    try {
        processorClazz = Class.forName(ExportManager.PROCESSOR_CLASS);
    } catch (ClassNotFoundException e) {
        throw new DeploymentCheckException("Export is a PRO version only feature");
    }
    ExportDataProcessor processor = null;
    try {
        processor = (ExportDataProcessor) processorClazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        hostLog.error("Unable to instantiate export processor", e);
        throw new DeploymentCheckException("Unable to instantiate export processor", e);
    }
    try {
        processor.addLogger(hostLog);

        processorProperties.put(ExportManager.CONFIG_CHECK_ONLY, "true");
        processor.checkProcessorConfig(processorProperties);
        processor.shutdown();
    } catch (Exception e) {
        hostLog.error("Export processor failed its configuration check", e);
        throw new DeploymentCheckException("Export processor failed its configuration check: " + e.getMessage(),
                e);
    }

    processorProperties.remove(ExportManager.CONFIG_CHECK_ONLY);
    return processorProperties;
}

From source file:org.nuxeo.ecm.core.TestSQLRepositoryQuery.java

@Test
public void testQueryLimits() throws Exception {
    DocumentModelList dml;// w  ww  .  j a v  a 2  s  .c  o  m
    createDocs();

    String sql = "SELECT * FROM Document ORDER BY ecm:name";

    dml = session.query(sql);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    // countUpTo = 0 -> no total count, dml set the total size to the list
    // size
    // equivalent to totalCount=false
    dml = session.query(sql, null, 0, 0, 0);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    dml = session.query(sql, null, 2, 2, 0);
    assertEquals(2, dml.size());
    assertEquals(2, dml.totalSize());

    dml = session.query(sql, null, 10, 10, 0);
    assertEquals(0, dml.size());
    assertEquals(0, dml.totalSize());

    // countUpTo = -1 -> ask for exact total size, regardless of
    // offset/limit
    // equivalent to totalCount=true
    dml = session.query(sql, null, 0, 0, -1);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    dml = session.query(sql, null, 2, 2, -1);
    assertEquals(2, dml.size());
    assertEquals(7, dml.totalSize());

    dml = session.query(sql, null, 2, 10, -1);
    assertEquals(0, dml.size());
    assertEquals(7, dml.totalSize());

    dml = session.query(sql, null, 20, 0, -1);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    // countUpTo = n
    // equivalent to totalCount=true if there are less than n results
    dml = session.query(sql, null, 0, 0, 10);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    dml = session.query(sql, null, 0, 0, 7);
    assertEquals(7, dml.size());
    assertEquals(7, dml.totalSize());

    // truncate result to 6
    dml = session.query(sql, null, 0, 0, 6);
    assertTrue(dml.totalSize() < 0);
    // watch out, the size of the list can be countUpTo + 1
    assertEquals(7, dml.size());

    // use limit to have an exact size
    dml = session.query(sql, null, 6, 0, 6);
    assertTrue(dml.totalSize() < 0);
    assertEquals(6, dml.size());

    // use limit to have an exact size
    dml = session.query(sql, null, 3, 0, 3);
    assertTrue(dml.totalSize() < 0);
    assertEquals(3, dml.size());

    // limit/offset overrides the countUpTo
    dml = session.query(sql, null, 5, 0, 2);
    assertTrue(dml.totalSize() < 0);
    assertEquals(5, dml.size());

    dml = session.query(sql, null, 3, 4, 2);
    assertTrue(dml.totalSize() < 0);
    assertEquals(3, dml.size());

    // Test limitation override when using totalCount=true
    dml = session.query(sql, null, 5, 0, true);
    assertEquals(5, dml.size());
    assertEquals(7, dml.totalSize());
    Properties properties = Framework.getProperties();
    properties.setProperty(AbstractSession.LIMIT_RESULTS_PROPERTY, "true");
    properties.setProperty(AbstractSession.MAX_RESULTS_PROPERTY, "5");
    // need to open a new session to refresh properties
    try (CoreSession admSession = CoreInstance.openCoreSession(session.getRepositoryName(), "Administrator")) {
        dml = admSession.query(sql, null, 5, 0, true);
        assertEquals(5, dml.size());
        assertTrue(dml.totalSize() < 0);
    } finally {
        properties.remove(AbstractSession.LIMIT_RESULTS_PROPERTY);
        properties.remove(AbstractSession.MAX_RESULTS_PROPERTY);
    }
}

From source file:com.streamsets.datacollector.cluster.TestShellClusterProvider.java

@Test
public void testCopyDpmToken() throws Exception {
    Properties sdcProperties = new Properties();
    sdcProperties.put(Configuration.CONFIG_INCLUDES, "dpm-test.properties");
    File etcDir = tempFolder.newFolder();
    Properties dpmProperties = new Properties();
    dpmProperties.setProperty("foo", "fooVal");
    dpmProperties.setProperty(RemoteSSOService.DPM_ENABLED, "true");
    File appTokenFile = tempFolder.newFile();
    try (PrintWriter out = new PrintWriter(appTokenFile)) {
        out.println("app-token-dummy-text");
    }/* w w w  . jav  a2  s  .c o m*/
    // dpm enabled and app token is absolute
    dpmProperties.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG,
            Configuration.FileRef.DELIMITER + appTokenFile.getAbsolutePath() + Configuration.FileRef.DELIMITER);

    try (OutputStream out = new FileOutputStream(new File(etcDir, "dpm-test.properties"))) {
        dpmProperties.store(out, null);
    }
    sparkProvider.copyDpmTokenIfRequired(sdcProperties, etcDir);
    try (InputStream in = new FileInputStream(new File(etcDir, "dpm-test.properties"))) {
        Properties gotProperties = new Properties();
        gotProperties.load(in);
        Assert.assertEquals("fooVal", gotProperties.getProperty("foo"));
        Assert.assertEquals("true", gotProperties.getProperty(RemoteSSOService.DPM_ENABLED));
        Assert.assertEquals(
                Configuration.FileRef.DELIMITER + ShellClusterProvider.CLUSTER_DPM_APP_TOKEN
                        + Configuration.FileRef.DELIMITER,
                gotProperties.getProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG));
        List<String> gotLines = Files.readAllLines(
                new File(etcDir, ShellClusterProvider.CLUSTER_DPM_APP_TOKEN).toPath(),
                Charset.defaultCharset());
        Assert.assertEquals(1, gotLines.size());
        Assert.assertEquals("app-token-dummy-text", gotLines.get(0));
    }
    // dpm not enabled
    etcDir = tempFolder.newFolder();
    dpmProperties = new Properties();
    dpmProperties.setProperty("foo", "fooNewVal");
    dpmProperties.setProperty(RemoteSSOService.DPM_ENABLED, "false");
    try (OutputStream out = new FileOutputStream(new File(etcDir, "dpm-test.properties"))) {
        dpmProperties.store(out, null);
    }
    sparkProvider.copyDpmTokenIfRequired(sdcProperties, etcDir);
    try (InputStream in = new FileInputStream(new File(etcDir, "dpm-test.properties"))) {
        Properties gotProperties = new Properties();
        gotProperties.load(in);
        Assert.assertEquals("fooNewVal", gotProperties.getProperty("foo"));
        Assert.assertEquals("false", gotProperties.getProperty(RemoteSSOService.DPM_ENABLED));
    }
    // dpm enabled but token relative
    etcDir = tempFolder.newFolder();
    dpmProperties = new Properties();
    dpmProperties.setProperty("foo", "fooDpmEnabledTokenRelative");
    dpmProperties.setProperty(RemoteSSOService.DPM_ENABLED, "true");
    dpmProperties.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG,
            Configuration.FileRef.DELIMITER + "relative_path_to_token.txt" + Configuration.FileRef.DELIMITER);
    try (OutputStream out = new FileOutputStream(new File(etcDir, "dpm-test.properties"))) {
        dpmProperties.store(out, null);
    }
    sparkProvider.copyDpmTokenIfRequired(sdcProperties, etcDir);
    try (InputStream in = new FileInputStream(new File(etcDir, "dpm-test.properties"))) {
        Properties gotProperties = new Properties();
        gotProperties.load(in);
        Assert.assertEquals("fooDpmEnabledTokenRelative", gotProperties.getProperty("foo"));
        Assert.assertEquals("true", gotProperties.getProperty(RemoteSSOService.DPM_ENABLED));
        Assert.assertEquals(
                Configuration.FileRef.DELIMITER + "relative_path_to_token.txt"
                        + Configuration.FileRef.DELIMITER,
                gotProperties.getProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG));
    }
    // all configs in sdc.properties (similar to parcels)
    sdcProperties.remove(Configuration.CONFIG_INCLUDES);
    sdcProperties.setProperty(RemoteSSOService.DPM_ENABLED, "true");
    sdcProperties.setProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG,
            Configuration.FileRef.DELIMITER + appTokenFile.getAbsolutePath() + Configuration.FileRef.DELIMITER);
    sparkProvider.copyDpmTokenIfRequired(sdcProperties, etcDir);
    Assert.assertEquals("true", sdcProperties.getProperty(RemoteSSOService.DPM_ENABLED));
    Assert.assertEquals(
            Configuration.FileRef.DELIMITER + ShellClusterProvider.CLUSTER_DPM_APP_TOKEN
                    + Configuration.FileRef.DELIMITER,
            sdcProperties.getProperty(RemoteSSOService.SECURITY_SERVICE_APP_AUTH_TOKEN_CONFIG));
}

From source file:org.marketcetera.strategy.LanguageTestBase.java

/**
 * Tests the ability of a strategy to request and cancel data flows from other modules.
 *
 * @throws Exception if an error occurs// ww  w .  ja  v a  2s .c om
 */
@Test
public void createDataFlows() throws Exception {
    // invalid URN
    final ModuleURN invalidURN = new ModuleURN("metc:something:something");
    // valid URN, but not started
    final ModuleURN validUnstartedURN = moduleManager.createModule(MockRecorderModule.Factory.PROVIDER_URN);
    // valid URN, started, but not emitter
    final ModuleURN validURNNotEmitter = SinkModuleFactory.INSTANCE_URN;
    // valid URN, started, but not receiver
    final ModuleURN validURNNotReceiver = BogusFeedModuleFactory.INSTANCE_URN;
    assertFalse(moduleManager.getModuleInfo(SinkModuleFactory.INSTANCE_URN).isEmitter());
    // valid, started receiver
    ModuleURN dataEmitterURN = createModule(StrategyDataEmissionModule.Factory.PROVIDER_URN);
    final Properties parameters = new Properties();
    // null URN list
    doDataFlowTest(parameters, false);
    // single URN (invalid flow, need two at least)
    parameters.setProperty("urns", dataEmitterURN.getValue());
    doDataFlowTest(parameters, false);
    // two URNs, but one is unstarted
    parameters.setProperty("urns", validUnstartedURN.getValue());
    parameters.setProperty("useStrategyURN", "true");
    doDataFlowTest(parameters, false);
    // two URNs, but one is invalid
    parameters.setProperty("urns", invalidURN.getValue());
    doDataFlowTest(parameters, false);
    // valid, started, but not emitter
    parameters.setProperty("urns", validURNNotEmitter.getValue());
    doDataFlowTest(parameters, false);
    // valid, started, but not receiver
    parameters.setProperty("urns", dataEmitterURN.getValue() + "," + validURNNotReceiver.getValue());
    doDataFlowTest(parameters, false);
    // valid simple test with 2 URNs
    parameters.setProperty("urns", dataEmitterURN.getValue());
    doDataFlowTest(parameters, true);
    // again, but this time setting up extra data flow tests
    parameters.setProperty("shouldCancelDataFlow", "true");
    doDataFlowTest(parameters, true);
    parameters.remove("shouldCancelDataFlow");
    // repeat the test, but sabotage the manual cancel
    parameters.setProperty("urns", dataEmitterURN.getValue());
    parameters.setProperty("shouldSkipCancel", "true");
    doDataFlowTest(parameters, true);
    parameters.remove("shouldSkipCancel");
    // all tests so far have been without the sink, now add the sink
    parameters.setProperty("routeToSink", "true");
    doDataFlowTest(parameters, true);
    // do a test that sets up a data flow that doesn't involve the strategy
    parameters.remove("useStrategyURN");
    parameters.remove("routeToSink");
    parameters.setProperty("urns",
            dataEmitterURN.getValue() + "," + MockRecorderModule.Factory.recorders.get(outputURN).getURN());
    doDataFlowTest(parameters, true);
    // a new test that tries to set up a data flow when the strategy can't accept new data
    parameters.setProperty("urns", dataEmitterURN.getValue());
    parameters.setProperty("useStrategyURN", "true");
    parameters.setProperty("shouldMakeNewRequest", "true");
    doDataFlowTest(parameters, true);
}

From source file:org.regenstrief.util.Util.java

public final static void set(final Properties prop, final String key, final String val) {
    if (val != null) {
        prop.setProperty(key, val);
    } else {// ww  w.j av  a2  s. c  om
        prop.remove(key);
    }
}

From source file:org.apache.jmeter.JMeter.java

private void initializeProperties(CLArgsParser parser) {
    if (parser.getArgumentById(PROPFILE_OPT) != null) {
        JMeterUtils.loadJMeterProperties(parser.getArgumentById(PROPFILE_OPT).getArgument());
    } else {//from  w w  w . ja  va 2  s .c om
        JMeterUtils.loadJMeterProperties(NewDriver.getJMeterDir() + File.separator + "bin" + File.separator // $NON-NLS-1$
                + "jmeter.properties");// $NON-NLS-1$
    }

    if (parser.getArgumentById(JMLOGFILE_OPT) != null) {
        String jmlogfile = parser.getArgumentById(JMLOGFILE_OPT).getArgument();
        jmlogfile = processLAST(jmlogfile, ".log");// $NON-NLS-1$
        JMeterUtils.setProperty(LoggingManager.LOG_FILE, jmlogfile);
    }

    JMeterUtils.initLogging();
    JMeterUtils.initLocale();
    // Bug 33845 - allow direct override of Home dir
    if (parser.getArgumentById(JMETER_HOME_OPT) == null) {
        JMeterUtils.setJMeterHome(NewDriver.getJMeterDir());
    } else {
        JMeterUtils.setJMeterHome(parser.getArgumentById(JMETER_HOME_OPT).getArgument());
    }

    Properties jmeterProps = JMeterUtils.getJMeterProperties();
    remoteProps = new Properties();

    // Add local JMeter properties, if the file is found
    String userProp = JMeterUtils.getPropDefault("user.properties", ""); //$NON-NLS-1$
    if (userProp.length() > 0) { //$NON-NLS-1$
        FileInputStream fis = null;
        try {
            File file = JMeterUtils.findFile(userProp);
            if (file.canRead()) {
                log.info("Loading user properties from: " + file.getCanonicalPath());
                fis = new FileInputStream(file);
                Properties tmp = new Properties();
                tmp.load(fis);
                jmeterProps.putAll(tmp);
                LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
            }
        } catch (IOException e) {
            log.warn("Error loading user property file: " + userProp, e);
        } finally {
            JOrphanUtils.closeQuietly(fis);
        }
    }

    // Add local system properties, if the file is found
    String sysProp = JMeterUtils.getPropDefault("system.properties", ""); //$NON-NLS-1$
    if (sysProp.length() > 0) {
        FileInputStream fis = null;
        try {
            File file = JMeterUtils.findFile(sysProp);
            if (file.canRead()) {
                log.info("Loading system properties from: " + file.getCanonicalPath());
                fis = new FileInputStream(file);
                System.getProperties().load(fis);
            }
        } catch (IOException e) {
            log.warn("Error loading system property file: " + sysProp, e);
        } finally {
            JOrphanUtils.closeQuietly(fis);
        }
    }

    // Process command line property definitions
    // These can potentially occur multiple times

    List<CLOption> clOptions = parser.getArguments();
    for (CLOption option : clOptions) {
        String name = option.getArgument(0);
        String value = option.getArgument(1);
        FileInputStream fis = null;

        switch (option.getDescriptor().getId()) {

        // Should not have any text arguments
        case CLOption.TEXT_ARGUMENT:
            throw new IllegalArgumentException("Unknown arg: " + option.getArgument());

        case PROPFILE2_OPT: // Bug 33920 - allow multiple props
            try {
                fis = new FileInputStream(new File(name));
                Properties tmp = new Properties();
                tmp.load(fis);
                jmeterProps.putAll(tmp);
                LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
            } catch (FileNotFoundException e) {
                log.warn("Can't find additional property file: " + name, e);
            } catch (IOException e) {
                log.warn("Error loading additional property file: " + name, e);
            } finally {
                JOrphanUtils.closeQuietly(fis);
            }
            break;
        case SYSTEM_PROPFILE:
            log.info("Setting System properties from file: " + name);
            try {
                fis = new FileInputStream(new File(name));
                System.getProperties().load(fis);
            } catch (IOException e) {
                log.warn("Cannot find system property file " + e.getLocalizedMessage());
            } finally {
                JOrphanUtils.closeQuietly(fis);
            }
            break;
        case SYSTEM_PROPERTY:
            if (value.length() > 0) { // Set it
                log.info("Setting System property: " + name + "=" + value);
                System.getProperties().setProperty(name, value);
            } else { // Reset it
                log.warn("Removing System property: " + name);
                System.getProperties().remove(name);
            }
            break;
        case JMETER_PROPERTY:
            if (value.length() > 0) { // Set it
                log.info("Setting JMeter property: " + name + "=" + value);
                jmeterProps.setProperty(name, value);
            } else { // Reset it
                log.warn("Removing JMeter property: " + name);
                jmeterProps.remove(name);
            }
            break;
        case JMETER_GLOBAL_PROP:
            if (value.length() > 0) { // Set it
                log.info("Setting Global property: " + name + "=" + value);
                remoteProps.setProperty(name, value);
            } else {
                File propFile = new File(name);
                if (propFile.canRead()) {
                    log.info("Setting Global properties from the file " + name);
                    try {
                        fis = new FileInputStream(propFile);
                        remoteProps.load(fis);
                    } catch (FileNotFoundException e) {
                        log.warn("Could not find properties file: " + e.getLocalizedMessage());
                    } catch (IOException e) {
                        log.warn("Could not load properties file: " + e.getLocalizedMessage());
                    } finally {
                        JOrphanUtils.closeQuietly(fis);
                    }
                }
            }
            break;
        case LOGLEVEL:
            if (value.length() > 0) { // Set category
                log.info("LogLevel: " + name + "=" + value);
                LoggingManager.setPriority(value, name);
            } else { // Set root level
                log.warn("LogLevel: " + name);
                LoggingManager.setPriority(name);
            }
            break;
        case REMOTE_STOP:
            remoteStop = true;
            break;
        default:
            // ignored
            break;
        }
    }

    String sampleVariables = (String) jmeterProps.get(SampleEvent.SAMPLE_VARIABLES);
    if (sampleVariables != null) {
        remoteProps.put(SampleEvent.SAMPLE_VARIABLES, sampleVariables);
    }
    jmeterProps.put("jmeter.version", JMeterUtils.getJMeterVersion());
}