Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jarek/6256: mvn command show progress #6366

Merged
merged 2 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Comm {
private KernelFunctionality kernel;
private List<Handler<Message>> msgCallbackList = new ArrayList<>();
private List<Handler<Message>> closeCallbackList = new ArrayList<>();
private Message parentMessage;

public Comm(String commId, String targetName) {
super();
Expand Down Expand Up @@ -133,11 +134,20 @@ public void clearCloseCallbackList() {
}

public void open() {
Message parentMessage = getParentMessage();// can be null
this.parentMessage = InternalVariable.getParentHeader();
doOpen(parentMessage);
}

public void open(Message parentMessage) {
this.parentMessage = parentMessage;
doOpen(parentMessage);
}

private void doOpen(Message parentMessage) {
Message message = new Message();
message.setHeader(new Header(COMM_OPEN, parentMessage != null ? parentMessage.getHeader().getSession() : null));
if (parentMessage != null) {
message.setParentHeader(getParentMessage().getHeader());
message.setParentHeader(parentMessage.getHeader());
}
HashMap<String, Serializable> map = new HashMap<>();
map.put(COMM_ID, getCommId());
Expand Down Expand Up @@ -212,7 +222,7 @@ public void sendUpdate(final String propertyName, final Object value) {
}

private Message getParentMessage() {
return InternalVariable.getParentHeader();
return this.parentMessage;
}

public void handleMsg(Message parentMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,26 @@
*/
package com.twosigma.beakerx.kernel.commands;


import com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand;
import org.apache.maven.shared.invoker.InvocationOutputHandler;

public class MavenInvocationSilentOutputHandler implements InvocationOutputHandler {

private ClasspathAddMvnMagicCommand.MvnLoggerWidget intProgress;

public MavenInvocationSilentOutputHandler(ClasspathAddMvnMagicCommand.MvnLoggerWidget intProgress) {
this.intProgress = intProgress;
}

@Override
public void consumeLine(String line) {
if (line != null && !line.trim().isEmpty() && (line.matches("Downlo.+") || acceptLineWhichShowDownloadingProgress(line))) {
intProgress.sendLog(line);
}
}

private boolean acceptLineWhichShowDownloadingProgress(String line) {
// line example 3/119 KB
return line.matches("\\d+/\\d+.+");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.twosigma.beakerx.kernel.commands.MavenInvocationSilentOutputHandler;
import com.twosigma.beakerx.kernel.commands.MavenJarResolverSilentLogger;
import com.twosigma.beakerx.kernel.magic.command.functionality.ClasspathAddMvnMagicCommand;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
Expand Down Expand Up @@ -50,15 +51,17 @@ public MavenJarResolver(final ResolverParams commandParams) {
this.pathToMavenRepo = getOrCreateFile(commandParams.getPathToNotebookJars()).getAbsolutePath();
}

public AddMvnCommandResult retrieve(String groupId, String artifactId, String version) {
public AddMvnCommandResult retrieve(String groupId, String artifactId, String version, ClasspathAddMvnMagicCommand.MvnLoggerWidget progress) {
File finalPom = null;
try {
finalPom = getPom(groupId, artifactId, version);
InvocationRequest request = createInvocationRequest();
request.setOffline(commandParams.getOffline());
request.setPomFile(finalPom);
Invoker invoker = getInvoker();
Invoker invoker = getInvoker(progress);
progress.display();
InvocationResult invocationResult = invoker.execute(request);
progress.close();
return getResult(invocationResult, groupId, artifactId, version);
} catch (Exception e) {
return AddMvnCommandResult.error(e.getMessage());
Expand All @@ -67,12 +70,12 @@ public AddMvnCommandResult retrieve(String groupId, String artifactId, String ve
}
}

private Invoker getInvoker() {
private Invoker getInvoker(ClasspathAddMvnMagicCommand.MvnLoggerWidget progress) {
Invoker invoker = new DefaultInvoker();
String mvn = findMvn();
System.setProperty("maven.home", mvn);
invoker.setLogger(new MavenJarResolverSilentLogger());
invoker.setOutputHandler(new MavenInvocationSilentOutputHandler());
invoker.setOutputHandler(new MavenInvocationSilentOutputHandler(progress));
invoker.setLocalRepositoryDirectory(getOrCreateFile(this.commandParams.getPathToCache()));
return invoker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.twosigma.beakerx.kernel.magic.command.MavenJarResolver;
import com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem;
import com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput;
import com.twosigma.beakerx.message.Message;
import com.twosigma.beakerx.widgets.strings.Label;

import java.util.Collection;

Expand Down Expand Up @@ -57,7 +59,8 @@ public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, ADD_MVN_FORMAT_ERROR_MESSAGE);
}
MavenJarResolver classpathAddMvnCommand = new MavenJarResolver(commandParams);
MavenJarResolver.AddMvnCommandResult result = classpathAddMvnCommand.retrieve(split[3], split[4], split[5]);
MvnLoggerWidget progress = new MvnLoggerWidget(param.getCode().getMessage());
MavenJarResolver.AddMvnCommandResult result = classpathAddMvnCommand.retrieve(split[3], split[4], split[5], progress);
if (result.isJarRetrieved()) {
Collection<String> newAddedJars = addJars(classpathAddMvnCommand.getPathToMavenRepo() + "/*");
if (newAddedJars.isEmpty()) {
Expand All @@ -69,4 +72,26 @@ public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, result.getErrorMessage());
}


public class MvnLoggerWidget {

private Label widget;

public MvnLoggerWidget(Message parentMessage) {
this.widget = new Label(parentMessage);
}

public void sendLog(String text) {
widget.setValue(text);
}

public void display() {
this.widget.display();
}

public void close() {
this.widget.close();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static com.twosigma.beakerx.handler.KernelHandlerWrapper.wrapBusyIdle;
import static com.twosigma.beakerx.kernel.msg.JupyterMessages.DISPLAY_DATA;
import static com.twosigma.beakerx.widgets.CompiledCodeRunner.runCommEvent;

import com.twosigma.beakerx.evaluator.InternalVariable;
import com.twosigma.beakerx.kernel.KernelManager;
import com.twosigma.beakerx.kernel.comm.Comm;
import com.twosigma.beakerx.kernel.comm.TargetNamesEnum;
Expand Down Expand Up @@ -60,9 +62,13 @@ public Widget() {
}

protected void openComm() {
openComm(InternalVariable.getParentHeader());
}

protected void openComm(Message parentMessage) {
comm.setData(createContent());
addValueChangeMsgCallback();
comm.open();
comm.open(parentMessage);
}

public void close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.twosigma.beakerx.widgets.strings;

import com.twosigma.beakerx.message.Message;

public class Label extends StringWidget {

public static final String VIEW_NAME_VALUE = "LabelView";
Expand All @@ -25,6 +27,11 @@ public Label() {
openComm();
}

public Label(Message parentMessage) {
super();
openComm(parentMessage);
}

@Override
public String getModelNameValue() {
return MODEL_NAME_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.twosigma.beakerx.jvm.object.SimpleEvaluationObjectWithTime;
import com.twosigma.beakerx.kernel.ImportPath;
import com.twosigma.beakerx.kernel.Imports;
import com.twosigma.beakerx.kernel.KernelManager;
import com.twosigma.beakerx.kernel.comm.Comm;
import com.twosigma.beakerx.kernel.magic.command.MavenJarResolver;
import com.twosigma.beakerx.kernel.magic.command.functionality.AddImportMagicCommand;
Expand Down Expand Up @@ -94,12 +95,14 @@ public KernelTest() {
public KernelTest(String id) {
this.id = id;
initMagicCommands();
KernelManager.register(this);
}

public KernelTest(String id, Evaluator evaluator) {
this.id = id;
this.evaluatorManager = new EvaluatorManager(this, evaluator);
initMagicCommands();
KernelManager.register(this);
}


Expand Down