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", ...@@ -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.jgit;bundle-version="4.0.0",
org.eclipse.egit.ui;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" 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", Import-Package: org.apache.commons.io;version="2.2.0",
org.eclipse.egit.github.core;version="4.0.0", org.eclipse.egit.github.core;version="4.0.0",
org.eclipse.egit.github.core.service;version="4.0.0", org.eclipse.egit.github.core.service;version="4.0.0",
......
...@@ -33,5 +33,24 @@ ...@@ -33,5 +33,24 @@
</command> </command>
</code> </code>
</extension> </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> </plugin>
...@@ -75,9 +75,9 @@ ...@@ -75,9 +75,9 @@
</annotation> </annotation>
<simpleType> <simpleType>
<restriction base="string"> <restriction base="string">
<enumeration value="Framework"> <enumeration value="ICE">
</enumeration> </enumeration>
<enumeration value="Physics"> <enumeration value="Framework">
</enumeration> </enumeration>
</restriction> </restriction>
</simpleType> </simpleType>
...@@ -106,6 +106,9 @@ ...@@ -106,6 +106,9 @@
</documentation> </documentation>
</annotation> </annotation>
<complexType> <complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element ref="parameter"/>
</sequence>
<attribute name="commandName" type="string" use="required"> <attribute name="commandName" type="string" use="required">
<annotation> <annotation>
<documentation> <documentation>
...@@ -126,6 +129,25 @@ ...@@ -126,6 +129,25 @@
</complexType> </complexType>
</element> </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> <annotation>
<appinfo> <appinfo>
<meta.section type="since"/> <meta.section type="since"/>
......
...@@ -13,6 +13,7 @@ package org.eclipse.ice.developer.actions; ...@@ -13,6 +13,7 @@ package org.eclipse.ice.developer.actions;
import java.io.File; import java.io.File;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Map; import java.util.Map;
...@@ -25,7 +26,12 @@ import org.eclipse.core.runtime.IProgressMonitor; ...@@ -25,7 +26,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; 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.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.eclipse.jgit.transport.URIish;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -58,11 +64,10 @@ public class GitCloneHandler extends AbstractHandler { ...@@ -58,11 +64,10 @@ public class GitCloneHandler extends AbstractHandler {
protected Map handlerParameters; protected Map handlerParameters;
/** /**
* Reference to the location that this handler should * Reference to the location that this handler should clone the repo to.
* clone the repo to.
*/ */
protected File cloneLocation; protected File cloneLocation;
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
...@@ -89,11 +94,22 @@ public class GitCloneHandler extends AbstractHandler { ...@@ -89,11 +94,22 @@ public class GitCloneHandler extends AbstractHandler {
// Get the name of the repository // Get the name of the repository
String repoName = repo.substring(repo.lastIndexOf("/") + 1, repo.length()); String repoName = repo.substring(repo.lastIndexOf("/") + 1, repo.length());
// Get the initial branch to check out. // Get the initial branch to check out.
String branch = handlerParameters.get("branchID") == null ? "master" : (String) handlerParameters.get("branchID"); 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"); // 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 not, then clone this repo to the current Workspace.
if (directory == null) { if (directory == null) {
...@@ -123,7 +139,14 @@ public class GitCloneHandler extends AbstractHandler { ...@@ -123,7 +139,14 @@ public class GitCloneHandler extends AbstractHandler {
cloneOperation = new CloneOperation(new URIish(repo), true, null, cloneLocation, branch, "origin", cloneOperation = new CloneOperation(new URIish(repo), true, null, cloneLocation, branch, "origin",
100); 100);
addPostCloneTasks(); addPostCloneTasks();
try {
UserPasswordCredentials credentials = SecureStoreUtils.getCredentials(new URIish(repo));
} catch (StorageException e) {
e.printStackTrace();
}
cloneOperation.run(monitor); cloneOperation.run(monitor);
final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
util.addConfiguredRepository(cloneOperation.getGitDir());
} catch (URISyntaxException | InvocationTargetException | InterruptedException e) { } catch (URISyntaxException | InvocationTargetException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
String message = "Git clone operation failed with the following stacktrace:\n" + e.getMessage(); String message = "Git clone operation failed with the following stacktrace:\n" + e.getMessage();
...@@ -149,7 +172,6 @@ public class GitCloneHandler extends AbstractHandler { ...@@ -149,7 +172,6 @@ public class GitCloneHandler extends AbstractHandler {
* GitCloneHandler's cloneOperation attribute. * GitCloneHandler's cloneOperation attribute.
*/ */
protected void addPostCloneTasks() { protected void addPostCloneTasks() {
return;
} }
} }
...@@ -107,9 +107,9 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor ...@@ -107,9 +107,9 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor
registry = Platform.getExtensionRegistry(); registry = Platform.getExtensionRegistry();
// Create the ICE Menu here so it's first in the list // Create the ICE Menu here so it's first in the list
MenuManager ice = new MenuManager("ICE", "ICEID"); //MenuManager ice = new MenuManager("ICE", "ICEID");
categoryMenus.put("ICE", ice); //categoryMenus.put("ICE", ice);
developerMenu.add(ice); //developerMenu.add(ice);
// Create the category sub-menus // Create the category sub-menus
for (CodeCategory c : CodeCategory.values()) { for (CodeCategory c : CodeCategory.values()) {
...@@ -270,6 +270,41 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor ...@@ -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 ...@@ -281,6 +316,8 @@ public class ICEExtensionContributionFactory extends ExtensionContributionFactor
*/ */
private enum CodeCategory { private enum CodeCategory {
ICE,
Framework, Framework,
Nuclear, 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