Author: rombert Date: Fri Jul 19 15:03:29 2013 New Revision: 1504903 URL: http://svn.apache.org/r1504903 Log: SLING-2973 - [Tooling] Align Eclipse tooling to proposed structure
Make the import action based on the Sling facet rather than the nature. Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java (with props) sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java (contents, props changed) - copied, changed from r1504902, sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java (with props) sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java (with props) Removed: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizardPage.java Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/plugin.xml sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-http/src/org/apache/sling/slingclipse/http/impl/RepositoryImpl.java Fri Jul 19 15:03:29 2013 @@ -18,6 +18,7 @@ package org.apache.sling.slingclipse.htt import java.io.File; import java.util.Map; + import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; @@ -46,7 +47,7 @@ public class RepositoryImpl extends Abst return new Command<Void>() { @Override public Result<Void> execute() { - PostMethod post = new PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation()); + PostMethod post = new PostMethod(createFullPath(fileInfo.getRelativeLocation())); try{ File f=new File(fileInfo.getLocation()); if (f.isFile()) { @@ -97,7 +98,8 @@ public class RepositoryImpl extends Abst return new Command<Void>() { @Override public Result<Void> execute() { - PostMethod post = new PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation()+"/"+fileInfo.getName()); + PostMethod post = new PostMethod(createFullPath(fileInfo.getRelativeLocation() + "/" + + fileInfo.getName())); try{ Part[] parts ={new StringPart(":operation", "delete")}; post.setRequestEntity(new MultipartRequestEntity(parts,post.getParams())); @@ -126,7 +128,7 @@ public class RepositoryImpl extends Abst @Override public Result<String> execute() { //TODO handle the response type - GetMethod get= new GetMethod(repositoryInfo.getUrl()+path+".1.json"); + GetMethod get = new GetMethod(createFullPath(path + ".1.json")); try{ httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); @@ -162,7 +164,7 @@ public class RepositoryImpl extends Abst @Override public Result<byte[]> execute() { - GetMethod get= new GetMethod(repositoryInfo.getUrl()+path); + GetMethod get = new GetMethod(createFullPath(path)); try{ httpClient.getParams().setAuthenticationPreemptive(true); @@ -190,13 +192,28 @@ public class RepositoryImpl extends Abst }; } + private String createFullPath(String relativePath) { + + boolean repoUrlHasTrailingSlash = repositoryInfo.getUrl().endsWith("/"); + boolean relativePathHasLeadingSlash = !relativePath.isEmpty() && relativePath.charAt(0) == '/'; + + if (repoUrlHasTrailingSlash ^ relativePathHasLeadingSlash) + return repositoryInfo.getUrl() + relativePath; + if (!repoUrlHasTrailingSlash && !relativePathHasLeadingSlash) + return repositoryInfo.getUrl() + '/' + relativePath; + if (repoUrlHasTrailingSlash && relativePathHasLeadingSlash) + return repositoryInfo.getUrl() + relativePath.substring(1); + + throw new AssertionError("unreachable"); + } + @Override public Command<String> newGetNodeContentCommand(final String path, final ResponseType responseType) { return new Command<String>() { @Override public Result<String> execute() { //TODO handle the response type - GetMethod get= new GetMethod(repositoryInfo.getUrl()+path+".json"); + GetMethod get = new GetMethod(createFullPath(path + ".json")); try{ httpClient.getParams().setAuthenticationPreemptive(true); Credentials defaultcreds = new UsernamePasswordCredentials(repositoryInfo.getUsername(), repositoryInfo.getPassword()); @@ -229,7 +246,7 @@ public class RepositoryImpl extends Abst return new Command<Void>() { @Override public Result<Void> execute() { - PostMethod post = new PostMethod(repositoryInfo.getUrl()+fileInfo.getRelativeLocation()); + PostMethod post = new PostMethod(createFullPath(fileInfo.getRelativeLocation())); try{ Part[] parts = new Part[properties.size()]; int counter=0; Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/plugin.xml Fri Jul 19 15:03:29 2013 @@ -19,23 +19,6 @@ </initializer> </extension> <extension - point="org.eclipse.ui.importWizards"> - <category - id="org.apache.sling.slingclipse.ui.wizards.sampleCategory" - name="Sling"> - </category> - <wizard - category="org.apache.sling.slingclipse.ui.wizards.sampleCategory" - class="org.apache.sling.slingclipse.ui.wizards.ImportWizard" - icon="src/org/apache/sling/slingclipse/images/sling-logo.png" - id="org.apache.sling.slingclipse.ui.wizards.ImportWizard" - name="Import from Sling Repository"> - <description> - Import a file from the local file system into the workspace. - </description> - </wizard> - </extension> - <extension id="org.apache.sling.slingclipse.SlingProjectNature" point="org.eclipse.core.resources.natures"> <runtime> @@ -54,23 +37,20 @@ class="org.apache.sling.slingclipse.internal.AddSlingNatureAction" id="org.apache.sling.slingclipse.enableNatureAction" label="Convert to Sling Project" - menubarPath="org.eclipse.ui.projectConfigure/additions" style="push"> </action> <visibility> - <and> - <objectState - name="open" - value="true"> - </objectState> - <not> - <objectState - name="nature" - value="org.apache.sling.slingclipse.SlingProjectNature"> - </objectState> - </not> - </and> + <objectState + name="open" + value="true"> + </objectState> </visibility> + <enablement> + <test + property="org.eclipse.wst.common.project.facet.core.projectFacet" + value="sling.content"> + </test> + </enablement> </objectContribution> </extension> <extension Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/META-INF/MANIFEST.MF Fri Jul 19 15:03:29 2013 @@ -19,7 +19,11 @@ Import-Package: org.apache.sling.slingcl org.eclipse.debug.ui.sourcelookup, org.eclipse.jdt.debug.ui.launchConfigurations, org.eclipse.jdt.launching, + org.eclipse.jface.action, + org.eclipse.jface.dialogs, org.eclipse.jface.viewers, + org.eclipse.jface.window, + org.eclipse.jface.wizard, org.eclipse.jst.common.project.facet.core, org.eclipse.jst.server.core, org.eclipse.swt, @@ -27,6 +31,7 @@ Import-Package: org.apache.sling.slingcl org.eclipse.swt.layout, org.eclipse.swt.widgets, org.eclipse.ui, + org.eclipse.ui.dialogs, org.eclipse.ui.forms, org.eclipse.ui.forms.widgets, org.eclipse.wst.common.project.facet.core, @@ -34,4 +39,5 @@ Import-Package: org.apache.sling.slingcl org.eclipse.wst.server.core.model, org.eclipse.wst.server.core.util, org.eclipse.wst.server.ui, - org.eclipse.wst.server.ui.editor + org.eclipse.wst.server.ui.editor, + org.json Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/plugin.xml URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/plugin.xml?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/plugin.xml (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/plugin.xml Fri Jul 19 15:03:29 2013 @@ -162,6 +162,45 @@ <image runtime-component-type="org.apache.sling.launchpad" path="icons/obj16/sling.gif"/> </extension> + + <!-- Menu contributions --> + <extension + point="org.eclipse.ui.popupMenus"> + <!-- All Sling contributions --> + <objectContribution + id="org.apache.sling.slingclipse.slingMenu" + objectClass="org.eclipse.core.resources.IProject"> + <menu id="org.apache.sling.slingclipse.slingMenu" + path="additions" + label="Sling"> + <groupMarker name="sling"/> + </menu> + </objectContribution> + <!-- Import. + I prefer to do this outside the import wizard section since I can restrict the destination --> + <objectContribution id="org.apache.sling.slingclipse.slingImport" + objectClass="org.eclipse.core.resources.IProject"> + + <action + class="org.apache.sling.ide.eclipse.wst.ui.internal.ImportContentAction" + id="org.apache.sling.slingclipse.importContentAction" + label="Import Content..." + menubarPath="org.apache.sling.slingclipse.slingMenu/sling" + style="push"> + </action> + <visibility> + <objectState + name="open" + value="true"> + </objectState> + </visibility> + <enablement> + <test + property="org.eclipse.wst.common.project.facet.core.projectFacet" + value="sling.content"/> + </enablement> + </objectContribution> + </extension> <!-- <extension point="org.eclipse.debug.ui.launchConfigurationTypeImages"> Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadBehaviour.java Fri Jul 19 15:03:29 2013 @@ -191,9 +191,9 @@ public class SlingLaunchpadBehaviour ext super.publishModule(kind, deltaKind, module, monitor); } - private Repository getRepository(IProgressMonitor monitor) { + public static Repository getRepository(IServer server, IProgressMonitor monitor) { - SlingLaunchpadServer launchpadServer = (SlingLaunchpadServer) getServer().loadAdapter( + SlingLaunchpadServer launchpadServer = (SlingLaunchpadServer) server.loadAdapter( SlingLaunchpadServer.class, monitor); SlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration(); @@ -201,7 +201,7 @@ public class SlingLaunchpadBehaviour ext Repository repository = SlingclipsePlugin.getDefault().getRepository(); try { // TODO configurable scheme? - URI uri = new URI("http", null, getServer().getHost(), configuration.getPort(), + URI uri = new URI("http", null, server.getHost(), configuration.getPort(), configuration.getContextPath(), null, null); RepositoryInfo repositoryInfo = new RepositoryInfo(configuration.getUsername(), configuration.getPassword(), uri.toString()); @@ -212,6 +212,11 @@ public class SlingLaunchpadBehaviour ext return repository; } + private Repository getRepository(IProgressMonitor monitor) { + + return getRepository(getServer(), monitor); + } + private void execute(Command<?> command) throws CoreException { if (command == null) { return; Modified: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java?rev=1504903&r1=1504902&r2=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/internal/SlingLaunchpadServer.java Fri Jul 19 15:03:29 2013 @@ -25,11 +25,17 @@ import org.eclipse.wst.server.core.model public class SlingLaunchpadServer extends ServerDelegate { + public static final int PUBLISH_STATE_NEVER = 1; + public static final int PUBLISH_STATE_RESOURCE_CHANGE = 2; + public static final int PUBLISH_STATE_BUILD_EVENT = 3; + public static final String PROP_PASSWORD = "launchpad.password"; public static final String PROP_USERNAME = "launchpad.username"; public static final String PROP_CONTEXT_PATH = "launchpad.contextPath"; public static final String PROP_PORT = "launchpad.port"; + private static final String PROP_AUTO_PUBLISH_SETTING = "auto-publish-setting"; + private static final String MODULE_TYPE_SLING_CONTENT = "sling.content"; private SlingLaunchpadConfiguration config; @@ -130,4 +136,14 @@ public class SlingLaunchpadServer extend setAttribute(PROP_PASSWORD, "admin"); } + + public int getPublishState() { + return getAttribute(PROP_AUTO_PUBLISH_SETTING, PUBLISH_STATE_NEVER); + } + + public void setPublishState(int publishState) { + System.out.println("[" + Thread.currentThread().getName() + "] Set " + PROP_AUTO_PUBLISH_SETTING + " to " + + publishState); + setAttribute(PROP_AUTO_PUBLISH_SETTING, publishState); + } } Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java?rev=1504903&view=auto ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java (added) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java Fri Jul 19 15:03:29 2013 @@ -0,0 +1,111 @@ +/************************************************************************* + * + * ADOBE CONFIDENTIAL + * __________________ + * + * Copyright 2013 Adobe Systems Incorporated + * All Rights Reserved. + * + * NOTICE: All information contained herein is, and remains + * the property of Adobe Systems Incorporated and its suppliers, + * if any. The intellectual and technical concepts contained + * herein are proprietary to Adobe Systems Incorporated and its + * suppliers and are protected by trade secret or copyright law. + * Dissemination of this information or reproduction of this material + * is strictly forbidden unless prior written permission is obtained + * from Adobe Systems Incorporated. + **************************************************************************/ +package org.apache.sling.ide.eclipse.wst.ui.internal; + +import java.util.Iterator; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExecutableExtension; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.PlatformUI; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.ServerUtil; + +/** + * The <tt>ImportContentAction</tt> TODO + * + */ +public class ImportContentAction implements IObjectActionDelegate, IExecutableExtension { + + private ISelection selection; + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + @Override + public void run(IAction action) { + if (!(selection instanceof IStructuredSelection)) { + return; + } + + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + + for (Iterator<?> it = structuredSelection.iterator(); it.hasNext();) { + Object selected = it.next(); + if (selected instanceof IProject) { + IProject project = (IProject) selected; + + IModule module = ServerUtil.getModule(project); + + if (!module.getModuleType().getId().equals("sling.content")) { + continue; + } + + ImportWizard wiz = new ImportWizard(); + wiz.init(PlatformUI.getWorkbench(), structuredSelection); + + WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wiz); + dialog.open(); + + } + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, + * org.eclipse.jface.viewers.ISelection) + */ + @Override + public void selectionChanged(IAction action, ISelection selection) { + this.selection = selection; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement + * , java.lang.String, java.lang.Object) + */ + @Override + public void setInitializationData(IConfigurationElement config, String propertyName, Object data) + throws CoreException { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, + * org.eclipse.ui.IWorkbenchPart) + */ + @Override + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + +} Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportContentAction.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Copied: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java (from r1504902, sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java) URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java?p2=sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java&p1=sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java&r1=1504902&r2=1504903&rev=1504903&view=diff ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-plugin/src/org/apache/sling/slingclipse/ui/wizards/ImportWizard.java (original) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java Fri Jul 19 15:03:29 2013 @@ -14,24 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.sling.slingclipse.ui.wizards; +package org.apache.sling.ide.eclipse.wst.ui.internal; import java.io.ByteArrayInputStream; -import java.lang.reflect.InvocationTargetException; import java.nio.charset.Charset; import java.util.Iterator; +import org.apache.sling.ide.eclipse.wst.internal.SlingLaunchpadBehaviour; +import org.apache.sling.ide.eclipse.wst.internal.SlingLaunchpadServer; import org.apache.sling.slingclipse.SlingclipsePlugin; import org.apache.sling.slingclipse.api.Command; import org.apache.sling.slingclipse.api.Repository; import org.apache.sling.slingclipse.api.RepositoryException; -import org.apache.sling.slingclipse.api.RepositoryInfo; import org.apache.sling.slingclipse.api.ResponseType; import org.apache.sling.slingclipse.api.Result; import org.apache.sling.slingclipse.helper.SlingclipseHelper; import org.apache.sling.slingclipse.helper.Tracer; -import org.apache.sling.slingclipse.images.SharedImages; -import org.apache.sling.slingclipse.preferences.PreferencesMessages; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; @@ -39,14 +37,14 @@ import org.eclipse.core.resources.Resour import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.ui.IImportWizard; import org.eclipse.ui.IWorkbench; +import org.eclipse.wst.server.core.IServer; import org.json.JSONException; import org.json.JSONML; import org.json.JSONObject; @@ -58,61 +56,77 @@ import org.json.JSONObject; public class ImportWizard extends Wizard implements IImportWizard { private ImportWizardPage mainPage; + /** + * Construct a new Import Wizard container instance. + */ + public ImportWizard() { + super(); + } + /* * (non-Javadoc) * * @see org.eclipse.jface.wizard.Wizard#performFinish() */ public boolean performFinish() { - - if ( !mainPage.isPageComplete() ) - return false; - - final Repository repository = SlingclipsePlugin.getDefault().getRepository(); - RepositoryInfo repositoryInfo = new RepositoryInfo( - mainPage.getUsername(), - mainPage.getPassword(), - mainPage.getRepositoryUrl()); - repository.setRepositoryInfo(repositoryInfo); - - IPath destinationPath = mainPage.getResourcePath(); - - final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]); - final IPath projectRelativePath = destinationPath.removeFirstSegments(1); - final String repositoryPath = mainPage.getRepositoryPath(); - try { - getContainer().run(false, true, new IRunnableWithProgress() { - - @Override - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - Tracer tracer = SlingclipsePlugin.getDefault().getTracer(); - - monitor = SubMonitor.convert(monitor, "Importing from " + mainPage.getRepositoryUrl() + " ...", - IProgressMonitor.UNKNOWN); + if (mainPage.isPageComplete()) { - IPreferenceStore store = SlingclipsePlugin.getDefault().getPreferenceStore(); - boolean autoSync = store.getBoolean(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey()); - try { - store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(), false); + final IServer server = mainPage.getServer(); + + IPath destinationPath = mainPage.getResourcePath(); + + final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(destinationPath.segments()[0]); + final IPath projectRelativePath = destinationPath.removeFirstSegments(1); + final String repositoryPath = mainPage.getRepositoryPath(); + + Job job = new Job("Import") { + + protected IStatus run(IProgressMonitor monitor) { + + Repository repository = SlingLaunchpadBehaviour.getRepository(server, monitor); + + Tracer tracer = SlingclipsePlugin.getDefault().getTracer(); + + monitor.setTaskName("Loading configuration..."); + monitor.worked(5); + SlingLaunchpadServer launchpad = (SlingLaunchpadServer) server.loadAdapter( + SlingLaunchpadServer.class, monitor); + + int oldPublishState = launchpad.getPublishState(); + // TODO disabling publish does not work; since the publish is done async + // Not sure if there is a simple workaround. Anyway, the only side effect is that we + // make too many calls after the import, functionality is not affected + if (server.canPublish().isOK() && oldPublishState != SlingLaunchpadServer.PUBLISH_STATE_NEVER) { + launchpad.setPublishState(SlingLaunchpadServer.PUBLISH_STATE_NEVER); + } - // TODO: We should try to make this give 'nice' progress feedback (aka here's what I'm - // processing) + try { - // TODO: check for cancellation + // TODO: We should try to make this give 'nice' progress feedback (aka here's what I'm processing) + monitor.setTaskName("Importing..."); + monitor.worked(10); // we create the root node and assume this is a folder createRoot(project, projectRelativePath, repositoryPath); - crawlChildrenAndImport(repository, repositoryPath, project, projectRelativePath, tracer); - } catch (Exception e) { - throw new InvocationTargetException(e); - } finally { - monitor.done(); - // restore to the original value - store.setValue(PreferencesMessages.REPOSITORY_AUTO_SYNC.getKey(), autoSync); - } - } + crawlChildrenAndImport(repository, repositoryPath, project, projectRelativePath, tracer); + + monitor.setTaskName("Import Complete"); + monitor.worked(100); + } catch ( Exception e) { + Status status = new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Failed importing repository ", e); + SlingclipsePlugin.getDefault().getLog().log(status); + return status; + }finally{ + if (oldPublishState != SlingLaunchpadServer.PUBLISH_STATE_NEVER) { + launchpad.setPublishState(oldPublishState); + } + + } + + return Status.OK_STATUS; + } private void createRoot(final IProject project, final IPath projectRelativePath, final String repositoryPath) throws CoreException { @@ -122,18 +136,14 @@ public class ImportWizard extends Wizard for (int i = rootImportPath.segmentCount() - 1; i > 0; i--) createFolder(project, rootImportPath.removeLastSegments(i)); } - }); - } catch (InterruptedException e) { - return false; - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - mainPage.setErrorMessage("Import error : " + cause.getMessage() - + " . Please see the error log for details."); - SlingclipsePlugin.getDefault().getLog() - .log(new Status(Status.ERROR, SlingclipsePlugin.PLUGIN_ID, "Repository import failed", cause)); - return false; - } - return true; + }; + job.setSystem(false); + job.setUser(true); + job.schedule(); + return true; + } else { + return false; + } } /* @@ -144,7 +154,6 @@ public class ImportWizard extends Wizard */ public void init(IWorkbench workbench, IStructuredSelection selection) { setWindowTitle("Repositoy Import"); // NON-NLS-1 - setDefaultPageImageDescriptor(SharedImages.SLING_LOG); setNeedsProgressMonitor(true); mainPage = new ImportWizardPage("Import from Repository", selection); // NON-NLS-1 } @@ -174,6 +183,9 @@ public class ImportWizard extends Wizard // TODO: This probably should be pushed into the service layer private void crawlChildrenAndImport(Repository repository,String path,IProject project, IPath projectRelativePath, Tracer tracer) throws JSONException, RepositoryException, CoreException{ + System.out.println("crawlChildrenAndImport(" + repository + ", " + path + ", " + project + ", " + + projectRelativePath + ")"); + String children = executeCommand(repository.newListChildrenNodeCommand(path, ResponseType.JSON), tracer); JSONObject json = new JSONObject(children); String primaryType= json.optString(Repository.JCR_PRIMARY_TYPE); @@ -193,8 +205,8 @@ public class ImportWizard extends Wizard createFile( project, projectRelativePath.append( path+"/"+SlingclipseHelper.CONTENT_XML), contentXml.getBytes(Charset.forName("UTF-8") /* TODO is this enough? */)); } - for (Iterator<String> keys = json.keys(); keys.hasNext();) { - String key = keys.next(); + for (Iterator<?> keys = json.keys(); keys.hasNext();) { + String key = (String) keys.next(); JSONObject innerjson=json.optJSONObject(key); if (innerjson!=null){ crawlChildrenAndImport(repository, path+"/"+key, project, projectRelativePath, tracer); @@ -212,7 +224,10 @@ public class ImportWizard extends Wizard } private void importFile(Repository repository,String path,IProject project, IPath destinationPath, Tracer tracer) throws JSONException, RepositoryException, CoreException{ - byte [] node= executeCommand(repository.newGetNodeCommand(path), tracer); + + System.out.println("importFile: " + path + " -> " + destinationPath); + + byte[] node = executeCommand(repository.newGetNodeCommand(path), tracer); createFile(project, destinationPath.append(path), node ); } Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizard.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java?rev=1504903&view=auto ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java (added) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java Fri Jul 19 15:03:29 2013 @@ -0,0 +1,234 @@ +/* + * 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.wst.ui.internal; + + +import java.util.List; + +import org.apache.sling.slingclipse.helper.SlingclipseHelper; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.WizardResourceImportPage; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.ServerCore; + +/** + * Wizard page for importing content from Sling Repositories. + */ +public class ImportWizardPage extends WizardResourceImportPage { + + private IStructuredSelection selection; + private Text path; + private ModifyListener modifyListener = new ModifyListener() { + @Override + public void modifyText(ModifyEvent event) { + try{ + determinePageCompletion(); + updateWidgetEnablements(); + }catch(Exception e){ + //TODO: Log or just ignore? + } + } + }; + private Combo repositoryCombo; + + /** + * Creates an import wizard page for importing from a Sling Repository. If + * the initial resource selection contains exactly one container resource + * then it will be used as the default import destination. Multiple + * selections are not supported, but are not disallowed. + * + * @param pageName + * the name of the page + * @param selection + * the current resource selection + */ + public ImportWizardPage(String pageName, IStructuredSelection selection) { + super(pageName, selection); + this.selection = selection; + setTitle(pageName); // NON-NLS-1 + setDescription("Import content from a Sling Repository into the workspace"); // NON-NLS-1 + + setContainerFieldValue(getProject(selection).getFullPath() + .append(SlingclipseHelper.JCR_ROOT).toOSString()); + } + + private IProject getProject(IStructuredSelection selection) { + return (IProject) selection.getFirstElement(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.dialogs.WizardResourceImportPage#allowNewContainerName() + */ + @Override + protected boolean allowNewContainerName() { + return false; + } + + @Override + protected void createOptionsGroup(Composite parent) { + + } + + @Override + protected void createSourceGroup(Composite parent) { + + // TODO: Currently only supports first selection + IResource resource = ((IResource) selection.getFirstElement()); + String pathStr = resource.getFullPath().toPortableString(); + + Composite container = new Composite(parent, SWT.NONE); + container.setLayout(new GridLayout(2, false)); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); + gridData.minimumWidth = 450; + container.setLayoutData(gridData); + + new Label(container, SWT.NONE).setText("Repository: "); + + repositoryCombo = new Combo(container, SWT.DROP_DOWN); + repositoryCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + List<IServer> servers = SelectionUtils.getServersLinkedToProject(selection, new NullProgressMonitor()); + if (servers.size() > 1) { + repositoryCombo.add(""); // force selection only if there is more than one server + } + for (IServer server : servers) { + repositoryCombo.add(server.getId()); + } + + if (servers.size() == 1) { + repositoryCombo.select(0); + } + + Label pathLabel = new Label(container, SWT.NONE); + pathLabel.setText("Repository Path:"); + path = new Text(container, SWT.BORDER); + path.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + path.addModifyListener(modifyListener); + + if (SlingclipseHelper.isValidSlingProjectPath(pathStr)) { + path.setText(SlingclipseHelper.getSlingProjectPath(pathStr)); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFileProvider() + */ + @Override + protected ITreeContentProvider getFileProvider() { + // TODO Not sure if I need to return anything here... + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.dialogs.WizardResourceImportPage#getFolderProvider() + */ + @Override + protected ITreeContentProvider getFolderProvider() { + // TODO Not sure if I need to return anything here... + return null; + } + + /** + * Returns the path from which to import from the Sling Repository. + * + * @return the repository path + */ + public String getRepositoryPath() { + return path != null ? path.getText() : null; + } + + public void handleEvent(Event event) { + super.handleEvent(event); + determinePageCompletion(); + } + + @Override + public IPath getResourcePath() { + return super.getResourcePath(); + } + + public IServer getServer() { + for (IServer server : ServerCore.getServers()) + if (server.getId().equals(repositoryCombo.getText())) + return server; + + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.dialogs.WizardDataTransferPage#validateOptionsGroup() + */ + @Override + protected boolean validateOptionsGroup() { + if (this.repositoryCombo == null || this.repositoryCombo.getSelectionIndex() == -1) { + setErrorMessage("Please select a valid index"); + return false; + } + + if ( !getRepositoryPath().startsWith("/") ) { + setErrorMessage("The repository path needs to be absolute"); + return false; + } + + IPath containerNameField = super.getResourcePath(); + // TODO - we should force it to be JCR_ROOT for now + if (!containerNameField.toOSString().endsWith(SlingclipseHelper.JCR_ROOT)) { + setErrorMessage("Please enter a valid Sling project folder (e.g. jcr_root)"); + return false; + } + + return true; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.dialogs.WizardDataTransferPage#validateSourceGroup() + */ + @Override + protected boolean validateSourceGroup() { + if (getRepositoryPath() == null + || getRepositoryPath().trim().length() == 0) { + setErrorMessage("Please enter a valid Sling Repository path"); + return false; + } + return true; + } +} Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/ImportWizardPage.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java URL: http://svn.apache.org/viewvc/sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java?rev=1504903&view=auto ============================================================================== --- sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java (added) +++ sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java Fri Jul 19 15:03:29 2013 @@ -0,0 +1,66 @@ +/* + * 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.wst.ui.internal; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.IServer; +import org.eclipse.wst.server.core.ServerCore; +import org.eclipse.wst.server.core.ServerUtil; + +public abstract class SelectionUtils { + + public static List<IServer> getServersLinkedToProject(IStructuredSelection sel, IProgressMonitor monitor) { + + if (sel.isEmpty()) { + return Collections.emptyList(); + } + + Object first = sel.iterator().next(); + + if (!(first instanceof IProject)) { + return Collections.emptyList(); + } + + IProject project = (IProject) first; + List<IServer> servers = new ArrayList<IServer>(); + + IModule module = ServerUtil.getModule(project); + + if (module == null) { + return Collections.emptyList(); + } + + for (IServer server : ServerCore.getServers()) { + if (ServerUtil.containsModule(server, module, monitor)) { + servers.add(server); + } + } + + return servers; + } + + private SelectionUtils() { + + } +} Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/whiteboard/asanso/plugins/eclipse/slingclipse-wst/src/org/apache/sling/ide/eclipse/wst/ui/internal/SelectionUtils.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL