Skip to content

Commit

Permalink
Merging [MelnormeLang]*
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-medeiros committed Dec 15, 2016
2 parents 978089e + f3ed0b1 commit d668e9e
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 82 deletions.
2 changes: 1 addition & 1 deletion melnorme_util/src/melnorme/utilbox/fields/EventSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void removeListener(T listener) {
listeners.removeListener(listener);
}

protected Indexable<T> getListeners() {
public Indexable<T> getListeners() {
return listeners.getListeners();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import java.util.Collection;

import org.eclipse.core.resources.IProject;
import org.junit.Test;

Expand All @@ -29,6 +31,7 @@
import melnorme.lang.ide.core.operations.ILangOperationsListener_Default.NullToolOperationMonitor;
import melnorme.lang.ide.core.operations.ToolManager;
import melnorme.lang.ide.core.operations.build.BuildManager_Test.TestsBuildManager.SampleStrictBuildType;
import melnorme.lang.ide.core.operations.build.BuildOperationCreator.ProjectBuildOperation;
import melnorme.lang.ide.core.operations.build.BuildTargetOperation.BuildOperationParameters;
import melnorme.lang.ide.core.project_model.LangBundleModel;
import melnorme.lang.ide.core.tests.CoreTestWithProject;
Expand Down Expand Up @@ -413,4 +416,21 @@ protected Iterable<String> getBuildOperation(ProjectBuildInfo buildInfo, BuildTa

}

/* ----------------- ----------------- */

// Util for other projects
public static void clearExistingBuilds(BuildManager buildManager, boolean awaitTermination) {
Collection<ProjectBuildOperation> oldBuilds = buildManager.cancelAllBuilds();
if(awaitTermination) {
for (ProjectBuildOperation oldOperation : oldBuilds) {
oldOperation.tryCancel();
try {
oldOperation.asFuture().awaitResult2();
} catch(OperationCancellation e) {
// Ok
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import org.junit.Before;
import org.junit.BeforeClass;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangCorePlugin;
import melnorme.lang.ide.core.LangNature;
import melnorme.lang.ide.core.operations.build.BuildManager_Test;
import melnorme.lang.ide.core.tests.utils.ErrorLogListener;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.ide.core.utils.ResourceUtils;
Expand Down Expand Up @@ -111,8 +113,11 @@ public static void checkLogErrors_() throws Throwable {
// be obtained the if the method fails its check.
@Before
public void checkLogErrors_before() throws Throwable {
BuildManager_Test.clearExistingBuilds(LangCore.getBuildManager(), true);

doCheckLogErrors();
}

@After
public void checkLogErrors_after() throws Throwable {
doCheckLogErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static melnorme.utilbox.core.CoreUtil.option;

import java.text.MessageFormat;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -588,9 +589,15 @@ protected BuildOperationCreator createBuildOperationCreator(

/* ----------------- ----------------- */

protected final HashMap2<Location, ProjectBuildOperation> buildOps = new HashMap2<>();
protected HashMap2<Location, ProjectBuildOperation> buildOps = new HashMap2<>();
protected final Object buildOps_mutex = new Object();

public ProjectBuildOperation getBuildOperation(Location location) {
synchronized (buildOps_mutex) {
return buildOps.get0(location);
}
}

public ProjectBuildOperation setNewBuildOperation(ProjectBuildOperation newOperation) {
Location location = newOperation.getLocation();
ProjectBuildOperation oldOp;
Expand All @@ -603,15 +610,16 @@ public ProjectBuildOperation setNewBuildOperation(ProjectBuildOperation newOpera
return oldOp;
}

public void cancelAllBuilds() {
public Collection<ProjectBuildOperation> cancelAllBuilds() {
HashMap2<Location, ProjectBuildOperation> oldBuildOps;
synchronized (buildOps_mutex) {
oldBuildOps = buildOps.copy();
buildOps.clear();
oldBuildOps = buildOps;
buildOps = new HashMap2<>();
}
for (ProjectBuildOperation buildOp : oldBuildOps.values()) {
buildOp.tryCancel();
}
return oldBuildOps.values();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public CompositeBuildOperation(Indexable<Operation> operations) {
this.opFuture = OperationFuture2.fromOperation(this::innerExecute);
}

public OperationFuture2<Void> asFuture() {
return opFuture;
}

@Override
public void execute(IOperationMonitor om) throws CommonException, OperationCancellation {
assertTrue(opFuture.canExecute());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ protected IStatus run(IProgressMonitor monitor) {
}


public static void runUnderAsynchJob(String jobName, IRunnableWithJob runnable) throws InterruptedException {
public static Job runUnderAsynchJob(
String jobName, IRunnableWithJob runnable
) throws InterruptedException {
EclipseAsynchJobAdapter job = new EclipseAsynchJobAdapter(jobName);
job.schedule();

Expand All @@ -55,6 +57,7 @@ public static void runUnderAsynchJob(String jobName, IRunnableWithJob runnable)
} finally {
job.done(EclipseCore.createOkStatus(null));
}
return job;
}

public static interface IRunnableWithJob {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.IOConsole;
import org.eclipse.ui.console.IOConsoleOutputStream;

import melnorme.lang.ide.ui.tools.console.ToolsConsole.IOConsoleOutputStreamExt;
import melnorme.util.swt.jface.text.ColorManager;

public abstract class AbstractProcessMessageConsole extends IOConsole {
Expand All @@ -29,8 +29,8 @@ protected ProcessMessageConsole(String name, ImageDescriptor imageDescriptor) {
}
}

public final IOConsoleOutputStream stdOut;
public final IOConsoleOutputStream stdErr;
public final IOConsoleOutputStreamExt stdOut;
public final IOConsoleOutputStreamExt stdErr;

public volatile boolean disposed;

Expand All @@ -41,9 +41,9 @@ protected ProcessMessageConsole(String name, ImageDescriptor imageDescriptor) {
protected AbstractProcessMessageConsole(String name, ImageDescriptor imageDescriptor) {
super(name, imageDescriptor);

stdOut = newOutputStream();
stdErr = newOutputStream();
stdErr.setActivateOnWrite(true);
stdOut = new IOConsoleOutputStreamExt(newOutputStream());
stdErr = new IOConsoleOutputStreamExt(newOutputStream());
stdErr.console().setActivateOnWrite(true);
}

protected void postToUI_initOutputStreamColors() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,33 @@
*******************************************************************************/
package melnorme.lang.ide.ui.tools.console;

import java.io.IOException;

import melnorme.lang.ide.ui.tools.console.ToolsConsole.IOConsoleOutputStreamExt;
import melnorme.utilbox.process.ExternalProcessNotifyingHelper.IProcessOutputListener;

import org.eclipse.ui.console.IOConsoleOutputStream;

public class ConsoleOutputProcessListener implements IProcessOutputListener {

protected final IOConsoleOutputStream processStdOut;
protected final IOConsoleOutputStream processStdErr;
protected final IOConsoleOutputStreamExt processStdOut;
protected final IOConsoleOutputStreamExt processStdErr;

public ConsoleOutputProcessListener(IOConsoleOutputStream processStdOut, IOConsoleOutputStream processStdErr) {
public ConsoleOutputProcessListener(IOConsoleOutputStreamExt processStdOut, IOConsoleOutputStreamExt processStdErr) {
this.processStdOut = processStdOut;
this.processStdErr = processStdErr;
}

@Override
public void notifyStdOutListeners(byte[] buffer, int offset, int readCount) {
try {
processStdOut.write(buffer, offset, readCount);
} catch (IOException e) {
// Ignore, it could simply mean the console page has been closed
}
processStdOut.write(buffer, offset, readCount);
}

@Override
public void notifyStdErrListeners(byte[] buffer, int offset, int readCount) {
try {
processStdErr.write(buffer, offset, readCount);
} catch (IOException e) {
// Ignore, it could simply mean the console page has been closed
}
processStdErr.write(buffer, offset, readCount);
}

@Override
public void notifyProcessTerminatedAndRead(int exitCode) {
try {
processStdOut.flush();
processStdErr.flush();
} catch (IOException e) {
// Ignore
}
processStdOut.flush();
processStdErr.flush();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.ui.console.IOConsoleOutputStream;

import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.LangUIPlugin_Actual;
import melnorme.lang.ide.ui.utils.ConsoleUtils;

public class EngineToolsConsole extends ToolsConsole {

public final IOConsoleOutputStream serverStdOut;
public final IOConsoleOutputStream serverStdErr;
public final IOConsoleOutputStreamExt serverStdOut;
public final IOConsoleOutputStreamExt serverStdErr;

public EngineToolsConsole(String name, ImageDescriptor imageDescriptor) {
super(name, imageDescriptor, false);

serverStdOut = newOutputStream();
serverStdErr = newOutputStream();
serverStdOut = new IOConsoleOutputStreamExt(newOutputStream());
serverStdErr = new IOConsoleOutputStreamExt(newOutputStream());

postToUI_initOutputStreamColors();
}
Expand All @@ -37,11 +36,11 @@ public EngineToolsConsole(String name, ImageDescriptor imageDescriptor) {
protected void ui_initStreamColors() {
super.ui_initStreamColors();

serverStdOut.setColor(getColorManager().getColor(new RGB(128, 0, 128)));
serverStdErr.setColor(getColorManager().getColor(new RGB(255, 0, 200)));
serverStdErr.setFontStyle(SWT.BOLD);
serverStdOut.console().setColor(getColorManager().getColor(new RGB(128, 0, 128)));
serverStdErr.console().setColor(getColorManager().getColor(new RGB(255, 0, 200)));
serverStdErr.console().setFontStyle(SWT.BOLD);

stdErr.setActivateOnWrite(false);
stdErr.console().setActivateOnWrite(false);
}

public static EngineToolsConsole getConsole() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static melnorme.utilbox.core.Assert.AssertNamespace.assertFail;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand All @@ -23,12 +22,12 @@
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.console.IOConsoleOutputStream;

import melnorme.lang.ide.core.ILangOperationsListener;
import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask.ProcessStartHelper;
import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.LangUIPlugin_Actual;
import melnorme.lang.ide.ui.tools.console.ToolsConsole.IOConsoleOutputStreamExt;
import melnorme.lang.ide.ui.utils.ConsoleUtils;
import melnorme.lang.ide.ui.utils.StatusMessageDialog2;
import melnorme.lang.ide.ui.utils.StatusMessageDialogWithIgnore;
Expand Down Expand Up @@ -143,7 +142,7 @@ protected IToolOperationMonitor doBeginOperation(ProcessStartKind kind, boolean
}

protected OperationConsoleMonitor createConsoleHandler(ProcessStartKind kind, ToolsConsole console,
IOConsoleOutputStream stdOut, IOConsoleOutputStream stdErr) {
IOConsoleOutputStreamExt stdOut, IOConsoleOutputStreamExt stdErr) {
return new OperationConsoleMonitor(kind, console, stdOut, stdErr);
}

Expand All @@ -153,14 +152,14 @@ public class OperationConsoleMonitor implements IToolOperationMonitor {

protected final ProcessStartKind kind;
protected final ToolsConsole console;
protected final IOConsoleOutputStream infoOut;
protected final IOConsoleOutputStream stdOut;
protected final IOConsoleOutputStream stdErr;
protected final IOConsoleOutputStreamExt infoOut;
protected final IOConsoleOutputStreamExt stdOut;
protected final IOConsoleOutputStreamExt stdErr;

public boolean errorOnNonZeroExitValueForBuild = false;

public OperationConsoleMonitor(ProcessStartKind kind, ToolsConsole console,
IOConsoleOutputStream stdOut, IOConsoleOutputStream stdErr) {
IOConsoleOutputStreamExt stdOut, IOConsoleOutputStreamExt stdErr) {
this.kind = assertNotNull(kind);
this.console = assertNotNull(console);
this.infoOut = console.infoOut;
Expand All @@ -179,12 +178,8 @@ public void handleProcessStart(String prefixText, String suffixText, ProcessBuil
{
String infoPrefaceText = getPrefaceText(prefixText, suffixText, pb);

try {
if(infoPrefaceText != null) {
infoOut.write(infoPrefaceText);
}
} catch (IOException e) {
// Do nothing
if(infoPrefaceText != null) {
infoOut.write(infoPrefaceText);
}

connectProcessOutputListener(processStartHelper);
Expand All @@ -200,12 +195,7 @@ protected void connectProcessOutputListener(ProcessStartHelper processStartHelpe
if(cause != null) {
text += " Reason: " + cause.getMessage() + "\n";
}
try {
infoOut.write(text);
} catch (IOException e) {
// Do nothing
}

infoOut.write(text);
}
}

Expand All @@ -227,12 +217,8 @@ protected void handleProcessTerminated(int exitCode) {
console.activate();
}

try {
infoOut.write(getProcessTerminatedMessage(exitCode));
infoOut.flush();
} catch (IOException e) {
// Ignore
}
infoOut.write(getProcessTerminatedMessage(exitCode));
infoOut.flush();
}

@Override
Expand Down
Loading

0 comments on commit d668e9e

Please sign in to comment.