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/08/29 16:45:20 UTC
svn commit: r1518664 - in /sling/trunk/tooling/ide/eclipse-ui: ./ META-INF/
src/org/apache/sling/ide/eclipse/ui/wizards/
src/org/apache/sling/ide/eclipse/ui/wizards/np/
Author: stefanegli
Date: Thu Aug 29 14:45:20 2013
New Revision: 1518664
URL: http://svn.apache.org/r1518664
Log:
SLING-3030 : add a 'convert to sling content-package project' action to the context-menu for a Project under 'Configure' : sets the 'sling-content' facet and configures the jcr_root
Added:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java (with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java (with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java (with props)
Modified:
sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
sling/trunk/tooling/ide/eclipse-ui/plugin.xml
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
Modified: sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF?rev=1518664&r1=1518663&r2=1518664&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF (original)
+++ sling/trunk/tooling/ide/eclipse-ui/META-INF/MANIFEST.MF Thu Aug 29 14:45:20 2013
@@ -79,4 +79,5 @@ Require-Bundle: org.eclipse.wst.common.p
org.eclipse.ui.views.properties.tabbed
Service-Component: OSGI-INF/*.xml
Export-Package: org.apache.sling.ide.eclipse.ui,
+ org.apache.sling.ide.eclipse.ui.wizards,
org.apache.sling.ide.eclipse.ui.wizards.np
Modified: sling/trunk/tooling/ide/eclipse-ui/plugin.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/plugin.xml?rev=1518664&r1=1518663&r2=1518664&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/plugin.xml (original)
+++ sling/trunk/tooling/ide/eclipse-ui/plugin.xml Thu Aug 29 14:45:20 2013
@@ -328,6 +328,23 @@
class="org.apache.sling.ide.eclipse.ui.internal.console.SlingConsoleFactory"
label="Sling Console">
</consoleFactory>
+ </extension>
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ objectClass="org.eclipse.core.resources.IProject"
+ adaptable="true"
+ id="org.apache.sling.ide.eclipse.ui.pluginProjectToolSet">
+
+ <action
+ label="Convert to Sling Content-Package Project"
+ class="org.apache.sling.ide.eclipse.ui.wizards.ConvertToContentPackageAction"
+ menubarPath="org.eclipse.ui.projectConfigure/additions"
+ enablesFor="+"
+ id="org.eclipse.pde.ui.ConvertedProjectWizard">
+ </action>
+ </objectContribution>
+
</extension>
</plugin>
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java?rev=1518664&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java Thu Aug 29 14:45:20 2013
@@ -0,0 +1,53 @@
+/*
+ * 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.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.apache.sling.ide.eclipse.core.MavenLaunchHelper;
+import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+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 ConfigurationHelper {
+
+ public static void convertToContentPackageProject(IProject aContentProject,
+ IProgressMonitor monitor, String jcr_root) throws CoreException {
+ IProjectFacet slingContentFacet = ProjectFacetsManager.getProjectFacet("sling.content");
+ IFacetedProject fp2 = ProjectFacetsManager.create(aContentProject, true, null);
+ fp2.installProjectFacet(slingContentFacet.getLatestVersion(), null, null);
+
+ ProjectUtil.setSyncDirectoryPath(aContentProject, jcr_root);
+
+ // temp hack: install the launch file
+ IFolder dotLaunches = aContentProject.getFolder(".settings").getFolder(".launches");
+ dotLaunches.create(true, true, monitor);
+ IFile launchFile = dotLaunches.getFile("clean_package_content_package_install.launch");
+ String l = MavenLaunchHelper.createMavenLaunchConfigMemento(aContentProject.getLocation().toOSString(),
+ "clean package content-package:install", null, false, null);
+ InputStream in = new ByteArrayInputStream(l.getBytes());
+ launchFile.create(in, true, monitor);
+ }
+
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConfigurationHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java?rev=1518664&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java Thu Aug 29 14:45:20 2013
@@ -0,0 +1,148 @@
+/*
+ * 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.lang.reflect.InvocationTargetException;
+
+import org.apache.maven.model.Model;
+import org.apache.sling.ide.eclipse.core.internal.ProjectHelper;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+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.swt.widgets.Display;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+
+public class ConvertToContentPackageAction implements IObjectActionDelegate {
+
+ private ISelection fSelection;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
+ * org.eclipse.ui.IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ if (fSelection instanceof IStructuredSelection) {
+ final IProject project = (IProject) ((IStructuredSelection) fSelection).getFirstElement();
+
+ String jcrRootLocation = "src/main/content/jcr_root";
+ final InputDialog id = new InputDialog(getDisplay().getActiveShell(), "Convert to Sling Content-Package Project",
+ "Confirm jcr_root location of "+project.getName()+":", jcrRootLocation, new IInputValidator() {
+
+ @Override
+ public String isValid(String newText) {
+ if (newText!=null && newText.trim().length()>0) {
+ final IResource l = project.findMember(newText);
+ if (l!=null && l.exists()) {
+ return null;
+ } else {
+ return "Directory not found: "+newText;
+ }
+ } else {
+ return "Please specify location of jcr_root";
+ }
+ }
+ });
+ if (id.open() == IStatus.OK) {
+ IRunnableWithProgress r = new IRunnableWithProgress() {
+
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ try {
+ ConfigurationHelper.convertToContentPackageProject(project, monitor, id.getValue());
+ } 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());
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
+ * org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection = selection;
+ if (selection instanceof IStructuredSelection) {
+ final IStructuredSelection iss = (IStructuredSelection) selection;
+ if (iss.toList().size()!=1) {
+ action.setEnabled(false);
+ } else {
+ Object firstElement = iss.getFirstElement();
+ if (firstElement!=null && (firstElement instanceof IProject)) {
+ final IProject project = (IProject) firstElement;
+ if (ProjectHelper.isContentProject(project)) {
+ action.setEnabled(false);
+ } else {
+ Model mavenModel = MavenHelper.getMavenModel(project);
+ if ("content-package".equals(mavenModel.getPackaging())) {
+ action.setEnabled(true);
+ } else {
+ action.setEnabled(false);
+ }
+ }
+ } else {
+ action.setEnabled(false);
+ }
+ }
+ } else {
+ action.setEnabled(false);
+ }
+ }
+
+ public Display getDisplay() {
+ Display display = Display.getCurrent();
+ if (display == null)
+ display = Display.getDefault();
+ return display;
+ }
+
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/ConvertToContentPackageAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java?rev=1518664&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java (added)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java Thu Aug 29 14:45:20 2013
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.maven.model.Model;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.m2e.core.MavenPlugin;
+
+
+public class MavenHelper {
+
+ 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;
+ }
+ }
+
+}
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/MavenHelper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java?rev=1518664&r1=1518663&r2=1518664&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/wizards/np/AbstractNewSlingApplicationWizard.java Thu Aug 29 14:45:20 2013
@@ -27,7 +27,7 @@ import java.util.Properties;
import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.model.Model;
import org.apache.sling.ide.eclipse.core.MavenLaunchHelper;
-import org.apache.sling.ide.eclipse.core.ProjectUtil;
+import org.apache.sling.ide.eclipse.ui.wizards.ConfigurationHelper;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
@@ -313,40 +313,11 @@ public abstract class AbstractNewSlingAp
fp2.installProjectFacet(slingContentFacet.getLatestVersion(), null, null);
}
- protected 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;
- }
- }
-
protected void configureContentProject(IProject aContentProject,
List<IProject> projects, IProgressMonitor monitor) throws CoreException {
- IProjectFacet slingContentFacet = ProjectFacetsManager.getProjectFacet("sling.content");
- IFacetedProject fp2 = ProjectFacetsManager.create(aContentProject, true, null);
- fp2.installProjectFacet(slingContentFacet.getLatestVersion(), null, null);
-
-
- ProjectUtil.setSyncDirectoryPath(aContentProject, "src/main/content/jcr_root");
-
- // temp hack: install the launch file
- IFolder dotLaunches = aContentProject.getFolder(".settings").getFolder(".launches");
- dotLaunches.create(true, true, monitor);
- IFile launchFile = dotLaunches.getFile("clean_package_content_package_install.launch");
- String l = MavenLaunchHelper.createMavenLaunchConfigMemento(aContentProject.getLocation().toOSString(),
- "clean package content-package:install", null, false, null);
- InputStream in = new ByteArrayInputStream(l.getBytes());
- launchFile.create(in, true, monitor);
+ ConfigurationHelper.convertToContentPackageProject(aContentProject, monitor, "src/main/content/jcr_root");
}
-
+
protected void configureReactorProject(IProject reactorProject, IProgressMonitor monitor) throws CoreException {
// temp hack: install the launch file
IFolder dotLaunches = reactorProject.getFolder(".settings").getFolder(".launches");