/* (non-Javadoc)
@see org.apache.maven.wagon.AbstractWagon#putDirectory(java.io.File, java.lang.String)
161889
@Override
	public void putDirectory(File sourceDirectory, String destinationDirectory)
			throws TransferFailedException, ResourceDoesNotExistException,
			AuthorizationException {
		String userName = getAuthenticationInfo().getUserName();
		String password = getAuthenticationInfo().getPassword();
		Repository repo = getRepository();
	
		String[] strings = StringUtils.split(repo.getBasedir(), '/');
		if(strings.length != 2){
			throw new IllegalArgumentException("GitHub url error, no repository owner or name.");
		}
		
		String repositoryName = strings[1];
		String repositoryOwner = strings[0];
		
		String branch = repo.getParameter("branch");
		String dryRun = repo.getParameter("dryRun");
		String force = repo.getParameter("force");
		String host = repo.getParameter("host");
		String merge = repo.getParameter("merge");
		String message = repo.getParameter("message");
		String noJekyll = repo.getParameter("noJekyll");
		String oauth2Token = repo.getParameter("oauth2Token");
		String repoUsername = repo.getUsername();
		String repoPassword = repo.getPassword();
		String threads = System.getProperty("threads", "1");
		
		if(StringUtils.isNotBlank(repoUsername)){
			fireTransferDebug("Override userName: " + userName + " -> " + repoUsername);
			userName = repoUsername;
		}
		if(StringUtils.isNotBlank(repoPassword)){
			fireTransferDebug("Override password by repository's.");
			password = repoPassword;
		}
		
		fireTransferDebug("userName: " + userName);
		fireTransferDebug("password: " + (password != null ? "***" : ""));
		fireTransferDebug("message: " + message);
		fireTransferDebug("branch: " + branch);
		fireTransferDebug("dryRun: " + dryRun);
		fireTransferDebug("force: " + force);
		fireTransferDebug("host: " + host);
		fireTransferDebug("merge: " + merge);
		fireTransferDebug("noJekyll: " + noJekyll);
		fireTransferDebug("oauth2Token: " + oauth2Token);
		fireTransferDebug("numThreads: " + threads);
		
		GitHub github = new GitHub();
		github.setUserName(userName);
		github.setPassword(password);
		github.setRepositoryName(repositoryName);
		github.setRepositoryOwner(repositoryOwner);
		
		if(StringUtils.isNotBlank(branch)){
			github.setBranch(branch);
		}
		if(StringUtils.isNotBlank(dryRun)){
			github.setDryRun("true".equals(dryRun));
		}
//		github.setExcludes(excludes);
		if(StringUtils.isNotBlank(force)){
			github.setForce("force".equals(force));
		}
		if(StringUtils.isNotBlank(host)){
			github.setHost(host);
		}
//		github.setIncludes(includes);
		if(StringUtils.isNotBlank(merge)){
			github.setMerge("true".equals(merge));
		}
		if(StringUtils.isNotBlank(message)){
			github.setMessage(message);
		}
		if(StringUtils.isNotBlank(noJekyll)){
			github.setNoJekyll("true".equals(noJekyll));
		}
		if(StringUtils.isNotBlank(oauth2Token)){
			github.setOauth2Token(oauth2Token);
		}
		if(StringUtils.isNumeric(threads)){
			github.setNumThreads(Integer.parseInt(threads));
		}
		
		try {
			github.deploy(sourceDirectory, destinationDirectory);
		} catch (GitHubException e) {
			throw new TransferFailedException(e.getMessage(), e);
		}
	}
1201453
public static void addFolder(Path p, JsonArray succeeded, JsonArray failed) throws IOException {
    FileSystem fs = FileSystem.get(p.toUri(), PersistHdfs.CONF);
    if(!fs.exists(p)){
      JsonObject o = new JsonObject();
      o.addProperty(Constants.FILE, p.toString());
      o.addProperty(Constants.ERROR, "Path does not exist!");
      failed.add(o);
      return;
    }
    addFolder(fs, p, succeeded, failed);
  }
1138540
public void setWorkingDirectory(Path dir) throws IOException {
    ensureState(JobState.DEFINE);
    conf.setWorkingDirectory(dir);
  }
491633
@Override
    public T addAsDirectory(String path) throws IllegalArgumentException {
        this.getArchive().addAsDirectory(path);
        return covarientReturn();
    }
498852
public void setCodeDirectory(String codeDirectory) {
        if (codeDirectory != null && codeDirectory.trim().length() > 0) {
            File file = new File(codeDirectory);
            if (file.exists() || file.mkdirs()) {
                this.codeDirectory = file;
            }
        }
    }
1156861
public static void createDirectory(final String directory) {
        if (directory == null) return;
        final File f = new File(directory);
        if (!f.isDirectory()) {
            if (!f.mkdir()) throw new RuntimeException("couldn't create "
                    + directory);
        }
    }
843259
public void put(String localFile, String remoteTargetDirectory) throws IOException {
        put(new String[]{localFile}, remoteTargetDirectory, "0600");
    }
281653
protected void writeFile(String subdir, String filename, String content) throws IOException {
        Path dir = root;
        if (subdir != null) {
            dir = dir.resolve(subdir);

            // If the dir does not exist, we need to create it
            if (Files.notExists(dir)) {
                Files.createDirectory(dir);
            }
        }
        Files.write(dir.resolve(filename), content.getBytes(StandardCharsets.UTF_8));
    }
765673
private void push(File directory) {
		// at this point file is guaranteed to be a directory
		stack.push(workingDirectory);
		workingDirectory = new Directory(directory);
		if (relativePath) {
			pathComponents.push(directory.getName());
		}
	}
180187
public final void setDirectory(final String directory) {
        if (SwingUtilities.isEventDispatchThread()) {
            setDirectoryIntern(directory);
        } else {
            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    public void run() {
                        setDirectoryIntern(directory);
                    }
                });
            } catch (final Exception ex) {
                ignore();
            }
        }
    }
318758
private void addFilesFromDir(File dir) {
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; i++) {
      if (!files[i].isDirectory()) {
        mFiles.add(files[i]);
      } else if (mRecursive) {
        addFilesFromDir(files[i]);
      }
    }
  }
560753
public void addOutputFile(String file) {
        if (file != null) {
            File f = new File(file);
            if (f.isDirectory()) {
                throw new IllegalArgumentException("output file parameter points to a directory, must be a file");
            } else if (f.exists() && !f.canWrite()) {
                throw new IllegalArgumentException(
                        "output file parameter points to a file we have no write permissions");
            }

            setOutputFile(f);
        }
    }
941060
public void setWorkingDirectory(String path) {
        if (path != null) {
            File dir = new File(path);
            checkWorkingDir(dir);
            workingDir = dir;
        } else {
            workingDir = null;
        }
    }
895287
public static void createParentDirectoryIfNecessary(final File file) {
        final File parentDirectory = file.getParentFile();
        if (parentDirectory == null || parentDirectory.mkdirs() || parentDirectory.exists()) {
            return;
	}
        throw new SdkClientException("Unable to create directory in the path: " + parentDirectory.getAbsolutePath());
    }
1318053
public static synchronized void chdir(String path) {
		if (path != null) {
			rootDir = new File(getAbsolutePath(path)).getAbsolutePath();
		}
	}
204907
public void setSrcdir(Path srcDir) {
        if (src == null) {
            src = srcDir;
        } else {
            src.append(srcDir);
        }
    }
246497
public static void copyDirectories(String[] directories, String storageFolder) throws IOException {
        copyDirectories(getFiles(directories), storageFolder);
    }