List of usage examples for org.eclipse.jgit.lib ProgressMonitor UNKNOWN
int UNKNOWN
To view the source code for org.eclipse.jgit.lib ProgressMonitor UNKNOWN.
Click Source Link
From source file:com.google.gerrit.pgm.ProtobufImport.java
License:Apache License
@Override public int run() throws Exception { mustHaveValidSite();/*from w w w. ja va 2s . c o m*/ Injector dbInjector = createDbInjector(SINGLE_USER); manager.add(dbInjector); manager.start(); RuntimeShutdown.add(new Runnable() { @Override public void run() { manager.stop(); } }); dbInjector.injectMembers(this); ProgressMonitor progress = new TextProgressMonitor(); progress.beginTask("Importing entities", ProgressMonitor.UNKNOWN); try (ReviewDb db = schemaFactory.open()) { for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) { relations.put(model.getRelationID(), Relation.create(model, db)); } Parser<UnknownFieldSet> parser = UnknownFieldSet.getDefaultInstance().getParserForType(); try (InputStream in = new BufferedInputStream(new FileInputStream(file))) { UnknownFieldSet msg; while ((msg = parser.parseDelimitedFrom(in)) != null) { Map.Entry<Integer, UnknownFieldSet.Field> e = Iterables.getOnlyElement(msg.asMap().entrySet()); Relation rel = checkNotNull(relations.get(e.getKey()), "unknown relation ID %s in message: %s", e.getKey(), msg); List<ByteString> values = e.getValue().getLengthDelimitedList(); checkState(values.size() == 1, "expected one string field in message: %s", msg); upsert(rel, values.get(0)); progress.update(1); } } progress.endTask(); } return 0; }
From source file:com.google.gerrit.pgm.Reindex.java
License:Apache License
private int indexAll() throws Exception { ProgressMonitor pm = new TextProgressMonitor(); pm.start(1);/* w w w. ja v a2 s. c o m*/ pm.beginTask("Collecting projects", ProgressMonitor.UNKNOWN); Set<Project.NameKey> projects = Sets.newTreeSet(); int changeCount = 0; try (ReviewDb db = sysInjector.getInstance(ReviewDb.class)) { for (Change change : db.changes().all()) { changeCount++; if (projects.add(change.getProject())) { pm.update(1); } } } pm.endTask(); SiteIndexer batchIndexer = sysInjector.getInstance(SiteIndexer.class); SiteIndexer.Result result = batchIndexer.setNumChanges(changeCount).setProgressOut(System.err) .setVerboseOut(verbose ? System.out : NullOutputStream.INSTANCE).indexAll(index, projects); int n = result.doneCount() + result.failedCount(); double t = result.elapsed(TimeUnit.MILLISECONDS) / 1000d; System.out.format("Reindexed %d changes in %.01fs (%.01f/s)\n", n, t, n / t); return result.success() ? 0 : 1; }
From source file:com.google.gerrit.server.index.account.AllAccountsIndexer.java
License:Apache License
private List<Account.Id> collectAccounts(ProgressMonitor progress) throws OrmException { progress.beginTask("Collecting accounts", ProgressMonitor.UNKNOWN); List<Account.Id> ids = new ArrayList<>(); try (ReviewDb db = schemaFactory.open()) { for (Account account : db.accounts().all()) { ids.add(account.getId());/*from w w w . j a v a 2 s.c o m*/ } } progress.endTask(); return ids; }
From source file:com.google.gerrit.server.index.change.AllChangesIndexer.java
License:Apache License
@Override public Result indexAll(ChangeIndex index) { ProgressMonitor pm = new TextProgressMonitor(); pm.beginTask("Collecting projects", ProgressMonitor.UNKNOWN); Set<Project.NameKey> projects = Sets.newTreeSet(); int changeCount = 0; Stopwatch sw = Stopwatch.createStarted(); for (Project.NameKey project : projectCache.all()) { try (Repository repo = repoManager.openRepository(project)) { changeCount += ChangeNotes.Factory.scan(repo).size(); } catch (IOException e) { log.error("Error collecting projects", e); return new Result(sw, false, 0, 0); }/*from w w w .j a v a 2s.c o m*/ projects.add(project); pm.update(1); } pm.endTask(); setTotalWork(changeCount); return indexAll(index, projects); }
From source file:com.google.gerrit.server.index.group.AllGroupsIndexer.java
License:Apache License
private List<AccountGroup.UUID> collectGroups(ProgressMonitor progress) throws OrmException { progress.beginTask("Collecting groups", ProgressMonitor.UNKNOWN); List<AccountGroup.UUID> uuids = new ArrayList<>(); try (ReviewDb db = schemaFactory.open()) { for (AccountGroup group : db.accountGroups().all()) { uuids.add(group.getGroupUUID()); }/* ww w. j a va2s. co m*/ } progress.endTask(); return uuids; }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private void downloadObject(final ProgressMonitor pm, final AnyObjectId id) throws TransportException { if (alreadyHave(id)) return;// w w w . j a v a2 s. c o m for (;;) { // Try a pack file we know about, but don't have yet. Odds are // that if it has this object, it has others related to it so // getting the pack is a good bet. // if (downloadPackedObject(pm, id)) return; // Search for a loose object over all alternates, starting // from the one we last successfully located an object through. // final String idStr = id.name(); final String subdir = idStr.substring(0, 2); final String file = idStr.substring(2); final String looseName = subdir + "/" + file; for (int i = lastRemoteIdx; i < remotes.size(); i++) { if (downloadLooseObject(id, looseName, remotes.get(i))) { lastRemoteIdx = i; return; } } for (int i = 0; i < lastRemoteIdx; i++) { if (downloadLooseObject(id, looseName, remotes.get(i))) { lastRemoteIdx = i; return; } } // Try to obtain more pack information and search those. // while (!noPacksYet.isEmpty()) { final WalkRemoteObjectDatabase wrr = noPacksYet.removeFirst(); final Collection<String> packNameList; try { pm.beginTask("Listing packs", ProgressMonitor.UNKNOWN); packNameList = wrr.getPackNames(); } catch (IOException e) { // Try another repository. // recordError(id, e); continue; } finally { pm.endTask(); } if (packNameList == null || packNameList.isEmpty()) continue; for (final String packName : packNameList) { if (packsConsidered.add(packName)) unfetchedPacks.add(new RemotePack(wrr, packName)); } if (downloadPackedObject(pm, id)) return; } // Try to expand the first alternate we haven't expanded yet. // Collection<WalkRemoteObjectDatabase> al = expandOneAlternate(id, pm); if (al != null && !al.isEmpty()) { for (final WalkRemoteObjectDatabase alt : al) { remotes.add(alt); noPacksYet.add(alt); noAlternatesYet.add(alt); } continue; } // We could not obtain the object. There may be reasons why. // List<Throwable> failures = fetchErrors.get(id); final TransportException te; te = new TransportException(MessageFormat.format(JGitText.get().cannotGet, id.name())); if (failures != null && !failures.isEmpty()) { if (failures.size() == 1) te.initCause(failures.get(0)); else te.initCause(new CompoundException(failures)); } throw te; } }
From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java
License:Eclipse Distribution License
private Collection<WalkRemoteObjectDatabase> expandOneAlternate(final AnyObjectId id, final ProgressMonitor pm) { while (!noAlternatesYet.isEmpty()) { final WalkRemoteObjectDatabase wrr = noAlternatesYet.removeFirst(); try {//w ww . ja va 2 s. c om pm.beginTask(JGitText.get().listingAlternates, ProgressMonitor.UNKNOWN); Collection<WalkRemoteObjectDatabase> altList = wrr.getAlternates(); if (altList != null && !altList.isEmpty()) return altList; } catch (IOException e) { // Try another repository. // recordError(id, e); } finally { pm.endTask(); } } return null; }
From source file:org.eclipse.egit.core.test.EclipseGitProgressTransformerTest.java
License:Open Source License
@Test public void testUnboundedMonitor() { final String title = "Title"; classUnderTest.beginTask(title, ProgressMonitor.UNKNOWN); Mockito.verify(eclipseMonitor).subTask("Title"); classUnderTest.update(10);//w w w . java2 s. co m classUnderTest.update(0); Mockito.verify(eclipseMonitor, Mockito.times(1)).subTask("Title, 10"); classUnderTest.update(20); Mockito.verify(eclipseMonitor).subTask("Title, 30"); }
From source file:org.eclipse.emf.compare.egit.internal.merge.RecursiveModelMerger.java
License:Open Source License
@Override protected boolean mergeTreeWalk(TreeWalk treeWalk, boolean ignoreConflicts) throws IOException { if (LOGGER.isInfoEnabled()) { LOGGER.info("STARTING Recursive model merge."); //$NON-NLS-1$ }// ww w . j a v a 2 s . co m final TreeWalkResourceVariantTreeProvider variantTreeProvider = new TreeWalkResourceVariantTreeProvider( getRepository(), treeWalk, T_BASE, T_OURS, T_THEIRS); final GitResourceVariantTreeSubscriber subscriber = new GitResourceVariantTreeSubscriber( variantTreeProvider); final RemoteResourceMappingContext remoteMappingContext = new SubscriberResourceMappingContext(subscriber, true); try { refreshRoots(subscriber.roots()); } catch (CoreException e) { // We cannot be sure that Team and/or the merger implementations // will properly handle unrefreshed files. Fall back to merging // without workspace awareness. Activator.logError(MergeText.RecursiveModelMerger_RefreshError, e); return super.mergeTreeWalk(treeWalk, ignoreConflicts); } monitor.beginTask(MergeText.RecursiveModelMerger_BuildLogicalModels, ProgressMonitor.UNKNOWN); // Eager lookup for the logical models to avoid issues in case we // iterate over a file that does not exist locally before the rest of // its logical model. final LogicalModels logicalModels = new LogicalModels(); logicalModels.build(variantTreeProvider.getKnownResources(), remoteMappingContext); monitor.endTask(); if (monitor.isCancelled()) { throw new OperationCanceledException(); } // We are done with the setup. We can now iterate over the tree walk and // either delegate to the logical model's merger if any or fall back to // standard git merging. Basically, any file that is not a part of a // logical model that defines its own specific merger will be handled as // it would by the RecursiveMerger. while (treeWalk.next()) { final int modeBase = treeWalk.getRawMode(T_BASE); final int modeOurs = treeWalk.getRawMode(T_OURS); final int modeTheirs = treeWalk.getRawMode(T_THEIRS); if (modeBase == 0 && modeOurs == 0 && modeTheirs == 0) { // untracked continue; } final String path = treeWalk.getPathString(); if (handledPaths.contains(path)) { // This one has been handled as a result of a previous model // merge. Simply make sure we use its latest content if it is // not in conflict. if (treeWalk.isSubtree() && enterSubtree) { treeWalk.enterSubtree(); } if (!unmergedPaths.contains(path)) { registerMergedPath(path); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Ignoring previously handled file: " + path); //$NON-NLS-1$ } } continue; } final int nonZeroMode = modeBase != 0 ? modeBase : modeOurs != 0 ? modeOurs : modeTheirs; final IResource resource = variantTreeProvider.getResourceHandleForLocation(getRepository(), path, FileMode.fromBits(nonZeroMode) == FileMode.TREE); Set<IResource> logicalModel = logicalModels.getModel(resource); IResourceMappingMerger modelMerger = null; if (logicalModel != null) { try { // We need to refresh because new resources may have been added refreshRoots(subscriber.roots()); modelMerger = LogicalModels.findAdapter(logicalModel, IResourceMappingMerger.class); } catch (CoreException e) { Activator.logError(MergeText.RecursiveModelMerger_AdaptError, e); // ignore this model and fall back to default if (!fallBackToDefaultMerge(treeWalk, ignoreConflicts)) { cleanUp(); if (LOGGER.isInfoEnabled()) { LOGGER.info( "FAILED - Recursive model merge, could not find appropriate merger and default merge failed."); //$NON-NLS-1$ } return false; } } } if (modelMerger != null) { enterSubtree = true; boolean success = new ModelMerge(this, subscriber, remoteMappingContext, path, logicalModel, modelMerger).run(new JGitProgressMonitorWrapper(monitor)); if (!success) { if (LOGGER.isInfoEnabled()) { LOGGER.info("FAILED - Recursive model merge."); //$NON-NLS-1$ } return false; } else if (!unmergedPaths.contains(path)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Merged model file: " + path); //$NON-NLS-1$ } registerMergedPath(path); } if (treeWalk.isSubtree()) { enterSubtree = true; } } else if (!fallBackToDefaultMerge(treeWalk, ignoreConflicts)) { cleanUp(); if (LOGGER.isInfoEnabled()) { LOGGER.info("FAILED - Recursive model merge, default merge failed."); //$NON-NLS-1$ } return false; } if (treeWalk.isSubtree() && enterSubtree) { treeWalk.enterSubtree(); } } if (!makeInSync.isEmpty()) { indexModelMergedFiles(); } if (LOGGER.isInfoEnabled()) { LOGGER.info("SUCCESS - Recursive model merge."); //$NON-NLS-1$ } return true; }