Author: rob.stryker(a)jboss.com
Date: 2011-10-26 05:24:57 -0400 (Wed, 26 Oct 2011)
New Revision: 36005
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
Log:
JBIDE-10006 - cleaner solution
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-10-26
07:40:32 UTC (rev 36004)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/core/behaviour/ExpressPublishMethod.java 2011-10-26
09:24:57 UTC (rev 36005)
@@ -1,17 +1,23 @@
package org.jboss.tools.openshift.express.internal.core.behaviour;
+import java.util.ArrayList;
+
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.ui.wizards.ConfigureProjectWizard;
+import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
import
org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
@@ -30,10 +36,15 @@
}
+ private ArrayList<IProject> projectsLackingGitRepo = null;
@Override
public int publishFinish(DeployableServerBehavior behaviour,
IProgressMonitor monitor) throws CoreException {
- // TODO Auto-generated method stub
+ if( projectsLackingGitRepo != null ) {
+ IProject[] projects = (IProject[]) projectsLackingGitRepo.toArray(new
IProject[projectsLackingGitRepo.size()]);
+ shareProjects(projects);
+ projectsLackingGitRepo = null;
+ }
return 0;
}
@@ -43,6 +54,18 @@
throws CoreException {
int state = behaviour.getServer().getModulePublishState(module);
IProject p = module[module.length-1].getProject();
+
+ if( deltaKind == ServerBehaviourDelegate.REMOVED)
+ return IServer.PUBLISH_STATE_NONE; // go ahead and remove it
+
+ Repository repository = EGitUtils.getRepository(p);
+ if (repository==null) {
+ if( projectsLackingGitRepo == null )
+ projectsLackingGitRepo = new ArrayList<IProject>();
+ projectsLackingGitRepo.add(p);
+ return IServer.PUBLISH_STATE_UNKNOWN;
+ }
+
int changed = EGitUtils.countCommitableChanges(p, new NullProgressMonitor() );
if( changed == 0 || (kind == IServer.PUBLISH_FULL || state ==
IServer.PUBLISH_STATE_FULL)) {
if( changed != 0 && requestCommitAndPushApproval(module, changed)) {
@@ -61,12 +84,28 @@
return IServer.PUBLISH_STATE_INCREMENTAL;
}
+ private void shareProjects(final IProject[] projects) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ String msg = "There are " + projects.length + " projects that are not
connected to any git repository. " +
+ "Would you like to share them now?";
+ String title = "Share projects?";
+ boolean approved = requestApproval(msg, title);
+ if( approved ) {
+ ConfigureProjectWizard.shareProjects(
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ projects);
+ }
+ }
+ });
+ }
+
private boolean requestCommitAndPushApproval(final IModule[] module, int changed) {
String projName = module[module.length-1].getProject().getName();
String msg = "There are " + changed + " local changes in \"" +
projName + "\". " +
"Do you want to publish to OpenShift by commiting the changes and pushing its
Git repository?";
String title = "Publish " + projName + "?";
- return requestApproval(module, msg, title);
+ return requestApproval(msg, title);
}
private boolean requestPushApproval(final IModule[] module) {
@@ -74,10 +113,10 @@
String msg = "The are no local changes in \"" + projName +
"\". " +
"Do you want to publish to OpenShift by pushing its Git repository?";
String title = "Publish " + projName + "?";
- return requestApproval(module, msg, title);
+ return requestApproval(msg, title);
}
- private boolean requestApproval(final IModule[] module, final String message, final
String title) {
+ private boolean requestApproval(final String message, final String title) {
final boolean[] b = new boolean[1];
Display.getDefault().syncExec(new Runnable() {
public void run() {