Skip to content

Commit f459329

Browse files
committed
Remove dependency on working directory
1 parent 8e08b6b commit f459329

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

kubernetes/src/test/java/oracle/kubernetes/operator/helm/ProcessedChart.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
import java.io.InputStream;
1313
import java.io.InputStreamReader;
1414
import java.net.URISyntaxException;
15-
import java.net.URL;
1615
import java.nio.charset.Charset;
1716
import java.nio.file.Files;
1817
import java.nio.file.Path;
19-
import java.nio.file.Paths;
2018
import java.util.ArrayList;
2119
import java.util.List;
2220
import java.util.Map;
2321
import java.util.Objects;
22+
import oracle.kubernetes.operator.utils.PathUtils;
2423
import oracle.kubernetes.operator.utils.YamlReader;
2524
import org.yaml.snakeyaml.Yaml;
2625

@@ -117,7 +116,7 @@ public Iterable<Object> getYamlDocuments() throws Exception {
117116
*
118117
* @return a map of values
119118
*/
120-
public Map<String, Object> getValues() throws Exception {
119+
Map<String, Object> getValues() throws Exception {
121120
getYamlDocuments();
122121

123122
return values;
@@ -164,23 +163,6 @@ private File getChartDir(String chartName) throws URISyntaxException {
164163
}
165164

166165
private File getChartsParentDir() throws URISyntaxException {
167-
return new File(getModuleDir(), "charts");
168-
}
169-
170-
private File getModuleDir() throws URISyntaxException {
171-
return getTargetDir(getClass()).getParentFile();
172-
}
173-
174-
private File getTargetDir(Class<?> aClass) throws URISyntaxException {
175-
File dir = getPackageDir(aClass);
176-
while (dir.getParent() != null && !dir.getName().equals("target")) {
177-
dir = dir.getParentFile();
178-
}
179-
return dir;
180-
}
181-
182-
private File getPackageDir(Class<?> aClass) throws URISyntaxException {
183-
URL url = aClass.getResource(aClass.getSimpleName() + ".class");
184-
return Paths.get(url.toURI()).toFile().getParentFile();
166+
return new File(PathUtils.getModuleDir(getClass()), "charts");
185167
}
186168
}

kubernetes/src/test/java/oracle/kubernetes/operator/utils/CreateOperatorInputs.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import static oracle.kubernetes.operator.utils.YamlUtils.newYaml;
88

9+
import java.io.File;
910
import java.io.Reader;
11+
import java.net.URISyntaxException;
1012
import java.nio.charset.Charset;
11-
import java.nio.file.FileSystems;
1213
import java.nio.file.Files;
1314
import java.nio.file.Path;
1415

@@ -26,7 +27,7 @@
2627
*/
2728
public class CreateOperatorInputs extends OperatorValues {
2829

29-
private static final String DEFAULT_INPUTS = "../kubernetes/create-weblogic-operator-inputs.yaml";
30+
private static final String DEFAULT_INPUTS = "create-weblogic-operator-inputs.yaml";
3031

3132
public static OperatorValues readDefaultInputsFile() throws Exception {
3233
return readInputsYamlFile(defaultInputsPath());
@@ -37,7 +38,7 @@ private static OperatorValues readInputsYamlFile(Path path) throws Exception {
3738
return newYaml().loadAs(r, CreateOperatorInputs.class);
3839
}
3940

40-
private static Path defaultInputsPath() {
41-
return FileSystems.getDefault().getPath(DEFAULT_INPUTS);
41+
private static Path defaultInputsPath() throws URISyntaxException {
42+
return new File(PathUtils.getModuleDir(CreateOperatorInputs.class), DEFAULT_INPUTS).toPath();
4243
}
4344
}

kubernetes/src/test/java/oracle/kubernetes/operator/utils/ExecCreateOperator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ public static ExecResult execCreateOperator(
3131
}
3232

3333
public static ExecResult execCreateOperator(String options) throws Exception {
34-
return ExecCommand.exec(CREATE_SCRIPT + options);
34+
return ExecCommand.exec(
35+
PathUtils.getModuleDir(ExecCreateOperator.class) + "/" + CREATE_SCRIPT + options);
3536
}
3637

37-
public static Path getInputsYamlPath(Path userProjectsPath) {
38+
private static Path getInputsYamlPath(Path userProjectsPath) {
3839
return userProjectsPath.resolve("create-weblogic-operator-inputs.yaml");
3940
}
4041
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package oracle.kubernetes.operator.utils;
2+
3+
import java.io.File;
4+
import java.net.URISyntaxException;
5+
import java.net.URL;
6+
import java.nio.file.Paths;
7+
8+
public class PathUtils {
9+
public static File getModuleDir(Class<?> aClass) throws URISyntaxException {
10+
return getTargetDir(aClass).getParentFile();
11+
}
12+
13+
private static File getTargetDir(Class<?> aClass) throws URISyntaxException {
14+
File dir = getPackageDir(aClass);
15+
while (dir.getParent() != null && !dir.getName().equals("target")) {
16+
dir = dir.getParentFile();
17+
}
18+
return dir;
19+
}
20+
21+
private static File getPackageDir(Class<?> aClass) throws URISyntaxException {
22+
URL url = aClass.getResource(aClass.getSimpleName() + ".class");
23+
return Paths.get(url.toURI()).toFile().getParentFile();
24+
}
25+
}

0 commit comments

Comments
 (0)