diff options
author | 2017-03-10 12:27:11 +0000 | |
---|---|---|
committer | 2017-03-10 14:12:10 +0000 | |
commit | 1a6bebaefb4cc9d92b024289fffd2624b62bf8d7 (patch) | |
tree | a9117938b9ce584e9b1472b27d935bce6e1f3000 | |
parent | f396da66ac2421373172e88538066051a22f0309 (diff) |
GitProgressMonitor: also post about progress
In this way, git clone progress will also be shown in the experimental UI.
--
Change-Id: Ic6f0f437ef9c403f82265b5bd0fa9059bd2abb97
Reviewed-on: https://cr.bazel.build/9314
PiperOrigin-RevId: 149746428
MOS_MIGRATED_REVID=149746428
3 files changed, 86 insertions, 21 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java index 9b347ae639..7d5c9490e8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitCloner.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.bazel.repository; import com.google.common.base.Ascii; import com.google.devtools.build.lib.bazel.repository.downloader.ProxyHelper; -import com.google.devtools.build.lib.events.EventHandler; +import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.rules.repository.RepositoryFunction.RepositoryFunctionException; import com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper; @@ -93,7 +93,9 @@ public class GitCloner { } public static SkyValue clone( - Rule rule, Path outputDirectory, EventHandler eventHandler, + Rule rule, + Path outputDirectory, + ExtendedEventHandler eventHandler, Map<String, String> clientEnvironment) throws RepositoryFunctionException { WorkspaceAttributeMapper mapper = WorkspaceAttributeMapper.of(rule); @@ -143,14 +145,17 @@ public class GitCloner { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } } - git = Git.cloneRepository() - .setURI(descriptor.remote) - .setCredentialsProvider(new NetRCCredentialsProvider()) - .setDirectory(descriptor.directory.getPathFile()) - .setCloneSubmodules(false) - .setNoCheckout(true) - .setProgressMonitor(new GitProgressMonitor("Cloning " + descriptor.remote, eventHandler)) - .call(); + git = + Git.cloneRepository() + .setURI(descriptor.remote) + .setCredentialsProvider(new NetRCCredentialsProvider()) + .setDirectory(descriptor.directory.getPathFile()) + .setCloneSubmodules(false) + .setNoCheckout(true) + .setProgressMonitor( + new GitProgressMonitor( + descriptor.remote, "Cloning " + descriptor.remote, eventHandler)) + .call(); git.checkout() .setCreateBranch(true) .setName("bazel-checkout") @@ -167,7 +172,7 @@ public class GitCloner { git.submoduleUpdate() .setProgressMonitor( new GitProgressMonitor( - "Cloning submodules for " + descriptor.remote, eventHandler)) + descriptor.remote, "Cloning submodules for " + descriptor.remote, eventHandler)) .call(); } } catch (InvalidRemoteException e) { diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitFetchProgress.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitFetchProgress.java new file mode 100644 index 0000000000..461ed2a14f --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitFetchProgress.java @@ -0,0 +1,49 @@ +// Copyright 2017 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.bazel.repository; + +import com.google.devtools.build.lib.events.ExtendedEventHandler.FetchProgress; + +/** Event reporting on progress mading fetching a remote git repository. */ +public class GitFetchProgress implements FetchProgress { + private final String remote; + private final String message; + private final boolean isFinished; + + GitFetchProgress(String remote, String message, boolean isFinished) { + this.remote = remote; + this.message = message; + this.isFinished = isFinished; + } + + GitFetchProgress(String remote, String message) { + this(remote, message, false); + } + + @Override + public String getResourceIdentifier() { + return remote; + } + + @Override + public String getProgress() { + return message; + } + + @Override + public boolean isFinished() { + return isFinished; + } +} diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitProgressMonitor.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitProgressMonitor.java index 76d0de4b9d..54ae208ef6 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/GitProgressMonitor.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/GitProgressMonitor.java @@ -15,33 +15,37 @@ package com.google.devtools.build.lib.bazel.repository; import com.google.devtools.build.lib.events.Event; -import com.google.devtools.build.lib.events.EventHandler; - +import com.google.devtools.build.lib.events.ExtendedEventHandler; import org.eclipse.jgit.lib.ProgressMonitor; /** * ProgressMonitor for reporting progress for Git repository rules. */ class GitProgressMonitor implements ProgressMonitor { - private String message; - private EventHandler eventHandler; + private final String remote; + private final String message; + private final ExtendedEventHandler eventHandler; private String workTitle; private int totalWork; private int completedWork; + private int unfinishedTasks; - GitProgressMonitor(String message, EventHandler eventHandler) { + GitProgressMonitor(String remote, String message, ExtendedEventHandler eventHandler) { + this.remote = remote; this.message = message; this.eventHandler = eventHandler; } @Override - public void start(int totalTasks) { } + public void start(int totalTasks) { + this.unfinishedTasks = totalTasks; + } private void report() { - eventHandler.handle( - Event.progress(message + ": " + workTitle - + " (" + completedWork + " / " + totalWork + ")")); + String progress = workTitle + " (" + completedWork + " / " + totalWork + ")"; + eventHandler.handle(Event.progress(message + ": " + progress)); + eventHandler.post(new GitFetchProgress(remote, progress)); } @Override @@ -62,5 +66,12 @@ class GitProgressMonitor implements ProgressMonitor { } @Override - public void endTask() { } + public void endTask() { + unfinishedTasks--; + // The number of tasks to do as reported on the start event is sometimes underestimated, so + // report a finished event after each task that could be the last one. + if (unfinishedTasks <= 0) { + eventHandler.post(new GitFetchProgress(remote, "done", true)); + } + } } |