Example usage for org.eclipse.jgit.transport RemoteConfig RemoteConfig

List of usage examples for org.eclipse.jgit.transport RemoteConfig RemoteConfig

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RemoteConfig RemoteConfig.

Prototype

public RemoteConfig(Config rc, String remoteName) throws URISyntaxException 

Source Link

Document

Parse a remote block from an existing configuration file.

Usage

From source file:com.genuitec.eclipse.gerrit.tools.internal.fbranches.BranchingUtils.java

License:Open Source License

public static PushOperationSpecification setupPush(Repository repository, String refSpec)
        throws IOException, URISyntaxException {
    PushOperationSpecification spec = new PushOperationSpecification();
    Collection<RemoteRefUpdate> updates = Transport.findRemoteRefUpdatesFor(repository,
            Collections.singletonList(new RefSpec(refSpec)), null);

    RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin");

    for (URIish uri : config.getPushURIs()) {
        spec.addURIRefUpdates(uri, updates);
        break;/*  w  w  w.  j  a  va2 s. co  m*/
    }
    if (spec.getURIsNumber() == 0) {
        for (URIish uri : config.getURIs()) {
            spec.addURIRefUpdates(uri, updates);
            break;
        }
    }
    if (spec.getURIsNumber() == 0) {
        throw new RuntimeException("Cannot find URI for push");
    }
    return spec;
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.gps.model.GpsGitRepositoriesConfig.java

License:Open Source License

private String getRepoUrl(Repository repository) {
    try {/*  w  w w  .j  a  v a2s. c om*/
        RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$
        for (URIish uri : config.getURIs()) {
            if (uri.getUser() != null) {
                return uri.setUser("user-name").toASCIIString(); //$NON-NLS-1$
            }
            return uri.toASCIIString();
        }
    } catch (Exception e) {
        GerritToolsPlugin.getDefault().log(e);
    }
    return null;
}

From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java

License:Open Source License

public static String getGerritProjectName(Repository repository) {
    try {/* w  w w  .ja  v a  2s .  co m*/
        RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$

        List<URIish> urls = new ArrayList<URIish>(config.getPushURIs());
        urls.addAll(config.getURIs());

        for (URIish uri : urls) {
            if (uri.getPort() == 29418) { //Gerrit refspec
                String path = uri.getPath();
                while (path.startsWith("/")) { //$NON-NLS-1$
                    path = path.substring(1);
                }
                return path;
            }
            break;
        }
    } catch (Exception e) {
        GerritToolsPlugin.getDefault().log(e);
    }
    return null;
}

From source file:com.genuitec.eclipse.gerrit.tools.utils.GerritUtils.java

License:Open Source License

public static String getGerritURL(Repository repository) {
    String best = null;/* w ww  . ja v  a  2 s . com*/
    try {
        RemoteConfig config = new RemoteConfig(repository.getConfig(), "origin"); //$NON-NLS-1$

        List<URIish> urls = new ArrayList<URIish>(config.getPushURIs());
        urls.addAll(config.getURIs());

        for (URIish uri : urls) {
            best = "https://" + uri.getHost(); //$NON-NLS-1$
            if (uri.getPort() == 29418) { //Gerrit refspec
                return best;
            }
            break;
        }
    } catch (Exception e) {
        GerritToolsPlugin.getDefault().log(e);
    }
    return best;
}

From source file:com.genuitec.eclipse.gerrit.tools.utils.RepositoryUtils.java

License:Open Source License

public static void fetchOrigin(Shell shell, final Repository repository) {
    //perform branch operation
    try {/*from ww  w. j a va 2s . c o  m*/
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
        progressDialog.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Fetching updates from origin", 100);
                    FetchOperationUI fetchOp = new FetchOperationUI(repository,
                            new RemoteConfig(repository.getConfig(), "origin"), 3000, false); //$NON-NLS-1$
                    fetchOp.setCredentialsProvider(new EGitCredentialsProvider());
                    fetchOp.execute(new SubProgressMonitor(monitor, 100));
                } catch (Exception e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InterruptedException e) {
        //ignore
    } catch (Exception e) {
        RepositoryUtils.handleException(e);
    }
}

From source file:com.google.gct.idea.appengine.synchronization.SampleSyncTaskTest.java

License:Apache License

@Override
public void setUp() throws Exception {
    super.setUp();

    mockAndroidRepoPath = System.getProperty("java.io.tmpdir") + "/android/mockAndroidRepo";
    String mockGitHubRepoGitPath = db.getDirectory().getPath();
    mockGitHubRepoPath = mockGitHubRepoGitPath.substring(0, mockGitHubRepoGitPath.lastIndexOf('/'));

    // Configure the mock github repo
    StoredConfig targetConfig = db.getConfig();
    targetConfig.setString("branch", "master", "remote", "origin");
    targetConfig.setString("branch", "master", "merge", "refs/heads/master");

    RemoteConfig config = new RemoteConfig(targetConfig, "origin");
    config.addURI(new URIish(mockGitHubRepoGitPath));
    config.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
    config.update(targetConfig);//from  ww w . j  ava  2  s  .  co  m

    targetConfig.save();

    mockGitHubRepo = new Git(db);

    // commit something
    writeTrashFile("Test.txt", "Hello world");
    mockGitHubRepo.add().addFilepattern("Test.txt").call();
    mockGitHubRepo.commit().setMessage("Initial commit").call();
    mockGitHubRepo.tag().setName("tag-initial").setMessage("Tag initial").call();

}

From source file:com.google.gdt.eclipse.gph.egit.wizard.CloneRepositoryWizardPage.java

License:Open Source License

private File getLocalDirForRepo(String repoURL) {
    RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();

    for (String configuredRepo : repoUtil.getConfiguredRepositories()) {
        try {/*from   www.jav  a  2s.  c om*/
            File repoFile = new File(configuredRepo);

            Repository repository = Activator.getDefault().getRepositoryCache().lookupRepository(repoFile);

            try {
                RemoteConfig originConfig = new RemoteConfig(repository.getConfig(), "origin");

                for (URIish uri : originConfig.getURIs()) {
                    String uriStr = uri.toString();

                    if (repoURL.equals(uriStr)) {
                        return repoFile.getParentFile();
                    }
                }
            } catch (URISyntaxException exception) {

            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return null;
}

From source file:com.google.gerrit.server.git.PushReplication.java

License:Apache License

private List<RemoteConfig> allRemotes(final FileBasedConfig cfg) throws ConfigInvalidException {
    List<String> names = new ArrayList<String>(cfg.getSubsections("remote"));
    Collections.sort(names);/*from  ww w  .ja  v  a 2 s  . c  om*/

    final List<RemoteConfig> result = new ArrayList<RemoteConfig>(names.size());
    for (final String name : names) {
        try {
            result.add(new RemoteConfig(cfg, name));
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException("remote " + name + " has invalid URL in " + cfg.getFile());
        }
    }
    return result;
}

From source file:com.googlesource.gerrit.plugins.github.replication.GitHubDestinations.java

License:Apache License

private static List<RemoteConfig> allRemotes(FileBasedConfig cfg) throws ConfigInvalidException {
    Set<String> names = cfg.getSubsections("remote");
    List<RemoteConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        try {/*from w  ww.j a  va2  s.co m*/
            if (name.equalsIgnoreCase(GITHUB_DESTINATION)) {
                result.add(new RemoteConfig(cfg, name));
            }
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException(
                    String.format("remote %s has invalid URL in %s", name, cfg.getFile()));
        }
    }
    return result;
}

From source file:com.googlesource.gerrit.plugins.replication.ReplicationFileBasedConfig.java

License:Apache License

private static List<RemoteConfig> allRemotes(FileBasedConfig cfg) throws ConfigInvalidException {
    Set<String> names = cfg.getSubsections("remote");
    List<RemoteConfig> result = Lists.newArrayListWithCapacity(names.size());
    for (String name : names) {
        try {/*from  w  w w.j  a  v  a2 s .  c  o m*/
            result.add(new RemoteConfig(cfg, name));
        } catch (URISyntaxException e) {
            throw new ConfigInvalidException(
                    String.format("remote %s has invalid URL in %s", name, cfg.getFile()));
        }
    }
    return result;
}