List of usage examples for org.eclipse.jgit.transport URIish URIish
private URIish(URIish u)
From source file:com.bacoder.scmtools.git.internal.CloneAndProcessCommand.java
License:Apache License
public void fetch() throws GitAPIException, IOException, URISyntaxException { URIish u = new URIish(uri); fetchResult = fetch(repository, u); }
From source file:com.bacoder.scmtools.git.internal.CloneAndProcessCommand.java
License:Apache License
public void init() throws GitAPIException, IOException, URISyntaxException { URIish u = new URIish(uri); repository = init(u);/*from w ww. j a v a2 s.c o m*/ fetchResult = fetch(repository, u); }
From source file:com.chungkwong.jgitgui.GitTreeItem.java
License:Open Source License
private void gitRemoteNew() { TextInputDialog dialog = new TextInputDialog(); dialog.setTitle(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("CHOOSE A NAME FOR THE NEW REMOTE CONFIGURE")); dialog.setHeaderText(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("ENTER THE NAME OF THE NEW REMOTE CONFIGURE:")); Optional<String> name = dialog.showAndWait(); dialog.setTitle(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("CHOOSE A URI FOR THE NEW REMOTE CONFIGURE")); dialog.setHeaderText(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("ENTER THE URI OF THE NEW REMOTE CONFIGURE:")); Optional<String> uri = dialog.showAndWait(); if (name.isPresent()) try {// w w w . j a va 2 s.c om RemoteAddCommand command = ((Git) getValue()).remoteAdd(); command.setName(name.get()); command.setUri(new URIish(uri.get())); getChildren().add(new RemoteTreeItem(command.call())); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } }
From source file:com.chungkwong.jgitgui.RemoteTreeItem.java
License:Open Source License
private void gitRemoteResetURL() { TextInputDialog branchDialog = new TextInputDialog(); branchDialog.setTitle(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("CHOOSE A NEW URL FOR THE REMOTE CONFIGURE")); branchDialog.setHeaderText(java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text") .getString("ENTER THE NEW URL OF THE REMOTE CONFIGURE:")); Optional<String> name = branchDialog.showAndWait(); if (name.isPresent()) try {/*from w ww . ja v a 2 s. c om*/ RemoteSetUrlCommand command = ((Git) getParent().getValue()).remoteSetUrl(); command.setName(((RemoteConfig) getValue()).getName()); command.setUri(new URIish(name.get())); command.setPush(true); command.call(); command = ((Git) getParent().getValue()).remoteSetUrl(); command.setName(((RemoteConfig) getValue()).getName()); command.setUri(new URIish(name.get())); command.setPush(false); command.call(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } }
From source file:com.cloudbees.eclipse.dev.scm.egit.ForgeEGitSync.java
License:Open Source License
public static boolean isAlreadyCloned(final String url) { try {/*from w w w. j a va 2 s .c om*/ if (url == null) { return false; } String bareUrl = ForgeUtil.stripGitPrefixes(url); if (bareUrl == null) { return false; } URIish proposalHTTPS = new URIish(ForgeUtil.PR_HTTPS + bareUrl); URIish proposalSSH = new URIish(ForgeUtil.PR_SSH + bareUrl); List<String> reps = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories(); for (String repo : reps) { try { FileRepository fr = new FileRepository(new File(repo)); List<RemoteConfig> allRemotes = RemoteConfig.getAllRemoteConfigs(fr.getConfig()); for (RemoteConfig remo : allRemotes) { List<URIish> uris = remo.getURIs(); for (URIish uri : uris) { //System.out.println("Checking URI: " + uri + " - " + proposal.equals(uri)); if (proposalHTTPS.equals(uri) || proposalSSH.equals(uri)) { return true; } } } } catch (Exception e) { CloudBeesCorePlugin.getDefault().getLogger().error(e); } } } catch (Exception e) { CloudBeesCorePlugin.getDefault().getLogger().error(e); } return false; }
From source file:com.cloudbees.eclipse.dev.scm.egit.ForgeEGitSync.java
License:Open Source License
private boolean openRemoteFile_(final String repo, final ChangeSetPathItem item, final IProgressMonitor monitor) { try {//w ww. ja va 2 s . com // TODO extract repo search into separate method RepositoryCache repositoryCache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache(); Repository repository = null; URIish proposal = new URIish(repo); List<String> reps = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories(); all: for (String rep : reps) { try { Repository fr = repositoryCache.lookupRepository(new File(rep)); List<RemoteConfig> allRemotes = RemoteConfig.getAllRemoteConfigs(fr.getConfig()); for (RemoteConfig remo : allRemotes) { List<URIish> uris = remo.getURIs(); for (URIish uri : uris) { CloudBeesDevCorePlugin.getDefault().getLogger() .info("Checking URI: " + uri + " - " + proposal.equals(uri)); if (proposal.equals(uri)) { repository = fr; break all; } } } } catch (Exception e) { CloudBeesDevCorePlugin.getDefault().getLogger().error(e); } } CloudBeesDevCorePlugin.getDefault().getLogger().info("Repo: " + repository); if (repository == null) { throw new CloudBeesException("Failed to find mapped repository for " + repo); } ObjectId commitId = ObjectId.fromString(item.parent.id); RevWalk rw = new RevWalk(repository); RevCommit rc = rw.parseCommit(commitId); final IFileRevision rev = CompareUtils.getFileRevision(item.path, rc, repository, null); final IEditorPart[] editor = new IEditorPart[1]; PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { @Override public void run() { IWorkbenchPage activePage = CloudBeesUIPlugin.getActiveWindow().getActivePage(); try { editor[0] = Utils.openEditor(activePage, rev, monitor); } catch (CoreException e) { e.printStackTrace(); // TODO } } }); return editor[0] != null; } catch (Exception e) { CloudBeesDevCorePlugin.getDefault().getLogger().error(e); // TODO handle better? return false; } }
From source file:com.cloudbees.eclipse.dev.scm.egit.ForgeEGitSync.java
License:Open Source License
public static File cloneRepo(String url, URI locationURI, IProgressMonitor monitor) throws InterruptedException, InvocationTargetException, URISyntaxException { //GitScmUrlImportWizardPage //GitImportWizard // See ProjectReferenceImporter for hints on cloning and importing! /*/*from w ww.j a va 2 s . c o m*/ CloneOperation clone = Utils.createInstance(CloneOperation.class, new Class[] { URIish.class, Boolean.TYPE, Collection.class, File.class, String.class, String.class, Integer.TYPE }, new Object[] { new URIish(url), true, Collections.EMPTY_LIST, new File(""), null, "origin", 5000 }); if (clone == null) { // old constructor didn't have timeout at the end clone = Utils.createInstance(CloneOperation.class, new Class[] { URIish.class, Boolean.TYPE, Collection.class, File.class, String.class, String.class }, new Object[] { new URIish(url), true, Collections.EMPTY_LIST, new File(""), null, "origin" }); }*/ if (monitor.isCanceled()) { return null; } try { int timeout = 60; // force plugin activation Activator.getDefault().getLog(); Platform.getPreferencesService().getInt("org.eclipse.egit.core", UIPreferences.REMOTE_CONNECTION_TIMEOUT, 60, null); String branch = "master"; url = reformatGitUrlToCurrent(url); URIish gitUrl = new URIish(url); File workDir = new File(locationURI); //final File repositoryPath = workDir.append(Constants.DOT_GIT_EXT).toFile(); String refName = Constants.R_HEADS + branch; GitConnectionType type = CloudBeesUIPlugin.getDefault().getGitConnectionType(); final CloneOperation cloneOperation = new CloneOperation(gitUrl, true, null, workDir, refName, Constants.DEFAULT_REMOTE_NAME, timeout); // https password if (type.equals(GitConnectionType.HTTPS)) { try { String username = CloudBeesUIPlugin.getDefault().getPreferenceStore() .getString(PreferenceConstants.P_EMAIL); String password = CloudBeesUIPlugin.getDefault().readP(); CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password); // Store to secure storage to ensure the connection remains available without reentering the password UserPasswordCredentials credentials = new UserPasswordCredentials(username, password); URIish uri = new URIish(url); SecureStoreUtils.storeCredentials(credentials, uri); cloneOperation.setCredentialsProvider(credentialsProvider); } catch (StorageException e) { throw new InvocationTargetException(new Exception("Failed to read credentials!", e)); } } cloneOperation.run(monitor); return workDir; } catch (final InvocationTargetException e1) { throw e1; } catch (InterruptedException e2) { throw e2; } }
From source file:com.crygier.git.rest.resources.RepositoryResource.java
License:Apache License
/** * Method handling HTTP GET requests. The returned object will be sent * to the client as "text/plain" media type. * * @return String that will be returned as a text/plain response. *//*w ww . j a va 2 s . c om*/ @GET @Path("/{repositoryName}/clone") @JSONP(queryParam = "callback") @Produces({ "application/javascript" }) public Map<String, Object> cloneRepository(@PathParam("repositoryName") String repositoryName, @QueryParam("url") String url, @QueryParam("directory") File directory) { Map<String, Object> answer = new HashMap<String, Object>(); try { URIish uri = new URIish(url); CloneCommand cloneCommand = Git.cloneRepository().setURI(url) .setDirectory(new File(directory, repositoryName.replaceAll(".git", ""))).setBare(false) .setProgressMonitor(new TextProgressMonitor()); Git git = cloneCommand.call(); answer.put("status", "ok"); git.getRepository().close(); answer.putAll(registerLocalRepository(repositoryName, directory)); } catch (GitAPIException e) { logger.log(Level.SEVERE, "Error Cloning", e); answer.put("errorMessage", e.getMessage()); } catch (URISyntaxException e) { logger.log(Level.SEVERE, "Invalid URL", e); answer.put("errorMessage", e.getMessage()); } return answer; }
From source file:com.docmd.behavior.GitManager.java
public boolean gitClone(String path, String remoteURL, JTextArea console) throws IOException, GitAPIException, URISyntaxException { //validate remoteURL URIish repositoryAdress = new URIish(remoteURL); if (!isValidRemoteRepository(repositoryAdress)) return false; //prepare a new folder for the cloned repository File localPath = new File(""); String repositoryName = ""; StringTokenizer st = new StringTokenizer(remoteURL, "/"); while (st.hasMoreTokens()) { repositoryName = st.nextToken(); }//from www . j a v a2 s . c om repositoryName = repositoryName.substring(0, repositoryName.length() - 4); if (SYSTEM.contains("Windows")) localPath = new File(path + "\\" + repositoryName); else localPath = new File(path + "/" + repositoryName); //if the directory does not exist, create it if (!localPath.exists()) { console.setText(""); console.append("creating directory: " + localPath.getName()); boolean result = false; try { localPath.mkdir(); result = true; } catch (SecurityException se) { se.printStackTrace(); } if (result) { console.append("\nDIR created"); } } // then clone console.append("\n$git clone " + remoteURL); console.append("\nCloning from " + remoteURL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(remoteURL).setDirectory(localPath) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(this.username, this.password)) .call()) { console.append("\nHaving repository: " + result.getRepository().getDirectory() + " on branch master"); this.repository = result.getRepository(); this.git = result; } return true; }
From source file:com.ericsson.gerrit.plugins.highavailability.peers.jgroups.MyUrlProvider.java
License:Apache License
private static String getMyUrlFromListenUrl(Config srvConfig) throws MyUrlProviderException { String[] listenUrls = srvConfig.getStringList(HTTPD_SECTION, null, LISTEN_URL_KEY); if (listenUrls.length != 1) { throw new MyUrlProviderException(String.format( "Can only determine myUrl from %s when there is exactly 1 value configured; found %d", LISTEN_URL, listenUrls.length)); }/* w ww . j a v a2 s. co m*/ String url = listenUrls[0]; if (url.startsWith(PROXY_PREFIX)) { throw new MyUrlProviderException(String.format( "Cannot determine myUrl from %s when configured as reverse-proxy: %s", LISTEN_URL, url)); } if (url.contains("*")) { throw new MyUrlProviderException(String .format("Cannot determine myUrl from %s when configured with wildcard: %s", LISTEN_URL, url)); } try { URIish u = new URIish(url); return u.setHost(InetAddress.getLocalHost().getHostName()).toString(); } catch (URISyntaxException | UnknownHostException e) { throw new MyUrlProviderException(String.format("Unable to determine myUrl from %s value [%s]: %s", LISTEN_URL, url, e.getMessage())); } }