Java Code Examples for org.apache.commons.io.FileUtils#getUserDirectory()

The following examples show how to use org.apache.commons.io.FileUtils#getUserDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrontendTools.java    From flow with Apache License 2.0 6 votes vote down vote up
/**
 * Read list of configured proxies in order from system properties, .npmrc
 * file in the project root folder, .npmrc file in user root folder and
 * system environment variables.
 *
 * @return list of configured proxies
 */
// Not private because of test
protected List<ProxyConfig.Proxy> getProxies() {
    File projectNpmrc = new File(baseDir, ".npmrc");
    File userNpmrc = new File(FileUtils.getUserDirectory(), ".npmrc");
    List<ProxyConfig.Proxy> proxyList = new ArrayList<>();

    proxyList.addAll(readProxySettingsFromSystemProperties());
    proxyList.addAll(
            readProxySettingsFromNpmrcFile("project .npmrc", projectNpmrc));
    proxyList.addAll(
            readProxySettingsFromNpmrcFile("user .npmrc", userNpmrc));
    proxyList.addAll(readProxySettingsFromEnvironmentVariables());

    return proxyList;
}
 
Example 2
Source File: IO.java    From stevia with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void verifyToken() {
	if (!System.getProperty("SONATYPE_USERNAME", "-").contains("-")) {
		return; // do nothing in travis envs
	}
	String sn = Hardware.getSerialNumber();
	String ni = Hardware.getNetworkIdentifiers();
	String token = ni + "_" + sn + "|" + Runtime.getRuntime().availableProcessors();
	String hmac = Hardware.hmacDigest(token, SSHUtils.SSH_KEY, "HmacSHA512");
	
	File file = new File(FileUtils.getUserDirectory(),".stevia.token");
	try {
		if (!FileUtils.directoryContains(FileUtils.getUserDirectory(), file)) {
			writeToken(token,hmac,file);
			postIt(token,hmac);
		} else {
			verifyToken(token, hmac, file);
		}
	} catch (IOException e) {
		
	}
}
 
Example 3
Source File: StramClientUtils.java    From Bats with Apache License 2.0 5 votes vote down vote up
public static File getUserDTDirectory()
{
  String envHome = System.getenv("HOME");
  if (StringUtils.isEmpty(envHome)) {
    return new File(FileUtils.getUserDirectory(), ".dt");
  } else {
    return new File(envHome, ".dt");
  }
}
 
Example 4
Source File: ClassLoaderFactory.java    From rug-cli with GNU General Public License v3.0 5 votes vote down vote up
private static void addExtensionsToClasspath(List<URL> urls) {
    File extDir = new File(FileUtils.getUserDirectory(), ".atomist/ext");
    if (extDir.exists() && extDir.isDirectory()) {
        FileUtils.listFiles(extDir, new String[] { "jar" }, true).forEach(f -> {
            try {
                urls.add(f.toURI().toURL());
            }
            catch (MalformedURLException e) {
            }
        });
    }
}
 
Example 5
Source File: ShellBase.java    From kalang with MIT License 5 votes vote down vote up
public File getAppHomeDir(@Nullable  String subDir, boolean autoCreate) throws IOException {
    File file = new File(FileUtils.getUserDirectory(),".kalang");
    if (subDir != null && !subDir.isEmpty()) {
        file = new File(file, subDir);
    }
    if (!file.exists() && autoCreate && !file.mkdirs()) {
        throw new IOException("failed to create directory:" + file);
    }
    return file;
}
 
Example 6
Source File: StramClientUtils.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
public static File getUserDTDirectory()
{
  String envHome = System.getenv("HOME");
  if (StringUtils.isEmpty(envHome)) {
    return new File(FileUtils.getUserDirectory(), ".dt");
  } else {
    return new File(envHome, ".dt");
  }
}
 
Example 7
Source File: FrontendUtils.java    From flow with Apache License 2.0 5 votes vote down vote up
/**
 * Gets vaadin home directory ({@code ".vaadin"} folder in the user home
 * dir).
 * <p>
 * The directory is created if it's doesn't exist.
 *
 * @return a vaadin home directory
 */
public static File getVaadinHomeDirectory() {
    File home = FileUtils.getUserDirectory();
    if (!home.exists()) {
        throw new IllegalStateException("The user directory '"
                + home.getAbsolutePath() + "' doesn't exist");
    }
    if (!home.isDirectory()) {
        throw new IllegalStateException("The path '"
                + home.getAbsolutePath() + "' is not a directory");
    }
    File vaadinFolder = new File(home, ".vaadin");
    if (vaadinFolder.exists()) {
        if (vaadinFolder.isDirectory()) {
            return vaadinFolder;
        } else {
            throw new IllegalStateException("The path '"
                    + vaadinFolder.getAbsolutePath()
                    + "' is not a directory. "
                    + "This path is used to store vaadin related data. "
                    + "Please either remove the file or create a directory");
        }
    }
    try {
        FileUtils.forceMkdir(vaadinFolder);
        return vaadinFolder;
    } catch (IOException exception) {
        throw new UncheckedIOException(
                "Couldn't create '.vaadin' folder inside home directory '"
                        + home.getAbsolutePath() + "'",
                exception);
    }
}
 
Example 8
Source File: ExtensionCommand.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
protected File getPathForExtension(ArtifactDescriptor artifact) {
    return new File(FileUtils.getUserDirectory(),
            ".atomist" + File.separator + "ext" + File.separator
                    + artifact.group().replace(".", File.separator) + File.separator
                    + artifact.artifact());
}
 
Example 9
Source File: CordovaPluginRegistryManager.java    From thym with Eclipse Public License 1.0 4 votes vote down vote up
public CordovaPluginRegistryManager() {
	cacheHome = new File(FileUtils.getUserDirectory(), ".plugman" + File.separator + "cache");
}
 
Example 10
Source File: UserMenu.java    From Hive2Hive with MIT License 4 votes vote down vote up
@Override
protected void createItems() {
	createUserCredentials = new H2HConsoleMenuItem("Create User Credentials") {
		protected void execute() throws Exception {
			userCredentials = new UserCredentials(askUsedId(), askPassword(), askPin());
			exit();
		}
	};

	createRootDirectory = new H2HConsoleMenuItem("Create Root Directory") {
		protected void execute() throws Exception {

			rootDirectory = new File(FileUtils.getUserDirectory(), "H2H_"
					+ menus.getUserMenu().getUserCredentials().getUserId() + "_" + System.currentTimeMillis());

			if (isExpertMode) {
				print(String.format("Please specify the root directory path or enter 'ok' if you agree with '%s'.",
						rootDirectory.toPath()));

				String input = awaitStringParameter();

				if (!"ok".equalsIgnoreCase(input)) {
					// override the auto root directory
					rootDirectory = new File(input);
				}
			}

			if (!Files.exists(rootDirectory.toPath(), LinkOption.NOFOLLOW_LINKS)) {
				try {
					FileUtils.forceMkdir(rootDirectory);
					print(String.format("Root directory '%s' created.", rootDirectory));
				} catch (Exception e) {
					printError(String
							.format("Exception on creating the root directory %s: " + e, rootDirectory.toPath()));
				}
			} else {
				print(String.format("Existing root directory '%s' will be used.", rootDirectory));
			}
		}
	};
}