-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathGemsConfig.java
More file actions
202 lines (162 loc) · 5.03 KB
/
GemsConfig.java
File metadata and controls
202 lines (162 loc) · 5.03 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
*
*/
package de.saumya.mojo.ruby.gems;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GemsConfig {
private static final String GEM_PATH = "GEM_PATH";
private static final String GEM_HOME = "GEM_HOME";
private String env;
private File gemBase;
private File gemHome;
private List<File> gemPaths = new ArrayList<File>();
private File[] gemsDirectory;
private File binDirectory;
private boolean addRI = false;
private boolean addRdoc = false;
private boolean verbose = false;
private boolean userInstall = false;
private boolean systemInstall = false;
public void setAddRI(final boolean addRI) {
this.addRI = addRI;
}
public boolean isAddRI() {
return this.addRI;
}
public void setAddRdoc(final boolean addRdoc) {
this.addRdoc = addRdoc;
}
public boolean isAddRdoc() {
return this.addRdoc;
}
public void setVerbose(final boolean verbose) {
this.verbose = verbose;
}
public boolean isVerbose() {
return this.verbose;
}
public void setUserInstall(final boolean userInstall) {
this.userInstall = userInstall;
}
public void setSystemInstall(final boolean systemInstall) {
this.systemInstall = systemInstall;
}
public boolean isUserInstall() {
return this.userInstall;
}
public boolean isSystemInstall() {
return this.systemInstall;
}
public File[] getGemsDirectory() {
if (this.gemsDirectory == null) {
File[] paths = getGemPath();
this.gemsDirectory = new File[paths.length];
int index = 0;
for(File path: paths){
this.gemsDirectory[index++] = new File(path, "gems");
}
}
return this.gemsDirectory;
}
public void setBinDirectory(File binDirectory) {
this.binDirectory = binDirectory;
}
public File getBinDirectory() {
if (this.binDirectory == null) {
if(getGemHome() != null){
return new File(getGemHome(), "bin");
}
else {
return null;
}
}
return this.binDirectory;
}
public File binScriptFile(final String scriptName) {
if (getBinDirectory() == null){
// TODO something better
return new File(scriptName);
}
else {
return new File(getBinDirectory(), scriptName);
}
}
public String getEnvironment() {
return this.env;
}
public void setEnvironment(final String env) {
this.env = env;
setGemBase(this.gemBase);
}
public void setGemBase(final File base) {
this.gemBase = base;
if (this.gemBase != null) {
final String postfix = this.env == null ? "" : "-" + this.env;
this.gemHome = new File(this.gemBase.getPath() + postfix);
this.gemPaths.set(0, new File(this.gemBase.getPath() + postfix));
}
}
public boolean hasGemBase() {
return this.gemBase != null;
}
public void setGemHome(final File home) {
this.gemHome = home;
this.gemBase = null;
}
public void addGemPath(final File path) {
if( path != null ){
this.gemPaths.add(path);
this.gemBase = null;
this.gemsDirectory = null;
}
}
public File getGemHome() {
if (this.gemHome == null || systemInstall) {
if (System.getenv(GEM_HOME) == null) {
return null;
}
else {
return new File(System.getenv(GEM_HOME));
}
}
else {
return this.gemHome;
}
}
public File[] getGemPath() {
if (this.gemPaths.size() == 0 || systemInstall) {
if (System.getenv(GEM_PATH) == null) {
return new File[0];
}
else {
return new File[] {new File(System.getenv(GEM_PATH))};
}
}
else {
return this.gemPaths.toArray(new File[this.gemPaths.size()]);
}
}
@Override
public GemsConfig clone() {
final GemsConfig clone = new GemsConfig();
clone.setEnvironment(this.env);
if (this.gemBase != null) {
clone.setGemBase(this.gemBase);
}
else {
clone.setGemHome(this.gemHome);
for(File path: this.gemPaths){
clone.addGemPath(path);
}
}
clone.addRdoc = this.addRdoc;
clone.addRI = this.addRI;
clone.userInstall = this.userInstall;
clone.systemInstall = this.systemInstall;
clone.verbose = this.verbose;
clone.binDirectory = this.binDirectory;
return clone;
}
}