Skip to content

Commit 2f0b30c

Browse files
committed
Make the working directory modular wherever they are used
1 parent ff7c49a commit 2f0b30c

File tree

6 files changed

+62
-14
lines changed

6 files changed

+62
-14
lines changed

src/main/java/com/neuronrobotics/bowlerstudio/BowlerStudio.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine;
2424
import com.neuronrobotics.bowlerstudio.scripting.ScriptingFileWidget;
2525
import com.neuronrobotics.bowlerstudio.scripting.StlLoader;
26+
import com.neuronrobotics.bowlerstudio.scripting.external.GroovyEclipseExternalEditor;
2627
import com.neuronrobotics.bowlerstudio.util.FileChangeWatcher;
2728
import com.neuronrobotics.bowlerstudio.vitamins.Vitamins;
2829
//import com.neuronrobotics.imageprovider.OpenCVJNILoader;
@@ -118,6 +119,12 @@ public class BowlerStudio extends Application {
118119

119120
@SuppressWarnings({ "unchecked", "restriction" })
120121
public static void main(String[] args) throws Exception {
122+
String relative = ScriptingEngine.getWorkingDirectory().getAbsolutePath();
123+
File file = new File(relative + delim() + "bowler-workspace" + delim());
124+
file.mkdirs();
125+
ScriptingEngine.setWorkspace(file);
126+
DownloadManager.setSTUDIO_INSTALL("BowlerStudioInstall");
127+
121128
if (args.length != 0) {
122129
//com.neuronrobotics.sdk.common.Log.error("Arguments detected, starting Kernel mode.");
123130
//SplashManager.closeSplash();
@@ -648,7 +655,7 @@ public static void select(File script, int lineNumber) {
648655
public static String getBowlerStudioBinaryVersion() throws FileNotFoundException {
649656
String latestVersionString;
650657
File currentVerFile = new File(System.getProperty("user.home") + delim() + "bin" + delim()
651-
+ "BowlerStudioInstall" + delim() + "currentversion.txt");
658+
+ getInstallDirStub() + delim() + "currentversion.txt");
652659
String s = "";
653660
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(currentVerFile)));
654661
String line;
@@ -663,7 +670,7 @@ public static String getBowlerStudioBinaryVersion() throws FileNotFoundException
663670
}
664671
private static void makeSymLinkOfCurrentVersion() throws Exception {
665672
String version = getBowlerStudioBinaryVersion();
666-
File installDir = new File(System.getProperty("user.home") + delim() + "bin" + delim()+ "BowlerStudioInstall" + delim());
673+
File installDir = new File(System.getProperty("user.home") + delim() + "bin" + delim()+ getInstallDirStub() + delim());
667674
File link = new File(installDir.getAbsolutePath()+delim()+"latest");
668675
File latest = new File(installDir.getAbsolutePath()+delim()+version);
669676
if(link.exists())
@@ -678,7 +685,8 @@ private static void makeSymLinkOfCurrentVersion() throws Exception {
678685
com.neuronrobotics.sdk.common.Log.error("Path created "+ret);
679686
}
680687
}
681-
688+
689+
682690
public static void ensureUpdated(String ... urls) {
683691
for(String s:urls) {
684692
if(s==null)
@@ -966,6 +974,16 @@ public void onDeviceRemoved(BowlerAbstractDevice arg0) {
966974
System.out.println("Bowler-Scripting-Kernel Version: " + BowlerKernelBuildInfo.getVersion());
967975
System.out.println("JavaCad Version: " + JavaCadBuildInfo.getVersion());
968976
System.out.println("Welcome to BowlerStudio!");
977+
978+
979+
try {
980+
File jarFile = new File(GroovyEclipseExternalEditor.getApplicationJarPath());
981+
System.out.println("Application at "+jarFile+" is "+(jarFile.exists()?"Found":"Missing!"));
982+
} catch (FileNotFoundException e) {
983+
// TODO Auto-generated catch block
984+
e.printStackTrace();
985+
986+
}
969987

970988
});
971989
closeSplash();
@@ -1168,4 +1186,11 @@ public static boolean checkValidURL(String url) {
11681186
}
11691187
return true;
11701188
}
1189+
public static String getInstallDirStub() {
1190+
return DownloadManager.getSTUDIO_INSTALL();
1191+
}
1192+
1193+
public static void setInstallDirStub(String installDirStub) {
1194+
DownloadManager.setSTUDIO_INSTALL(installDirStub);
1195+
}
11711196
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/external/ArduinoExternalEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public static void main(String[] args) throws Exception {
9696
*/
9797
// File exe = DownloadManager.getRunExecutable("arduino2", null);
9898
// File file = new File();
99-
String absolutePath = "C:\\Users\\Kevin Bad Name\\bin\\BowlerStudioInstall\\arduino2\\Arduino IDE.exe";// exe.getAbsolutePath();
100-
run(null, new File("C:\\Users\\Kevin Bad Name\\bin\\BowlerStudioInstall\\arduino2"), System.err, Arrays.asList(
99+
String absolutePath = "C:\\Users\\Kevin Bad Name\\bin\\" + DownloadManager.getSTUDIO_INSTALL() + "\\arduino2\\Arduino IDE.exe";// exe.getAbsolutePath();
100+
run(null, new File("C:\\Users\\Kevin Bad Name\\bin\\" + DownloadManager.getSTUDIO_INSTALL() + "\\arduino2"), System.err, Arrays.asList(
101101
absolutePath,
102102
"C:\\Users\\Kevin Bad Name\\Documents\\bowler-workspace\\gitcache\\github.com\\OperationSmallKat\\LunaMotherboardFirmware\\LunaMotherboardFirmware.ino"));
103103

src/main/java/com/neuronrobotics/bowlerstudio/scripting/external/EclipseExternalEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void launch(File file, Button advanced) {
150150
environment.putAll(env);
151151
File settings = new File(ScriptingEngine.getWorkspace().getAbsolutePath() + delim() + "appdata"
152152
+ delim() + "bowler-settings.epf");
153-
File java = DownloadManager.getConfigExecutable("java8", null);
153+
File java = DownloadManager.getConfigExecutable("java17", null);
154154
if (!wsDir.exists()) {
155155
File prefssource = ScriptingEngine.fileFromGit(
156156
"https://github.com/CommonWealthRobotics/ExternalEditorsBowlerStudio.git",

src/main/java/com/neuronrobotics/bowlerstudio/scripting/external/GroovyEclipseExternalEditor.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.neuronrobotics.bowlerstudio.BowlerStudio;
88
import com.neuronrobotics.bowlerstudio.scripting.BashLoader;
99
import com.neuronrobotics.bowlerstudio.scripting.CaDoodleLoader;
10+
import com.neuronrobotics.bowlerstudio.scripting.DownloadManager;
1011
import com.neuronrobotics.bowlerstudio.scripting.GroovyHelper;
1112
import com.neuronrobotics.bowlerstudio.scripting.JsonRunner;
1213
import com.neuronrobotics.bowlerstudio.scripting.RobotHelper;
@@ -37,6 +38,7 @@
3738

3839
public class GroovyEclipseExternalEditor extends EclipseExternalEditor {
3940

41+
4042
public void onProcessExit(int ev) {
4143
advanced.setDisable(false);
4244
}
@@ -95,12 +97,8 @@ protected void setUpEclipseProjectFiles(File dir , File project, String name) th
9597
// }
9698
//latestVersionString = BowlerStudio.getBowlerStudioBinaryVersion();
9799

98-
String jar = System.getProperty("user.home") + delim()+"bin"+delim()+"BowlerStudioInstall"+ delim()+ "latest"
99-
+delim()+ "BowlerStudio.jar";
100-
if(!new File(jar).exists()) {
101-
jar = System.getProperty("user.home") + delim()+"bin"+delim()+"BowlerStudioInstall"+ delim()+ BowlerStudio.getBowlerStudioBinaryVersion()
102-
+delim()+ "BowlerStudio.jar";
103-
}
100+
String jar = getApplicationJarPath();
101+
104102
String classpathContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<classpath>\n"
105103
+ " <classpathentry kind=\"src\" path=\"\"/>\n"
106104
+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.launching.JRE_CONTAINER\">\n"
@@ -114,6 +112,11 @@ protected void setUpEclipseProjectFiles(File dir , File project, String name) th
114112
}
115113

116114

115+
public static String getApplicationJarPath() throws FileNotFoundException {
116+
return getApplicationBinaryDirectory()+ getSTUDIO_JAR();
117+
}
118+
119+
117120

118121
public static void main(String[] args) throws Exception {
119122
JavaFXInitializer.go();
@@ -134,4 +137,24 @@ protected boolean checkForExistingProjectFiles(File dir ) {
134137
public List<Class> getSupportedLangauge() {
135138
return Arrays.asList( GroovyHelper.class,BashLoader.class, JsonRunner.class,RobotHelper.class,CaDoodleLoader.class);
136139
}
140+
141+
142+
public static String getSTUDIO_JAR() throws FileNotFoundException {
143+
File dir = new File(getApplicationBinaryDirectory());
144+
for(String s:dir.list()) {
145+
if(s.toLowerCase().endsWith(".jar")) {
146+
return s;
147+
}
148+
}
149+
throw new RuntimeException("Studio Jar can not be found in "+dir.getAbsolutePath());
150+
}
151+
152+
153+
public static String getApplicationBinaryDirectory() throws FileNotFoundException {
154+
return System.getProperty("user.home") + delim()+"bin"+delim()+DownloadManager.getSTUDIO_INSTALL()+ delim()+ BowlerStudio.getBowlerStudioBinaryVersion()
155+
+delim();
156+
}
157+
158+
159+
137160
}

src/main/java/com/neuronrobotics/bowlerstudio/scripting/external/SceneBuilderExternalEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void launch(File file, Button advanced) {
4343
try {
4444
File dir = file.getAbsoluteFile().getParentFile();
4545
File scenebuilder = DownloadManager.getRunExecutable("scenebuilder", null);
46-
File java = DownloadManager.getRunExecutable("java8", null);
46+
File java = DownloadManager.getRunExecutable("java17", null);
4747

4848
List<String> asList = Arrays.asList(
4949
java.getAbsolutePath(),

0 commit comments

Comments
 (0)