Commit 300a73eb authored by amccaskey's avatar amccaskey
Browse files

Updated Handler Hierarchy and Added Build ICE Command



This commit updates the developer abstract handler hierarchy with a
GitCloneHandler that simple clones a repository, but provides a hook for
subclasses to provide PostCloneTasks, such as importing projects or
creating make targets. 

This commit also provides a new Build ICE command that grabs the
ILaunchManager and uses it to launch ICE's Maven Build launch
configuration files. 
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent 6937bf0e
......@@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.eclipse.cdt.core.settings.model,
org.eclipse.core.commands,
org.eclipse.core.runtime.jobs,
org.eclipse.egit.core.op;version="4.0.0",
org.eclipse.egit.github.core;version="4.0.0",
org.eclipse.egit.github.core.client;version="4.0.0",
org.eclipse.egit.github.core.service;version="4.0.0",
......@@ -16,12 +17,14 @@ Import-Package: org.eclipse.cdt.core.settings.model,
org.eclipse.jface.wizard,
org.eclipse.jgit.api;version="4.0.0",
org.eclipse.jgit.api.errors;version="4.0.0",
org.eclipse.jgit.lib;version="4.0.0",
org.eclipse.swt,
org.eclipse.swt.events,
org.eclipse.swt.layout,
org.eclipse.swt.widgets,
org.eclipse.ui,
org.eclipse.ui.handlers,
org.eclipse.ui.wizards,
org.slf4j;version="1.7.2"
Require-Bundle: org.eclipse.cdt;bundle-version="8.7.0",
org.eclipse.cdt.core,
......
......@@ -6,20 +6,21 @@
name="MOOSE Developer Tooling"
point="org.eclipse.ice.developer.code">
<code
branch="devel"
codeCategory="Framework"
codeName="MOOSE"
repoURL="https://github.com/idaholab/moose">
<command
commandName="Fork the Stork"
implementation="org.eclipse.ice.developer.moose.actions.ForkStorkHandler">
implementation="org.eclipse.ice.developer.moose.actions.StorkForkHandler">
</command>
<command
commandName="Clone MOOSE"
implementation="org.eclipse.ice.developer.actions.GitHubCloneHandler">
implementation="org.eclipse.ice.developer.moose.actions.MooseCloneHandler">
</command>
<command
commandName="Fork MOOSE"
implementation="org.eclipse.ice.developer.moose.actions.ForkMOOSEHandler">
implementation="org.eclipse.ice.developer.moose.actions.MooseForkHandler">
</command>
</code>
</extension>
......
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* 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:
* Alex McCaskey - Initial API and implementation and/or initial documentation
*
*******************************************************************************/
package org.eclipse.ice.developer.moose.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
/**
* This handler triggers the "Clone MOOSE" action.
*
* TODO Update this documentation with more appropriate details.
*
* @author Alex McCaskey
*
*/
public class CloneMOOSEHandler extends AbstractHandler {
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get the current shell from the HandlerUtil.
Shell shell = HandlerUtil.getActiveWorkbenchWindow(event).getShell();
// TODO Implement. Note: This is using the UI thread.
return null;
}
}
\ No newline at end of file
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* 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:
* Alex McCaskey - Initial API and implementation and/or initial documentation
*
*******************************************************************************/
package org.eclipse.ice.developer.moose.actions;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
import org.eclipse.cdt.core.settings.model.CSourceEntry;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICFolderDescription;
import org.eclipse.cdt.core.settings.model.ICLanguageSetting;
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
import org.eclipse.cdt.core.settings.model.extension.CConfigurationData;
import org.eclipse.cdt.make.core.IMakeCommonBuildInfo;
import org.eclipse.cdt.make.core.IMakeTarget;
import org.eclipse.cdt.make.core.IMakeTargetManager;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.Configuration;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.internal.core.ManagedProject;
import org.eclipse.cdt.managedbuilder.ui.wizards.CfgHolder;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.egit.core.op.CloneOperation.PostCloneTask;
import org.eclipse.ice.developer.actions.GitCloneHandler;
import org.eclipse.ice.developer.moose.nature.MooseNature;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.wizards.IWizardDescriptor;
/**
* This handler triggers the "Clone MOOSE" action.
*
* @author Alex McCaskey
*
*/
@SuppressWarnings("restriction")
public class MooseCloneHandler extends GitCloneHandler {
/**
* This implementation of addPostCloneTasks attempts to show a Existing
* Project Import Wizard.
*/
protected void addPostCloneTasks() {
cloneOperation.addPostCloneTask(new ImportMooseTask());
}
/**
*
* @author Alex McCaskey
*
*/
private class ImportMooseTask implements PostCloneTask {
@Override
public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
// Get the project and project description handles
String os = System.getProperty("os.name");
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("moose");
IProjectDescription description = workspace.newProjectDescription("moose");
monitor.subTask("Converting application to CDT C++ Project...");
try {
// Create the CDT Project
CCorePlugin.getDefault().createCDTProject(description, project, new NullProgressMonitor());
// Add the CPP nature
CCProjectNature.addCCNature(project, new NullProgressMonitor());
// Set up build information
ICProjectDescriptionManager pdMgr = CoreModel.getDefault().getProjectDescriptionManager();
ICProjectDescription projDesc = pdMgr.createProjectDescription(project, false);
ManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
ManagedProject mProj = new ManagedProject(projDesc);
info.setManagedProject(mProj);
// Grab the correct toolchain
// FIXME this should be better...
IToolChain toolChain = null;
for (IToolChain tool : ManagedBuildManager.getRealToolChains()) {
if (os.contains("Mac") && tool.getName().contains("Mac") && tool.getName().contains("GCC")) {
toolChain = tool;
break;
} else if (os.contains("Linux") && tool.getName().contains("Linux")
&& tool.getName().contains("GCC")) {
toolChain = tool;
break;
} else if (os.contains("Windows") && tool.getName().contains("Cygwin")) {
toolChain = tool;
break;
} else {
toolChain = null;
}
}
// Set up the Build configuratino
CfgHolder cfgHolder = new CfgHolder(toolChain, null);
String s = toolChain == null ? "0" : toolChain.getId(); //$NON-NLS-1$
IConfiguration config = new Configuration(mProj,
(org.eclipse.cdt.managedbuilder.internal.core.ToolChain) toolChain,
ManagedBuildManager.calculateChildId(s, null), cfgHolder.getName());
IBuilder builder = config.getEditableBuilder();
builder.setManagedBuildOn(false);
CConfigurationData data = config.getConfigurationData();
projDesc.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, data);
pdMgr.setProjectDescription(project, projDesc);
// Now create a default Make Target for the Moose user to
// use to
// build the new app
IProject cProject = projDesc.getProject();
IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
String[] ids = manager.getTargetBuilders(cProject);
IMakeTarget mooseTarget = manager.createTarget(cProject, "Build Moose", ids[0]);
mooseTarget.setStopOnError(false);
mooseTarget.setRunAllBuilders(false);
mooseTarget.setUseDefaultBuildCmd(false);
mooseTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND, "make -j $MOOSE_JOBS -C framework");
mooseTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_LOCATION, cProject.getLocation().toOSString());
mooseTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, "");
mooseTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, "");
manager.addTarget(cProject, mooseTarget);
IMakeTarget libmeshTarget = manager.createTarget(cProject, "Build LibMesh", ids[0]);
libmeshTarget.setStopOnError(false);
libmeshTarget.setRunAllBuilders(false);
libmeshTarget.setUseDefaultBuildCmd(false);
libmeshTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_COMMAND,
"sh scripts/updated_and_rebuild_libmesh.sh");
libmeshTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_LOCATION,
cProject.getLocation().toOSString());
libmeshTarget.setBuildAttribute(IMakeCommonBuildInfo.BUILD_ARGUMENTS, "");
libmeshTarget.setBuildAttribute(IMakeTarget.BUILD_TARGET, "");
manager.addTarget(cProject, libmeshTarget);
// Set the include and src folders as actual CDT source
// folders
ICProjectDescription cDescription = CoreModel.getDefault().getProjectDescriptionManager()
.createProjectDescription(cProject, false);
ICConfigurationDescription cConfigDescription = cDescription
.createConfiguration(ManagedBuildManager.CFG_DATA_PROVIDER_ID, config.getConfigurationData());
cDescription.setActiveConfiguration(cConfigDescription);
cConfigDescription.setSourceEntries(null);
IFolder frameworkFolder = cProject.getFolder("framework");
IFolder srcFolder = frameworkFolder.getFolder("src");
IFolder includeFolder = frameworkFolder.getFolder("include");
ICSourceEntry srcFolderEntry = new CSourceEntry(srcFolder, null, ICSettingEntry.RESOLVED);
ICSourceEntry includeFolderEntry = new CSourceEntry(includeFolder, null, ICSettingEntry.RESOLVED);
cConfigDescription.setSourceEntries(new ICSourceEntry[] { srcFolderEntry, includeFolderEntry });
// Add the Moose include paths
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(cProject, true);
ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
for (ICConfigurationDescription configDescription : configDecriptions) {
ICFolderDescription projectRoot = configDescription.getRootFolderDescription();
ICLanguageSetting[] settings = projectRoot.getLanguageSettings();
for (ICLanguageSetting setting : settings) {
List<ICLanguageSettingEntry> includes = getIncludePaths(project);
includes.addAll(setting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH));
setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, includes);
}
}
CoreModel.getDefault().setProjectDescription(cProject, projectDescription);
// Add a MOOSE Project Nature
IProjectDescription desc = project.getDescription();
String[] prevNatures = desc.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length] = MooseNature.NATURE_ID;
desc.setNatureIds(newNatures);
project.setDescription(desc, new NullProgressMonitor());
} catch (CoreException e) {
logger.error(getClass().getName() + " Exception!", e);
String errorMessage = "ICE could not import the new MOOSE application as a C++ project.";
// return new Status(IStatus.ERROR,
// "org.eclipse.ice.client.widgets.moose", 1,
// errorMessage, null);
}
}
/**
* This private method configures the include paths for the CDT project.
*
* @param mooseProject
* @return
*/
private List<ICLanguageSettingEntry> getIncludePaths(IProject mooseProject) {
// Create a list of ICLanguageSettingEntry to hold the include paths.
List<ICLanguageSettingEntry> includes = new ArrayList<ICLanguageSettingEntry>();
try {
mooseProject.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
// Get the header file directory
IFolder includeFolder = mooseProject.getFolder("framework").getFolder("include");
// Create a File from that IFolder and search for all its
// sub directories
File includeDirFile = includeFolder.getLocation().toFile();
String[] directories = includeDirFile.list(new FilenameFilter() {
@Override
public boolean accept(File current, String name) {
return new File(current, name).isDirectory();
}
});
// Loop over all directories and add them to the include paths
for (String directory : directories) {
includes.add(new CIncludePathEntry("/moose/framework/include/" + directory,
ICSettingEntry.VALUE_WORKSPACE_PATH));
}
// Add libmesh too
includes.add(new CIncludePathEntry("/moose/libmesh/installed/include",
ICSettingEntry.VALUE_WORKSPACE_PATH));
return includes;
}
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @author Alex McCaskey
*
*/
public class ForkMOOSEHandler extends AbstractHandler {
public class MooseForkHandler extends AbstractHandler {
/*
* (non-Javadoc)
......
......@@ -62,6 +62,7 @@ import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.RepositoryId;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.eclipse.ice.developer.moose.nature.MooseNature;
import org.eclipse.ice.developer.moose.wizards.ForkStorkWizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
......@@ -81,12 +82,12 @@ import org.slf4j.LoggerFactory;
* @author Alex McCaskey
*
*/
public class ForkStorkHandler extends AbstractHandler {
public class StorkForkHandler extends AbstractHandler {
/**
* Logger for handling event messages and other information.
*/
private static final Logger logger = LoggerFactory.getLogger(ForkStorkHandler.class);
private static final Logger logger = LoggerFactory.getLogger(StorkForkHandler.class);
/**
* (non-Javadoc)
......
......@@ -10,7 +10,7 @@
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.developer.moose.actions;
package org.eclipse.ice.developer.moose.wizards;
import java.util.ArrayList;
......
......@@ -10,7 +10,7 @@
* Jordan H. Deyton, Dasha Gorin, Alexander J. McCaskey, Taylor Patterson,
* Claire Saunders, Matthew Wang, Anna Wojtowicz
*******************************************************************************/
package org.eclipse.ice.developer.moose.actions;
package org.eclipse.ice.developer.moose.wizards;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
......
......@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0",
org.eclipse.egit.core;bundle-version="4.0.0",
org.eclipse.jgit;bundle-version="4.0.0",
org.eclipse.egit.ui;bundle-version="4.0.0",
org.eclipse.core.commands
org.eclipse.core.commands,
org.eclipse.debug.core;bundle-version="3.10.0"
Import-Package: org.apache.commons.io;version="2.2.0",
org.eclipse.egit.github.core;version="4.0.0",
org.eclipse.egit.github.core.service;version="4.0.0",
......
......@@ -19,12 +19,17 @@
name="ICE Developer Tooling"
point="org.eclipse.ice.developer.code">
<code
branch="next"
codeCategory="Framework"
codeName="ICE"
repoURL="https://github.com/eclipse/ice">
<command
commandName="Clone ICE"
implementation="org.eclipse.ice.developer.actions.GitHubCloneHandler">
implementation="org.eclipse.ice.developer.actions.ICECloneHandler">
</command>
<command
commandName="Build ICE"
implementation="org.eclipse.ice.developer.actions.BuildICEHandler">
</command>
</code>
</extension>
......
......@@ -89,6 +89,13 @@
</documentation>
</annotation>
</attribute>
<attribute name="branch" type="string">
<annotation>
<documentation>
This attribute is to specify a branch other than master to initially check out.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
......
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* 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:
* Alex McCaskey - Initial API and implementation and/or initial documentation
*
*******************************************************************************/
package org.eclipse.ice.developer.actions;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The BuildICEHandler is a subclass of AbstractHandler that provides
* an execute implementation that grabs the ICE Build Launch Configuration
* files and launches them with the ILaunchManager to build ICE in its
* entirety.
*
* @author Alex McCaskey
*
*/
public class BuildICEHandler extends AbstractHandler {
/**
* Logger for handling event messages and other information.
*/
protected static final Logger logger = LoggerFactory.getLogger(GitCloneHandler.class);
/*
* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get the Launch Manager
ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
if (manager != null) {
IProject iceProject = ResourcesPlugin.getWorkspace().getRoot().getProject("ice");
if (iceProject != null) {
// Get the Launch Configurations files
IFile mvnInitialInstall = iceProject.getFile("ICE Build - Initial Install.launch");
IFile mvnCleanInstall = iceProject.getFile("ICE Build - Clean and Install.launch");
// Get the Launch Configuration from those files
ILaunchConfiguration initialConfig = manager.getLaunchConfiguration(mvnInitialInstall);
ILaunchConfiguration installConfig = manager.getLaunchConfiguration(mvnCleanInstall);
// Create and launch the Job.
Job job = new WorkspaceJob("Building ICE") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
initialConfig.launch(ILaunchManager.RUN_MODE, monitor);
installConfig.launch(ILaunchManager.RUN_MODE, monitor);
return Status.OK_STATUS;
}
};
job.schedule();
} else {
logger.info("Info: Could not build ICE because it hasn't been cloned yet. Please clone ICE to the current workspace.");
}
} else {
logger.error("Error in launching the ICE Build - Could not get the Launch Manager.");
}
return null;
}
}
/*******************************************************************************
* Copyright (c) 2015 UT-Battelle, LLC.
* 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:
* Alex McCaskey - Initial API and implementation and/or initial documentation
*
*******************************************************************************/
package org.eclipse.ice.developer.actions;