|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.fail;
|
4 | 4 |
|
| 5 | +import java.io.IOException; |
| 6 | +import java.net.URISyntaxException; |
| 7 | +import java.net.URL; |
| 8 | + |
5 | 9 | import org.eclipse.cdt.core.model.ICModelMarker;
|
6 | 10 | import org.eclipse.core.resources.IMarker;
|
7 | 11 | import org.eclipse.core.resources.IProject;
|
8 | 12 | import org.eclipse.core.resources.IResource;
|
9 | 13 | import org.eclipse.core.runtime.CoreException;
|
| 14 | +import org.eclipse.core.runtime.FileLocator; |
10 | 15 | import org.eclipse.core.runtime.IPath;
|
11 | 16 | import org.eclipse.core.runtime.Path;
|
12 | 17 | import org.eclipse.core.runtime.Platform;
|
13 | 18 | import org.eclipse.core.runtime.jobs.IJobManager;
|
14 | 19 | import org.eclipse.core.runtime.jobs.Job;
|
| 20 | +import org.osgi.framework.Bundle; |
15 | 21 |
|
16 | 22 | import io.sloeber.core.api.BoardsManager;
|
17 | 23 | import io.sloeber.core.api.Other;
|
@@ -70,53 +76,21 @@ public static void waitForAllJobsToFinish() {
|
70 | 76 |
|
71 | 77 | public static IPath getTemplateFolder(String templateName) {
|
72 | 78 |
|
73 |
| - String gitHome = System.getenv("HOME"); |
| 79 | + try { |
| 80 | + Bundle bundle = Platform.getBundle("io.sloeber.tests"); |
| 81 | + Path path = new Path("src/templates/" + templateName); |
| 82 | + URL fileURL = FileLocator.find(bundle, path, null); |
| 83 | + URL resolvedFileURL=FileLocator.toFileURL(fileURL); |
| 84 | + return new Path(resolvedFileURL.toURI().getPath()); |
| 85 | + } catch (URISyntaxException e) { |
| 86 | + e.printStackTrace(); |
| 87 | + } catch (IOException e) { |
| 88 | + e.printStackTrace(); |
| 89 | + } |
74 | 90 |
|
75 |
| - if (Platform.getOS().equals(Platform.OS_WIN32)) { |
76 |
| - if (gitHome == null) { |
77 |
| - gitHome = System.getenv("HOMEDRIVE") + System.getenv("HOMEPATH"); |
78 |
| - } |
79 |
| - } else { |
80 |
| - if (gitHome == null) { |
81 |
| - System.err.println("Git HOME envvar is not define. Using default value"); |
82 |
| - gitHome = "~"; |
83 |
| - } |
84 | 91 |
|
85 |
| - } |
86 |
| - Path path = new Path(gitHome + "/git/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
87 |
| - if (path.toFile().exists()) { |
88 |
| - return path; |
89 |
| - } |
90 |
| - path = new Path(gitHome + "/.git/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
91 |
| - if (path.toFile().exists()) { |
92 |
| - return path; |
93 |
| - } |
94 |
| - path = new Path(gitHome + "/git/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
95 |
| - if (path.toFile().exists()) { |
96 |
| - return path; |
97 |
| - } |
98 |
| - path = new Path( |
99 |
| - gitHome + "/.git/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
100 |
| - if (path.toFile().exists()) { |
101 |
| - return path; |
102 |
| - } |
103 |
| - path = new Path(gitHome + "/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
104 |
| - if (path.toFile().exists()) { |
105 |
| - return path; |
106 |
| - } |
107 |
| - path = new Path( |
108 |
| - gitHome + "/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
109 |
| - if (path.toFile().exists()) { |
110 |
| - return path; |
111 |
| - } |
112 |
| - System.err.println("Failed to find templates in git repository. Checked following locations"); |
113 |
| - System.err.println("->"+gitHome + "/git/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
114 |
| - System.err.println("->"+gitHome + "/.git/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
115 |
| - System.err.println("->"+gitHome + "/git/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
116 |
| - System.err.println("->"+gitHome + "/.git/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
117 |
| - System.err.println("->"+gitHome + "/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
118 |
| - System.err.println("->"+gitHome + "/Sloeber/arduino-eclipse-plugin/io.sloeber.tests/src/templates/" + templateName); |
119 |
| - return path; |
| 92 | + System.err.println("Failed to find templates in io.sloeber.tests plugin."); |
| 93 | + return new Path(new String()); |
120 | 94 | }
|
121 | 95 |
|
122 | 96 | }
|
0 commit comments