Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2b4c048faea48cea13420753085cff991a2d5a3f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*******************************************************************************
 * Copyright (c) 2008-2015 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.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IProject;
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.ui.IWorkingSet;
import org.eclipse.ui.progress.IProgressConstants;

import org.eclipse.m2e.core.project.IMavenProjectImportResult;
import org.eclipse.m2e.core.ui.internal.actions.OpenMavenConsoleAction;


public abstract class AbstractCreateMavenProjectJob extends WorkspaceJob {

  @Deprecated
  private List<IWorkingSet> workingSets;

  private List<IProject> createdProjects;

  /**
   * @since 1.8
   */
  public AbstractCreateMavenProjectJob(String name) {
    super(name);
  }

  /**
   * A {@link #AbstractCreateMavenProjectJob(String)} constructor should be used along with a
   * {@link MavenProjectWorkspaceAssigner} instead.
   */
  @Deprecated
  public AbstractCreateMavenProjectJob(String name, List<IWorkingSet> workingSets) {
    super(name);
    this.workingSets = workingSets;
  }

  @Override
  public final IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
    setProperty(IProgressConstants.ACTION_PROPERTY, new OpenMavenConsoleAction());
    createdProjects = null;
    AbstractCreateMavenProjectsOperation op = new AbstractCreateMavenProjectsOperation(workingSets) {
      @Override
      protected List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException {
        return AbstractCreateMavenProjectJob.this.doCreateMavenProjects(monitor);
      }
    };
    try {
      op.run(monitor);
      List<IProject> projects = op.getCreatedProjects();
      if(projects != null) {
        createdProjects = Collections.unmodifiableList(projects);
      }
    } catch(InvocationTargetException e) {
      return AbstractCreateMavenProjectsOperation.toStatus(e);
    } catch(InterruptedException e) {
      return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
  }

  protected abstract List<IProject> doCreateMavenProjects(IProgressMonitor monitor) throws CoreException;

  protected static ArrayList<IProject> toProjects(List<IMavenProjectImportResult> results) {
    return AbstractCreateMavenProjectsOperation.toProjects(results);
  }

  /**
   * @return an unmodifiable list of created projects, or <code>null</code>
   * @since 1.6
   */
  public List<IProject> getCreatedProjects() {
    return createdProjects;
  }
}

Back to the top