Author: adietish
Date: 2011-12-21 09:00:08 -0500 (Wed, 21 Dec 2011)
New Revision: 37490
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectOperation.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
Removed:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationStrategy.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectStrategy.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectStrategy.java
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/IImportApplicationStrategy.java
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java
Log:
[JBIDE-10542] extracted server adapter creation (from import strategy) to its own factory
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
(from rev 37484,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationStrategy.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * 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.appimport;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.egit.core.RepositoryUtil;
+import org.eclipse.egit.core.op.CloneOperation;
+import org.eclipse.egit.ui.Activator;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.transport.JschConfigSessionFactory;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.osgi.util.NLS;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+abstract class AbstractImportApplicationOperation implements IImportApplicationStrategy
{
+
+ private static final int CLONE_TIMEOUT = 10 * 1024;
+
+ private String projectName;
+ private IApplication application;
+ private String remoteName;
+ private IUser user;
+
+ public AbstractImportApplicationOperation(String projectName, IApplication application,
String remoteName,
+ IUser user) {
+ this.projectName = projectName;
+ this.application = application;
+ this.remoteName = remoteName;
+ this.user = user;
+ }
+
+ /**
+ * Clones the repository of the selected OpenShift application to the user
+ * provided path
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @return
+ * @throws URISyntaxException
+ * @throws OpenShiftException
+ * @throws InvocationTargetException
+ * @throws InterruptedException
+ *
+ * @see AbstractImportApplicationOperation#getApplication()
+ * @see #getRepositoryPath()
+ */
+ protected File cloneRepository(IApplication application, String remoteName, File
destination, IProgressMonitor monitor)
+ throws OpenShiftException, InvocationTargetException, InterruptedException,
URISyntaxException {
+ monitor.subTask(NLS.bind("Cloning repository for application {0}...",
application.getName()));
+ cloneRepository(application.getGitUri(), remoteName, destination, monitor);
+ return destination;
+ }
+
+ private void cloneRepository(String uri, String remoteName, File destination,
IProgressMonitor monitor)
+ throws OpenShiftException, URISyntaxException, InvocationTargetException,
InterruptedException {
+ ensureEgitUIIsStarted();
+ URIish gitUri = new URIish(uri);
+ CloneOperation cloneOperation =
+ new CloneOperation(gitUri, true, null, destination, Constants.HEAD, remoteName,
CLONE_TIMEOUT);
+ cloneOperation.run(monitor);
+ RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
+ repositoryUtil.addConfiguredRepository(new File(destination, Constants.DOT_GIT));
+ }
+
+ /**
+ * The EGit UI plugin initializes the ssh factory to present the user a
+ * passphrase prompt if the ssh key was not read yet. If this initialization
+ * is not executed, the ssh connection to the git repo would just fail with
+ * an authentication error. We therefore have to make sure that the EGit UI
+ * plugin is started and initializes the JSchConfigSessionFactory.
+ * <p>
+ * EGit initializes the SshSessionFactory with the EclipseSshSessionFactory.
+ * The EclipseSshSessionFactory overrides JschConfigSessionFactory#configure
+ * to present a UserInfoPrompter if the key passphrase was not entered
+ * before.
+ *
+ * @see Activator#start(org.osgi.framework.BundleContext)
+ * @see Activator#setupSSH
+ * @see JschConfigSessionFactory#configure
+ * @see EclipseSshSessionFactory#configure
+ */
+ private void ensureEgitUIIsStarted() {
+ Activator.getDefault();
+ }
+
+ protected String getProjectName() {
+ return projectName;
+ }
+
+ /**
+ * Returns the workspace project with the given name if it exists. Returns
+ * <code>null</code> otherwise.
+ *
+ * @param name
+ * the project name
+ * @return the project with the given name
+ */
+ protected IProject getProject(String name) {
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ Assert.isTrue(project != null && project.exists(),
+ NLS.bind("Could not find project {0} in your workspace.", name));
+ return project;
+ }
+
+ protected IApplication getApplication() {
+ return application;
+ }
+
+ protected String getRemoteName() {
+ return remoteName;
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationStrategy.java 2011-12-21
13:58:58 UTC (rev 37489)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AbstractImportApplicationStrategy.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -1,261 +0,0 @@
-/*******************************************************************************
- * 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.appimport;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.egit.core.RepositoryUtil;
-import org.eclipse.egit.core.op.CloneOperation;
-import org.eclipse.egit.ui.Activator;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.transport.JschConfigSessionFactory;
-import org.eclipse.jgit.transport.URIish;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.IServerType;
-import org.eclipse.wst.server.core.IServerWorkingCopy;
-import org.eclipse.wst.server.core.ServerUtil;
-import org.eclipse.wst.server.core.internal.Server;
-import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
-import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
-
-import com.openshift.express.client.IApplication;
-import com.openshift.express.client.IUser;
-import com.openshift.express.client.OpenShiftException;
-
-/**
- * @author André Dietisheim <adietish(a)redhat.com>
- */
-abstract class AbstractImportApplicationStrategy implements IImportApplicationStrategy {
-
- private static final int CLONE_TIMEOUT = 10 * 1024;
-
- private String projectName;
- private IApplication application;
- private String remoteName;
- private boolean isCreateServer;
- private IServerType serverType;
- private IRuntime runtime;
- private String mode;
- private IUser user;
-
- public AbstractImportApplicationStrategy(String projectName, IApplication application,
String remoteName,
- boolean isCreateServer, IServerType serverType, IRuntime runtime, String mode,
- IUser user) {
- this.projectName = projectName;
- this.application = application;
- this.remoteName = remoteName;
- this.isCreateServer = isCreateServer;
- this.serverType = serverType;
- this.runtime = runtime;
- this.mode = mode;
- this.user = user;
- }
-
- /**
- * Clones the repository of the selected OpenShift application to the user
- * provided path
- *
- * @param monitor
- * the monitor to report progress to
- * @return
- * @throws URISyntaxException
- * @throws OpenShiftException
- * @throws InvocationTargetException
- * @throws InterruptedException
- *
- * @see AbstractImportApplicationStrategy#getApplication()
- * @see #getRepositoryPath()
- */
- protected File cloneRepository(IApplication application, String remoteName, File
destination, IProgressMonitor monitor)
- throws OpenShiftException, InvocationTargetException, InterruptedException,
URISyntaxException {
- monitor.subTask(NLS.bind("Cloning repository for application {0}...",
application.getName()));
- cloneRepository(application.getGitUri(), remoteName, destination, monitor);
- return destination;
- }
-
- private void cloneRepository(String uri, String remoteName, File destination,
IProgressMonitor monitor)
- throws OpenShiftException, URISyntaxException, InvocationTargetException,
InterruptedException {
- ensureEgitUIIsStarted();
- URIish gitUri = new URIish(uri);
- CloneOperation cloneOperation =
- new CloneOperation(gitUri, true, null, destination, Constants.HEAD, remoteName,
CLONE_TIMEOUT);
- cloneOperation.run(monitor);
- RepositoryUtil repositoryUtil = Activator.getDefault().getRepositoryUtil();
- repositoryUtil.addConfiguredRepository(new File(destination, Constants.DOT_GIT));
- }
-
- /**
- * The EGit UI plugin initializes the ssh factory to present the user a
- * passphrase prompt if the ssh key was not read yet. If this initialization
- * is not executed, the ssh connection to the git repo would just fail with
- * an authentication error. We therefore have to make sure that the EGit UI
- * plugin is started and initializes the JSchConfigSessionFactory.
- * <p>
- * EGit initializes the SshSessionFactory with the EclipseSshSessionFactory.
- * The EclipseSshSessionFactory overrides JschConfigSessionFactory#configure
- * to present a UserInfoPrompter if the key passphrase was not entered
- * before.
- *
- * @see Activator#start(org.osgi.framework.BundleContext)
- * @see Activator#setupSSH
- * @see JschConfigSessionFactory#configure
- * @see EclipseSshSessionFactory#configure
- */
- private void ensureEgitUIIsStarted() {
- Activator.getDefault();
- }
-
- /**
- * creates an OpenShift server adapter for the user chosen project.
- *
- * @param monitor
- * the monitor to report progress to.
- * @throws OpenShiftException
- */
- protected void createServerAdapter(IProject project, IServerType serverType, IRuntime
runtime, String mode,
- IApplication application, IUser user, IProgressMonitor monitor) throws
OpenShiftException {
- String name = project.getName();
- monitor.subTask(NLS.bind("Creating server adapter for project {0}", name));
- createServerAdapter(Collections.singletonList(project), serverType, runtime, mode,
application, user,
- monitor);
- }
-
- protected void createServerAdapter(List<IProject> importedProjects, IServerType
serverType,
- IRuntime runtime, String mode, IApplication application, IUser user, IProgressMonitor
monitor) {
- try {
- renameWebContextRoot(importedProjects);
- IServer server = doCreateServerAdapter(serverType, runtime, mode, application, user);
- addModules(getModules(importedProjects), server, monitor);
- } catch (CoreException ce) {
- OpenShiftUIActivator.getDefault().getLog().log(ce.getStatus());
- } catch (OpenShiftException ose) {
- IStatus s = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
- "Cannot create openshift server adapter", ose);
- OpenShiftUIActivator.getDefault().getLog().log(s);
- }
- }
-
- private void renameWebContextRoot(List<IProject> importedProjects) {
- for (IProject project : importedProjects) {
- ComponentUtilities.setServerContextRoot(project, "/");
- }
- }
-
- private IServer doCreateServerAdapter(IServerType serverType, IRuntime rt, String mode,
IApplication application,
- IUser user) throws CoreException,
- OpenShiftException {
- Assert.isLegal(serverType != null);
- Assert.isLegal(mode != null);
- Assert.isLegal(application != null);
- Assert.isLegal(user != null);
-
- String serverNameBase = application.getName() + " OpenShift Server";
- String serverName =
org.jboss.ide.eclipse.as.core.util.ServerUtil.getDefaultServerName(serverNameBase);
-
- IServer server = ExpressServerUtils.createServer(rt, serverType, serverName);
- ExpressServerUtils.fillServerWithOpenShiftDetails(server,
application.getApplicationUrl(),
- user.getRhlogin(), user.getPassword(),
- user.getDomain().getNamespace(), application.getName(), application.getUUID(),
mode);
- return server;
- }
-
- private void addModules(List<IModule> modules, IServer server, IProgressMonitor
monitor) throws CoreException {
- if (modules == null
- || modules.size() == 0) {
- return;
- }
- IServerWorkingCopy wc = server.createWorkingCopy();
- IModule[] add = modules.toArray(new IModule[modules.size()]);
- wc.modifyModules(add, new IModule[0], new NullProgressMonitor());
- server = wc.save(true, monitor);
- ((Server) server).setModulePublishState(add, IServer.PUBLISH_STATE_NONE);
- }
-
- private List<IModule> getModules(List<IProject> importedProjects) {
- Iterator<IProject> i = importedProjects.iterator();
- ArrayList<IModule> toAdd = new ArrayList<IModule>();
- while (i.hasNext()) {
- IProject p = i.next();
- IModule[] m = ServerUtil.getModules(p);
- if (m != null && m.length > 0) {
- toAdd.addAll(Arrays.asList(m));
- }
- }
- return toAdd;
- }
-
- public String getProjectName() {
- return projectName;
- }
-
- /**
- * Returns the workspace project with the given name if it exists. Returns
- * <code>null</code> otherwise.
- *
- * @param name
- * the project name
- * @return the project with the given name
- */
- protected IProject getProject(String name) {
- IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
- Assert.isTrue(project != null && project.exists(),
- NLS.bind("Could not find project {0} in your workspace.", name));
- return project;
- }
-
- public IApplication getApplication() {
- return application;
- }
-
- public String getRemoteName() {
- return remoteName;
- }
-
- public boolean isCreateServer() {
- return isCreateServer;
- }
-
- public IServerType getServerType() {
- return serverType;
- }
-
- public IRuntime getRuntime() {
- return runtime;
- }
-
- public String getMode() {
- return mode;
- }
-
- public IUser getUser() {
- return user;
- }
-
-}
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectOperation.java
(from rev 37484,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectStrategy.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectOperation.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectOperation.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * 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.appimport;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.tools.openshift.egit.core.GitIgnore;
+import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+public class AddToExistingProjectOperation extends AbstractImportApplicationOperation {
+
+ public AddToExistingProjectOperation(String projectName, IApplication application,
String remoteName,
+ IUser user) {
+ super(projectName, application, remoteName, user);
+ }
+
+ /**
+ * Enables the user chosen project to be used on the chosen OpenShift
+ * application. Clones the application git repository, copies the
+ * configuration files to the user project (in the workspace), shares the
+ * user project with git and creates the server adapter.
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @return
+ * @throws URISyntaxException
+ * The OpenShift application repository could not be cloned,
+ * because the uri it is located at is not a valid git uri
+ * @throws OpenShiftException
+ *
+ * @throws InvocationTargetException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation failed.
+ * @throws InterruptedException
+ * The OpenShift application repository could not be cloned, the
+ * clone operation was interrupted.
+ * @throws IOException
+ * The configuration files could not be copied from the git
+ * clone to the user project
+ * @throws CoreException
+ * The user project could not be shared with the git
+ *
+ * @see #cloneRepository
+ * @see #copyOpenshiftConfiguration
+ * @see #shareProject
+ * @see #createServerAdapterIfRequired
+ */
+ @Override
+ public List<IProject> execute(IProgressMonitor monitor)
+ throws OpenShiftException, InvocationTargetException, InterruptedException,
IOException, CoreException,
+ URISyntaxException {
+ // File repositoryFile =
+ // model.cloneRepository(monitor);
+ // model.importProject(repositoryFile, monitor);
+ // Repository repository =
+ // model.shareProject(monitor);
+ // model.mergeWithApplicationRepository(repository,
+ // monitor);
+ File tmpFolder = FileUtils.getRandomTmpFolder();
+ File repositoryFile = cloneRepository(getApplication(), getRemoteName(), tmpFolder,
monitor);
+ IProject project = getProject(getProjectName());
+ copyOpenshiftConfiguration(repositoryFile, project, monitor);
+ FileUtil.safeDelete(tmpFolder);
+
+ shareProject(project, monitor);
+ return Collections.singletonList(project);
+ }
+
+ private void shareProject(IProject project, IProgressMonitor monitor) throws
CoreException {
+ monitor.subTask(NLS.bind("Sharing project {0}...", project.getName()));
+ EGitUtils.share(project, monitor);
+ }
+
+ /**
+ * Copies the openshift configuration from the given source folder to the
+ * given project.
+ *
+ * @param sourceFolder
+ * the source to copy the openshift config from
+ * @param project
+ * the project to copy the configuration to.
+ * @param monitor
+ * the monitor to report progress to
+ * @throws IOException
+ */
+ private void copyOpenshiftConfiguration(final File sourceFolder, IProject project,
IProgressMonitor monitor)
+ throws IOException {
+ Assert.isLegal(project != null);
+ File projectFolder = project.getLocation().toFile();
+ monitor.subTask(NLS.bind("Copying openshift configuration to project {0}...",
project.getName()));
+ FileUtils.copy(new File(sourceFolder, ".git"), projectFolder, false);
+ FileUtils.copy(new File(sourceFolder, ".openshift"), projectFolder, false);
+ FileUtils.copy(new File(sourceFolder, "deployments"), projectFolder, false);
+ FileUtils.copy(new File(sourceFolder, "pom.xml"), projectFolder, false);
+ createGitIgnore(projectFolder);
+ }
+
+ /**
+ * Creates the git ignore file with a predefined set of entries. An existing
+ * .gitignore file is not overwritten, we then just dont do anything.
+ *
+ * @param projectFolder
+ * @throws IOException
+ */
+ private void createGitIgnore(File projectFolder) throws IOException {
+ GitIgnore gitIgnore = new GitIgnore(projectFolder);
+ // TODO: merge existing .gitignore
+ // (
https://issues.jboss.org/browse/JBIDE-10391)
+ if (gitIgnore.exists()) {
+ return;
+ }
+ gitIgnore.add("target")
+ .add(".settings")
+ .add(".project")
+ .add(".classpath")
+ .add(".factorypath");
+ gitIgnore.write(false);
+ }
+
+ @SuppressWarnings("unused")
+ private void mergeWithApplicationRepository(Repository repository, IApplication
application,
+ IProgressMonitor monitor)
+ throws MalformedURLException, URISyntaxException, IOException, OpenShiftException,
CoreException,
+ InvocationTargetException {
+ URIish uri = new URIish(application.getGitUri());
+ EGitUtils.addRemoteTo("openshift", uri, repository);
+ EGitUtils.mergeWithRemote(uri, "refs/remotes/openshift/HEAD", repository,
monitor);
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectStrategy.java 2011-12-21
13:58:58 UTC (rev 37489)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/AddToExistingProjectStrategy.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -1,162 +0,0 @@
-/*******************************************************************************
- * 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.appimport;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.transport.URIish;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServerType;
-import org.jboss.ide.eclipse.as.core.util.FileUtil;
-import org.jboss.tools.openshift.egit.core.EGitUtils;
-import org.jboss.tools.openshift.egit.core.GitIgnore;
-import org.jboss.tools.openshift.express.internal.ui.utils.FileUtils;
-
-import com.openshift.express.client.IApplication;
-import com.openshift.express.client.IUser;
-import com.openshift.express.client.OpenShiftException;
-
-/**
- * @author André Dietisheim <adietish(a)redhat.com>
- */
-public class AddToExistingProjectStrategy extends AbstractImportApplicationStrategy {
-
- public AddToExistingProjectStrategy(String projectName, IApplication application, String
remoteName,
- boolean isCreateServer, IServerType serverType, IRuntime runtime, String mode,
- IUser user) {
- super(projectName, application, remoteName, isCreateServer, serverType, runtime, mode,
user);
- }
-
- /**
- * Enables the user chosen project to be used on the chosen OpenShift
- * application. Clones the application git repository, copies the
- * configuration files to the user project (in the workspace), shares the
- * user project with git and creates the server adapter.
- *
- * @param monitor
- * the monitor to report progress to
- * @throws URISyntaxException
- * The OpenShift application repository could not be cloned,
- * because the uri it is located at is not a valid git uri
- * @throws OpenShiftException
- *
- * @throws InvocationTargetException
- * The OpenShift application repository could not be cloned, the
- * clone operation failed.
- * @throws InterruptedException
- * The OpenShift application repository could not be cloned, the
- * clone operation was interrupted.
- * @throws IOException
- * The configuration files could not be copied from the git
- * clone to the user project
- * @throws CoreException
- * The user project could not be shared with the git
- *
- * @see #cloneRepository
- * @see #copyOpenshiftConfiguration
- * @see #shareProject
- * @see #createServerAdapterIfRequired
- */
- @Override
- public void execute(IProgressMonitor monitor)
- throws OpenShiftException, InvocationTargetException, InterruptedException,
IOException, CoreException,
- URISyntaxException {
- // File repositoryFile =
- // model.cloneRepository(monitor);
- // model.importProject(repositoryFile, monitor);
- // Repository repository =
- // model.shareProject(monitor);
- // model.mergeWithApplicationRepository(repository,
- // monitor);
- File tmpFolder = FileUtils.getRandomTmpFolder();
- File repositoryFile = cloneRepository(getApplication(), getRemoteName(), tmpFolder,
monitor);
- IProject project = getProject(getProjectName());
- copyOpenshiftConfiguration(repositoryFile, project, monitor);
- FileUtil.safeDelete(tmpFolder);
-
- shareProject(project, monitor);
- if (isCreateServer()) {
- createServerAdapter(
- project, getServerType(), getRuntime(), getMode(), getApplication(), getUser(),
monitor);
- }
- }
-
- private void shareProject(IProject project, IProgressMonitor monitor) throws
CoreException {
- monitor.subTask(NLS.bind("Sharing project {0}...", project.getName()));
- EGitUtils.share(project, monitor);
- }
-
- /**
- * Copies the openshift configuration from the given source folder to the
- * given project.
- *
- * @param sourceFolder
- * the source to copy the openshift config from
- * @param project
- * the project to copy the configuration to.
- * @param monitor
- * the monitor to report progress to
- * @throws IOException
- */
- private void copyOpenshiftConfiguration(final File sourceFolder, IProject project,
IProgressMonitor monitor)
- throws IOException {
- Assert.isLegal(project != null);
- File projectFolder = project.getLocation().toFile();
- monitor.subTask(NLS.bind("Copying openshift configuration to project {0}...",
project.getName()));
- FileUtils.copy(new File(sourceFolder, ".git"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, ".openshift"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, "deployments"), projectFolder, false);
- FileUtils.copy(new File(sourceFolder, "pom.xml"), projectFolder, false);
- createGitIgnore(projectFolder);
- }
-
- /**
- * Creates the git ignore file with a predefined set of entries. An existing
- * .gitignore file is not overwritten, we then just dont do anything.
- *
- * @param projectFolder
- * @throws IOException
- */
- private void createGitIgnore(File projectFolder) throws IOException {
- GitIgnore gitIgnore = new GitIgnore(projectFolder);
- // TODO: merge existing .gitignore
- // (
https://issues.jboss.org/browse/JBIDE-10391)
- if (gitIgnore.exists()) {
- return;
- }
- gitIgnore.add("target")
- .add(".settings")
- .add(".project")
- .add(".classpath")
- .add(".factorypath");
- gitIgnore.write(false);
- }
-
- @SuppressWarnings("unused")
- private void mergeWithApplicationRepository(Repository repository, IApplication
application,
- IProgressMonitor monitor)
- throws MalformedURLException, URISyntaxException, IOException, OpenShiftException,
CoreException,
- InvocationTargetException {
- URIish uri = new URIish(application.getGitUri());
- EGitUtils.addRemoteTo("openshift", uri, repository);
- EGitUtils.mergeWithRemote(uri, "refs/remotes/openshift/HEAD", repository,
monitor);
- }
-}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/IImportApplicationStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/IImportApplicationStrategy.java 2011-12-21
13:58:58 UTC (rev 37489)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/IImportApplicationStrategy.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.wizard.appimport;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
/**
@@ -17,6 +20,14 @@
*/
public interface IImportApplicationStrategy {
- public void execute(IProgressMonitor monitor) throws Exception;
-
+ /**
+ * Executes this import operation and returns the projects that were
+ * imported.
+ *
+ * @param monitor the monitor to report progress to
+ * @return the list of projects that were imported to the workspace.
+ * @throws Exception
+ */
+ public List<IProject> execute(IProgressMonitor monitor) throws Exception;
+
}
Copied:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectOperation.java
(from rev 37484,
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectStrategy.java)
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectOperation.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectOperation.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * 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.appimport;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.util.Collections;
+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.jgit.lib.Repository;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.openshift.egit.core.EGitUtils;
+import org.jboss.tools.openshift.express.internal.ui.ImportFailedException;
+import org.jboss.tools.openshift.express.internal.ui.WontOverwriteException;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.project.GeneralProjectImportOperation;
+import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.project.MavenProjectImportOperation;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+public class ImportNewProjectOperation extends AbstractImportApplicationOperation {
+
+ private File cloneDestination;
+
+ public ImportNewProjectOperation(String projectName, IApplication application, String
remoteName,
+ File cloneDestination, IUser user) {
+ super(projectName, application, remoteName, user);
+ this.cloneDestination = cloneDestination;
+ }
+
+ /**
+ * Imports the (new) project that the user has chosen into the workspace.
+ *
+ * @param monitor
+ * the monitor to report progress to
+ * @throws OpenShiftException
+ * @throws CoreException
+ * @throws InterruptedException
+ * @throws URISyntaxException
+ * @throws InvocationTargetException
+ */
+ public List<IProject> execute(IProgressMonitor monitor)
+ throws OpenShiftException, CoreException, InterruptedException, URISyntaxException,
+ InvocationTargetException {
+ if (cloneDestinationExists()) {
+ throw new WontOverwriteException(
+ NLS.bind("There's already a folder at {0}. The new OpenShift project would
overwrite it. " +
+ "Please choose another destination to clone to.",
+ getCloneDestination().getAbsolutePath()));
+ }
+
+ File repositoryFolder =
+ cloneRepository(getApplication(), getRemoteName(), cloneDestination, monitor);
+ List<IProject> importedProjects = importProjectsFrom(repositoryFolder, monitor);
+ if (importedProjects.size() == 0) {
+ throw new ImportFailedException(
+ NLS.bind("Could not import project {0}. One of the possible reasons is that
there's already a " +
+ "project in your workspace that matches the openshift application/maven name
of the " +
+ "OpenShift application. " +
+ "Please rename your workspace project in that case and start over
again."
+ , getProjectName()));
+ }
+
+ connectToGitRepo(importedProjects, repositoryFolder, monitor);
+ return importedProjects;
+ }
+
+ @SuppressWarnings("unused")
+ private void mergeWithApplicationRepository(Repository repository, IApplication
application,
+ IProgressMonitor monitor)
+ throws MalformedURLException, URISyntaxException, IOException, OpenShiftException,
CoreException,
+ InvocationTargetException {
+ URIish uri = new URIish(application.getGitUri());
+ EGitUtils.addRemoteTo("openshift", uri, repository);
+ EGitUtils.mergeWithRemote(uri, "refs/remotes/openshift/HEAD", repository,
monitor);
+ }
+
+ /**
+ * Imports the projects that are within the given folder. Supports maven and
+ * general projects
+ *
+ * @param folder
+ * the folder the projects are located in
+ * @param monitor
+ * the monitor to report progress to
+ * @return
+ * @throws CoreException
+ * @throws InterruptedException
+ */
+ private List<IProject> importProjectsFrom(final File folder, IProgressMonitor
monitor)
+ throws CoreException, InterruptedException {
+ MavenProjectImportOperation mavenImport = new MavenProjectImportOperation(folder);
+ List<IProject> importedProjects = Collections.emptyList();
+ if (mavenImport.isMavenProject()) {
+ importedProjects = mavenImport.importToWorkspace(monitor);
+ } else {
+ importedProjects = new
GeneralProjectImportOperation(folder).importToWorkspace(monitor);
+ }
+ return importedProjects;
+ }
+
+ private void connectToGitRepo(List<IProject> projects, File projectFolder,
IProgressMonitor monitor)
+ throws CoreException {
+ for (IProject project : projects) {
+ if (project != null) {
+ EGitUtils.connect(project, monitor);
+ }
+ }
+ }
+
+ protected File getCloneDestination() {
+ return cloneDestination;
+ }
+
+ protected boolean cloneDestinationExists() {
+ return cloneDestination != null
+ && cloneDestination.exists();
+ }
+
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectOperation.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectStrategy.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectStrategy.java 2011-12-21
13:58:58 UTC (rev 37489)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportNewProjectStrategy.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * 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.appimport;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.util.Collections;
-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.jgit.lib.Repository;
-import org.eclipse.jgit.transport.URIish;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServerType;
-import org.jboss.tools.openshift.egit.core.EGitUtils;
-import org.jboss.tools.openshift.express.internal.ui.ImportFailedException;
-import org.jboss.tools.openshift.express.internal.ui.WontOverwriteException;
-import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.project.GeneralProjectImportOperation;
-import
org.jboss.tools.openshift.express.internal.ui.wizard.appimport.project.MavenProjectImportOperation;
-
-import com.openshift.express.client.IApplication;
-import com.openshift.express.client.IUser;
-import com.openshift.express.client.OpenShiftException;
-
-/**
- * @author André Dietisheim <adietish(a)redhat.com>
- */
-public class ImportNewProjectStrategy extends AbstractImportApplicationStrategy {
-
- private File cloneDestination;
-
- public ImportNewProjectStrategy(String projectName, IApplication application, String
remoteName,
- File cloneDestination, boolean isCreateServer, IServerType serverType, IRuntime
runtime, String mode,
- IUser user) {
- super(projectName, application, remoteName, isCreateServer, serverType, runtime, mode,
user);
- this.cloneDestination = cloneDestination;
- }
-
- /**
- * Imports the (new) project that the user has chosen into the workspace.
- *
- * @param monitor
- * the monitor to report progress to
- * @throws OpenShiftException
- * @throws CoreException
- * @throws InterruptedException
- * @throws URISyntaxException
- * @throws InvocationTargetException
- */
- public void execute(IProgressMonitor monitor)
- throws OpenShiftException, CoreException, InterruptedException, URISyntaxException,
- InvocationTargetException {
- if (cloneDestinationExists()) {
- throw new WontOverwriteException(
- NLS.bind("There's already a folder at {0}. The new OpenShift project would
overwrite it. " +
- "Please choose another destination to clone to.",
- getCloneDestination().getAbsolutePath()));
- }
-
- File repositoryFolder =
- cloneRepository(getApplication(), getRemoteName(), cloneDestination, monitor);
- List<IProject> importedProjects = importProjectsFrom(repositoryFolder, monitor);
- if (importedProjects.size() == 0) {
- throw new ImportFailedException(
- NLS.bind("Could not import project {0}. One of the possible reasons is that
there's already a " +
- "project in your workspace that matches the openshift application/maven name
of the " +
- "OpenShift application. " +
- "Please rename your workspace project in that case and start over
again."
- , getProjectName()));
- }
-
- connectToGitRepo(importedProjects, repositoryFolder, monitor);
- if (isCreateServer()) {
- createServerAdapter(importedProjects, getServerType(), getRuntime(), getMode(),
getApplication(),
- getUser(), monitor);
- }
- }
-
- @SuppressWarnings("unused")
- private void mergeWithApplicationRepository(Repository repository, IApplication
application,
- IProgressMonitor monitor)
- throws MalformedURLException, URISyntaxException, IOException, OpenShiftException,
CoreException,
- InvocationTargetException {
- URIish uri = new URIish(application.getGitUri());
- EGitUtils.addRemoteTo("openshift", uri, repository);
- EGitUtils.mergeWithRemote(uri, "refs/remotes/openshift/HEAD", repository,
monitor);
- }
-
- /**
- * Imports the projects that are within the given folder. Supports maven and
- * general projects
- *
- * @param folder
- * the folder the projects are located in
- * @param monitor
- * the monitor to report progress to
- * @return
- * @throws CoreException
- * @throws InterruptedException
- */
- private List<IProject> importProjectsFrom(final File folder, IProgressMonitor
monitor)
- throws CoreException, InterruptedException {
- MavenProjectImportOperation mavenImport = new MavenProjectImportOperation(folder);
- List<IProject> importedProjects = Collections.emptyList();
- if (mavenImport.isMavenProject()) {
- importedProjects = mavenImport.importToWorkspace(monitor);
- } else {
- importedProjects = new
GeneralProjectImportOperation(folder).importToWorkspace(monitor);
- }
- return importedProjects;
- }
-
- private void connectToGitRepo(List<IProject> projects, File projectFolder,
IProgressMonitor monitor)
- throws CoreException {
- for (IProject project : projects) {
- if (project != null) {
- EGitUtils.connect(project, monitor);
- }
- }
- }
-
- protected File getCloneDestination() {
- return cloneDestination;
- }
-
- protected boolean cloneDestinationExists() {
- return cloneDestination != null
- && cloneDestination.exists();
- }
-
-}
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java 2011-12-21
13:58:58 UTC (rev 37489)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ImportProjectWizardModel.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -15,7 +15,10 @@
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.util.HashMap;
+import java.util.List;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.server.core.IRuntime;
@@ -62,15 +65,12 @@
*/
public void importProject(IProgressMonitor monitor) throws OpenShiftException,
CoreException, InterruptedException,
URISyntaxException, InvocationTargetException {
- new ImportNewProjectStrategy(getProjectName()
+ List<IProject> importedProjects = new ImportNewProjectOperation(getProjectName()
, getApplication()
, getRemoteName()
, getRepositoryFile()
- , isCreateServer()
- , getServerType()
- , getRuntime()
- , getMode()
, getUser()).execute(monitor);
+ createServerAdapter(monitor, importedProjects);
}
/**
@@ -101,18 +101,22 @@
public void addToExistingProject(IProgressMonitor monitor)
throws OpenShiftException, InvocationTargetException, InterruptedException,
IOException, CoreException,
URISyntaxException {
- new AddToExistingProjectStrategy(
+ List<IProject> importedProjects = new AddToExistingProjectOperation(
getProjectName()
, getApplication()
, getRemoteName()
- , isCreateServer()
- , getServerType()
- , getRuntime()
- , getMode()
, getUser())
.execute(monitor);
+ createServerAdapter(monitor, importedProjects);
}
+ private void createServerAdapter(IProgressMonitor monitor, List<IProject>
importedProjects)
+ throws OpenShiftException {
+ Assert.isTrue(importedProjects.size() > 0);
+ IProject project = importedProjects.get(0);
+ new ServerAdapterFactory().create(project, getServerType(), getRuntime(), getMode(),
getApplication(), getUser(), monitor);
+ }
+
public File getRepositoryFile() {
String repositoryPath = getRepositoryPath();
if (repositoryPath == null
Added:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
(rev 0)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java 2011-12-21
14:00:08 UTC (rev 37490)
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * 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.appimport;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerType;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.internal.Server;
+import org.jboss.tools.openshift.express.internal.core.behaviour.ExpressServerUtils;
+import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
+
+import com.openshift.express.client.IApplication;
+import com.openshift.express.client.IUser;
+import com.openshift.express.client.OpenShiftException;
+
+/**
+ * @author André Dietisheim <adietish(a)redhat.com>
+ */
+class ServerAdapterFactory {
+
+ public ServerAdapterFactory() {
+ }
+
+ public void create(IProject project, IServerType serverType, IRuntime runtime, String
mode,
+ IApplication application, IUser user, IProgressMonitor monitor) throws
OpenShiftException {
+ createServerAdapter(project, serverType, runtime, mode, application, user, monitor);
+ }
+
+ /**
+ * creates an OpenShift server adapter for the user chosen project.
+ *
+ * @param monitor
+ * the monitor to report progress to.
+ * @throws OpenShiftException
+ */
+ protected void createServerAdapter(IProject project, IServerType serverType, IRuntime
runtime, String mode,
+ IApplication application, IUser user, IProgressMonitor monitor) throws
OpenShiftException {
+ String name = project.getName();
+ monitor.subTask(NLS.bind("Creating server adapter for project {0}", name));
+ createServerAdapter(Collections.singletonList(project), serverType, runtime, mode,
application, user,
+ monitor);
+ }
+
+ protected void createServerAdapter(List<IProject> importedProjects, IServerType
serverType,
+ IRuntime runtime, String mode, IApplication application, IUser user, IProgressMonitor
monitor) {
+ try {
+ renameWebContextRoot(importedProjects);
+ IServer server = doCreateServerAdapter(serverType, runtime, mode, application, user);
+ addModules(getModules(importedProjects), server, monitor);
+ } catch (CoreException ce) {
+ OpenShiftUIActivator.getDefault().getLog().log(ce.getStatus());
+ } catch (OpenShiftException ose) {
+ IStatus s = new Status(IStatus.ERROR, OpenShiftUIActivator.PLUGIN_ID,
+ "Cannot create openshift server adapter", ose);
+ OpenShiftUIActivator.getDefault().getLog().log(s);
+ }
+ }
+
+ private void renameWebContextRoot(List<IProject> importedProjects) {
+ for (IProject project : importedProjects) {
+ ComponentUtilities.setServerContextRoot(project, "/");
+ }
+ }
+
+ private IServer doCreateServerAdapter(IServerType serverType, IRuntime rt, String mode,
IApplication application,
+ IUser user) throws CoreException,
+ OpenShiftException {
+ Assert.isLegal(serverType != null);
+ Assert.isLegal(mode != null);
+ Assert.isLegal(application != null);
+ Assert.isLegal(user != null);
+
+ String serverNameBase = application.getName() + " OpenShift Server";
+ String serverName =
org.jboss.ide.eclipse.as.core.util.ServerUtil.getDefaultServerName(serverNameBase);
+
+ IServer server = ExpressServerUtils.createServer(rt, serverType, serverName);
+ ExpressServerUtils.fillServerWithOpenShiftDetails(server,
application.getApplicationUrl(),
+ user.getRhlogin(), user.getPassword(),
+ user.getDomain().getNamespace(), application.getName(), application.getUUID(),
mode);
+ return server;
+ }
+
+ private void addModules(List<IModule> modules, IServer server, IProgressMonitor
monitor) throws CoreException {
+ if (modules == null
+ || modules.size() == 0) {
+ return;
+ }
+ IServerWorkingCopy wc = server.createWorkingCopy();
+ IModule[] add = modules.toArray(new IModule[modules.size()]);
+ wc.modifyModules(add, new IModule[0], new NullProgressMonitor());
+ server = wc.save(true, monitor);
+ ((Server) server).setModulePublishState(add, IServer.PUBLISH_STATE_NONE);
+ }
+
+ private List<IModule> getModules(List<IProject> importedProjects) {
+ Iterator<IProject> i = importedProjects.iterator();
+ ArrayList<IModule> toAdd = new ArrayList<IModule>();
+ while (i.hasNext()) {
+ IProject p = i.next();
+ IModule[] m = ServerUtil.getModules(p);
+ if (m != null && m.length > 0) {
+ toAdd.addAll(Arrays.asList(m));
+ }
+ }
+ return toAdd;
+ }
+}
Property changes on:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/ServerAdapterFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain