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
/
ProjectBuildArtifactValidator.java
108 lines (83 loc) · 3.99 KB
/
ProjectBuildArtifactValidator.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
100
101
102
103
104
105
106
107
108
/*******************************************************************************
* 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.launch;
import java.nio.file.Path;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import melnorme.lang.ide.core.LangCore;
import melnorme.lang.ide.core.operations.build.BuildManager;
import melnorme.lang.ide.core.operations.build.BuildTarget;
import melnorme.lang.ide.core.operations.build.BuildTargetRunner;
import melnorme.lang.ide.core.utils.ProjectValidator;
import melnorme.lang.ide.core.utils.ResourceUtils;
import melnorme.lang.tooling.data.AbstractValidator2;
import melnorme.lang.tooling.data.StatusException;
import melnorme.lang.tooling.data.ValidationMessages;
import melnorme.utilbox.core.CommonException;
import melnorme.utilbox.misc.Location;
public class ProjectBuildArtifactValidator extends AbstractValidator2 {
protected final ProjectBuildExecutableSettings settings;
public ProjectBuildArtifactValidator(ProjectBuildExecutableSettings settings) {
this.settings = settings;
}
protected BuildManager getBuildManager() {
return LangCore.getBuildManager();
}
public static interface ProjectBuildExecutableSettings {
public abstract String getProject_Attribute() throws CoreException;
public abstract String getExecutablePath_Attribute() throws CoreException;
public abstract String getBuildTarget_Attribute() throws CoreException;
}
/* ----------------- ----------------- */
public IProject getProject() throws StatusException, CoreException {
return getProject(settings.getProject_Attribute());
}
public IProject getProject(String projectName) throws StatusException, CoreException {
return getProjectValidator().getProject(projectName);
}
protected ProjectValidator getProjectValidator() {
return new ProjectValidator();
}
/* ----------------- ----------------- */
public BuildTargetValidator getBuildTargetValidator() {
return new BuildTargetValidator(false);
}
public BuildTarget getBuildTarget() throws CoreException, CommonException {
return getBuildTargetValidator().getBuildTarget(getProject(), settings.getBuildTarget_Attribute());
}
public BuildTarget getBuildTarget_NonNull() throws CoreException, CommonException {
return getBuildTargetValidator().getBuildTarget_nonNull(getProject(), settings.getBuildTarget_Attribute());
}
/* ----------------- ----------------- */
protected Path getValidExecutableFilePath2() throws CoreException, CommonException {
BuildTarget buildTarget = getBuildTarget_NonNull();
BuildTargetRunner buildTargetOperation = getBuildManager().getBuildTargetOperation(getProject(), buildTarget);
String exePathString = settings.getExecutablePath_Attribute();
if(exePathString != null) {
return buildTargetOperation.getValidArtifactPath(exePathString);
}
return buildTargetOperation.getValidArtifactPath();
}
public Location toAbsolute(Path exePath) throws StatusException, CoreException {
if(exePath.isAbsolute()) {
return Location.fromAbsolutePath(exePath);
}
// Otherwise path is relative to project location
return ResourceUtils.loc(getProject().getLocation()).resolve(exePath);
}
public Location getValidExecutableFileLocation() throws CoreException, CommonException {
Location location = toAbsolute(getValidExecutableFilePath2());
if(location.toFile().exists() && !location.toFile().isFile()) {
error(ValidationMessages.Location_NotAFile(location));
}
return location;
}
}