blob: b1862d26aa861ca8f1a865e539367535937ba95f (
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
94
95
96
97
98
99
100
101
102
103
|
/*******************************************************************************
* Copyright (c) 2008, 2010 Intel Corporation, QNX Software Systems, and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Intel Corporation - initial API and implementation
* QNX Software Systems - [272416] Rework the working set configurations
*******************************************************************************/
package org.eclipse.cdt.internal.ui.workingsets;
import java.util.Collection;
import org.eclipse.cdt.internal.ui.newui.Messages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
/**
* A job that builds a bunch of workspace projects or a working set configuration.
*/
public final class BuildJob extends Job {
private Collection<IProject> projects;
private IWorkingSetConfiguration workingSetConfig;
/**
* Initializes me with a bunch projects to build in their active configurations.
*
* @param projects
* the projects to build
*/
public BuildJob(Collection<IProject> projects) {
super(Messages.WorkingSetConfigAction_21);
this.projects = new java.util.ArrayList<>(projects);
}
/**
* Initializes me with a working set configuration to build.
*
* @param workingSetConfig
* the working set configuration to build
*/
public BuildJob(IWorkingSetConfiguration workingSetConfig) {
super(Messages.WorkingSetConfigAction_21);
this.workingSetConfig = workingSetConfig;
}
@Override
protected IStatus run(IProgressMonitor monitor) {
if (projects != null) {
return buildProjects(monitor);
} else {
return buildWorkingSetConfig(monitor);
}
}
private IStatus buildProjects(IProgressMonitor monitor) {
try {
for (IProject p : projects) {
try {
setName(Messages.WorkingSetConfigAction_21 + p.getName());
p.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
} catch (CoreException e) {
return new MultiStatus(CUIPlugin.PLUGIN_ID, 0, new IStatus[] { e.getStatus() },
Messages.WorkingSetConfigAction_22, null);
}
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
}
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
private IStatus buildWorkingSetConfig(IProgressMonitor monitor) {
try {
return workingSetConfig.build(monitor);
} finally {
monitor.done();
}
}
@Override
public boolean belongsTo(Object family) {
return ResourcesPlugin.FAMILY_MANUAL_BUILD == family;
}
}
|