You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2013/09/12 15:16:49 UTC

svn commit: r1522564 - in /sling/trunk/tooling/ide: eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/

Author: stefanegli
Date: Thu Sep 12 13:16:49 2013
New Revision: 1522564

URL: http://svn.apache.org/r1522564
Log:
SLING-3009 : support batch-conversion of maven 'bundle' typed projects to 'sling/osgi bundle' projects

Added:
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java   (with props)
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java   (with props)
Modified:
    sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
    sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java

Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java?rev=1522564&r1=1522563&r2=1522564&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ProjectHelper.java Thu Sep 12 13:16:49 2013
@@ -16,18 +16,32 @@
  */
 package org.apache.sling.ide.eclipse.core.internal;
 
+import org.apache.maven.model.Model;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jdt.core.IJavaModel;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.m2e.core.MavenPlugin;
 import org.eclipse.wst.common.project.facet.core.IFacetedProject;
 import org.eclipse.wst.common.project.facet.core.IProjectFacet;
 import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
 
 public class ProjectHelper {
 
+	public static boolean isPotentialBundleProject(IProject project) {
+		Model mavenModel = getMavenModel(project);
+		return (mavenModel!=null && "bundle".equals(mavenModel.getPackaging()));
+	}
+	
+	public static boolean isPotentialContentProject(IProject project) {
+		Model mavenModel = ProjectHelper.getMavenModel(project);
+		return (mavenModel!=null && "content-package".equals(mavenModel.getPackaging()));
+	}
+	
 	public static boolean isBundleProject(IProject project) {
 		return containsFacet(project, SlingBundleModuleFactory.SLING_BUNDLE_FACET_ID);
 	}
@@ -60,5 +74,20 @@ public class ProjectHelper {
 			return null;
 		}
 	}
+
+	public static Model getMavenModel(IProject project) {
+		IFile pomFile = project.getFile("pom.xml");
+		if (!pomFile.exists()) {
+			return null;
+		}
+		try {
+			Model model = MavenPlugin.getMavenModelManager().readMavenModel(pomFile);
+			return model;
+		} catch (CoreException e) {
+			// TODO proper logging
+			e.printStackTrace();
+			return null;
+		}
+	}
 	
 }

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java?rev=1522564&r1=1522563&r2=1522564&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/Activator.java Thu Sep 12 13:16:49 2013
@@ -19,12 +19,12 @@ package org.apache.sling.ide.eclipse.ui.
 import org.apache.sling.ide.eclipse.core.ServiceUtil;
 import org.apache.sling.ide.filter.FilterLocator;
 import org.apache.sling.ide.serialization.SerializationManager;
-import org.eclipse.core.runtime.Plugin;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.event.EventAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class Activator extends Plugin {
+public class Activator extends AbstractUIPlugin {
 
     public static final String PLUGIN_ID = "org.apache.sling.ide.eclipse-core";
     public static Activator INSTANCE;

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java?rev=1522564&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java Thu Sep 12 13:16:49 2013
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/** In parts adapted from org.eclipse.pde.internal.ui.wizards.tools.ConvertedProjectPage **/
+public class ConvertProjectsPage extends WizardPage {
+	private IProject[] initialSelection;
+	private List<IProject> projects;
+	private Label counterLabel;
+	private CheckboxTableViewer ctv;
+	private List<IProject> resultingSelection;
+
+	public class ProjectLabelProvider extends LabelProvider implements ITableLabelProvider {
+		public String getColumnText(Object element, int columnIndex) {
+			if (columnIndex == 0 && (element instanceof IProject)) {
+				return ((IProject)element).getName();
+			} else {
+				return "";
+			}
+		}
+
+		public Image getColumnImage(Object obj, int index) {
+			return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
+		}
+	}
+
+	public ConvertProjectsPage(List<IProject> projects, List<IProject> initialSelection, String title, String description) {
+		super("convertSlingProjects"); //$NON-NLS-1$
+		setTitle(title);
+		setDescription(description);
+		this.initialSelection = initialSelection.toArray(new IProject[0]);
+		this.projects = projects;
+	}
+
+	public void createControl(Composite parent) {
+		Composite container = new Composite(parent, SWT.NONE);
+		GridLayout layout = new GridLayout();
+		layout.numColumns = 2;
+		layout.marginHeight = 0;
+		layout.marginWidth = 5;
+		container.setLayout(layout);
+		
+		Table table = new Table(container, SWT.MULTI | SWT.CHECK | SWT.BORDER);
+		GridData gd = new GridData(GridData.FILL_BOTH);
+		table.setLayoutData(gd);
+		ctv = new CheckboxTableViewer(table);
+		ctv.setLabelProvider(new ProjectLabelProvider());
+		ctv.add(projects.toArray());
+		ctv.setCheckedElements(initialSelection);
+
+		setControl(container);
+		Dialog.applyDialogFont(container);
+	}
+
+	@SuppressWarnings("unchecked")
+	public boolean finish() {
+		resultingSelection = new LinkedList<IProject>(
+				(Collection<? extends IProject>) Arrays.asList(ctv.getCheckedElements()));
+		return true;
+	}
+
+	public List<IProject> getSelectedProjects() {
+		return resultingSelection;
+	}
+
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsPage.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java?rev=1522564&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java Thu Sep 12 13:16:49 2013
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.ui.wizards;
+
+import java.util.List;
+
+import org.apache.sling.ide.eclipse.ui.internal.Activator;
+import org.apache.sling.ide.eclipse.ui.internal.SharedImages;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.wizard.Wizard;
+
+/** In parts adapted from org.eclipse.pde.internal.ui.wizards.tools.ConvertedProjectWizard **/
+public class ConvertProjectsWizard extends Wizard {
+	private ConvertProjectsPage mainPage;
+	private List<IProject> initialSelection;
+	private List<IProject> projects;
+	private String title;
+	private String description;
+
+	public ConvertProjectsWizard(List<IProject> projects, List<IProject> initialSelection, String title, String description) {
+		setDefaultPageImageDescriptor(SharedImages.SLING_LOG);
+		setWindowTitle(title);
+		setDialogSettings(Activator.getDefault().getDialogSettings());
+		setNeedsProgressMonitor(true);
+		this.title = title;
+		this.description = description;
+		this.initialSelection = initialSelection;
+		this.projects = projects;
+	}
+
+	public void addPages() {
+		mainPage = new ConvertProjectsPage(projects, initialSelection, title, description);
+		addPage(mainPage);
+	}
+
+	public boolean performFinish() {
+		return mainPage.finish();
+	}
+
+	public List<IProject> getSelectedProjects() {
+		return mainPage.getSelectedProjects();
+	}
+}

Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertProjectsWizard.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java?rev=1522564&r1=1522563&r2=1522564&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToBundleAction.java Thu Sep 12 13:16:49 2013
@@ -17,23 +17,31 @@
 package org.apache.sling.ide.eclipse.ui.wizards;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
 
-import org.apache.maven.model.Model;
 import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.PlatformUI;
 
-public class ConvertToBundleAction  implements IObjectActionDelegate {
+public class ConvertToBundleAction implements IObjectActionDelegate {
 
 	private ISelection fSelection;
 
@@ -53,33 +61,77 @@ public class ConvertToBundleAction  impl
 	 */
 	public void run(IAction action) {
 		if (fSelection instanceof IStructuredSelection) {
-			final IProject project = (IProject) ((IStructuredSelection) fSelection).getFirstElement();
+			List<IProject> applicableProjects = new LinkedList<IProject>();
+			IProject[] allProjects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+			for (int i = 0; i < allProjects.length; i++) {
+				IProject p = allProjects[i];
+				if (p.isOpen() && !ProjectHelper.isBundleProject(p) && ProjectHelper.isPotentialBundleProject(p)) {
+					applicableProjects.add(p);
+				}
+			}
+			Object[] elems = ((IStructuredSelection) fSelection).toArray();
+			List<IProject> initialSelection = new ArrayList<IProject>(elems.length);
+
+			for (int i = 0; i < elems.length; i++) {
+				Object elem = elems[i];
+				IProject project = null;
+
+				if (elem instanceof IFile) {
+					IFile file = (IFile) elem;
+					project = file.getProject();
+				} else if (elem instanceof IProject) {
+					project = (IProject) elem;
+				} else if (elem instanceof IJavaProject) {
+					project = ((IJavaProject) elem).getProject();
+				}
+				if (project != null)
+					initialSelection.add(project);
+			}
 
-			boolean confirmed = MessageDialog.openConfirm(getDisplay().getActiveShell(), "Convert to Sling/OSGi Bundle Project", 
-					"Confirm the conversion of this project to a Sling/OSGi Bundle Project");
-			
-			if (confirmed) {
-				IRunnableWithProgress r = new IRunnableWithProgress() {
-					
-					@Override
-					public void run(IProgressMonitor monitor) throws InvocationTargetException,
-							InterruptedException {
-						try {
+			ConvertProjectsWizard wizard = new ConvertProjectsWizard(applicableProjects, initialSelection, 
+					"Convert Project(s) to Sling/OSGi Bundle(s)",
+					"Select project(s) to convert to Sling/OSGi bundle project(s)");
+
+			final Display display = getDisplay();
+			final WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
+			BusyIndicator.showWhile(display, new Runnable() {
+				public void run() {
+					dialog.open();
+				}
+			});
+			if (dialog.getReturnCode()!=WizardDialog.OK) {
+				// user did not click OK
+				return;
+			}
+			final List<IProject> selectedProjects = wizard.getSelectedProjects();
+			if (selectedProjects == null || selectedProjects.size()==0) {
+				// no project was selected
+				return;
+			}
+			IRunnableWithProgress r = new IRunnableWithProgress() {
+				
+				@Override
+				public void run(IProgressMonitor monitor) throws InvocationTargetException,
+						InterruptedException {
+					try {
+						for (Iterator<IProject> it = selectedProjects.iterator(); it
+								.hasNext();) {
+							IProject project = it.next();
 							ConfigurationHelper.convertToBundleProject(project);
-						} catch (CoreException e) {
-							e.printStackTrace();
-							MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
-									e.getMessage());
 						}
+					} catch (CoreException e) {
+						e.printStackTrace();
+						MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
+								e.getMessage());
 					}
-				};
-				try {
-					PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
-				} catch (Exception e) {
-					e.printStackTrace();
-					MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
-							e.getMessage());
 				}
+			};
+			try {
+				PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
+			} catch (Exception e) {
+				e.printStackTrace();
+				MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project",
+						e.getMessage());
 			}
 		}
 	}
@@ -94,26 +146,30 @@ public class ConvertToBundleAction  impl
 		fSelection = selection;
 		if (selection instanceof IStructuredSelection) {
 			final IStructuredSelection iss = (IStructuredSelection) selection;
-			if (iss.toList().size()!=1) {
+			Iterator<Object> it = iss.iterator();
+			if (!it.hasNext()) {
 				action.setEnabled(false);
-			} else {
-				Object firstElement = iss.getFirstElement();
-				if (firstElement!=null && (firstElement instanceof IProject)) {
-					final IProject project = (IProject) firstElement;
+				return;
+			}
+			while(it.hasNext()) {
+				Object elem = it.next();
+				if (elem!=null && (elem instanceof IProject)) {
+					final IProject project = (IProject) elem;
 					if (ProjectHelper.isBundleProject(project)) {
 						action.setEnabled(false);
+						return;
+					} else if (ProjectHelper.isPotentialBundleProject(project)) {
+						continue;
 					} else {
-						Model mavenModel = MavenHelper.getMavenModel(project);
-						if (mavenModel!=null && "bundle".equals(mavenModel.getPackaging())) {
-							action.setEnabled(true);
-						} else {
-							action.setEnabled(false);
-						}
+						action.setEnabled(false);
+						return;
 					}
 				} else {
 					action.setEnabled(false);
+					return;
 				}
 			}
+			action.setEnabled(true);
 		} else {
 			action.setEnabled(false);
 		}