Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

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

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:pl.project13.maven.git.GitCommitIdMojoIntegrationTest.java

@Test
@Parameters(method = "useNativeGit")
public void testDetectDirtyWorkingDirectory(boolean useNativeGit) throws Exception {
    // given/*from w  w w . ja  v a 2 s.c o  m*/
    mavenSandbox.withParentProject("my-pom-project", "pom").withChildProject("my-jar-module", "jar")
            .withGitRepoInChild(AvailableGitTestRepo.WITH_ONE_COMMIT) // GIT_WITH_CHANGES
            .create();
    MavenProject targetProject = mavenSandbox.getChildProject();

    setProjectToExecuteMojoIn(targetProject);

    GitDescribeConfig gitDescribeConfig = createGitDescribeConfig(true, 7);
    String dirtySuffix = "-dirtyTest";
    gitDescribeConfig.setDirty(dirtySuffix);
    alterMojoSettings("gitDescribe", gitDescribeConfig);

    alterMojoSettings("useNativeGit", useNativeGit);
    alterMojoSettings("commitIdGenerationMode", "flat");

    // when
    mojo.execute();

    // then
    Properties properties = targetProject.getProperties();
    assertThat(properties.get("git.dirty")).isEqualTo("true");
    assertThat(properties).includes(entry("git.commit.id.describe", "0b0181b" + dirtySuffix)); // assert dirtySuffix at the end!
}

From source file:com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory.java

/**
 * Gets the policy instance./*from   ww w  . ja v a 2s . co m*/
 * 
 * @param policy
 *            the policy
 * @param conProperties
 *            the con properties
 * @return the policy instance
 */
private LoadBalancingPolicy getPolicyInstance(BalancingPolicy policy, Properties conProperties) {

    LoadBalancingPolicy loadBalancingPolicy = null;
    String isTokenAware = (String) conProperties.get("isTokenAware");
    String isLatencyAware = (String) conProperties.get("isLatencyAware");
    String whiteList = (String) conProperties.get("whiteList");
    String hostFilterPolicy = (String) conProperties.get("hostFilterPolicy");
    // Policy.v
    switch (policy) {

    case DCAwareRoundRobinPolicy:

        String usedHostsPerRemoteDc = (String) conProperties.get("usedHostsPerRemoteDc");
        String localdc = (String) conProperties.get("localdc");
        String allowRemoteDCsForLocalConsistencyLevel = (String) conProperties
                .get("allowRemoteDCsForLocalConsistencyLevel");
        DCAwareRoundRobinPolicy.Builder policyBuilder = DCAwareRoundRobinPolicy.builder();
        policyBuilder.withLocalDc(localdc == null ? "DC1" : localdc);
        policyBuilder.withUsedHostsPerRemoteDc(
                usedHostsPerRemoteDc != null ? Integer.parseInt(usedHostsPerRemoteDc) : 0);
        if (allowRemoteDCsForLocalConsistencyLevel != null
                && "true".equalsIgnoreCase(allowRemoteDCsForLocalConsistencyLevel)) {
            policyBuilder.allowRemoteDCsForLocalConsistencyLevel();
        }
        loadBalancingPolicy = policyBuilder.build();
        break;

    // case RoundRobinPolicy:
    // loadBalancingPolicy = new RoundRobinPolicy();
    // break;

    default:
        // default is RoundRobinPolicy
        loadBalancingPolicy = new RoundRobinPolicy();
        break;
    }

    if (loadBalancingPolicy != null && Boolean.valueOf(isTokenAware)) {
        loadBalancingPolicy = new TokenAwarePolicy(loadBalancingPolicy);
    } else if (loadBalancingPolicy != null && Boolean.valueOf(isLatencyAware)) {
        loadBalancingPolicy = LatencyAwarePolicy.builder(loadBalancingPolicy).build();
    }

    if (loadBalancingPolicy != null && whiteList != null) {
        Collection<InetSocketAddress> whiteListCollection = buildWhiteListCollection(whiteList);

        loadBalancingPolicy = new WhiteListPolicy(loadBalancingPolicy, whiteListCollection);
    }

    if (loadBalancingPolicy != null && hostFilterPolicy != null) {
        Predicate<com.datastax.driver.core.Host> predicate = getHostFilterPredicate(hostFilterPolicy);

        loadBalancingPolicy = new HostFilterPolicy(loadBalancingPolicy, predicate);
    }

    return loadBalancingPolicy;
}

From source file:com.antonjohansson.geolocation.config.Configuration.java

private <T> T getInstance(Properties properties, Class<T> target) {
    String type = target.getSimpleName().toLowerCase();
    String className = properties.getProperty(type);
    Class<?> clazz = getClass(className);
    if (!target.isAssignableFrom(clazz)) {
        throw new RuntimeException("'" + clazz.getName() + "' is not a valid " + type);
    }/*  w  w w  . j  av a2  s.  co m*/
    T instance = newInstance(clazz.asSubclass(target));

    List<String> keys = properties.keySet().stream().filter(key -> key instanceof String)
            .map(key -> (String) key).filter(key -> key.startsWith(type))
            .filter(key -> key.length() > type.length()).map(key -> key.substring(type.length() + 1))
            .filter(key -> isWriteable(instance, key)).collect(toList());

    for (String key : keys) {
        Object value = properties.get(type + "." + key);
        try {
            setProperty(instance, key, value);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    return instance;
}

From source file:org.alfresco.bm.tools.BMTestRunnerTest.java

@Test
public void testWithProperties() throws Throwable {
    // Override the Mongo configuration host to something that fails
    final Properties testProperties = new Properties();
    testProperties.setProperty(PROP_MONGO_TEST_DATABASE, "testWithProperties");

    /**/*  w w  w  . j a  v a2s .co  m*/
     * A listener that ensures that we've pushed the test run results into the correct database
     */
    BMTestRunnerListener listener = new BMTestRunnerListenerAdaptor() {
        @Override
        public void testRunStarted(ApplicationContext testCtx, String test, String run) {
            TestRunServicesCache services = testCtx.getBean(TestRunServicesCache.class);
            ResultService rsCheck = services.getResultService(test, run);
            String expectedDataLocation = testProperties.get(PROP_MONGO_TEST_DATABASE) + "." + test + "." + run
                    + ".results";
            Assert.assertEquals("Data location was not changed for test.", expectedDataLocation,
                    rsCheck.getDataLocation());
        }
    };
    BMTestRunner runner = new BMTestRunner(60000L);
    runner.addListener(listener);
    runner.run(null, null, testProperties);
}

From source file:com.cyclopsgroup.waterview.servlet.WaterviewServlet.java

/**
 * Override method init in super class of MainServlet
 *
 * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig)
 *///from w  w  w  .  j ava 2 s . c  om
public void init(ServletConfig config) throws ServletException {
    applicationBase = config.getInitParameter("application.base");

    servletConfig = config;
    String basedir = config.getServletContext().getRealPath("");
    Properties initProperties = new Properties();
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);
    Enumeration i = config.getInitParameterNames();
    while (i.hasMoreElements()) {
        String key = (String) i.nextElement();
        String value = config.getInitParameter(key);
        initProperties.setProperty(key, value);
    }
    try {
        container = new WaterviewPlexusContainer();
        serviceManager = new ServiceManagerAdapter(container);
        for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
            String initPropertyName = (String) j.next();
            container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
        }

        container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
        container.initialize();
        container.start();
    } catch (Exception e) {
        container.getLogger().fatalError("Can not start container", e);
    }
}

From source file:com.mirth.connect.server.controllers.DefaultExtensionController.java

@Override
public void setPluginProperties(String pluginName, Properties properties) throws ControllerException {
    configurationController.removePropertiesForGroup(pluginName);

    for (Object name : properties.keySet()) {
        configurationController.saveProperty(pluginName, (String) name, (String) properties.get(name));
    }//from   ww w  . j  a v a 2s .co m
}

From source file:de.iritgo.aktario.framework.IritgoEngine.java

/**
 * Initialize the framework./*from w  w  w  .  ja v  a  2s.c  om*/
 *
 * @param options The command line options.
 * @throws InitIritgoException If an error occurred during initialization.
 */
private void init(CommandLine options) {
    try {
        commandLine = options;

        File sysDir = new File(".");

        if (commandLine.hasOption("s")) {
            sysDir = new File(commandLine.getOptionValue("s").trim());
        }

        try {
            Properties sysProperties = new Properties();

            sysProperties.load(new FileInputStream(new File(sysDir, "sys.properties")));

            for (Object key : sysProperties.keySet()) {
                System.setProperty(key.toString(), sysProperties.get(key).toString());
            }
        } catch (FileNotFoundException x1) {
        } catch (IOException x1) {
        }

        AppContext appContext = AppContext.instance();
        ServerAppContext serverAppContext = ServerAppContext.serverInstance();

        if (options.hasOption("d")) {
            Log.setLevel(NumberTools.toInt(options.getOptionValue("d"), Log.ERROR));
        } else if (System.getProperty("iritgo.debug.level") != null) {
            Log.setLevel(NumberTools.toInt(System.getProperty("iritgo.debug.level"), Log.ERROR));
        } else {
            Log.setLevel(Log.ERROR);
        }

        initEngine();

        if (mode == IritgoEngine.START_CLIENT) {
            try {
                //TODO: xml rpc port Hack!
                String xmlRPCPort = commandLine.getOptionValue("x");

                if (!StringTools.isEmpty(xmlRPCPort)) {
                    System.out.println("****************** xmlRPCPort:" + xmlRPCPort);
                    appContext.put("xmlrpcport", xmlRPCPort);
                }

                splash = (Splash) Class.forName("de.iritgo.aktario.core.splash.CustomSplash").newInstance();
            } catch (Exception x) {
                splash = new Splash();
            }
        }

        if (splash != null) {
            splash.setText("Initializing: Engine");
        }

        initIdGenerator();
        registerDefaultActions();
        registerDefaultManager();
        registerConsoleCommands();
        initCommandProcessor();
        initConfiguration();

        if (mode == IritgoEngine.START_SERVER) {
            server = Server.instance();
            server.init();
            serverAppContext.setServer(true);
            serverAppContext.setClient(false);
            appContext.setServer(true);
            appContext.setClient(false);
        }

        if (mode == IritgoEngine.START_CLIENT) {
            checkLoginOptions(commandLine);
            client = Client.instance();
            client.init();
            serverAppContext.setServer(false);
            serverAppContext.setClient(true);
            appContext.setServer(false);
            appContext.setClient(true);
        }

        initPlugins();
        AgentManager.createAgentManager(mode);

        registerDefaultDataObjects();

        if (mode == IritgoEngine.START_SERVER) {
            server = Server.instance();
            server.start();
        }

        if (mode == IritgoEngine.START_CLIENT) {
            splash.setText("Initializing: Client");
            client = Client.instance();
            client.initGUI();
            client.startGUI();
            client.startApplication();
            splash.startCoolDown();
        }
    } catch (InitIritgoException x) {
        if (engine != null) {
            engine.stop();
        }
    }
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.BuildReportRenderer.java

private void renderMultiTupleValue(final Properties buildMetaDataProperties, final Object value,
        final String subKeyPrefix) {
    final String stringValue = Constant.prettify((String) value);
    if (hasMultipleValues(stringValue)) {
        final StringTokenizer tokenizer = new StringTokenizer(stringValue, ",");
        sink.numberedList(Sink.NUMBERING_DECIMAL);
        while (tokenizer.hasMoreTokens()) {
            final String profileName = tokenizer.nextToken().trim();
            final String subKey = subKeyPrefix + '.' + profileName;
            final Object subValue = buildMetaDataProperties.get(subKey);
            final String item = profileName + ':' + subValue;
            sink.listItem();/*w w w  .j av  a  2s .co  m*/
            sink.text(item);
            sink.listItem_();
        }
        sink.numberedList_();
    } else {
        sink.text(String.valueOf(value));
    }
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.comment.ApiCommentInterface.java

public JAXBComment getCommentForApi(Properties properties) throws Throwable {
    JAXBComment jaxbComment = null;/*from w  w w .j a v a  2 s .  c o m*/
    try {
        String idParam = properties.getProperty("id");
        if (!StringUtils.isNumeric(idParam)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR,
                    "The comment id must be an integer", Response.Status.ACCEPTED);
        }
        IIdeaComment comment = this.getIdeaCommentManager().getComment(new Integer(idParam));
        if (null == comment) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
                    "comment with code '" + idParam + "' does not exist", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.validateComment(comment, user);
        jaxbComment = new JAXBComment(comment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting comment", t);
        throw new ApsSystemException("Error extracting comment", t);
    }
    return jaxbComment;
}

From source file:com.basistech.ReleaseNoteMojo.java

private String getTagName() throws MojoExecutionException {
    if (tag != null) {
        return tag;
    }//w  w w.j  av a  2 s.c  om

    String scmTag = (String) project.getProperties().get("scm.tag");
    if (scmTag != null) {
        return scmTag;
    }

    File releasePropsFile = new File(project.getBasedir(), "release.properties");
    if (releasePropsFile.exists()) {
        Properties releaseProps = new Properties();
        InputStream is = null;
        try {
            is = new FileInputStream(releasePropsFile);
            releaseProps.load(is);
        } catch (IOException ie) {
            throw new MojoExecutionException("Failed to read release.properties", ie);
        } finally {
            IOUtils.closeQuietly(is);
        }

        String propTag = (String) releaseProps.get("scm.tag");
        if (propTag != null) {
            return propTag;
        }
    }
    throw new MojoExecutionException("No scm tag information available.");
}