diff options
author | Igor Fedorenko | 2011-02-09 02:51:06 +0000 |
---|---|---|
committer | Igor Fedorenko | 2011-02-09 03:19:23 +0000 |
commit | 2f45d5f5759604bb5c802bfe2972d015570b8fb0 (patch) | |
tree | c96016ea3f23029078b665eb72038687e6d44f68 /org.eclipse.m2e.core.ui | |
parent | 8bbff917cb93e5b8b72881b5885f73d3c033cfed (diff) | |
download | m2e-core-2f45d5f5759604bb5c802bfe2972d015570b8fb0.tar.gz m2e-core-2f45d5f5759604bb5c802bfe2972d015570b8fb0.tar.xz m2e-core-2f45d5f5759604bb5c802bfe2972d015570b8fb0.zip |
moved rest of scm code to m2e.scm bundle
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.core.ui')
11 files changed, 25 insertions, 1225 deletions
diff --git a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF index adc6bfe8..38c0065e 100644 --- a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF @@ -25,7 +25,7 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.5.2", org.eclipse.equinox.common;bundle-version="3.5.1", org.eclipse.ui.workbench;bundle-version="3.5.2", org.eclipse.swt;bundle-version="3.5.2", - org.eclipse.m2e.core;bundle-version="0.13.0", + org.eclipse.m2e.core;bundle-version="[0.13.0,0.14.0)", org.eclipse.jface;bundle-version="3.5.2", org.eclipse.core.resources;bundle-version="3.5.2", org.eclipse.core.runtime;bundle-version="3.5.0", @@ -39,6 +39,5 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.5.2", org.eclipse.core.filesystem;bundle-version="1.2.1", org.eclipse.core.expressions;bundle-version="3.4.101", org.eclipse.search;bundle-version="3.5.1", - org.eclipse.ui.forms;bundle-version="3.4.1", - org.eclipse.m2e.scm;bundle-version="0.13.0" + org.eclipse.ui.forms;bundle-version="3.4.1" Service-Component: OSGI-INF/mavenconsole.xml diff --git a/org.eclipse.m2e.core.ui/plugin.properties b/org.eclipse.m2e.core.ui/plugin.properties index 8719dd58..ac26ab3e 100644 --- a/org.eclipse.m2e.core.ui/plugin.properties +++ b/org.eclipse.m2e.core.ui/plugin.properties @@ -51,9 +51,6 @@ m2.wizard.project.description=Create a Maven Project m2.wizard.import.name=Existing Maven Projects m2.wizard.import.description=Import Existing Maven Projects -m2.wizard.materialize.name=Materialize Maven Projects -m2.wizard.materialize.description=Materialize Maven Projects - m2.wizard.module.name=Maven Module m2.wizard.module.description=Create a Maven module @@ -62,7 +59,6 @@ m2.editor.pom.name=Maven POM Editor m2.shortcut.addDependency=Add Maven Dependency m2.shortcut.addPlugin=Add Maven Plugin -checkoutaction.label = Check out as Maven Project... openpomaction.label = Open POM openpomaction.label2 = Open POM openpomaction.label3 = Open POM @@ -78,11 +74,7 @@ keyword.label = maven page.installations.name = Installations page.usersettings.name = User Settings page.archetypes.name = Archetypes -wizard.checkout.name = Checkout Maven Projects from SCM -wizard.checkout.description = Check out Maven Project from SVN category.general.name = General -wizard.checkout2.name = Check out Maven Projects from SCM -wizard.checkout2.description = Checkout Maven Project from SCM wizard.install.name = Install or deploy an artifact to a Maven repository wizard.install.description = Install or Deploy an artifact (archive) into a Maven repository consoleFactory.label = Maven Console diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml index 0befbb61..1e7249d1 100644 --- a/org.eclipse.m2e.core.ui/plugin.xml +++ b/org.eclipse.m2e.core.ui/plugin.xml @@ -453,16 +453,6 @@ </action> </objectContribution> - - <objectContribution id="org.eclipse.m2e.core.scmUrl" - objectClass="org.eclipse.m2e.core.scm.ScmUrl" - adaptable="true"> - <action id="org.eclipse.m2e.core.ui.checkoutAsMaven" - label="%checkoutaction.label" - class="org.eclipse.m2e.core.ui.internal.actions.CheckoutAsMavenAction" - menubarPath="checkoutGroup"/> - </objectContribution> - <objectContribution id="org.eclipse.m2e.core.openPomArtifact" objectClass="org.apache.maven.artifact.Artifact" adaptable="false"> @@ -644,42 +634,12 @@ project="true"> <description>%m2.wizard.module.description</description> </wizard> - - <wizard id="org.eclipse.m2e.core.wizards.MavenCheckoutWizard" - name="%wizard.checkout.name" - class="org.eclipse.m2e.core.ui.internal.wizards.MavenCheckoutWizard" - category="org.eclipse.m2e" - icon="icons/import_m2_project.gif" project="true"> - <description>%wizard.checkout.description</description> - <!-- - <selection class="org.tigris.subversion.subclipse.core.ISVNRemoteFolder"/> - --> - </wizard> </extension> <extension point="org.eclipse.ui.importWizards"> <category id="org.eclipse.ui.Basic" name="%category.general.name"/> <category id="org.eclipse.m2e" name="%m2.wizard.name"/> - <wizard id="org.eclipse.m2e.core.wizards.MavenPomCheckoutWizard" - class="org.eclipse.m2e.core.ui.internal.wizards.MavenMaterializePomWizard" - category="org.eclipse.m2e" - name="%m2.wizard.materialize.name" - icon="icons/import_m2_project.gif"> - <description>%m2.wizard.materialize.description</description> - </wizard> - - <wizard id="org.eclipse.m2e.core.wizards.MavenCheckoutWizard" - class="org.eclipse.m2e.core.ui.internal.wizards.MavenCheckoutWizard" - category="org.eclipse.m2e" - name="%wizard.checkout2.name" - icon="icons/import_m2_project.gif"> - <description>%wizard.checkout2.description</description> - <!-- - <selection class="org.tigris.subversion.subclipse.core.ISVNRemoteFolder"/> - --> - </wizard> - <wizard id="org.eclipse.m2e.core.wizards.MavenInstallFileWizard" class="org.eclipse.m2e.core.ui.internal.wizards.MavenInstallFileWizard" category="org.eclipse.m2e" @@ -701,12 +661,12 @@ <extension point="org.eclipse.ui.console.consoleFactories"> <consoleFactory label="%consoleFactory.label" icon="icons/m2.gif" - class="org.eclipse.m2e.core.ui.internal.MavenConsoleFactory"/> + class="org.eclipse.m2e.core.internal.console.MavenConsoleFactory"/> </extension> <extension point="org.eclipse.ui.console.consolePageParticipants"> <consolePageParticipant - class="org.eclipse.m2e.core.ui.internal.MavenConsolePageParticipant" + class="org.eclipse.m2e.core.internal.console.MavenConsolePageParticipant" id="org.eclipse.m2e.core.launch.console.Maven2ConsolePageParticipant"> <enablement> <instanceof value="org.eclipse.m2e.core.internal.console.MavenConsoleImpl"/> diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/CheckoutAsMavenAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/CheckoutAsMavenAction.java deleted file mode 100644 index f6bf95d2..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/CheckoutAsMavenAction.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.actions; - -import java.util.Iterator; - -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.m2e.core.ui.internal.M2EUIPluginActivator; -import org.eclipse.m2e.core.ui.internal.wizards.MavenCheckoutWizard; -import org.eclipse.m2e.scm.ScmUrl; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; - - -/** - * Checkout as Maven project action - * - * @author @author Eugene Kuleshov - */ -public class CheckoutAsMavenAction implements IObjectActionDelegate { - - private IStructuredSelection selection; - private IWorkbenchPart targetPart; - - /* (non-Javadoc) - * @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - if (selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; - } - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - this.targetPart = targetPart; - } - - - /* (non-Javadoc) - * @see org.eclipse.ui.actions.ActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - ScmUrl[] urls = null; - if(selection != null) { - urls = new ScmUrl[selection.size()]; - int i = 0; - for(Iterator<?> it = selection.iterator(); it.hasNext();) { - urls[i++] = (ScmUrl) it.next(); - } - } - - MavenCheckoutWizard wizard = new MavenCheckoutWizard(urls); - WizardDialog dialog = new WizardDialog(getShell(), wizard); - dialog.open(); - } - - protected Shell getShell() { - Shell shell = null; - if(targetPart != null) { - shell = targetPart.getSite().getShell(); - } - if(shell != null) { - return shell; - } - - IWorkbench workbench = M2EUIPluginActivator.getDefault().getWorkbench(); - if(workbench == null) { - return null; - } - - IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); - return window == null ? null : window.getShell(); - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MaterializeAction.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MaterializeAction.java deleted file mode 100644 index 5f11bb52..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MaterializeAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.actions; - -import org.apache.maven.model.Dependency; -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.m2e.core.ui.internal.wizards.MavenMaterializePomWizard; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PlatformUI; - - -public class MaterializeAction implements IObjectActionDelegate { - - public static final String ID = "org.eclipse.m2e.materializeAction"; //$NON-NLS-1$ - - private IStructuredSelection selection; - - public void run(IAction action) { - MavenMaterializePomWizard wizard = new MavenMaterializePomWizard(); - wizard.init(PlatformUI.getWorkbench(), selection); - - Dependency[] dependencies = wizard.getDependencies(); - if(dependencies!=null && dependencies.length>0) { - WizardDialog dialog = new WizardDialog(Display.getCurrent().getActiveShell(), wizard); - dialog.open(); - } else { - // TODO show info dialog - } - } - - public void selectionChanged(IAction action, ISelection selection) { - if(selection instanceof IStructuredSelection) { - this.selection = (IStructuredSelection) selection; - } else { - this.selection = null; - } - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java index 95e37be3..66f698d6 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/views/MavenRepositoryView.java @@ -34,7 +34,6 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.index.IndexListener; @@ -46,7 +45,6 @@ import org.eclipse.m2e.core.internal.index.IndexedArtifactGroup; import org.eclipse.m2e.core.internal.index.NexusIndex; import org.eclipse.m2e.core.repository.IRepository; import org.eclipse.m2e.core.ui.internal.MavenImages; -import org.eclipse.m2e.core.ui.internal.actions.MaterializeAction; import org.eclipse.m2e.core.ui.internal.actions.OpenPomAction; import org.eclipse.m2e.core.ui.internal.util.M2EUIUtils; import org.eclipse.m2e.core.ui.internal.views.nodes.AbstractIndexedRepositoryNode; @@ -100,7 +98,7 @@ public class MavenRepositoryView extends ViewPart { private BaseSelectionListenerAction copyUrlAction; - private BaseSelectionListenerAction materializeProjectAction; + //private BaseSelectionListenerAction materializeProjectAction; TreeViewer viewer; private RepositoryViewContentProvider contentProvider; @@ -218,7 +216,7 @@ public class MavenRepositoryView extends ViewPart { void fillContextMenu(IMenuManager manager) { manager.add(openPomAction); manager.add(copyUrlAction); - manager.add(materializeProjectAction); +// manager.add(materializeProjectAction); manager.add(new Separator()); manager.add(updateAction); manager.add(rebuildAction); @@ -434,22 +432,22 @@ public class MavenRepositoryView extends ViewPart { copyUrlAction.setToolTipText(Messages.MavenRepositoryView_action_copy_tooltip); copyUrlAction.setImageDescriptor(MavenImages.COPY); - materializeProjectAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_materialize) { - public void run() { - Object element = getStructuredSelection().getFirstElement(); - if(element instanceof IndexedArtifactFileNode){ - MaterializeAction action = new MaterializeAction(); - StructuredSelection sel = new StructuredSelection(new Object[]{((IndexedArtifactFileNode) element).getIndexedArtifactFile()}); - action.selectionChanged(this, sel); - action.run(this); - } - } - - protected boolean updateSelection(IStructuredSelection selection) { - return selection.getFirstElement() instanceof IndexedArtifactFileNode; - } - }; - materializeProjectAction.setImageDescriptor(MavenImages.IMPORT_PROJECT); +// materializeProjectAction = new BaseSelectionListenerAction(Messages.MavenRepositoryView_action_materialize) { +// public void run() { +// Object element = getStructuredSelection().getFirstElement(); +// if(element instanceof IndexedArtifactFileNode){ +// MaterializeAction action = new MaterializeAction(); +// StructuredSelection sel = new StructuredSelection(new Object[]{((IndexedArtifactFileNode) element).getIndexedArtifactFile()}); +// action.selectionChanged(this, sel); +// action.run(this); +// } +// } +// +// protected boolean updateSelection(IStructuredSelection selection) { +// return selection.getFirstElement() instanceof IndexedArtifactFileNode; +// } +// }; +// materializeProjectAction.setImageDescriptor(MavenImages.IMPORT_PROJECT); viewer.addSelectionChangedListener(openPomAction); viewer.addSelectionChangedListener(updateAction); @@ -458,7 +456,7 @@ public class MavenRepositoryView extends ViewPart { viewer.addSelectionChangedListener(enableFullAction); viewer.addSelectionChangedListener(rebuildAction); viewer.addSelectionChangedListener(copyUrlAction); - viewer.addSelectionChangedListener(materializeProjectAction); +// viewer.addSelectionChangedListener(materializeProjectAction); } protected void setIndexDetails(AbstractIndexedRepositoryNode node, String details) { @@ -481,7 +479,7 @@ public class MavenRepositoryView extends ViewPart { } public void dispose() { - viewer.removeSelectionChangedListener(materializeProjectAction); +// viewer.removeSelectionChangedListener(materializeProjectAction); viewer.removeSelectionChangedListener(copyUrlAction); viewer.removeSelectionChangedListener(rebuildAction); viewer.removeSelectionChangedListener(disableAction); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java index 74a272cb..95b65de4 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/AbstractMavenProjectWizard.java @@ -27,7 +27,7 @@ public abstract class AbstractMavenProjectWizard extends Wizard { protected IStructuredSelection selection; - protected ProjectImportConfiguration importConfiguration; + protected ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(); protected List<IWorkingSet> workingSets = new ArrayList<IWorkingSet>(); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutLocationPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutLocationPage.java deleted file mode 100644 index 33c26a4a..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutLocationPage.java +++ /dev/null @@ -1,422 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.wizards; - -import java.util.LinkedHashSet; -import java.util.Set; - -import org.apache.maven.model.Scm; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.wizard.IWizardContainer; -import org.eclipse.m2e.core.internal.Messages; -import org.eclipse.m2e.core.project.ProjectImportConfiguration; -import org.eclipse.m2e.scm.ScmHandlerFactory; -import org.eclipse.m2e.scm.ScmHandlerUi; -import org.eclipse.m2e.scm.ScmTag; -import org.eclipse.m2e.scm.ScmUrl; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - - -/** - * @author Eugene Kuleshov - */ -public class MavenCheckoutLocationPage extends AbstractMavenWizardPage { - - String scmType; - ScmUrl[] scmUrls; - String scmParentUrl; - - Combo scmTypeCombo; - - Combo scmUrlCombo; - - Button scmUrlBrowseButton; - - Button headRevisionButton; - - Label revisionLabel; - - Text revisionText; - - Button revisionBrowseButton; - - private Button checkoutAllProjectsButton; - - protected MavenCheckoutLocationPage(ProjectImportConfiguration projectImportConfiguration) { - super("MavenCheckoutLocationPage", projectImportConfiguration); - setTitle(Messages.MavenCheckoutLocationPage_title); - setDescription(Messages.MavenCheckoutLocationPage_description); - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(5, false); - gridLayout.verticalSpacing = 0; - composite.setLayout(gridLayout); - setControl(composite); - - SelectionAdapter selectionAdapter = new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - updatePage(); - } - }; - - if(scmUrls == null || scmUrls.length < 2) { - Label urlLabel = new Label(composite, SWT.NONE); - urlLabel.setText(Messages.MavenCheckoutLocationPage_lblurl); - - scmTypeCombo = new Combo(composite, SWT.READ_ONLY); - GridData gd_scmTypeCombo = new GridData(SWT.FILL, SWT.CENTER, false, false); - gd_scmTypeCombo.widthHint = 80; - scmTypeCombo.setLayoutData(gd_scmTypeCombo); - scmTypeCombo.setData("name", "mavenCheckoutLocation.typeCombo"); //$NON-NLS-1$ //$NON-NLS-2$ - String[] types = ScmHandlerFactory.getTypes(); - for(int i = 0; i < types.length; i++ ) { - scmTypeCombo.add(types[i]); - } - scmTypeCombo.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String newScmType = scmTypeCombo.getText(); - if(!newScmType.equals(scmType)) { - scmType = newScmType; - scmUrlCombo.setText(""); //$NON-NLS-1$ - updatePage(); - } - } - }); - - if(scmUrls!=null && scmUrls.length == 1) { - try { - scmType = ScmUrl.getType(scmUrls[0].getUrl()); - } catch(CoreException ex) { - } - } - - scmUrlCombo = new Combo(composite, SWT.NONE); - scmUrlCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); - scmUrlCombo.setData("name", "mavenCheckoutLocation.urlCombo"); //$NON-NLS-1$ //$NON-NLS-2$ - - scmUrlBrowseButton = new Button(composite, SWT.NONE); - scmUrlBrowseButton.setText(Messages.MavenCheckoutLocationPage_btnBrowse); - } - - headRevisionButton = new Button(composite, SWT.CHECK); - GridData headRevisionButtonData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 5, 1); - headRevisionButtonData.verticalIndent = 5; - headRevisionButton.setLayoutData(headRevisionButtonData); - headRevisionButton.setText(Messages.MavenCheckoutLocationPage_btnHead); - headRevisionButton.setSelection(true); - headRevisionButton.addSelectionListener(selectionAdapter); - - revisionLabel = new Label(composite, SWT.RADIO); - GridData revisionButtonData = new GridData(); - revisionButtonData.horizontalIndent = 10; - revisionLabel.setLayoutData(revisionButtonData); - revisionLabel.setText(Messages.MavenCheckoutLocationPage_lblRevision); - // revisionButton.addSelectionListener(selectionAdapter); - - revisionText = new Text(composite, SWT.BORDER); - GridData revisionTextData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1); - revisionTextData.widthHint = 115; - revisionTextData.verticalIndent = 3; - revisionText.setLayoutData(revisionTextData); - - if(scmUrls != null) { - ScmTag tag = scmUrls[0].getTag(); - if(tag!=null) { - headRevisionButton.setSelection(false); - revisionText.setText(tag.getName()); - } - } - - revisionText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - updatePage(); - } - }); - - revisionBrowseButton = new Button(composite, SWT.NONE); - GridData gd_revisionBrowseButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1); - gd_revisionBrowseButton.verticalIndent = 3; - revisionBrowseButton.setLayoutData(gd_revisionBrowseButton); - revisionBrowseButton.setText(Messages.MavenCheckoutLocationPage_btnRevSelect); - revisionBrowseButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String url = scmParentUrl; - if(url==null) { - return; - } - - String scmType = scmTypeCombo.getText(); - - ScmHandlerUi handlerUi = ScmHandlerFactory.getHandlerUiByType(scmType); - String revision = handlerUi.selectRevision(getShell(), scmUrls[0], revisionText.getText()); - if(revision!=null) { - revisionText.setText(revision); - headRevisionButton.setSelection(false); - updatePage(); - } - } - }); - - checkoutAllProjectsButton = new Button(composite, SWT.CHECK); - GridData checkoutAllProjectsData = new GridData(SWT.LEFT, SWT.TOP, true, false, 5, 1); - checkoutAllProjectsData.verticalIndent = 10; - checkoutAllProjectsButton.setLayoutData(checkoutAllProjectsData); - checkoutAllProjectsButton.setText(Messages.MavenCheckoutLocationPage_btnCheckout); - checkoutAllProjectsButton.setSelection(true); - checkoutAllProjectsButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - updatePage(); - } - }); - - GridData advancedSettingsData = new GridData(SWT.FILL, SWT.TOP, true, false, 5, 1); - advancedSettingsData.verticalIndent = 10; - createAdvancedSettings(composite, advancedSettingsData); - - if(scmUrls!=null && scmUrls.length == 1) { - scmTypeCombo.setText(scmType == null ? "" : scmType); //$NON-NLS-1$ - scmUrlCombo.setText(scmUrls[0].getProviderUrl()); - } - - if(scmUrls == null || scmUrls.length < 2) { - scmUrlBrowseButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - ScmHandlerUi handlerUi = ScmHandlerFactory.getHandlerUiByType(scmType); - // XXX should use null if there is no scmUrl selected - ScmUrl currentUrl = scmUrls==null || scmUrls.length==0 ? new ScmUrl("scm:" + scmType + ":") : scmUrls[0]; //$NON-NLS-1$ //$NON-NLS-2$ - ScmUrl scmUrl = handlerUi.selectUrl(getShell(), currentUrl); - if(scmUrl!=null) { - scmUrlCombo.setText(scmUrl.getProviderUrl()); - if(scmUrls==null) { - scmUrls = new ScmUrl[1]; - } - scmUrls[0] = scmUrl; - scmParentUrl = scmUrl.getUrl(); - updatePage(); - } - } - }); - - scmUrlCombo.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent e) { - final String url = scmUrlCombo.getText(); - if(url.startsWith("scm:")) { //$NON-NLS-1$ - try { - final String type = ScmUrl.getType(url); - scmTypeCombo.setText(type); - scmType = type; - Display.getDefault().asyncExec(new Runnable() { - public void run() { - scmUrlCombo.setText(url.substring(type.length() + 5)); - } - }); - } catch(CoreException ex) { - } - return; - } - - if(scmUrls==null) { - scmUrls = new ScmUrl[1]; - } - - ScmUrl scmUrl = new ScmUrl("scm:" + scmType + ":" + url); //$NON-NLS-1$ //$NON-NLS-2$ - scmUrls[0] = scmUrl; - scmParentUrl = scmUrl.getUrl(); - updatePage(); - } - }); - } - - updatePage(); - } - - /* (non-Javadoc) - * @see org.eclipse.m2e.wizards.AbstractMavenWizardPage#setVisible(boolean) - */ - public void setVisible(boolean visible) { - super.setVisible(visible); - - if(dialogSettings!=null && scmUrlCombo!=null) { - String[] items = dialogSettings.getArray("scmUrl"); //$NON-NLS-1$ - if(items != null) { - String text = scmUrlCombo.getText(); - scmUrlCombo.setItems(items); - if (text.length() > 0) { - // setItems() clears the text input, so we need to restore it - scmUrlCombo.setText(text); - } - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.m2e.wizards.AbstractMavenWizardPage#dispose() - */ - public void dispose() { - if(dialogSettings != null && scmUrlCombo!=null) { - Set<String> history = new LinkedHashSet<String>(MAX_HISTORY); - - String lastValue = scmUrlCombo.getText(); - if ( lastValue!=null && lastValue.trim().length() > 0 ) { - history.add("scm:" + scmType + ":" + lastValue); //$NON-NLS-1$ //$NON-NLS-2$ - } - - String[] items = scmUrlCombo.getItems(); - for(int j = 0; j < items.length && history.size() < MAX_HISTORY; j++ ) { - history.add(items[j]); - } - - dialogSettings.put("scmUrl", history.toArray(new String[history.size()])); //$NON-NLS-1$ - } - - super.dispose(); - } - - public IWizardContainer getContainer() { - return super.getContainer(); - } - - void updatePage() { - boolean canSelectUrl = false ; - boolean canSelectRevision = false; - ScmHandlerUi handlerUi = ScmHandlerFactory.getHandlerUiByType(scmType); - if(handlerUi!=null) { - canSelectUrl = handlerUi.canSelectUrl(); - canSelectRevision = handlerUi.canSelectRevision(); - } - - if(scmUrlBrowseButton!=null) { - scmUrlBrowseButton.setEnabled(canSelectUrl); - } - - revisionBrowseButton.setEnabled(canSelectRevision); - - boolean isHeadRevision = isHeadRevision(); - revisionLabel.setEnabled(!isHeadRevision); - revisionText.setEnabled(!isHeadRevision); - - setPageComplete(isPageValid()); - } - - private boolean isPageValid() { - setErrorMessage(null); - - if(scmUrls != null && scmUrls.length < 2) { - if(scmType == null) { - setErrorMessage(Messages.MavenCheckoutLocationPage_error_empty); - return false; - } - } - - ScmHandlerUi handlerUi = ScmHandlerFactory.getHandlerUiByType(scmType); - - if(scmUrls == null || scmUrls.length < 2) { - if(scmUrls == null || scmUrls.length == 0) { - setErrorMessage(Messages.MavenCheckoutLocationPage_error_empty_url); - return false; - } - - if(handlerUi!=null && !handlerUi.isValidUrl(scmUrls[0].getUrl())) { - setErrorMessage(Messages.MavenCheckoutLocationPage_error_url_empty); - return false; - } - } - - if(!isHeadRevision()) { - String revision = revisionText.getText().trim(); - if(revision.length()==0) { - setErrorMessage(Messages.MavenCheckoutLocationPage_error_scm_empty); - return false; - } - - if(handlerUi!=null && !handlerUi.isValidRevision(null, revision)) { - setErrorMessage(Messages.MavenCheckoutLocationPage_error_scm_invalid); - return false; - } - } - - return true; - } - - public void setParent(String parentUrl) { - this.scmParentUrl = parentUrl; - } - - public void setUrls(ScmUrl[] urls) { - this.scmUrls = urls; - } - - public ScmUrl[] getUrls() { - return scmUrls; - } - - public Scm[] getScms() { - if(scmUrls==null) { - return new Scm[0]; - } - - String revision = getRevision(); - Scm[] scms = new Scm[scmUrls.length]; - for(int i = 0; i < scms.length; i++ ) { - Scm scm = new Scm(); - scm.setConnection(scmUrls[i].getUrl()); - scm.setTag(revision); - scms[i] = scm; - } - return scms; - } - - public boolean isCheckoutAllProjects() { - return checkoutAllProjectsButton.getSelection(); - } - - public boolean isHeadRevision() { - return headRevisionButton.getSelection(); - } - - public String getRevision() { - if(isHeadRevision()) { - return "HEAD"; //$NON-NLS-1$ - } - return revisionText.getText().trim(); - } - - public void addListener(final SelectionListener listener) { - ModifyListener listenerProxy = new ModifyListener() { - public void modifyText(ModifyEvent e) { - Event event = new Event(); - event.widget = e.widget; - listener.widgetSelected(new SelectionEvent(event)); - } - }; - scmUrlCombo.addModifyListener(listenerProxy); - revisionText.addModifyListener(listenerProxy); - headRevisionButton.addSelectionListener(listener); - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutWizard.java deleted file mode 100644 index 1705d282..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenCheckoutWizard.java +++ /dev/null @@ -1,171 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.wizards; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.maven.model.Scm; -import org.eclipse.core.runtime.IAdapterManager; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.m2e.core.core.IMavenConstants; -import org.eclipse.m2e.core.internal.Messages; -import org.eclipse.m2e.core.project.MavenProjectScmInfo; -import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil; -import org.eclipse.m2e.scm.ScmUrl; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; - - -/** - * Maven checkout wizard - * - * @author Eugene Kuleshov - */ -public class MavenCheckoutWizard extends AbstractMavenProjectWizard implements IImportWizard, INewWizard { - - private ScmUrl[] urls; - - private String parentUrl; - - private MavenCheckoutLocationPage scheckoutPage; - - private MavenProjectWizardLocationPage locationPage; - - public MavenCheckoutWizard() { - this(null); - setNeedsProgressMonitor(true); - } - - public MavenCheckoutWizard(ScmUrl[] urls) { - setUrls(urls); - setNeedsProgressMonitor(true); - setWindowTitle(Messages.MavenCheckoutWizard_title); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - super.init(workbench, selection); - - this.selection = selection; - - ArrayList<ScmUrl> urls = new ArrayList<ScmUrl>(); - IAdapterManager adapterManager = Platform.getAdapterManager(); - for(Iterator<?> it = selection.iterator(); it.hasNext();) { - ScmUrl url = (ScmUrl) adapterManager.getAdapter(it.next(), ScmUrl.class); - if(url != null) { - urls.add(url); - } - } - setUrls(urls.toArray(new ScmUrl[urls.size()])); - } - - private void setUrls(ScmUrl[] urls) { - if(urls!=null && urls.length>0) { - this.urls = urls; - this.parentUrl = getParentUrl(urls); - } - } - - private String getParentUrl(ScmUrl[] urls) { - if(urls.length==1) { - return urls[0].getUrl(); - } - - String parent = urls[0].getParentUrl(); - for(int i = 1; parent!=null && i < urls.length; i++ ) { - String url = urls[i].getParentUrl(); - if(!parent.equals(url)) { - parent = null; - } - } - return parent; - } - - public void addPages() { - scheckoutPage = new MavenCheckoutLocationPage(importConfiguration); - scheckoutPage.setUrls(urls); - scheckoutPage.setParent(parentUrl); - - locationPage = new MavenProjectWizardLocationPage(importConfiguration, // - Messages.MavenCheckoutWizard_location1, - Messages.MavenCheckoutWizard_location2, workingSets); - locationPage.setLocationPath(SelectionUtil.getSelectedLocation(selection)); - - addPage(scheckoutPage); - addPage(locationPage); - } - -// /** Adds the listeners after the page controls are created. */ -// public void createPageControls(Composite pageContainer) { -// super.createPageControls(pageContainer); -// -// locationPage.addListener(new SelectionAdapter() { -// public void widgetSelected(SelectionEvent e) { -// projectsPage.setScms(locationPage.getScms(new NullProgressMonitor())); -// } -// }); -// -// projectsPage.setScms(locationPage.getScms(new NullProgressMonitor())); -// } - - public boolean canFinish() { - if(scheckoutPage.isCheckoutAllProjects() && scheckoutPage.isPageComplete()) { - return true; - } - return super.canFinish(); - } - - public boolean performFinish() { - if(!canFinish()) { - return false; - } - - final boolean checkoutAllProjects = scheckoutPage.isCheckoutAllProjects(); - - Scm[] scms = scheckoutPage.getScms(); - - final Collection<MavenProjectScmInfo> mavenProjects = new ArrayList<MavenProjectScmInfo>(); - for(int i = 0; i < scms.length; i++ ) { - String url = scms[i].getConnection(); - String revision = scms[i].getTag(); - - if(url.endsWith("/")) { //$NON-NLS-1$ - url = url.substring(0, url.length()-1); - } - - int n = url.lastIndexOf("/"); //$NON-NLS-1$ - String label = (n == -1 ? url : url.substring(n)) + "/" + IMavenConstants.POM_FILE_NAME; //$NON-NLS-1$ - MavenProjectScmInfo projectInfo = new MavenProjectScmInfo(label, null, // - null, revision, url, url); - mavenProjects.add(projectInfo); - } - - MavenProjectCheckoutJob job = new MavenProjectCheckoutJob(importConfiguration, checkoutAllProjects, workingSets) { - protected Collection<MavenProjectScmInfo> getProjects(IProgressMonitor monitor) { - return mavenProjects; - } - }; - - if(!locationPage.isInWorkspace()) { - job.setLocation(locationPage.getLocationPath().toFile()); - } - - job.schedule(); - - return true; - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenMaterializePomWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenMaterializePomWizard.java deleted file mode 100644 index 1abc4f79..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenMaterializePomWizard.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.wizards; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.maven.model.Dependency; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.m2e.core.MavenPlugin; -import org.eclipse.m2e.core.embedder.ArtifactKey; -import org.eclipse.m2e.core.internal.Messages; -import org.eclipse.m2e.core.project.MavenProjectPomScanner; -import org.eclipse.m2e.core.project.MavenProjectScmInfo; -import org.eclipse.m2e.core.project.ProjectImportConfiguration; -import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; - - -/** - * A wizard used to import projects for Maven artifacts - * - * @author Eugene Kuleshov - */ -public class MavenMaterializePomWizard extends AbstractMavenProjectWizard implements IImportWizard, INewWizard { - - MavenDependenciesWizardPage selectionPage; - - MavenProjectWizardLocationPage locationPage; - - Button checkOutAllButton; - - Button useDeveloperConnectionButton; - - // TODO replace with ArtifactKey - private Dependency[] dependencies; - - public MavenMaterializePomWizard() { - importConfiguration = new ProjectImportConfiguration(); - setNeedsProgressMonitor(true); - setWindowTitle(Messages.MavenMaterializePomWizard_title); - } - - public void setDependencies(Dependency[] dependencies) { - this.dependencies = dependencies; - } - - public Dependency[] getDependencies() { - return dependencies; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - super.init(workbench, selection); - - ArrayList<Dependency> dependencies = new ArrayList<Dependency>(); - - for(Iterator<?> it = selection.iterator(); it.hasNext();) { - Object element = it.next(); - ArtifactKey artifactKey = SelectionUtil.getType(element, ArtifactKey.class); - if(artifactKey!=null) { - Dependency d = new Dependency(); - d.setGroupId(artifactKey.getGroupId()); - d.setArtifactId(artifactKey.getArtifactId()); - d.setVersion(artifactKey.getVersion()); - d.setClassifier(artifactKey.getClassifier()); - dependencies.add(d); - } - } - - setDependencies(dependencies.toArray(new Dependency[dependencies.size()])); - } - - public void addPages() { - selectionPage = new MavenDependenciesWizardPage(importConfiguration, // - Messages.MavenMaterializePomWizard_dialog_title, // - Messages.MavenMaterializePomWizard_dialog_message) { - protected void createAdvancedSettings(Composite composite, GridData gridData) { - checkOutAllButton = new Button(composite, SWT.CHECK); - checkOutAllButton.setText(Messages.MavenMaterializePomWizard_btnCheckout); - checkOutAllButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1)); - - useDeveloperConnectionButton = new Button(composite, SWT.CHECK); - useDeveloperConnectionButton.setText(Messages.MavenMaterializePomWizard_btnDev); - useDeveloperConnectionButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1)); - - super.createAdvancedSettings(composite, gridData); - } - }; - selectionPage.setDependencies(dependencies); - - locationPage = new MavenProjectWizardLocationPage(importConfiguration, // - Messages.MavenMaterializePomWizard_location_title, - Messages.MavenMaterializePomWizard_location_message, workingSets); - locationPage.setLocationPath(SelectionUtil.getSelectedLocation(selection)); - - addPage(selectionPage); - addPage(locationPage); - } - - public boolean canFinish() { - return super.canFinish(); - } - - public boolean performFinish() { - if(!canFinish()) { - return false; - } - - final Dependency[] dependencies = selectionPage.getDependencies(); - - final boolean checkoutAllProjects = checkOutAllButton.getSelection(); - final boolean developer = useDeveloperConnectionButton.getSelection(); - - MavenProjectCheckoutJob job = new MavenProjectCheckoutJob(importConfiguration, checkoutAllProjects, workingSets) { - protected List<MavenProjectScmInfo> getProjects(IProgressMonitor monitor) throws InterruptedException { - MavenPlugin plugin = MavenPlugin.getDefault(); - MavenProjectPomScanner<MavenProjectScmInfo> scanner = new MavenProjectPomScanner<MavenProjectScmInfo>(developer, dependencies, // - plugin.getMavenModelManager(), // - plugin.getConsole()); - scanner.run(monitor); - // XXX handle errors/warnings - - return scanner.getProjects(); - } - }; - - if(!locationPage.isInWorkspace()) { - job.setLocation(locationPage.getLocationPath().toFile()); - } - - job.schedule(); - - return true; - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectCheckoutJob.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectCheckoutJob.java deleted file mode 100644 index e0bc6205..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectCheckoutJob.java +++ /dev/null @@ -1,257 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are 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: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.wizards; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -import org.apache.maven.model.Model; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.FileUtils; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.IJobChangeEvent; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.JobChangeAdapter; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.m2e.core.MavenPlugin; -import org.eclipse.m2e.core.core.MavenConsole; -import org.eclipse.m2e.core.core.MavenLogger; -import org.eclipse.m2e.core.embedder.MavenModelManager; -import org.eclipse.m2e.core.internal.Messages; -import org.eclipse.m2e.core.project.IMavenProjectImportResult; -import org.eclipse.m2e.core.project.LocalProjectScanner; -import org.eclipse.m2e.core.project.MavenProjectInfo; -import org.eclipse.m2e.core.project.MavenProjectScmInfo; -import org.eclipse.m2e.core.project.ProjectImportConfiguration; -import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction; -import org.eclipse.m2e.scm.MavenCheckoutOperation; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.TextTransfer; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkingSet; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.NewProjectAction; -import org.eclipse.ui.progress.IProgressConstants; - - -/** - * Maven project checkout Job - * - * @author Eugene Kuleshov - */ -public abstract class MavenProjectCheckoutJob extends WorkspaceJob { - - final ProjectImportConfiguration configuration; - - boolean checkoutAllProjects; - - Collection<MavenProjectInfo> projects; - - File location; - - List<String> collectedLocations = new ArrayList<String>(); - - final List<IWorkingSet> workingSets; - - public MavenProjectCheckoutJob(ProjectImportConfiguration importConfiguration, boolean checkoutAllProjects, - List<IWorkingSet> workingSets) { - super(Messages.MavenProjectCheckoutJob_title); - this.configuration = importConfiguration; - this.checkoutAllProjects = checkoutAllProjects; - this.workingSets = workingSets; - - setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction()); - addJobChangeListener(new CheckoutJobChangeListener()); - } - - public void setLocation(File location) { - this.location = location; - } - - protected abstract Collection<MavenProjectScmInfo> getProjects(IProgressMonitor monitor) throws InterruptedException; - - - // WorkspaceJob - - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - try { - MavenPlugin plugin = MavenPlugin.getDefault(); - MavenConsole console = plugin.getConsole(); - - MavenCheckoutOperation operation = new MavenCheckoutOperation(location, getProjects(monitor), console); - operation.run(monitor); - collectedLocations.addAll(operation.getLocations()); - - IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); - - MavenModelManager modelManager = plugin.getMavenModelManager(); - - LocalProjectScanner scanner = new LocalProjectScanner(workspace.getLocation().toFile(), operation.getLocations(), - true, modelManager); - scanner.run(monitor); - - this.projects = plugin.getProjectConfigurationManager().collectProjects(scanner.getProjects()); - - if(checkoutAllProjects) { - // check if there any project name conflicts - for(MavenProjectInfo projectInfo : projects) { - Model model = projectInfo.getModel(); - if(model == null) { - model = modelManager.readMavenModel(projectInfo.getPomFile()); - projectInfo.setModel(model); - } - - String projectName = configuration.getProjectName(model); - IProject project = workspace.getProject(projectName); - if(project.exists()) { - checkoutAllProjects = false; - break; - } - } - } - - return Status.OK_STATUS; - - } catch(InterruptedException ex) { - return Status.CANCEL_STATUS; - } - } - - /** - * Checkout job listener - */ - final class CheckoutJobChangeListener extends JobChangeAdapter { - - public void done(IJobChangeEvent event) { - IStatus result = event.getResult(); - if(result.getSeverity() == IStatus.CANCEL) { - return; - } else if(!result.isOK()) { - // XXX report errors - return; - } - - if(projects.isEmpty()) { - MavenPlugin.getDefault().getConsole().logMessage("No Maven projects to import"); - - if(collectedLocations.size()==1) { - final String location = collectedLocations.get(0); - - DirectoryScanner projectScanner = new DirectoryScanner(); - projectScanner.setBasedir(location); - projectScanner.setIncludes(new String[] {"**/.project"}); //$NON-NLS-1$ - projectScanner.scan(); - - String[] projectFiles = projectScanner.getIncludedFiles(); - if(projectFiles!=null && projectFiles.length>0) { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - boolean res = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), // - Messages.MavenProjectCheckoutJob_confirm_title, // - Messages.MavenProjectCheckoutJob_confirm_message); - if(res) { - IWizard wizard = new ProjectsImportWizard(collectedLocations.get(0)); - WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard); - dialog.open(); - } else { - cleanup(collectedLocations); - } - } - }); - return; - } - - Display.getDefault().syncExec(new Runnable() { - public void run() { - boolean res = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), // - Messages.MavenProjectCheckoutJob_confirm2_title, // - Messages.MavenProjectCheckoutJob_confirm2_message); - if(res) { - Clipboard clipboard = new Clipboard(Display.getDefault()); - clipboard.setContents(new Object[] { location }, new Transfer[] { TextTransfer.getInstance() }); - - NewProjectAction newProjectAction = new NewProjectAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()); - newProjectAction.run(); - } else { - cleanup(collectedLocations); - } - } - }); - return; - } - - cleanup(collectedLocations); - } - - if(checkoutAllProjects) { - final MavenPlugin plugin = MavenPlugin.getDefault(); - WorkspaceJob job = new AbstactCreateMavenProjectJob(Messages.MavenProjectCheckoutJob_job, workingSets) { - @Override - protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException { - Set<MavenProjectInfo> projectSet = plugin.getProjectConfigurationManager().collectProjects(projects); - - List<IMavenProjectImportResult> results = plugin.getProjectConfigurationManager().importProjects( - projectSet, configuration, monitor); - - return toProjects(results); - } - }; - ISchedulingRule rule = ResourcesPlugin.getWorkspace().getRuleFactory() - .modifyRule(ResourcesPlugin.getWorkspace().getRoot()); - job.setRule(rule); - job.schedule(); - - } else { - Display.getDefault().asyncExec(new Runnable() { - public void run() { - MavenImportWizard wizard = new MavenImportWizard(configuration, collectedLocations); - WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard); - int res = dialog.open(); - if(res == Window.CANCEL) { - cleanup(collectedLocations); - } - } - }); - } - } - - protected void cleanup(List<String> locations) { - MavenConsole console = MavenPlugin.getDefault().getConsole(); - for(String location : locations) { - try { - FileUtils.deleteDirectory(location); - } catch(IOException ex) { - String msg = "Can't delete " + location; - console.logError(msg + "; " + (ex.getMessage()==null ? ex.toString() : ex.getMessage())); //$NON-NLS-1$ - MavenLogger.log(msg, ex); - } - } - } - - } - -} |