Skip to content
This repository has been archived by the owner on Apr 3, 2018. It is now read-only.

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 1ddb969 + 646f660 commit 450b312
Show file tree
Hide file tree
Showing 28 changed files with 656 additions and 400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public static <RET> OperationResult<RET> fromException(CommonException resultExc
return new OperationResult<RET>(null, resultException);
}

public static <RET> OperationResult<RET> cancellationResult() {
return new OperationResult<RET>(null, new OperationCancellation());
}

@Override
public DATA get() throws CommonException, OperationCancellation {
throwIfExceptionResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangNature;
Expand Down Expand Up @@ -52,7 +53,7 @@ public SampleProject(String name, boolean create) throws CoreException, CommonEx
public final void create() throws CoreException, CommonException {
CoreOperation operation = (pm) -> doCreate();
try {
ResourceUtils.runWorkspaceOperation(null, operation);
ResourceUtils.runWorkspaceOperation(new NullProgressMonitor(), operation);
} catch(OperationCancellation e) {
assertFail();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void doProjectReconcile(IProject project, ICancelMonitor cm) {

try {
NullOperationMonitor om = new NullOperationMonitor(cm);
buildMgr.newProjectBuildOperation(om, opMonitor, project, true, true).execute();
buildMgr.requestProjectBuildOperation(opMonitor, project, true, true).execute(om);
} catch(CommonException e) {
opMonitor.writeInfoMessage("Error during auto-check:\n" + e.getSingleLineRender() + "\n");
} catch(OperationCancellation e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@
package melnorme.lang.ide.core.operations;

import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask.ProcessStartHelper;
import melnorme.utilbox.status.StatusLevel;

public interface ILangOperationsListener_Default {

default void notifyMessage(StatusLevel statusLevel, String title, String message) {
notifyMessage(null, statusLevel, title, message);
}

/** Report a message to the user. */
void notifyMessage(String msgId, StatusLevel statusLevel, String title, String message);

/* ----------------- ----------------- */
public interface ILangOperationsListener_Default extends IStatusMessageHandler {

public enum ProcessStartKind {
BUILD,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*******************************************************************************
* Copyright (c) 2016 Bruno Medeiros and other Contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.operations;

import melnorme.utilbox.status.StatusLevel;

public interface IStatusMessageHandler {

/** Report a message to the user. */
void notifyMessage(String msgId, StatusLevel statusLevel, String title, String message);

default void notifyMessage(StatusLevel statusLevel, String title, String message) {
notifyMessage(null, statusLevel, title, message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,25 @@
package melnorme.lang.ide.core.operations;


import static melnorme.lang.ide.core.operations.build.BuildManagerMessages.MSG_Starting_LANG_Build;
import static melnorme.lang.ide.core.utils.TextMessageUtils.headerVeryBig;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertTrue;

import java.text.MessageFormat;
import java.util.Map;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.EclipseCore;
import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.operations.ILangOperationsListener_Default.IToolOperationMonitor;
import melnorme.lang.ide.core.operations.build.BuildManager;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.tooling.common.ops.IOperationMonitor;
import melnorme.lang.tooling.common.ops.Operation;
import melnorme.utilbox.collections.HashMap2;
import melnorme.lang.ide.core.utils.operation.EclipseJobOperation;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
Expand All @@ -59,14 +51,6 @@ protected ToolManager getToolManager() {

/* ----------------- helpers ----------------- */

protected void deleteProjectBuildMarkers() {
try {
getProject().deleteMarkers(LangCore_Actual.BUILD_PROBLEM_ID, true, IResource.DEPTH_INFINITE);
} catch (CoreException ce) {
EclipseCore.logStatus(ce);
}
}

protected String getBuildProblemId() {
return LangCore_Actual.BUILD_PROBLEM_ID;
}
Expand Down Expand Up @@ -96,76 +80,51 @@ protected void startupOnInitialize() {
assertTrue(getProject() != null);
}

protected static HashMap2<String, IToolOperationMonitor> workspaceOpMonitorMap = new HashMap2<>();
protected IToolOperationMonitor workspaceOpMonitor;

protected void prepareForBuild(IProgressMonitor pm) throws CoreException, OperationCancellation {
handleBeginWorkspaceBuild(pm);
}

protected void handleBeginWorkspaceBuild(IProgressMonitor pm) throws CoreException, OperationCancellation {
workspaceOpMonitor = workspaceOpMonitorMap.get(LangCore.NATURE_ID);
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
assertTrue(kind != CLEAN_BUILD);

if(workspaceOpMonitor != null) {
return;
if(kind == IncrementalProjectBuilder.AUTO_BUILD) {
return null; // Ignore auto build
}
workspaceOpMonitor = getToolManager().startNewBuildOperation();
workspaceOpMonitorMap.put(LangCore.NATURE_ID, workspaceOpMonitor);

ResourceUtils.getWorkspace().addResourceChangeListener(new IResourceChangeListener() {
@Override
public void resourceChanged(IResourceChangeEvent event) {
int type = event.getType();
if(type == IResourceChangeEvent.POST_BUILD || type == IResourceChangeEvent.PRE_BUILD) {
workspaceOpMonitor = null;
workspaceOpMonitorMap.remove(LangCore.NATURE_ID);
ResourceUtils.getWorkspace().removeResourceChangeListener(this);
}
}
}, IResourceChangeEvent.POST_BUILD | IResourceChangeEvent.PRE_BUILD);
ArrayList2<IProject> referenced =
ArrayList2.createFrom(getContext().getAllReferencedBuildConfigs())
.map((buildConfig) -> buildConfig.getProject())
.filterx(new ArrayList2<>(), (project) -> project.hasNature(LangCore.NATURE_ID))
;

workspaceOpMonitor.writeInfoMessage(
headerVeryBig(MessageFormat.format(MSG_Starting_LANG_Build, LangCore_Actual.NAME_OF_LANGUAGE))
);
ArrayList2<IProject> referencing =
ArrayList2.createFrom(getContext().getAllReferencingBuildConfigs())
.map((buildConfig) -> buildConfig.getProject())
.filterx(new ArrayList2<>(), (project) -> project.hasNature(LangCore.NATURE_ID))
;

clearWorkspaceErrorMarkers(pm);
}

protected void clearWorkspaceErrorMarkers(IProgressMonitor pm) throws CoreException, OperationCancellation {
clearErrorMarkers(getProject(), pm);
boolean firstCall = referenced.isEmpty();

for(IBuildConfiguration buildConfig : getContext().getAllReferencingBuildConfigs()) {
clearErrorMarkers(buildConfig.getProject(), pm);
}
}

protected void clearErrorMarkers(IProject project, IProgressMonitor pm)
throws CoreException, OperationCancellation {
Operation clearMarkersOp = buildManager.newProjectClearMarkersOperation(workspaceOpMonitor, project);
EclipseUtils.execute_asCore(EclipseUtils.om(pm), clearMarkersOp);
}

protected void handleEndWorkspaceBuild2() {
workspaceOpMonitor = null;
}

@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
assertTrue(kind != CLEAN_BUILD);
ArrayList2<IProject> allOurProjects = referencing;
allOurProjects.add(getProject());

IProject project = assertNotNull(getProject());
if(!firstCall) {
return null;
}

try {
prepareForBuild(monitor);

return doBuild(project, kind, args, monitor);
EclipseUtils.execute_asCore(monitor, (om) -> {
EclipseJobOperation job = buildManager.requestMultiBuild(om, allOurProjects, false);
if(!runAsynchronousBuild()) {
try {
job.join();
} catch(InterruptedException e) {
throw new OperationCancellation();
}
}
});
return null;
}
catch(OperationCancellation cancel) {
forgetLastBuiltState();
return null;
} catch(CoreException ce) {
forgetLastBuiltState();

if(monitor.isCanceled()) {
// This shouldn't usually happen, a OperationCancellation should have been thrown,
// but sometimes its not wrapped correctly.
Expand All @@ -174,34 +133,22 @@ protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor
EclipseCore.logStatus(ce);
throw ce;
}
finally {
getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);

if(isLastProjectOfKind()) {
handleEndWorkspaceBuild2();
}
}

}

@SuppressWarnings("unused")
protected IProject[] doBuild(final IProject project, int kind, Map<String, String> args, IProgressMonitor monitor)
throws CoreException, OperationCancellation {

if(kind == IncrementalProjectBuilder.AUTO_BUILD) {
return null; // Ignore auto build
}
try {
IOperationMonitor om = EclipseUtils.om(monitor);
buildManager.newProjectBuildOperation(om, workspaceOpMonitor, getProject(), false, false).execute();
} catch (CommonException ce) {
throw EclipseCore.createCoreException(ce);
}
return null;
public boolean runAsynchronousBuild() {
return true;
}

/* ----------------- Clean ----------------- */

protected void deleteProjectBuildMarkers() {
try {
getProject().deleteMarkers(LangCore_Actual.BUILD_PROBLEM_ID, true, IResource.DEPTH_INFINITE);
} catch (CoreException ce) {
EclipseCore.logStatus(ce);
}
}

@Override
protected void clean(IProgressMonitor monitor) throws CoreException {
deleteProjectBuildMarkers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
/**
* Abstract class for running external tools and notifying interested listeners (normally the UI only).
*/
public abstract class ToolManager extends EventSource<ILangOperationsListener> {
public abstract class ToolManager extends EventSource<ILangOperationsListener>
implements IStatusMessageHandler
{

protected final CoreSettings settings;

Expand Down Expand Up @@ -147,10 +149,7 @@ public void logAndNotifyError(String msgId, String title, StatusException ce) {
notifyMessage(msgId, ce.getSeverity().toStatusLevel(), title, ce.getMessage());
}

public void notifyMessage(StatusLevel statusLevel, String title, String message) {
notifyMessage(null, statusLevel, title, message);
}

@Override
public void notifyMessage(String msgId, StatusLevel statusLevel, String title, String message) {
for(ILangOperationsListener listener : getListeners()) {
listener.notifyMessage(msgId, statusLevel, title, message);
Expand Down
Loading

0 comments on commit 450b312

Please sign in to comment.