Author: adietish
Date: 2011-10-11 12:15:08 -0400 (Tue, 11 Oct 2011)
New Revision: 35544
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenshiftWizardPage.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizard.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java
Log:
[JBIDE-9793] import general project works now, next step: add maven nature (etc) if maven
proj
Modified: trunk/as/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/as/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2011-10-11
15:54:38 UTC (rev 35543)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2011-10-11
16:15:08 UTC (rev 35544)
@@ -21,7 +21,8 @@
org.eclipse.wst.server.core;bundle-version="[1.1.3,2.0.0)",
org.eclipse.debug.core;bundle-version="[3.7.0,4.0.0)",
org.jboss.ide.eclipse.as.ui;bundle-version="[2.3.0,3.0.0)",
- org.eclipse.wst.server.ui;bundle-version="[1.1.3,2.0.0)"
+ org.eclipse.wst.server.ui;bundle-version="[1.1.3,2.0.0)",
+ org.eclipse.ui.ide;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.jboss.tools.common.databinding,
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenshiftWizardPage.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenshiftWizardPage.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/AbstractOpenshiftWizardPage.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -43,9 +43,7 @@
@Override
public void createControl(Composite parent) {
this.dbc = new DataBindingContext();
- ParametrizableWizardPageSupport.create(
- IStatus.ERROR | IStatus.INFO | IStatus.WARNING | IStatus.CANCEL, this,
- dbc);
+ setupWizardPageSupport(dbc);
Composite container = new Composite(parent, SWT.NONE);
GridLayoutFactory.fillDefaults().margins(6,6).applyTo(container);
Composite child = new Composite(container, SWT.NONE);
@@ -55,6 +53,12 @@
doCreateControls(child, dbc);
}
+ protected void setupWizardPageSupport(DataBindingContext dbc) {
+ ParametrizableWizardPageSupport.create(
+ IStatus.ERROR | IStatus.INFO | IStatus.WARNING | IStatus.CANCEL, this,
+ dbc);
+ }
+
protected void initPageChangedListener() {
IWizardContainer wizardContainer = getContainer();
if (wizardContainer instanceof WizardDialog) {
@@ -84,4 +88,9 @@
protected abstract void doCreateControls(Composite parent, DataBindingContext dbc);
+
+ protected DataBindingContext getDataBindingContext() {
+ return dbc;
+ }
+
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ApplicationWizardPage.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -207,7 +207,7 @@
@Override
public void widgetSelected(SelectionEvent e) {
try {
- if (MessageDialog.openConfirm(getShell(),
+ if (MessageDialog.openQuestion(getShell(),
"Delete Application",
NLS.bind(
"You're up to delete all data within an application. The data may not
be recovered. "
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPage.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -154,7 +154,7 @@
}
};
}
-
+
private static class CredentialsStatusValidator implements IValidator {
public IStatus validate(Object value) {
if (value instanceof IStatus) {
@@ -168,4 +168,5 @@
return ValidationStatus.error("The given credentials are not valid");
}
}
+
}
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CredentialsWizardPageModel.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -120,7 +120,11 @@
return credentialsValidity;
}
- public void validateCredentials() {
+ public boolean areCredentialsValidated() {
+ return credentialsValidity != null;
+ }
+
+ public IStatus validateCredentials() {
IStatus status = new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID, "Your
credentails are not valid.");
try {
this.user = new User(getRhLogin(), getPassword(), ID);
@@ -135,6 +139,7 @@
}
wizardModel.setUser(user);
setCredentialsStatus(status);
+ return status;
}
public IUser getUser() {
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizard.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizard.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizard.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -10,8 +10,7 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
+import java.io.File;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -52,7 +51,8 @@
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- model.setupProject();
+ File repositoryFile = model.cloneRepository(monitor);
+ model.importProject(repositoryFile, monitor);
return Status.OK_STATUS;
} catch (OpenshiftException e) {
return new Status(IStatus.ERROR, OpenshiftUIActivator.PLUGIN_ID,
Modified:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java 2011-10-11
15:54:38 UTC (rev 35543)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java 2011-10-11
16:15:08 UTC (rev 35544)
@@ -15,11 +15,15 @@
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.ui.Activator;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.InitCommand;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
@@ -33,6 +37,12 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.transport.URIish;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.client.IApplication;
@@ -47,11 +57,11 @@
private static final String REMOTE_NAME = "openshift";
private IUser user;
private IApplication application;
-
+
public void setUser(IUser user) {
this.user = user;
}
-
+
public IUser getUser() {
return user;
}
@@ -64,31 +74,123 @@
this.application = application;
}
- public void setupProject() throws OpenshiftException, URISyntaxException,
InvocationTargetException, InterruptedException, IOException, NoHeadException,
ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException,
WrongRepositoryStateException, NoMessageException, CoreException {
- String applicationWorkingdir = "openshift-" + application.getName();
-// File workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
- String userHome = System.getProperty("java.io.tmpdir");
-// File workDir = new File(workspace, applicationWorkingdir);
- File clonedDirectory = new File(userHome, applicationWorkingdir);
- URIish gitUri = new URIish(application.getGitUri());
- if (clonedDirectory.exists()) {
- FileUtil.completeDelete(clonedDirectory);
- }
- CloneOperation cloneOperation = new CloneOperation(gitUri, true, null, clonedDirectory,
Constants.HEAD, "origin", 10 * 1024);
-// cloneOperation.setCredentialsProvider(new
UsernamePasswordCredentialsProvider(user.getRhlogin(), user.getPassword()));
+ public void importProject(File projectDirectory, IProgressMonitor monitor) throws
OpenshiftException,
+ URISyntaxException,
+ InvocationTargetException, InterruptedException, IOException, NoHeadException,
+ ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException,
+ WrongRepositoryStateException, NoMessageException, CoreException {
+ final String projectName = projectDirectory.getName();
+
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject(projectName);
+ overwriteExistingProject(project, monitor);
+
+ importToNewProject(projectDirectory, monitor, project);
+
+ createServerAdapterIfRequired();
+ }
+
+ private void importToNewProject(File projectDirectory, IProgressMonitor monitor,
IProject project)
+ throws CoreException, InvocationTargetException, InterruptedException {
+ project.create(monitor);
+ project.open(monitor);
+ ImportOperation operation =
+ new ImportOperation(
+ project.getFullPath()
+ , projectDirectory
+ , FileSystemStructureProvider.INSTANCE
+ , new IOverwriteQuery() {
+ public String queryOverwrite(String file) {
+ return IOverwriteQuery.ALL;
+ }
+ });
+ operation.setCreateContainerStructure(false);
+ operation.run(monitor);
+ }
+
+ private void overwriteExistingProject(final IProject project, IProgressMonitor monitor)
+ throws CoreException {
+ if (project == null
+ || !project.exists()) {
+ return;
+ }
+
+ final boolean[] overwrite = new boolean[1];
+ Display.getDefault().syncExec(new Runnable() {
+
+ public void run() {
+ overwrite[0] = MessageDialog.openQuestion(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Overwrite project?",
+ NLS.bind(
+ "A project \"{0}\" already exists in the workspace.\n"
+ + "If you want to import the OpenShift \"{0}\", the project in
your workspace will "
+ + "get overwritten and may not be recovered.\n\n"
+ + "Are you sure that you want to overwrite the project \"{0}\"
in your workspace?",
+ project.getName()));
+ }
+
+ });
+ if (overwrite[0]) {
+ project.delete(true, true, monitor);
+ }
+ }
+
+ public File cloneRepository(IProgressMonitor monitor) throws URISyntaxException,
OpenshiftException,
+ InvocationTargetException,
+ InterruptedException {
+ File destination = getDestinationDirectory(application);
+ cloneRepository(application.getGitUri(), destination, monitor);
+ return destination;
+ }
+
+ private void cloneRepository(String uri, File destination, IProgressMonitor monitor)
throws URISyntaxException,
+ OpenshiftException,
+ InvocationTargetException,
+ InterruptedException {
+ if (destination.exists()) {
+ FileUtil.completeDelete(destination);
+ }
+ URIish gitUri = new URIish(uri);
+ CloneOperation cloneOperation =
+ new CloneOperation(gitUri, true, null, destination, Constants.HEAD,
"origin", 10 * 1024);
cloneOperation.run(null);
- File gitDirectory = new File(clonedDirectory, Constants.DOT_GIT);
+ File gitDirectory = new File(destination, Constants.DOT_GIT);
Activator.getDefault().getRepositoryUtil().addConfiguredRepository(gitDirectory);
-// File repositoryFile = createRepositoryFile(applicationWorkingdir);
-// Git git = createGit(repositoryFile);
- // TODO replace remote name by user setting
-// Repository repository = git.getRepository();
-// EGitUtils.addRemoteTo(REMOTE_NAME, new URIish(application.getGitUri()), repository);
-// mergeWithRemote(git, REMOTE_NAME);
-
- createServerAdapterIfRequired();
}
-
+
+ private boolean isEclipseProject(File destination) {
+ if (isReadable(destination)) {
+ return false;
+ }
+
+ return isReadable(new File(destination, ".project"));
+
+ }
+
+ private boolean isMavenProject(File destination) {
+ if (isReadable(destination)) {
+ return false;
+ }
+
+ return isReadable(new File(destination, "pom.xml"));
+ }
+
+ private boolean isReadable(File destination) {
+ return destination == null
+ || !destination.exists()
+ || !destination.canRead();
+ }
+
+ private File getDestinationDirectory(IApplication application) {
+ String applicationDirectory = "openshift-" + application.getName();
+ // File workspace =
+ // ResourcesPlugin.getWorkspace().getRoot().getLocation().toFile();
+ String userHome = System.getProperty("java.io.tmpdir");
+ // File workDir = new File(workspace, applicationWorkingdir);
+ return new File(userHome, applicationDirectory);
+ }
+
private void mergeWithRemote(Git git, String remoteName) throws CoreException,
NoHeadException,
ConcurrentRefUpdateException, CheckoutConflictException, InvalidMergeHeadsException,
WrongRepositoryStateException, NoMessageException, IOException {
@@ -114,5 +216,5 @@
File repositoryFile = new File(gitRepoProject.toFile(), Constants.DOT_GIT);
return repositoryFile;
}
-
+
}