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

Commit

Permalink
Merge remote-tracking branch 'LangEclipseIDE/master'
Browse files Browse the repository at this point in the history
Conflicts:
	plugin_ide.core/src/LANG_PROJECT_ID/ide/core/bundle_model/LANGUAGE_BundleModelManager.java
  • Loading branch information
bruno-medeiros committed Oct 20, 2015
2 parents 7b9ad93 + 0802bb8 commit 629b800
Show file tree
Hide file tree
Showing 15 changed files with 252 additions and 35 deletions.
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 @@ -19,7 +19,7 @@
import melnorme.lang.ide.core.engine.EngineClient;
import melnorme.lang.ide.core.operations.AbstractToolManager;
import melnorme.lang.ide.core.operations.build.BuildManager;
import melnorme.lang.ide.core.project_model.IBundleModelManager;
import melnorme.lang.ide.core.project_model.BundleModelManager;
import melnorme.lang.ide.core.project_model.LangBundleModel;
import melnorme.lang.ide.core.utils.EclipseUtils;
import melnorme.lang.tooling.data.StatusException;
Expand All @@ -44,7 +44,7 @@ public static LangCore getInstance() {

protected static final AbstractToolManager toolManager = LangCore_Actual.createToolManagerSingleton();
protected static final EngineClient engineClient = LangCore_Actual.createEngineClient();
protected static final IBundleModelManager bundleManager = LangCore_Actual.createBundleModelManager();
protected static final BundleModelManager<?> bundleManager = LangCore_Actual.createBundleModelManager();
protected static final BuildManager buildManager = LangCore_Actual.createBuildManager();

public static AbstractToolManager getToolManager() {
Expand All @@ -53,7 +53,7 @@ public static AbstractToolManager getToolManager() {
public static EngineClient getEngineClient() {
return engineClient;
}
public static IBundleModelManager getBundleModelManager() {
public static BundleModelManager<?> getBundleModelManager() {
return bundleManager;
}
public static LangBundleModel getBundleModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public class LangCoreMessages implements ProcessHelperMessages {

public static final String BUILD_ClearingProblemMarkers = "Clearing problem markers";

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

public static final String RunningCommand =
"Running command: ";

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import melnorme.utilbox.concurrency.ICancelMonitor;
import melnorme.utilbox.concurrency.NamingThreadFactory;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.misc.ListenerListHelper;
import melnorme.utilbox.fields.ListenerListHelper;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.misc.SimpleLogger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
import melnorme.lang.tooling.data.StatusLevel;
import melnorme.lang.tooling.ops.IOperationHelper;
import melnorme.lang.tooling.ops.util.PathValidator;
import melnorme.lang.utils.EventSource;
import melnorme.lang.utils.ProcessUtils;
import melnorme.utilbox.concurrency.ICancelMonitor;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.ListenerListHelper;
import melnorme.utilbox.misc.Location;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;

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

public AbstractToolManager() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Path;

import melnorme.lang.ide.core.BundleInfo;
import melnorme.lang.ide.core.utils.CoreTaskAgent;
Expand Down Expand Up @@ -74,6 +76,14 @@ protected void doShutdown() {

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

public boolean isBundleManifestFile(IFile file) {
return file.getProjectRelativePath().equals(getDefaultBundleManifestPath());
}

protected abstract Path getDefaultBundleManifestPath();

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

@Override
public BUNDLE_MODEL getModel() {
return model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import org.eclipse.core.resources.IProject;

import melnorme.utilbox.misc.ListenerListHelper;
import melnorme.utilbox.fields.ListenerListHelper;
import melnorme.utilbox.misc.SimpleLogger;

public abstract class ProjectBasedModel<INFO> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.googlecode.goclipse.core.engine;

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

import com.googlecode.goclipse.core.engine.GoBundleModelManager.GoBundleModel;

Expand All @@ -34,10 +35,14 @@ protected BundleManifestResourceListener init_createResourceListener() {
return new ManagerResourceListener(null);
}


@Override
protected BundleInfo createNewInfo(IProject project) {
return new BundleInfo();
}

@Override
protected Path getDefaultBundleManifestPath() {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2015 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.ui.actions;

import org.eclipse.jface.action.Action;

public class RunUIOperationAction extends Action {

protected final AbstractUIOperation operation;

public RunUIOperationAction(AbstractUIOperation operation) {
this.operation = operation;

setText(operation.getOperationName());
}

@Override
public void run() {
operation.executeAndHandle();
}

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


import melnorme.lang.ide.ui.LangUIPlugin;
import melnorme.utilbox.misc.ListenerListHelper;
import melnorme.utilbox.fields.ListenerListHelper;

import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
package melnorme.lang.ide.ui.navigator;


import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
Expand All @@ -21,8 +24,14 @@
import org.eclipse.ui.actions.ActionGroup;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonMenuConstants;
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;

import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.project_model.view.DependenciesContainer;
import melnorme.lang.ide.ui.LangImages;
import melnorme.lang.ide.ui.actions.AbstractUIOperation;
import melnorme.lang.ide.ui.actions.RunUIOperationAction;
import melnorme.utilbox.collections.ArrayList2;

public abstract class LangNavigatorActionProvider extends CommonActionProvider {
Expand Down Expand Up @@ -96,4 +105,52 @@ protected Object getSelectionFirstElement() {
}

}

public static abstract class BundleOperationsActionGroup extends ViewPartActionGroup {

public BundleOperationsActionGroup(IViewPart viewPart) {
super(viewPart);
}

public IProject getBundleProjectFromSelection() {
Object selElement = getSelectionFirstElement();
if(selElement instanceof IProject) {
return (IProject) selElement;
}
if(selElement instanceof DependenciesContainer) {
DependenciesContainer dependenciesContainer = (DependenciesContainer) selElement;
return dependenciesContainer.getParent();
}
if(selElement instanceof IFile) {
IFile file = (IFile) selElement;
if(LangCore.getBundleModelManager().isBundleManifestFile(file)) {
return file.getProject();
}
}
return null;
}

@Override
public void fillContextMenu(IMenuManager menu) {
IProject project = getBundleProjectFromSelection();
if(project == null)
return;

MenuManager bundleOpsMenu = new MenuManager(getMenuName(), LangImages.NAV_Library, "bundleMenu");

initActions(bundleOpsMenu, project);

menu.prependToGroup(ICommonMenuConstants.GROUP_BUILD, bundleOpsMenu);
}

protected abstract String getMenuName();

protected abstract void initActions(MenuManager bundleOpsMenu, IProject project);

protected void addRunOperationAction(MenuManager bundleOpsMenu, AbstractUIOperation operation) {
bundleOpsMenu.add(new RunUIOperationAction(operation));
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************************************************************
* Copyright (c) 2015 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.ui.operations;

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.LangCoreMessages;
import melnorme.lang.ide.core.operations.AbstractToolManager;
import melnorme.lang.ide.core.operations.AbstractToolManager.RunProcessTask;
import melnorme.lang.ide.core.operations.MessageEventInfo;
import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.lang.ide.core.utils.TextMessageUtils;
import melnorme.lang.ide.ui.actions.AbstractUIOperation;
import melnorme.utilbox.collections.Indexable;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;

public abstract class RunToolOperation extends AbstractUIOperation {

protected final IProject project;
protected final Indexable<String> commands;

public RunToolOperation(String operationName, IProject project, Indexable<String> commands) {
super(operationName);
this.project = project;
this.commands = commands;
}

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

@Override
protected void doBackgroundComputation(IProgressMonitor monitor)
throws CoreException, CommonException, OperationCancellation {
ProcessBuilder pb = createProcessBuilder();

OperationInfo opInfo = getToolManager().startNewToolOperation();

getToolManager().notifyMessageEvent(new MessageEventInfo(opInfo,
TextMessageUtils.headerBIG(getOperationStartMessage())));

RunProcessTask runToolTask = getToolManager().newRunToolTask(opInfo, pb, monitor);
runProcessTask(runToolTask);
}

protected String getOperationStartMessage() {
return LangCoreMessages.RunningCommand;
}

protected ProcessBuilder createProcessBuilder() throws CoreException, CommonException {
return AbstractToolManager.createProcessBuilder(project, getCommands());
}

protected void runProcessTask(RunProcessTask runToolTask) throws CommonException, OperationCancellation {
runToolTask.runProcess();
}

protected String[] getCommands() {
return commands.toArray(String.class);
}

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

public abstract static class RunSDKToolOperation extends RunToolOperation {

public RunSDKToolOperation(String operationName, IProject project, Indexable<String> commands) {
super(operationName, project, commands);
}

@Override
protected ProcessBuilder createProcessBuilder() throws CoreException, CommonException {
return getToolManager().createSDKProcessBuilder(project, getCommands());
}

}

}
40 changes: 40 additions & 0 deletions plugin_tooling/src-lang/melnorme/lang/utils/EventSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2015 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.utils;


import melnorme.utilbox.collections.Indexable;
import melnorme.utilbox.fields.IEventSource;
import melnorme.utilbox.fields.ListenerListHelper;

public class EventSource<T> implements IEventSource<T> {

protected final ListenerListHelper<T> listeners = new ListenerListHelper<>();

public EventSource() {
super();
}

@Override
public void addListener(T listener) {
listeners.addListener(listener);
}

@Override
public void removeListener(T listener) {
listeners.removeListener(listener);
}

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

}
Loading

0 comments on commit 629b800

Please sign in to comment.