Example usage for java.lang System setProperties

List of usage examples for java.lang System setProperties

Introduction

In this page you can find the example usage for java.lang System setProperties.

Prototype

public static void setProperties(Properties props) 

Source Link

Document

Sets the system properties to the Properties argument.

Usage

From source file:org.xmlsh.sh.shell.Shell.java

public static void uninitialize() {
    if (!bInitialized)
        return;/*from   w w  w .ja va  2  s. c  o  m*/

    System.setProperties(mSavedSystemProperties);
    mSavedSystemProperties = null;
    SystemEnvironment.uninitialize();
    ThreadLocalShell.set(null);
    bInitialized = false;
}

From source file:org.sonatype.sisu.bl.jsw.JSWConfigTest.java

@Test
public void wrapperSystemPropertiesOverrideDisabled() throws Exception {
    Properties backup = new Properties();
    backup.putAll(System.getProperties());

    Map<String, String> testProps = Maps.newHashMap();
    testProps.put("wrapper.prop", "something");
    System.getProperties().putAll(testProps);

    jswConfig.setWrapperSystemOverridesEnabled(false);
    jswConfig.load();//from  w  w  w.j  a va  2s .  c om

    jswConfig.save();

    // check that overridden properties are written
    assertThat(config, doesNotContain("#  system overrides"));
    assertThat(config, doesNotContain("wrapper.prop=something"));

    // reset system properties
    System.setProperties(backup);

}

From source file:TransformThread.java

/** Sets the appropriate system properties if XSLTC is
 * to be used (according to USE_XSLTC)//  ww  w.  j a v  a 2  s  . co  m
 */
private static void initSystemProperties() {
    if (USE_XSLTC) {
        // Set the TransformerFactory system property if XSLTC is required
        // Note: To make this sample more flexible, load properties from a properties file.
        // The setting for the Xalan Transformer is "org.apache.xalan.processor.TransformerFactoryImpl"
        String key = "javax.xml.transform.TransformerFactory";
        String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
        Properties props = System.getProperties();
        props.put(key, value);
        System.setProperties(props);
    }
}

From source file:edu.umich.ctools.sectionsUtilityTool.Friend.java

/**
 * Returns to uninitialized state.//  w  w  w.j  av  a2 s  .co  m
 */
public void destroy() {
    M_log.info(this + ".destroy()");

    if (sslInitialized) {
        // remove ssl system settings
        // configure JSSE system properties: 
        // http://fusesource.com/docs/broker/5.3/security/SSL-SysProps.html
        Properties systemProps = System.getProperties();
        //systemProps.remove("javax.net.debug");
        //important: http://stackoverflow.com/questions/6680416/apache-cxf-exception-in-ssl-communication-sockettimeout
        //java.lang.System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");
        systemProps.remove("javax.net.ssl.keyStoreType");
        systemProps.remove("javax.net.ssl.trustStoreType");
        systemProps.remove("javax.net.ssl.keyStore");
        systemProps.remove("javax.net.ssl.keyStorePassword");
        System.setProperties(systemProps);

        sslInitialized = false;
    }
}

From source file:org.jboss.as.capedwarf.extension.CapedwarfSubsystemAdd.java

/**
 * {@inheritDoc}//from w w w. j ava  2  s .  co m
 */
@Override
public void performBoottime(final OperationContext context, ModelNode operation, ModelNode model,
        ServiceVerificationHandler verificationHandler, final List<ServiceController<?>> newControllers)
        throws OperationFailedException {

    final ModelNode appEngineModel = CapedwarfDefinition.APPENGINE_API.resolveModelAttribute(context, model);
    final String appengineAPI = appEngineModel.isDefined() ? appEngineModel.asString() : null;

    final ModelNode adminTGTModel = CapedwarfDefinition.ADMIN_TGT.resolveModelAttribute(context, model);
    final String adminTGT = adminTGTModel.isDefined() ? adminTGTModel.asString() : null;

    final CapedwarfProperties properties = new CapedwarfProperties(System.getProperties());
    System.setProperties(properties); // override global properties, w/o synched code ...

    // register custom URLStreamHandlerFactory
    registerURLStreamHandlerFactory();

    // register custom Socket Factory
    registerSocketFactory();

    addTiffSupport();

    readCapedwarfConf();

    context.addStep(new AbstractDeploymentChainStep() {
        public void execute(DeploymentProcessorTarget processorTarget) {
            final ServiceTarget serviceTarget = context.getServiceTarget();

            addQueueConsumer(serviceTarget, newControllers);

            final ThreadsHandler handler = new SimpleThreadsHandler();
            putExecutorServiceToRegistry(serviceTarget, newControllers, handler);
            putThreadFactoryToRegistry(serviceTarget, newControllers, handler);
            addHttpClient(serviceTarget, newControllers);

            addServicesToRegistry(serviceTarget, newControllers);

            final TempDir tempDir = createTempDir(serviceTarget, newControllers);

            final int initialStructureOrder = Math.max(
                    Math.max(Phase.STRUCTURE_WAR, Phase.STRUCTURE_WAR_DEPLOYMENT_INIT), Phase.STRUCTURE_EAR);
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.STRUCTURE,
                    initialStructureOrder + 10, new CapedwarfInitializationProcessor());
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.STRUCTURE,
                    initialStructureOrder + 20, new CapedwarfSubsystemProcessor());
            final int initialParseOrder = Math.min(Phase.PARSE_WEB_DEPLOYMENT, Phase.PARSE_PERSISTENCE_UNIT);
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 20,
                    new CapedwarfEarAppInfoParseProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 18,
                    new CapedwarfWebAppInfoParseProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 16,
                    new CapedwarfAppIdProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 14,
                    new CapedwarfXmlsParserProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 12,
                    new CapedwarfCompatibilityParseProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE, initialParseOrder - 10,
                    new CapedwarfPersistenceModificationProcessor(tempDir)); // before persistence.xml parsing
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE,
                    Phase.PARSE_WEB_DEPLOYMENT + 1, new CapedwarfWebCleanupProcessor()); // right after web.xml parsing
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE,
                    Phase.PARSE_WEB_COMPONENTS - 1, new CapedwarfWebComponentsDeploymentProcessor(adminTGT));
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.PARSE,
                    Phase.PARSE_WELD_DEPLOYMENT + 10, new CapedwarfWeldParseProcessor()); // before Weld web integration
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.REGISTER,
                    Phase.REGISTER_BUNDLE_INSTALL - 10, new CapedwarfJPAProcessor()); // before default JPA processor
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.DEPENDENCIES,
                    Phase.DEPENDENCIES_WELD - 10, new CapedwarfWeldProcessor()); // before Weld
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.DEPENDENCIES,
                    Phase.DEPENDENCIES_JPA - 10, new CapedwarfExcludeGaeApiProcessor(appengineAPI)); // before CapedwarfDeploymentProcessor
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.DEPENDENCIES,
                    Phase.DEPENDENCIES_JPA - 7, new CapedwarfEarDeploymentProcessor()); // ear CL deps
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.DEPENDENCIES,
                    Phase.DEPENDENCIES_JPA - 5, new CapedwarfDeploymentProcessor(appengineAPI)); // web CL deps
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.DEPENDENCIES,
                    Phase.DEPENDENCIES_JPA - 1, new CapedwarfCacheEntriesTopProcessor()); // gather cache configs
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_INJECTION_ANNOTATION - 9, new CapedwarfModuleProcessor()); // right after module
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_INJECTION_ANNOTATION - 1, new CapedwarfEnvironmentProcessor(properties)); // after module
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_LOGGING_CONFIG - 1, new CapedwarfLoggingParseProcessor()); // just before AS logging configuration
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS + 10, new CapedwarfCDIExtensionProcessor()); // after Weld portable extensions lookup
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS + 20, new CapedwarfEntityProcessor()); // adjust as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS + 30, new CapedwarfPostModuleJPAProcessor()); // after entity processor
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS + 40, new CapedwarfSynchHackProcessor()); // after module, adjust as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_SAR_SERVICE_COMPONENT + 2, new CapedwarfCacheEntriesWebProcessor()); // gather cache configs
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_SAR_SERVICE_COMPONENT + 4, new CapedwarfCleanupProcessor()); // we still need module/CL
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_SAR_SERVICE_COMPONENT + 5, new CapedwarfSubCleanupProcessor()); // we still need module/CL
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.POST_MODULE,
                    Phase.POST_MODULE_SAR_SERVICE_COMPONENT + 6, new CapedwarfWebContextProcessor()); // before web context lifecycle
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.INSTALL,
                    Phase.INSTALL_WAR_DEPLOYMENT - 2, new CapedwarfCacheProcessor()); // after module
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.INSTALL,
                    Phase.INSTALL_WAR_DEPLOYMENT - 1, new CapedwarfMuxIdProcessor()); // adjust order as needed
            processorTarget.addDeploymentProcessor(Constants.CAPEDWARF, Phase.INSTALL,
                    Phase.INSTALL_MODULE_JNDI_BINDINGS - 2, new CapedwarfDependenciesProcessor()); // after logging
        }
    }, OperationContext.Stage.RUNTIME);

}

From source file:org.metaeffekt.dcc.commons.script.CommandScriptExecutor.java

private void executeCommandScriptSameJvm(Commands command, File scriptFile, final Id<UnitId> unitId,
        Id<PackageId> packageId, final File executionPropertiesFile, File prerequisitesPropertiesFile) {

    final File packageDir = new File(executionContext.getPackageDir(), packageId.getValue());

    final Project project = new ProjectAdapter();
    try {//from w  w w .j  a  v  a  2s  .c  om
        project.setUserProperty(ANT_FILE, scriptFile.getAbsolutePath());

        // all executions are relative to the package
        project.setBaseDir(packageDir);

        if (executionPropertiesFile != null) {
            project.setProperty(DCC_EXECUTION_PROPERTIES, executionPropertiesFile.getAbsolutePath());
        }

        if (prerequisitesPropertiesFile != null) {
            project.setProperty(DCC_PREREQUISITES_PROPERTIES, prerequisitesPropertiesFile.getAbsolutePath());
        }

        if (executionContext.getUpgradePropertiesFile() != null) {
            project.setProperty(DCC_UPGRADE_PROPERTIES,
                    executionContext.getUpgradePropertiesFile().getAbsolutePath());
        }

        project.setProperty(DCC_COMMAND, command.toString());
        project.setProperty(DCC_TARGET_DIR, executionContext.getTargetDir().getAbsolutePath());
        project.setProperty(DCC_SOLUTION_DIR, executionContext.getSolutionDir().getAbsolutePath());
        project.setProperty(DCC_PACKAGE_DIR, executionContext.getPackageDir().getAbsolutePath());

        project.setProperty(DCC_UNIT_ID, unitId.getValue());
        project.setProperty(DCC_PACKAGE_ID, packageId.getValue());
        project.setProperty(DCC_JAVA_HOME, System.getProperty("java.home"));
        project.setProperty(DCC_DEPLOYMENT_ID, executionContext.getDeploymentId().getValue());

        project.init();

        final ProjectHelper helper = ProjectHelper.getProjectHelper();
        project.addReference(ANT_PROJECT_HELPER, helper);
        helper.parse(project, scriptFile);

        // the project helper modifies the projects baseDir; we ensure it points to the right
        // spot
        project.setBaseDir(packageDir);

        // preserve properties to avoid side-effects in between script executions
        final Properties originalSystemProperties = isolateSystemProperties();
        try {
            // execute the scripts default target
            project.executeTarget(project.getDefaultTarget());
        } finally {
            // restore original properties
            System.setProperties(originalSystemProperties);
        }
    } finally {
        //cleans the loaded classes
        project.fireBuildFinished(null);
    }
}

From source file:org.gradle.integtests.fixtures.executer.InProcessGradleExecuter.java

private BuildResult doRun(OutputStream outputStream, OutputStream errorStream, BuildListenerImpl listener) {
    // Capture the current state of things that we will change during execution
    InputStream originalStdIn = System.in;
    Properties originalSysProperties = new Properties();
    originalSysProperties.putAll(System.getProperties());
    File originalUserDir = new File(originalSysProperties.getProperty("user.dir")).getAbsoluteFile();
    Map<String, String> originalEnv = new HashMap<String, String>(System.getenv());

    GradleInvocation invocation = buildInvocation();
    Set<String> changedEnvVars = new HashSet<String>(invocation.environmentVars.keySet());

    try {/*from  w  w  w  .  j a va2s.  c  o m*/
        return executeBuild(invocation, outputStream, errorStream, listener);
    } finally {
        // Restore the environment
        System.setProperties(originalSysProperties);
        resetTempDirLocation();
        processEnvironment.maybeSetProcessDir(originalUserDir);
        for (String envVar : changedEnvVars) {
            String oldValue = originalEnv.get(envVar);
            if (oldValue != null) {
                processEnvironment.maybeSetEnvironmentVariable(envVar, oldValue);
            } else {
                processEnvironment.maybeRemoveEnvironmentVariable(envVar);
            }
        }
        System.setProperty("user.dir", originalSysProperties.getProperty("user.dir"));
        System.setIn(originalStdIn);
    }
}

From source file:com.vmware.identity.idm.server.clientcert.IdmCertificatePathValidator.java

/**
 * Set a ThreadLocal property to System property.
 *
 * @param key//from   w  w  w.j  av a2 s . com
 * @param val
 * @throws CertificateRevocationCheckException
 */
private void setThreadLocalSystemProperty(String key, String val) throws CertificateRevocationCheckException {
    if (System.getProperties() instanceof ThreadLocalProperties) {
        ThreadLocalProperties properties = (ThreadLocalProperties) System.getProperties();
        properties.setThreadLocalProperty(key, val);
        System.setProperties(properties);
    } else {
        throw new CertificateRevocationCheckException(
                "System properties was not initialized to ThreadLocalProperties");
    }
}

From source file:org.universAAL.itests.IntegrationTest.java

/**
 * Sets run arguments of uAAL platform.//from  ww  w.  j  a v  a 2 s . co m
 *
 * @param p
 *            Properties which represent run arguments.
 */
protected void setRunArguments(final Properties p) {
    System.setProperties(p);
    runArgsAreSet = true;
}

From source file:org.atomserver.utils.test.TestingAtomServer.java

private Server createServer(int port, String atomserverServletContext) {
    // set up the server and the atomserver web application context
    Server server = new Server(port);
    Context context = new Context(server, "/" + atomserverServletContext, true /*sessions*/,
            false /*no security*/);

    // we need to hard-code certain system properties to get the behavior we want here - we
    // will re-set them when we're done
    Properties properties = (Properties) System.getProperties().clone();
    System.setProperty("atomserver.env", "asdev-hsql-mem");
    System.setProperty("atomserver.servlet.context", atomserverServletContext);

    // TODO: this should be removed
    System.setProperty("atomserver.servlet.mapping", "v1");

    // our Spring application context will start off by loading the basic built-in bean
    // definitions
    appContext = new GenericWebApplicationContext();

    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/propertyConfigurerBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/databaseBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/logBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/storageBeans.xml"));
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/abderaBeans.xml"));

    // if we were given a Spring config location, we use that -- otherwise we configure the
    // workspaces that were set up through the API
    if (springBeansLocation != null) {
        xmlReader.loadBeanDefinitions(new ClassPathResource(springBeansLocation));
    } else {//from   ww w  . j a v  a 2  s  .c  om
        RootBeanDefinition workspaces = new RootBeanDefinition(HashSet.class);
        ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues();
        constructorArgumentValues.addGenericArgumentValue(workspaceSet);
        workspaces.setConstructorArgumentValues(constructorArgumentValues);

        appContext.registerBeanDefinition("org.atomserver-workspaces", workspaces);
    }

    // override the base content storage to use DB-based storage
    RootBeanDefinition storage = new RootBeanDefinition(DBBasedContentStorage.class);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("contentDAO", new RuntimeBeanReference("org.atomserver-contentDAO"));
    propertyValues.addPropertyValue("entriesDAO", new RuntimeBeanReference("org.atomserver-entriesDAO"));
    storage.setPropertyValues(propertyValues);
    appContext.registerBeanDefinition("org.atomserver-contentStorage", storage);

    // clear the existing ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // refresh the context to actually instantiate everything.
    appContext.refresh();

    // re-set the system properties
    System.setProperties(properties);

    // clear the update ENV
    ConfigurationAwareClassLoader.invalidateENV();

    // put our app context into the servlet context
    context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext);

    // load and init the service context for v1
    final ServiceContext serviceContext = (ServiceContext) appContext.getBean(ServiceContext.class.getName());
    serviceContext.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servlet = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContext;
        }
    };

    // load and init the service context for v2
    final ServiceContext serviceContextV2 = (ServiceContext) appContext
            .getBean("org.atomserver-serviceContext.v2");
    serviceContextV2.init(new Abdera(), Collections.EMPTY_MAP);

    // create a new AtomServerServlet - but override the createServiceContext method
    AtomServerServlet servletV2 = new AtomServerServlet() {
        protected ServiceContext createServiceContext() {
            return serviceContextV2;
        }
    };

    // register the servlets
    context.addServlet(new ServletHolder(servlet), "/v1/*");
    context.addServlet(new ServletHolder(servletV2), "/v2/*");

    EntriesDAOiBatisImpl entriesDAO = (EntriesDAOiBatisImpl) appContext.getBean("org.atomserver-entriesDAO");
    entriesDAO.setUseWorkspaceCollectionCache(false);

    // ready to be started
    return server;
}