Author: adietish
Date: 2011-10-12 10:23:49 -0400 (Wed, 12 Oct 2011)
New Revision: 35569
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/AbstractProjectImportOperation.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/GeneralProjectImportOperation.java
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/MavenProjectImportOperation.java
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/ServerAdapterWizardModel.java
Log:
[JBIDE-9793] now importing maven project (was: created new and added maven nature)
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-12
12:23:38 UTC (rev 35568)
+++ trunk/as/plugins/org.jboss.tools.openshift.express.ui/META-INF/MANIFEST.MF 2011-10-12
14:23:49 UTC (rev 35569)
@@ -23,7 +23,8 @@
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.ui.ide;bundle-version="3.7.0"
+ org.eclipse.ui.ide;bundle-version="3.7.0",
+ org.eclipse.m2e.core.ui;bundle-version="1.0.100"
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/ServerAdapterWizardModel.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java 2011-10-12
12:23:38 UTC (rev 35568)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/ServerAdapterWizardModel.java 2011-10-12
14:23:49 UTC (rev 35569)
@@ -14,9 +14,10 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.List;
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;
@@ -24,7 +25,6 @@
import org.eclipse.egit.core.op.CloneOperation;
import org.eclipse.egit.core.op.ConnectProviderOperation;
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;
@@ -38,27 +38,19 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.transport.URIish;
-import org.eclipse.m2e.core.internal.MavenPluginActivator;
-import org.eclipse.m2e.core.project.IProjectConfigurationManager;
-import org.eclipse.m2e.core.project.ResolverConfiguration;
-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;
import org.jboss.tools.openshift.express.client.IUser;
import org.jboss.tools.openshift.express.client.OpenshiftException;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.projectimport.GeneralProjectImportOperation;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.projectimport.MavenProjectImportOperation;
/**
- * @author André Dietisheim
+ * @author André Dietisheim <adietish(a)redhat.com>
*/
public class ServerAdapterWizardModel extends ObservableUIPojo {
- private static final String REMOTE_NAME = "openshift";
private IUser user;
private IApplication application;
@@ -78,83 +70,30 @@
this.application = application;
}
- 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();
+ public void importProject(File projectFolder, IProgressMonitor monitor) throws
OpenshiftException, CoreException, InterruptedException {
+ MavenProjectImportOperation mavenImport = new
MavenProjectImportOperation(projectFolder);
+ List<IProject> importedProjects = Collections.emptyList();
+ if (mavenImport.isMavenProject()) {
+ importedProjects = mavenImport.importToWorkspace(monitor);
+ } else {
+ importedProjects = new
GeneralProjectImportOperation(projectFolder).importToWorkspace(monitor);
+ }
- IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
- IProject project = workspaceRoot.getProject(projectName);
- overwriteExistingProject(project, monitor);
+ connectToGitRepo(importedProjects, monitor);
- importToNewProject(projectDirectory, project, monitor);
- conntectToGitRepo(project, monitor);
-
- if (isMavenProject(projectDirectory)) {
- configureMavenNature(project, monitor);
- }
-
createServerAdapterIfRequired();
}
- private void conntectToGitRepo(IProject project, IProgressMonitor monitor) throws
CoreException {
- new ConnectProviderOperation(project).execute(monitor);
+ private void connectToGitRepo(List<IProject> projects, IProgressMonitor monitor)
throws CoreException {
+ for (IProject project : projects) {
+ connectToGitRepo(project, monitor);
+ }
}
- private void configureMavenNature(IProject project, IProgressMonitor monitor) throws
CoreException {
- IProjectConfigurationManager manager =
MavenPluginActivator.getDefault().getProjectConfigurationManager();
- ResolverConfiguration resolverConfiguration =
manager.getResolverConfiguration(project);
- manager.enableMavenNature(project, resolverConfiguration, monitor);
+ private void connectToGitRepo(IProject project, IProgressMonitor monitor) throws
CoreException {
+ new ConnectProviderOperation(project).execute(monitor);
}
- private void importToNewProject(File projectDirectory, IProject project,
IProgressMonitor monitor)
- 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 {
@@ -178,29 +117,6 @@
Activator.getDefault().getRepositoryUtil().addConfiguredRepository(gitDirectory);
}
- 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 =
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/AbstractProjectImportOperation.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/AbstractProjectImportOperation.java
(rev 0)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/AbstractProjectImportOperation.java 2011-10-12
14:23:49 UTC (rev 35569)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard.projectimport;
+
+import java.io.File;
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+public class AbstractProjectImportOperation {
+
+ private File projectFolder;
+
+ public AbstractProjectImportOperation(File projectDirectory) {
+ this.projectFolder = projectDirectory;
+ }
+
+ protected File getProjectDirectory() {
+ return projectFolder;
+ }
+
+ protected boolean isReadable(File destination) {
+ return destination != null
+ && destination.exists()
+ && destination.canRead();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/AbstractProjectImportOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/GeneralProjectImportOperation.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/GeneralProjectImportOperation.java
(rev 0)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/GeneralProjectImportOperation.java 2011-10-12
14:23:49 UTC (rev 35569)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard.projectimport;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collections;
+import java.util.List;
+
+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.IProgressMonitor;
+import org.eclipse.jface.dialogs.MessageDialog;
+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;
+
+/**
+ * @author Andre Dietisheim <adietish(a)redhat.com>
+ *
+ */
+public class GeneralProjectImportOperation extends AbstractProjectImportOperation {
+
+ public GeneralProjectImportOperation(File projectDirectory) {
+ super(projectDirectory);
+ }
+
+ public List<IProject> importToWorkspace(IProgressMonitor monitor)
+ throws CoreException, InterruptedException {
+
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ IProject project = workspaceRoot.getProject(getProjectDirectory().getName());
+ overwriteExistingProject(project, monitor);
+ return Collections.singletonList(project);
+ }
+
+ private void importToNewProject(File projectDirectory, IProject project,
IProgressMonitor monitor)
+ 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);
+ }
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/GeneralProjectImportOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/MavenProjectImportOperation.java
===================================================================
---
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/MavenProjectImportOperation.java
(rev 0)
+++
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/MavenProjectImportOperation.java 2011-10-12
14:23:49 UTC (rev 35569)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.openshift.express.internal.ui.wizard.projectimport;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.m2e.core.embedder.MavenModelManager;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
+import org.eclipse.m2e.core.project.IMavenProjectImportResult;
+import org.eclipse.m2e.core.project.IProjectConfigurationManager;
+import org.eclipse.m2e.core.project.LocalProjectScanner;
+import org.eclipse.m2e.core.project.MavenProjectInfo;
+import org.eclipse.m2e.core.project.ProjectImportConfiguration;
+
+/**
+ * @author Andre Dietisheim <adietish(a)redhat.com>
+ *
+ */
+public class MavenProjectImportOperation extends AbstractProjectImportOperation {
+
+ private static final String POM_FILE = "pom.xml";
+
+ public MavenProjectImportOperation(File projectFolder) {
+ super(projectFolder);
+ }
+
+ public List<IProject> importToWorkspace(IProgressMonitor monitor)
+ throws CoreException, InterruptedException {
+ MavenPluginActivator mavenPlugin = MavenPluginActivator.getDefault();
+ IProjectConfigurationManager configurationManager =
mavenPlugin.getProjectConfigurationManager();
+ MavenModelManager modelManager = mavenPlugin.getMavenModelManager();
+ List<MavenProjectInfo> projectInfos = getMavenProjects(getProjectDirectory(),
modelManager, monitor);
+ ProjectImportConfiguration projectImportConfiguration =
+ new ProjectImportConfiguration();
+ List<IMavenProjectImportResult> importResults =
+ configurationManager.importProjects(projectInfos, projectImportConfiguration,
monitor);
+ return toProjects(importResults);
+ }
+
+ private List<IProject> toProjects(List<IMavenProjectImportResult>
importResults) {
+ List<IProject> projects = new ArrayList<IProject>();
+ for (IMavenProjectImportResult importResult : importResults) {
+ projects.add(importResult.getProject());
+ }
+ return projects;
+ }
+
+ private List<MavenProjectInfo> getMavenProjects(File directory, MavenModelManager
modelManager,
+ IProgressMonitor monitor) throws InterruptedException {
+ LocalProjectScanner scanner = new LocalProjectScanner(directory, directory.toString(),
false,
+ modelManager);
+ scanner.run(monitor);
+ return scanner.getProjects();
+ }
+
+ public boolean isMavenProject() {
+ if (!isReadable(getProjectDirectory())
+ || !getProjectDirectory().isDirectory()) {
+ return false;
+ }
+
+ return isReadable(new File(getProjectDirectory(), POM_FILE));
+ }
+}
Property changes on:
trunk/as/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/projectimport/MavenProjectImportOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain