GitLab will be shut down on June 25 to move to a new facility. https://www.eclipsestatus.io/incidents/5ffy27gwcbx7

Commit b6429571 authored by amccaskey's avatar amccaskey
Browse files

Adding the ImportLocalICEHandler action.



This action builds off the ICECloneHandler to let users use the EGit
import local repository action in a more user-friendly way. It also
handles importing all Eclipse projects into the Project Explorer. 
Signed-off-by: default avataramccaskey <mccaskeyaj@ornl.gov>
parent c60b30b2
......@@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.11.0",
org.eclipse.core.commands,
org.eclipse.debug.core;bundle-version="3.10.0",
org.eclipse.equinox.security;bundle-version="1.2.100",
org.eclipse.m2e.core;bundle-version="1.6.0"
org.eclipse.m2e.core;bundle-version="1.6.0",
org.eclipse.ui.ide
Import-Package: org.apache.commons.io;version="2.2.0",
org.apache.commons.lang,
org.eclipse.egit.github.core;version="4.0.0",
......@@ -26,6 +27,5 @@ Import-Package: org.apache.commons.io;version="2.2.0",
org.eclipse.ui.actions,
org.eclipse.ui.menus,
org.eclipse.ui.services,
org.eclipse.ui.wizards.datatransfer,
org.slf4j;version="1.7.2"
Export-Package: org.eclipse.ice.developer.actions
......@@ -35,6 +35,10 @@
commandName="Launch New ICE Instance"
implementation="org.eclipse.ice.developer.actions.LaunchNewICEHandler">
</command>
<command
commandName="Import Local ICE"
implementation="org.eclipse.ice.developer.actions.ImportLocalICEHandler">
</command>
</code>
</extension>
<extension
......
......@@ -12,13 +12,8 @@
package org.eclipse.ice.developer.actions;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashSet;
......@@ -49,7 +44,6 @@ import org.eclipse.egit.ui.internal.clone.ProjectUtils;
import org.eclipse.equinox.security.storage.StorageException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PartInitException;
......
......@@ -11,34 +11,17 @@
*******************************************************************************/
package org.eclipse.ice.developer.actions;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
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.egit.core.internal.util.ProjectUtil;
import org.eclipse.egit.core.op.CloneOperation.PostCloneTask;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.clone.ProjectRecord;
import org.eclipse.egit.ui.internal.clone.ProjectUtils;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.ui.IWorkingSet;
/**
* The ICECloneHandler clones the ICE repository and adds PostCloneTasks that
......@@ -62,31 +45,37 @@ public class ICECloneHandler extends GitCloneHandler {
cloneOperation.addPostCloneTask(new PostCloneTask() {
@Override
public void execute(Repository repository, IProgressMonitor monitor) throws CoreException {
// This is a fix for the errors that occur with the new ICE Build for
// certain maven goals.
String file = MavenPlugin.getMavenConfiguration().getWorkspaceLifecycleMappingMetadataFile();
try {
Path path = Paths.get(file);
if (Files.exists(path)) {
Files.write(Paths.get(file), lifecycleXML.getBytes());
} else {
Files.write(Paths.get(file), lifecycleXML.getBytes(), StandardOpenOption.CREATE_NEW);
}
} catch (IOException e) {
e.printStackTrace();
}
fixMavenLifecycleFile();
}
});
// Import all projects
super.addPostCloneTasks();
}
/**
*
*/
protected void fixMavenLifecycleFile() {
// This is a fix for the errors that occur with the new ICE Build for
// certain maven goals.
String file = MavenPlugin.getMavenConfiguration().getWorkspaceLifecycleMappingMetadataFile();
try {
Path path = Paths.get(file);
if (Files.exists(path)) {
Files.write(Paths.get(file), lifecycleXML.getBytes());
} else {
Files.write(Paths.get(file), lifecycleXML.getBytes(), StandardOpenOption.CREATE_NEW);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Reference to the XML file contents we need for life cycle management M2e file.
*/
private String lifecycleXML =
protected String lifecycleXML =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<lifecycleMappingMetadata>\n"
+ " <pluginExecutions>\n"
+ " <pluginExecution>\n"
......
/*******************************************************************************
* 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 java.io.File;
import java.io.IOException;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
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.RepositoryCache;
import org.eclipse.egit.core.RepositoryUtil;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.CommonUtils;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.progress.IProgressConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The ImportLocalICEHandler is a subclass of the ICECloneHandler that
* allows users to navigate to an existing, locally cloned ICE repository and
* import it into the Git Repositories view. It also imports all projects into the
* Project Explorer.
*
* @author Alex McCaskey
*
*/
@SuppressWarnings("restriction")
public class ImportLocalICEHandler extends ICECloneHandler {
/**
* Logger for handling event messages and other information.
*/
protected static final Logger logger = LoggerFactory.getLogger(ImportLocalICEHandler.class);
/*
* (non-Javadoc)
* @see org.eclipse.ice.developer.actions.GitCloneHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Grab the Util and Cache for repositories
RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
RepositoryCache cache = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
for (String dir : repositoryUtil.getConfiguredRepositories()) {
File repoDir = new File(dir);
try {
Repository repo = cache.lookupRepository(repoDir);
// FIXME Find a better way to find the recently added
// ICE repo
if (repo.getDirectory().getParentFile().getName().equals("ice")) {
Job badJob = new Job("Import Local ICE") {
@Override
protected IStatus run(IProgressMonitor monitor) {
return new Status(IStatus.ERROR, "org.eclipse.ice.developer", 1, "ICE is already cloned and imported into the Project Explorer.", null);
}
};
// Start the job
badJob.schedule();
return null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
// Fix the maven build errors.
fixMavenLifecycleFile();
// Execute the Add Repository EGit action
IHandlerService service = CommonUtils.getService(PlatformUI.getWorkbench().getActiveWorkbenchWindow(),
IHandlerService.class);
UIUtils.executeCommand(service,
"org.eclipse.egit.ui.RepositoriesViewAddRepository");
// Find the ICE repository.
for (String dir : repositoryUtil.getConfiguredRepositories()) {
File repoDir = new File(dir);
try {
Repository repo = cache.lookupRepository(repoDir);
// FIXME Find a better way to find the recently added
// ICE repo
if (repo.getDirectory().getParentFile().getName().equals("ice")) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
try {
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
.showView(IProgressConstants.PROGRESS_VIEW_ID);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
importProjects(repo, new IWorkingSet[0]);
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
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