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

Commit

Permalink
LANG: refactor BuildManager, BuildTarget, related classes.
Browse files Browse the repository at this point in the history
Added initial Build Target tools.
  • Loading branch information
bruno-medeiros committed Jul 2, 2015
1 parent 8382d8d commit 5c06e86
Show file tree
Hide file tree
Showing 24 changed files with 782 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class BuildTargetsSerializer_Test extends CommonTest {
}

protected BuildTarget createBuildTarget(boolean enabled, String name) {
return new BuildTarget(enabled, name);
return LangCore.getBuildManager().createBuildTarget(enabled, name);
}

protected void testSerialize(ArrayList2<BuildTarget> buildTargets) {
Expand Down
6 changes: 3 additions & 3 deletions plugin_ide.core/src-lang/melnorme/lang/ide/core/LangCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
package melnorme.lang.ide.core;

import melnorme.lang.ide.core.engine.EngineClient;
import melnorme.lang.ide.core.operations.AbstractToolsManager;
import melnorme.lang.ide.core.operations.AbstractToolManager;
import melnorme.lang.ide.core.project_model.BuildManager;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.tooling.data.StatusException;
Expand Down Expand Up @@ -40,11 +40,11 @@ public static LangCore getInstance() {

/* ----------------- Owned singletons: ----------------- */

protected static final AbstractToolsManager toolManager = LangCore_Actual.createToolManagerSingleton();
protected static final AbstractToolManager toolManager = LangCore_Actual.createToolManagerSingleton();
protected static final EngineClient engineClient = LangCore_Actual.createEngineClient();
protected static final BuildManager buildManager = LangCore_Actual.createBuildManager();

public static AbstractToolsManager getToolManager() {
public static AbstractToolManager getToolManager() {
return toolManager;
}
public static EngineClient getEngineClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,77 @@

import java.nio.file.Path;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.ILangOperationsListener;
import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.ide.core.utils.process.AbstractRunProcessTask;
import melnorme.lang.ide.core.utils.process.EclipseCancelMonitor;
import melnorme.lang.tooling.data.PathValidator;
import melnorme.lang.tooling.data.StatusException;
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.lang.utils.ProcessUtils;
import melnorme.utilbox.concurrency.ICancelMonitor;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.fields.IValidatedField;
import melnorme.utilbox.misc.ListenerListHelper;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;
import melnorme.utilbox.process.ExternalProcessNotifyingHelper;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

/**
* Abstract class for running external tools and notifying interested listeners (normally the UI only).
*/
public abstract class AbstractToolsManager extends ListenerListHelper<ILangOperationsListener> {
public abstract class AbstractToolManager extends ListenerListHelper<ILangOperationsListener> {

public AbstractToolsManager() {
public AbstractToolManager() {
}

public void shutdownNow() {
}

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

public Path getSDKToolPath() throws CommonException {
return getSDKToolPathField().getValidatedField();
}

protected IValidatedField<Path> getSDKToolPathField() {
return new SDKToolPathField(getSDKToolPathValidator());
}

public static class SDKToolPathField implements IValidatedField<Path> {

protected final PathValidator pathValidator;

public SDKToolPathField(PathValidator pathValidator) {
this.pathValidator = pathValidator;
}

protected String getRawFieldValue() {
return ToolchainPreferences.SDK_PATH.get();
}

@Override
public Path getValidatedField() throws StatusException {
String pathString = getRawFieldValue();
return getPathValidator().getValidatedPath(pathString);
}

protected PathValidator getPathValidator() {
return pathValidator;
}

}

protected abstract PathValidator getSDKToolPathValidator();

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

public ProcessBuilder createToolProcessBuilder(Path buildToolCmdPath, Location workingDir,
String... arguments) {
return ProcessUtils.createProcessBuilder(buildToolCmdPath, workingDir, true, arguments);
Expand Down Expand Up @@ -153,7 +192,7 @@ public RunEngineClientOperation(ProcessBuilder pb, ICancelMonitor cancelMonitor)

@Override
protected void handleProcessStartResult(ExternalProcessNotifyingHelper processHelper, CommonException ce) {
for (ILangOperationsListener listener : AbstractToolsManager.this.getListeners()) {
for (ILangOperationsListener listener : AbstractToolManager.this.getListeners()) {
listener.engineClientToolStart(pb, ce, processHelper);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 IBM Corporation and others.
* 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 java.nio.file.Path;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.LangCore;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

public abstract class AbstractToolManagerOperation implements IBuildTargetOperation {

protected final IProject project;

public AbstractToolManagerOperation(IProject project) {
this.project = project;
}

public IProject getProject() {
return project;
}

protected AbstractToolManager getToolManager() {
return LangCore.getToolManager();
}

protected Path getBuildToolPath() throws CommonException {
return getToolManager().getSDKToolPath();
}

protected ExternalProcessResult runBuildTool(IProgressMonitor monitor, ProcessBuilder pb)
throws CommonException, OperationCancellation {
return getToolManager().newRunToolTask(pb, getProject(), monitor).runProcess();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*******************************************************************************
* Copyright (c) 2015, 2015 IBM Corporation and others.
* 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 static java.text.MessageFormat.format;
import static melnorme.lang.ide.core.utils.TextMessageUtils.headerBIG;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import java.nio.file.Path;
import java.util.concurrent.Callable;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.LangCore_Actual;
import melnorme.lang.ide.core.project_model.BuildManager;
import melnorme.lang.ide.core.project_model.BuildManagerMessages;
import melnorme.lang.ide.core.project_model.ProjectBuildInfo;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;

public class BuildOperationCreator implements BuildManagerMessages {

protected final BuildManager buildMgr = LangCore.getBuildManager();

protected final IProject project;
protected final OperationInfo parentOpInfo;
protected final boolean fullBuild;

public BuildOperationCreator(IProject project, OperationInfo parentOpInfo, boolean fullBuild) {
this.project = project;
this.fullBuild = fullBuild;
this.parentOpInfo = assertNotNull(parentOpInfo);
}

public IBuildTargetOperation getBuildOperation() throws CommonException {
return new CompositeBuildOperation(createBuildOperations());
}

protected ArrayList2<IBuildTargetOperation> createBuildOperations() throws CommonException {
ArrayList2<IBuildTargetOperation> operations = ArrayList2.create();

String startMsg = headerBIG(format(MSG_BuildingProject, LangCore_Actual.LANGUAGE_NAME, project.getName()));
operations.add(newMessageOperation(project, startMsg, true));

ProjectBuildInfo buildInfo = buildMgr.getBuildInfo(project);
if(buildInfo == null) {
operations.add(newMessageOperation(project, headerBIG(MSG_NoBuildTargetsEnabled), false));
return operations;
}

for(BuildTarget buildTarget : buildInfo.getBuildTargets()) {
if(buildTarget.isEnabled()) {
operations.add(newBuildTargetOperation(project, buildTarget));
}
}

operations.add(newMessageOperation(project, headerBIG(MSG_BuildTerminated), false));

return operations;
}

protected CommonBuildTargetOperation newBuildTargetOperation(IProject project, BuildTarget buildTarget)
throws CommonException {
return buildTarget.newBuildTargetOperation(parentOpInfo, project, fullBuild);
}

protected IBuildTargetOperation newMessageOperation(IProject project, String msg, boolean clearConsole) {
return new BuildMessageOperation(parentOpInfo.createSubOperation(project, clearConsole, msg));
}

protected class BuildMessageOperation implements IBuildTargetOperation, Callable<OperationInfo> {

protected final OperationInfo opInfo;

public BuildMessageOperation(OperationInfo opInfo) {
this.opInfo = opInfo;
}

@Override
public void execute(IProgressMonitor monitor) {
executeDo();
}

protected void executeDo() {
call();
}

@Override
public OperationInfo call() throws RuntimeException {
LangCore.getToolManager().notifyOperationStarted(opInfo);
return opInfo;
}
}

public static abstract class CommonBuildTargetOperation implements IBuildTargetOperation {

protected final OperationInfo parentOperationInfo;
protected final BuildTarget buildTarget;
protected final Path buildToolPath;

public CommonBuildTargetOperation(OperationInfo parentOperationInfo, Path buildToolPath,
BuildTarget buildTarget) {
this.buildToolPath = buildToolPath;
this.parentOperationInfo = assertNotNull(parentOperationInfo);
this.buildTarget = assertNotNull(buildTarget);
}

protected Path getBuildToolPath() throws CommonException {
return buildToolPath;
}

protected String getBuildTargetName() {
return buildTarget.getTargetName();
}

@Override
public abstract void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@

import static melnorme.utilbox.core.CoreUtil.areEqual;

import java.nio.file.Path;

import org.eclipse.core.resources.IProject;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.BuildOperationCreator.CommonBuildTargetOperation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.HashcodeUtil;

public class BuildTarget {
public abstract class BuildTarget {

protected final boolean enabled;
protected final String targetName;
Expand Down Expand Up @@ -49,4 +56,17 @@ public int hashCode() {
return HashcodeUtil.combinedHashCode(enabled, targetName);
}

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

protected Path getSDKToolPath() throws CommonException {
return getToolManager().getSDKToolPath();
}

public AbstractToolManager getToolManager() {
return LangCore.getToolManager();
}

public abstract CommonBuildTargetOperation newBuildTargetOperation(OperationInfo parentOpInfo, IProject project,
boolean fullBuild) throws CommonException;

}
Loading

0 comments on commit 5c06e86

Please sign in to comment.