Java Code Examples for org.eclipse.jgit.api.CloneCommand#setURI()

The following examples show how to use org.eclipse.jgit.api.CloneCommand#setURI() . 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: UIGit.java    From hop with Apache License 2.0 6 votes vote down vote up
public boolean cloneRepo( String directory, String uri ) {
  CloneCommand cmd = Git.cloneRepository();
  cmd.setDirectory( new File( directory ) );
  cmd.setURI( uri );
  cmd.setCredentialsProvider( credentialsProvider );
  try {
    Git git = cmd.call();
    git.close();
    return true;
  } catch ( Exception e ) {
    if ( ( e instanceof TransportException )
        && ( ( e.getMessage().contains( "Authentication is required but no CredentialsProvider has been registered" )
          || e.getMessage().contains( "not authorized" ) ) ) ) {
      if ( promptUsernamePassword() ) {
        return cloneRepo( directory, uri );
      }
    } else {
      showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), e.getMessage() );
    }
  }
  return false;
}
 
Example 2
Source File: ExtensionPointAction.java    From maestro-java with Apache License 2.0 5 votes vote down vote up
private void doClone() throws GitAPIException, IOException {
    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(REPOSITORY_URL);

    File repositoryDir = new File(directory, name);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(new TextProgressMonitor());

    cloneCommand.call();
    System.out.println("Project directory for project created at " + repositoryDir);

    FileUtils.deleteDirectory(new File(repositoryDir, ".git"));
}
 
Example 3
Source File: ProjectWebsiteTest.java    From jbake with MIT License 5 votes vote down vote up
private void cloneJbakeWebsite() throws GitAPIException {
    CloneCommand cmd = Git.cloneRepository();
    cmd.setBare(false);
    cmd.setBranch("master");
    cmd.setRemote("origin");
    cmd.setURI(WEBSITE_REPO_URL);
    cmd.setDirectory(projectFolder);

    cmd.call();

    assertThat(new File(projectFolder,"README.md").exists()).isTrue();
}
 
Example 4
Source File: MaestroAgent.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(final AgentSourceRequest note) {
    logger.info("Source request arrived");

    final String sourceUrl = note.getSourceUrl();
    final String branch = note.getBranch();

    if (branch == null) {
        logger.info("Preparing to download code from {}", sourceUrl);
    }
    else {
        logger.info("Preparing to download code from {} from branch {}", sourceUrl, branch);
    }
    final String projectDir = UUID.randomUUID().toString();

    final File repositoryDir = new File(sourceRoot + File.separator + projectDir + File.separator);

    if (!repositoryDir.exists()) {
        if (!repositoryDir.mkdirs()) {
            logger.warn("Unable to create directory: {}", repositoryDir);
        }
    }

    CloneCommand cloneCommand = Git.cloneRepository();

    cloneCommand.setURI(sourceUrl);
    cloneCommand.setDirectory(repositoryDir);
    cloneCommand.setProgressMonitor(NullProgressMonitor.INSTANCE);


    if (branch != null) {
        cloneCommand.setBranch(branch);
    }

    try {
        cloneCommand.call();
        logger.info("Source directory for project created at {}", repositoryDir);
        extensionPoints.add(new ExtensionPoint(new File(repositoryDir, "requests"), true));

        getClient().replyOk(note);
    } catch (GitAPIException e) {
        logger.error("Unable to clone repository: {}", e.getMessage(), e);
        getClient().replyInternalError(note,"Unable to clone repository: %s", e.getMessage());
    }
}
 
Example 5
Source File: SyncableRepository.java    From github-bucket with ISC License 4 votes vote down vote up
default CloneCommand clone(CloneCommand cmd) {
    return cmd.setURI(getUri().toASCIIString());
}
 
Example 6
Source File: SyncableRepository.java    From github-bucket with ISC License 4 votes vote down vote up
default CloneCommand clone(CloneCommand cmd) {
    return cmd.setURI(getUri().toASCIIString());
}
 
Example 7
Source File: Clone.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(Wandora wandora, Context context) {
    if(cloneUI == null) {
        cloneUI = new CloneUI();
    }
    
    cloneUI.setUsername(getUsername());
    cloneUI.setPassword(getPassword());
    cloneUI.openInDialog();
    
    if(cloneUI.wasAccepted()) {
        setDefaultLogger();
        setLogTitle("Git clone");
        
        String cloneUrl = cloneUI.getCloneUrl();
        String destinationDirectory = cloneUI.getDestinationDirectory();
        String username = cloneUI.getUsername();
        String password = cloneUI.getPassword();
        
        setUsername(username);
        setPassword(password);

        log("Cloning git repository from "+cloneUrl);
        
        try {
            CloneCommand clone = Git.cloneRepository();
            clone.setURI(cloneUrl);
            clone.setDirectory(new File(destinationDirectory));
            
            if(isNotEmpty(username)) {
                CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( username, password );
                clone.setCredentialsProvider(credentialsProvider);
            }
            
            clone.call();
            
            if(cloneUI.getOpenProject()) {
                log("Opening project.");
                LoadWandoraProject loadProject = new LoadWandoraProject(destinationDirectory);
                loadProject.setToolLogger(this);
                loadProject.execute(wandora, context);
            }
            log("Ready.");
        } 
        catch (GitAPIException ex) {
            log(ex.toString());
        }
        catch (Exception e) {
            log(e);
        }
        setState(WAIT);
    }
}