Example usage for org.apache.commons.lang SystemUtils getUserHome

List of usage examples for org.apache.commons.lang SystemUtils getUserHome

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils getUserHome.

Prototype

public static File getUserHome() 

Source Link

Document

Gets the user home directory as a File.

Usage

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

@Test
public void testSetEnumOption() throws CmdLineParseException {
    FetcherConfig config = new FetcherConfig();

    File expectedDir = new File(SystemUtils.getUserHome(), FilenameUtils.separatorsToSystem(".sdkfido/work"));

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(false));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(expectedDir));
    Assert.assertThat("Config.outputType", config.getOutputType(), is(OutputProjectType.SDK));

    File otherWork = testingdir.getFile("work");

    StringWriter capture = new StringWriter();
    ConfigCmdLineParser parser = new ConfigCmdLineParser(this, config);
    parser.setOut(capture);// w  w w. j a  va2  s.c  om
    String[] args = { "--dryRun", "true", "--workDir", otherWork.getAbsolutePath(), "--outputType", "SDK" };
    parser.parse(args);

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(true));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(otherWork));
    Assert.assertThat("Config.outputType", config.getOutputType(), is(OutputProjectType.SDK));
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

@Test
public void testSaveConfig() throws CmdLineParseException, IOException {
    testingdir.ensureEmpty();/*from   w  w  w  .  j a v  a  2 s  .  c om*/

    FetcherConfig config = new FetcherConfig();

    File expectedDir = new File(SystemUtils.getUserHome(), FilenameUtils.separatorsToSystem(".sdkfido/work"));

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(false));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(expectedDir));
    Assert.assertThat("Config.outputType", config.getOutputType(), is(OutputProjectType.SDK));

    File confFile = testingdir.getFile("config.properties");

    StringWriter capture = new StringWriter();
    ConfigCmdLineParser parser = new ConfigCmdLineParser(this, config);
    parser.setOut(capture);
    String[] args = { "--save-config", "--config", confFile.getAbsolutePath() };
    parser.parse(args);

    PathAssert.assertFileExists("Config File", confFile);

    Properties props = loadProps(confFile);

    Assert.assertThat("props[dryRun]", props.getProperty("dryRun"), is("false"));
    Assert.assertThat("props[workDir]", props.getProperty("workDir"), is(expectedDir.getAbsolutePath()));
    Assert.assertThat("props[outputType]", props.getProperty("outputType"), is("SDK"));
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

@Test
public void testLoadConfig() throws CmdLineParseException, IOException {
    FetcherConfig config = new FetcherConfig();

    File expectedDir = new File(SystemUtils.getUserHome(), FilenameUtils.separatorsToSystem(".sdkfido/work"));

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(false));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(expectedDir));
    Assert.assertThat("Config.outputType", config.getOutputType(), is(OutputProjectType.SDK));

    File confFile = MavenTestingUtils.getTestResourceFile("config2.properties");

    StringWriter capture = new StringWriter();
    ConfigCmdLineParser parser = new ConfigCmdLineParser(this, config);
    parser.setOut(capture);/*  ww w . ja va 2s . c  o m*/
    String[] args = { "--config", confFile.getAbsolutePath() };
    parser.parse(args);

    PathAssert.assertFileExists("Config File", confFile);

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(true));
    Assert.assertThat("config.maven.groupId", config.getMaven().getGroupId(), is("com.android.sdk.testee"));
    Assert.assertThat("config.maven.artifactId", config.getMaven().getArtifactId(), is("artifact-test"));
    Assert.assertThat("config.maven.includeStubJar", config.getMaven().isIncludeStubJar(), is(false));
    Assert.assertThat("config.outputType", config.getOutputType(), is(OutputProjectType.MAVEN_MULTI));
}

From source file:de.erdesignerng.util.ApplicationPreferences.java

/**
 * Get the directory where the datatype configuration is located.
 *
 * @return the directory//ww  w .j  a va  2 s. c  o m
 */
public File getDatatypeConfigDirectory() {
    File theUserHomeFile = SystemUtils.getUserHome();
    if (theUserHomeFile == null) {
        return getRelativeFile("dataTypes");
    }

    String theVersionNumber = MavenPropertiesLocator.getERDesignerVersionInfo();
    if (theVersionNumber.equals(MavenPropertiesLocator.CANNOT_IDENTIFY_VERSION)) {
        theVersionNumber = "development";
    }
    theVersionNumber = theVersionNumber.replace(".", "_");
    theVersionNumber = theVersionNumber.replace(" ", "_");
    theVersionNumber = theVersionNumber.replace("-", "_");

    File theMogwaiHome = new File(theUserHomeFile, ".mogwai");
    File theVersionHome = new File(theMogwaiHome, theVersionNumber);
    return new File(theVersionHome, "dataTypes");
}

From source file:org.excalibur.core.util.SystemUtils2.java

/**
 * <p>//from  www  .ja va  2  s  .  c  om
 * Returns a {@link String} representing the default application's data path.
 * 
 * <p>
 * <strong>Notice:</strong>The default directory is ~/.excalibur. However, it can be redefined through the system property:
 * <em>org.excalibur.application.data.dir</em>.
 * 
 * @return a {@link String} representing the default application's data directory.
 */
public static String getApplicationDataPath() {
    return System.getProperty(APPLICATION_DATA_DIR_PROPERTY_KEY,
            String.format("%s%s", SystemUtils.getUserHome().getAbsolutePath(), DEFAULT_EXCALIBUR_DATA_DIR_KEY));
}

From source file:org.jboss.tools.openshift.internal.ui.preferences.OpenShiftPreferencePage.java

public void createFieldEditors() {
    Link link = new Link(getFieldEditorParent(), SWT.WRAP);
    link.setText(/*from   w ww . j  a  v a 2 s  . c  o m*/
            "The OpenShift Client binary (oc) is required for features such as Port Forwarding or Log Streaming. "
                    + "You can find more information about how to install it from <a>here</a>.");
    GridDataFactory.fillDefaults().span(3, 1).hint(300, SWT.DEFAULT).applyTo(link);
    link.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL,
                    OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
        }
    });
    this.cliLocationEditor = new FileFieldEditor(IOpenShiftCoreConstants.OPENSHIFT_CLI_LOC,
            NLS.bind("''{0}'' executable location", ocBinary.getName()), getFieldEditorParent()) {

        @Override
        public boolean doCheckState() {
            return validateLocation(getStringValue());
        }

    };
    cliLocationEditor.setFilterPath(SystemUtils.getUserHome());
    cliLocationEditor.setFileExtensions(ocBinary.getExtensions());
    cliLocationEditor.setValidateStrategy(FileFieldEditor.VALIDATE_ON_KEY_STROKE);
    addField(cliLocationEditor);
}

From source file:org.springframework.integration.twitter.oauth.ConsoleBasedAccessTokenInitialRequestProcessListener.java

public static void main(String[] args) throws Exception {
    File twitterProps = new File(SystemUtils.getUserHome(), "Desktop/twitter.properties");

    PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
    propertiesFactoryBean.setLocation(new FileSystemResource(twitterProps));
    propertiesFactoryBean.afterPropertiesSet();
    Properties props = propertiesFactoryBean.getObject();

    String key = StringUtils.trim(props.getProperty("twitter.oauth.consumerKey"));
    String secret = StringUtils.trim(props.getProperty("twitter.oauth.consumerSecret"));

    ConsoleBasedAccessTokenInitialRequestProcessListener consoleBasedAccessTokenInitialRequestProcessListener = new ConsoleBasedAccessTokenInitialRequestProcessListener();

    Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance(key, secret);

    RequestToken requestToken = twitter.getOAuthRequestToken();
    AccessToken accessToken = null;/*from  w  w w.j  av a2s .  c om*/
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (null == accessToken) {
        String pin = consoleBasedAccessTokenInitialRequestProcessListener
                .openUrlAndReturnPin(requestToken.getAuthorizationURL());

        try {
            if (pin.length() > 0) {
                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
            } else {
                accessToken = twitter.getOAuthAccessToken();
            }
        } catch (TwitterException te) {
            if (401 == te.getStatusCode()) {
                System.out.println("Unable to get the access token.");
            } else {
                te.printStackTrace();
            }
        }
    }

    consoleBasedAccessTokenInitialRequestProcessListener.persistReturnedAccessToken(accessToken);

}

From source file:wasr.UserSettings.java

public static synchronized File getFolder() {
    File home = SystemUtils.getUserHome();
    File wasr = new File(home, ".wasr");
    if (!wasr.exists()) {
        wasr.mkdirs();//from  ww  w .  java  2s .c  om
    }
    return wasr;
}