diff options
Diffstat (limited to 'org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenCheckoutWizard.java')
-rw-r--r-- | org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenCheckoutWizard.java | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenCheckoutWizard.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenCheckoutWizard.java new file mode 100644 index 00000000..53f3b54a --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/wizards/MavenCheckoutWizard.java @@ -0,0 +1,180 @@ +/******************************************************************************* + * 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.wizards; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +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.jface.wizard.Wizard; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.INewWizard; +import org.eclipse.ui.IWorkbench; + +import org.apache.maven.model.Scm; + +import org.eclipse.m2e.core.actions.SelectionUtil; +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.project.ProjectImportConfiguration; +import org.eclipse.m2e.core.scm.ScmUrl; + + +/** + * Maven checkout wizard + * + * @author Eugene Kuleshov + */ +public class MavenCheckoutWizard extends Wizard implements IImportWizard, INewWizard { + + private final ProjectImportConfiguration importConfiguration = new ProjectImportConfiguration(); + + private ScmUrl[] urls; + + private String parentUrl; + + private MavenCheckoutLocationPage scheckoutPage; + + private MavenProjectWizardLocationPage locationPage; + + private IStructuredSelection selection; + + + 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) { + this.selection = selection; + + importConfiguration.setWorkingSet(SelectionUtil.getSelectedWorkingSet(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); + 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) { + protected Collection<MavenProjectScmInfo> getProjects(IProgressMonitor monitor) { + return mavenProjects; + } + }; + + if(!locationPage.isInWorkspace()) { + job.setLocation(locationPage.getLocationPath().toFile()); + } + + job.schedule(); + + return true; + } + +} |