Commit 2490845c authored by amccaskey's avatar amccaskey
Browse files

Set up clone ICETests dev menu action.



This commit fixes a bug where the cloned repo wasn't added to the git
repositories view. Also, it adds code to check for the user credentials
on a git repo if need be. 

Added an extension point that let's users clone the ICETests repo from
github. To acheive this, I added the ability to provide custom
parameters to a given command. The ICETests extension point uses this to
specify the clone directory as @user.home.
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent d1ba0502
......@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0",
org.eclipse.jgit;bundle-version="4.0.0",
org.eclipse.egit.ui;bundle-version="4.0.0",
org.eclipse.core.commands,
org.eclipse.debug.core;bundle-version="3.10.0"
org.eclipse.debug.core;bundle-version="3.10.0",
org.eclipse.equinox.security;bundle-version="1.2.100"
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",
......
......@@ -33,5 +33,24 @@
</command>
</code>
</extension>
<extension
id="org.eclipse.ice.developer.icetests"
name="ICE Tests"
point="org.eclipse.ice.developer.code">
<code
branch="master"
codeCategory="ICE"
codeName="ICE Tests"
repoURL="https://github.com/jayjaybillings/ICETests">
<command
commandName="Clone ICETests to user.home"
implementation="org.eclipse.ice.developer.actions.GitCloneHandler">
<parameter
name="cloneDirectory"
value="@user.home">
</parameter>
</command>
</code>
</extension>
</plugin>
......@@ -75,9 +75,9 @@
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="Framework">
<enumeration value="ICE">
</enumeration>
<enumeration value="Physics">
<enumeration value="Framework">
</enumeration>
</restriction>
</simpleType>
......@@ -106,6 +106,9 @@
</documentation>
</annotation>
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="parameter"/>
</sequence>
<attribute name="commandName" type="string" use="required">
<annotation>
<documentation>
......@@ -126,6 +129,25 @@
</complexType>
</element>
<element name="parameter">
<complexType>
<attribute name="name" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
<attribute name="value" type="string" use="required">
<annotation>
<documentation>
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
......
......@@ -13,6 +13,7 @@ package org.eclipse.ice.developer.actions;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
......@@ -25,7 +26,12 @@ 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.egit.core.RepositoryUtil;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.securestorage.UserPasswordCredentials;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.SecureStoreUtils;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.jgit.transport.URIish;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -58,11 +64,10 @@ public class GitCloneHandler extends AbstractHandler {
protected Map handlerParameters;
/**
* Reference to the location that this handler should
* clone the repo to.
* Reference to the location that this handler should clone the repo to.
*/
protected File cloneLocation;
/*
* (non-Javadoc)
*
......@@ -89,11 +94,22 @@ public class GitCloneHandler extends AbstractHandler {
// Get the name of the repository
String repoName = repo.substring(repo.lastIndexOf("/") + 1, repo.length());
// Get the initial branch to check out.
String branch = handlerParameters.get("branchID") == null ? "master" : (String) handlerParameters.get("branchID");
// See if we have been given a cloneDirectory parameter.
String directory = (String) handlerParameters.get("cloneDirectory");
// Get the initial branch to check out.
String branch = handlerParameters.get("branchID") == null ? "master"
: (String) handlerParameters.get("branchID");
// See if we have been given a cloneDirectory parameter.
String directory = (String) handlerParameters.get("cloneDirectoryID");
// Get the user provided directory
if (directory != null) {
if (directory.startsWith("@")) {
directory = new File(System.getProperty(directory.replace("@", ""))).isDirectory()
? System.getProperty(directory.replace("@", "")) : null;
} else {
directory = new File(directory).isDirectory() ? directory : null;
}
}
// If not, then clone this repo to the current Workspace.
if (directory == null) {
......@@ -123,7 +139,14 @@ public class GitCloneHandler extends AbstractHandler {
cloneOperation = new CloneOperation(new URIish(repo), true, null, cloneLocation, branch, "origin",
100);
addPostCloneTasks();
try {
UserPasswordCredentials credentials = SecureStoreUtils.getCredentials(new URIish(repo));
} catch (StorageException e) {
e.printStackTrace();
}
cloneOperation.run(monitor);
final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
util.addConfiguredRepository(cloneOperation.getGitDir());
} catch (URISyntaxException | InvocationTargetException | InterruptedException e) {
e.printStackTrace();
String message = "Git clone operation failed with the following stacktrace:\n" + e.getMessage();
......@@ -149,7 +172,6 @@ public class GitCloneHandler extends AbstractHandler {
* GitCloneHandler's cloneOperation attribute.
*/
protected void addPostCloneTasks() {
return;
}
}
......@@ -107,9 +107,9 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor
registry = Platform.getExtensionRegistry();
// Create the ICE Menu here so it's first in the list
MenuManager ice = new MenuManager("ICE", "ICEID");
categoryMenus.put("ICE", ice);
developerMenu.add(ice);
//MenuManager ice = new MenuManager("ICE", "ICEID");
//categoryMenus.put("ICE", ice);
//developerMenu.add(ice);
// Create the category sub-menus
for (CodeCategory c : CodeCategory.values()) {
......@@ -270,6 +270,41 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor
}
});
}
// The given command could have added parameters...
// Add them here
for (IConfigurationElement e : element.getChildren("parameter")) {
// generateParameters(e);
String value = e.getAttribute("value");
String name = e.getAttribute("name");
parameters.add(new IParameter() {
@Override
public String getId() {
return name + "ID";
}
@Override
public String getName() {
return value;
}
@Override
public IParameterValues getValues() throws ParameterValuesException {
return new IParameterValues() {
@Override
public Map getParameterValues() {
HashMap<String, String> map = new HashMap<String, String>();
map.put(getId(), getName());
return map;
};
};
}
@Override
public boolean isOptional() {
return false;
}
});
}
}
/**
......@@ -281,6 +316,8 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor
*/
private enum CodeCategory {
ICE,
Framework,
Nuclear,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment