forked from rayh/xcode-hudson-plugin
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathXcodeInstallation.java
More file actions
130 lines (113 loc) · 4.31 KB
/
XcodeInstallation.java
File metadata and controls
130 lines (113 loc) · 4.31 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package hudson.plugins.xcode;
import hudson.EnvVars;
import hudson.Extension;
import hudson.model.EnvironmentSpecific;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.slaves.NodeSpecific;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
import hudson.tools.ToolProperty;
import hudson.util.FormValidation;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
/**
* Information about Xcode installation.
*
* @author Kazuhide Takahashi
*/
public class XcodeInstallation extends ToolInstallation implements NodeSpecific<XcodeInstallation>, EnvironmentSpecific<XcodeInstallation> {
/**
* Constructor for XcodeInstallation.
*
* @param name Tool name (for example, "Xcode 9.3")
* @param home Tool location (usually "/Applications/Xcode.app/Contents/Developer")
* @param properties {@link java.util.List} of properties for this tool
*/
@DataBoundConstructor
public XcodeInstallation(String name, String home, List<? extends ToolProperty<?>> properties) {
super(name, home, properties);
}
public static XcodeInstallation[] allInstallations() {
Jenkins instance = Jenkins.getInstance();
if ( instance != null ) {
DescriptorImpl descriptor = instance.getDescriptorByType(DescriptorImpl.class);
if ( descriptor != null ) {
XcodeInstallation[] installations = descriptor.getInstallations();
if ( installations != null ) {
return installations;
}
}
}
return new XcodeInstallation[0];
}
/**
* getXcodebuild.
*
* @return {@link java.lang.String} that will be used to execute xcodebuild (e.g. "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild")
*/
public String getXcodebuild() {
return getHome() + "/usr/bin/xcodebuild";
}
private static XcodeInstallation[] getInstallations(DescriptorImpl descriptor) {
XcodeInstallation[] installations = null;
try {
installations = descriptor.getInstallations();
} catch (NullPointerException e) {
installations = new XcodeInstallation[0];
}
return installations;
}
public XcodeInstallation forNode(Node node, TaskListener log) throws IOException, InterruptedException {
return new XcodeInstallation(getName(), translateFor(node, log), Collections.<ToolProperty<?>>emptyList());
}
public XcodeInstallation forEnvironment(EnvVars environment) {
return new XcodeInstallation(getName(), environment.expand(getHome()), Collections.<ToolProperty<?>>emptyList());
}
@Override
public DescriptorImpl getDescriptor() {
Jenkins jenkinsInstance = Jenkins.getInstance();
if (jenkinsInstance == null) {
/* Throw AssertionError exception to match behavior of Jenkins.getDescriptorOrDie */
throw new AssertionError("No Jenkins instance");
}
return (DescriptorImpl) jenkinsInstance.getDescriptorOrDie(getClass());
}
@Extension @Symbol("xcode")
public static class DescriptorImpl extends ToolDescriptor<XcodeInstallation> {
public DescriptorImpl() {
load();
}
@Override
public String getDisplayName() {
return "Xcode tools";
}
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray(new XcodeInstallation[0]));
save();
return true;
}
public FormValidation doCheckHome(@QueryParameter File value) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
String path = value.getPath() + "/usr/bin/xcodebuild";
return FormValidation.validateExecutable(path);
}
public XcodeInstallation getInstallation(String name) {
for(XcodeInstallation i : getInstallations()) {
if(i.getName().equals(name)) {
return i;
}
}
return null;
}
}
}