This repository has been archived by the owner on Apr 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 290
/
CommonBuildTargetOperation.java
99 lines (78 loc) · 3.88 KB
/
CommonBuildTargetOperation.java
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
/*******************************************************************************
* Copyright (c) 2015 Bruno Medeiros and other Contributors.
* 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:
* Bruno Medeiros - initial API and implementation
*******************************************************************************/
package melnorme.lang.ide.core.operations.build;
import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import java.nio.file.Path;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import melnorme.lang.ide.core.launch.LaunchUtils;
import melnorme.lang.ide.core.operations.AbstractToolManagerOperation;
import melnorme.lang.ide.core.operations.OperationInfo;
import melnorme.utilbox.collections.ArrayList2;
import melnorme.utilbox.concurrency.OperationCancellation;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.StringUtil;
import melnorme.utilbox.process.ExternalProcessHelper.ExternalProcessResult;
public abstract class CommonBuildTargetOperation extends AbstractToolManagerOperation {
protected final BuildManager buildManager;
protected final OperationInfo parentOperationInfo;
protected final BuildTargetRunner buildTarget;
protected final Path buildToolPath;
protected final boolean fullBuild;
public CommonBuildTargetOperation(BuildManager buildManager, OperationInfo parentOpInfo, IProject project,
Path buildToolPath, BuildTargetRunner buildTarget, boolean fullBuild) {
super(project);
this.buildManager = assertNotNull(buildManager);
this.buildToolPath = buildToolPath;
this.fullBuild = fullBuild;
this.parentOperationInfo = assertNotNull(parentOpInfo);
this.buildTarget = assertNotNull(buildTarget);
}
protected Path getBuildToolPath() throws CommonException {
return buildToolPath;
}
protected String getConfiguration() {
return StringUtil.nullAsEmpty(buildTarget.getBuildConfigName());
}
public String getBuildType() {
return StringUtil.nullAsEmpty(buildTarget.getBuildTypeName());
}
protected String getEffectiveBuildOptions() throws CommonException, CoreException {
return buildTarget.getEffectiveBuildOptions();
}
protected String[] getEvaluatedAndParserArguments() throws CoreException, CommonException {
return LaunchUtils.getEvaluatedAndParsedArguments(getEffectiveBuildOptions());
}
@Override
public void execute(IProgressMonitor pm) throws CoreException, CommonException, OperationCancellation {
ProcessBuilder pb = getToolProcessBuilder();
ExternalProcessResult processResult = runBuildTool(pm, pb);
processBuildOutput(processResult);
}
protected ProcessBuilder getToolProcessBuilder() throws CoreException, CommonException, OperationCancellation {
ArrayList2<String> commands = new ArrayList2<String>();
addToolCommand(commands);
addMainArguments(commands);
commands.addElements(getEvaluatedAndParserArguments());
return getProcessBuilder(commands);
}
protected void addToolCommand(ArrayList2<String> commands)
throws CoreException, CommonException, OperationCancellation {
commands.add(getBuildToolPath().toString());
}
protected abstract void addMainArguments(ArrayList2<String> commands)
throws CoreException, CommonException, OperationCancellation;
protected abstract ProcessBuilder getProcessBuilder(ArrayList2<String> commands)
throws CommonException, OperationCancellation, CoreException;
protected abstract void processBuildOutput(ExternalProcessResult processResult)
throws CoreException, CommonException, OperationCancellation;
}