Skip to content

Commit 13ca370

Browse files
author
madhe
committed
2 parents 4d514eb + 227e62a commit 13ca370

File tree

10 files changed

+204
-148
lines changed

10 files changed

+204
-148
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,51 +125,51 @@ jobs:
125125
GITHUB_TOKEN: ${{ github.token }}
126126
with:
127127
upload_url: ${{ steps.create_release.outputs.upload_url }}
128-
asset_path: BowlerLauncher-x86_64.AppImage
129-
asset_name: BowlerLauncher-x86_64.AppImage
128+
asset_path: BowlerLauncher-Linux-x86_64.AppImage
129+
asset_name: BowlerLauncher-Linux-x86_64.AppImage
130130
asset_content_type: application/octet-stream
131131
- name: upload Debian
132132
uses: actions/upload-release-asset@v1
133133
env:
134134
GITHUB_TOKEN: ${{ github.token }}
135135
with:
136136
upload_url: ${{ steps.create_release.outputs.upload_url }}
137-
asset_path: BowlerLauncher-x86_64.deb
138-
asset_name: BowlerLauncher-x86_64.deb
137+
asset_path: BowlerLauncher-Linux-x86_64.deb
138+
asset_name: BowlerLauncher-Linux-x86_64.deb
139139
asset_content_type: application/octet-stream
140140
- name: upload Windows exe
141141
uses: actions/upload-release-asset@v1
142142
env:
143143
GITHUB_TOKEN: ${{ github.token }}
144144
with:
145145
upload_url: ${{ steps.create_release.outputs.upload_url }}
146-
asset_path: BowlerLauncher-x86_64.exe
147-
asset_name: BowlerLauncher-x86_64.exe
146+
asset_path: BowlerLauncher-Windows-x86_64.exe
147+
asset_name: BowlerLauncher-Windows-x86_64.exe
148148
asset_content_type: application/exe
149149
- name: upload Windows zip
150150
uses: actions/upload-release-asset@v1
151151
env:
152152
GITHUB_TOKEN: ${{ github.token }}
153153
with:
154154
upload_url: ${{ steps.create_release.outputs.upload_url }}
155-
asset_path: BowlerLauncher-x86_64.zip
156-
asset_name: BowlerLauncher-x86_64.zip
155+
asset_path: BowlerLauncher-Windows-x86_64.zip
156+
asset_name: BowlerLauncher-Windows-x86_64.zip
157157
asset_content_type: application/zip
158158
- name: upload MacOS dmg x86
159159
uses: actions/upload-release-asset@v1
160160
env:
161161
GITHUB_TOKEN: ${{ github.token }}
162162
with:
163163
upload_url: ${{ steps.create_release.outputs.upload_url }}
164-
asset_path: BowlerLauncher-x86_64.dmg
165-
asset_name: BowlerLauncher-x86_64.dmg
164+
asset_path: BowlerLauncher-MacOS-x86_64.dmg
165+
asset_name: BowlerLauncher-MacOS-x86_64.dmg
166166
asset_content_type: application/octet-stream
167167
- name: upload MacOS dmg arm
168168
uses: actions/upload-release-asset@v1
169169
env:
170170
GITHUB_TOKEN: ${{ github.token }}
171171
with:
172172
upload_url: ${{ steps.create_release.outputs.upload_url }}
173-
asset_path: BowlerLauncher-arm64.dmg
174-
asset_name: BowlerLauncher-arm64.dmg
173+
asset_path: BowlerLauncher-MacOS-arm64.dmg
174+
asset_name: BowlerLauncher-MacOS-arm64.dmg
175175
asset_content_type: application/octet-stream

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ HatRack*
1919
/zulu*.zip*
2020
/zulu*.tar*
2121
**.deb
22-
/release/
22+
release
23+
**.DS_Store**

lib/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/bin/

lib/bin/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/bin/test/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 108 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.commonwealthrobotics;
22

33
import java.io.BufferedInputStream;
4+
import java.io.BufferedReader;
45
import java.io.File;
56
import java.io.FileInputStream;
67
import java.io.FileNotFoundException;
78
import java.io.FileOutputStream;
89
import java.io.IOException;
910
import java.io.InputStream;
11+
import java.io.InputStreamReader;
1012
import java.io.OutputStream;
1113
import java.lang.reflect.Type;
1214
import java.net.MalformedURLException;
1315
import java.net.URL;
1416
import java.net.URLConnection;
1517
import java.nio.charset.Charset;
18+
import java.nio.charset.StandardCharsets;
1619
import java.nio.file.Files;
1720
import java.nio.file.Path;
1821
import java.nio.file.Paths;
@@ -21,13 +24,16 @@
2124
import java.util.HashMap;
2225
import java.util.List;
2326
import java.util.Map;
24-
import java.util.zip.ZipEntry;
25-
import java.util.zip.ZipFile;
27+
import java.util.stream.Collectors;
28+
//import java.util.zip.ZipEntry;
29+
//import java.util.zip.ZipFile;
2630

2731
import org.apache.commons.compress.archivers.examples.Archiver;
2832
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
2933
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
3034
import org.apache.commons.compress.archivers.tar.TarUtils;
35+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
36+
import org.apache.commons.compress.archivers.zip.ZipFile;
3137
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
3238
import org.apache.commons.compress.utils.IOUtils;
3339
import org.apache.commons.io.FilenameUtils;
@@ -43,8 +49,11 @@ public class JvmManager {
4349

4450
public static String getCommandString(String project, String repo, String version, String downloadJsonURL,
4551
long sizeOfJson, ProgressBar progress, String bindir) throws Exception {
46-
47-
File exe = download(version, downloadJsonURL, sizeOfJson, progress, bindir, "jvm.json");
52+
if(version==null)
53+
throw new RuntimeException("Version can not be null");
54+
File exe;
55+
56+
exe= download(version, downloadJsonURL, sizeOfJson, progress, bindir, "jvm.json");
4857
Type TT_mapStringString = new TypeToken<HashMap<String, Object>>() {
4958
}.getType();
5059
// chreat the gson object, this is the parsing factory
@@ -53,28 +62,7 @@ public static String getCommandString(String project, String repo, String versio
5362

5463
HashMap<String, Object> database = gson.fromJson(jsonText, TT_mapStringString);
5564
String key = "UNKNOWN";
56-
if (LatestFromGithubLaunchUI.isLin()) {
57-
if (LatestFromGithubLaunchUI.isArm()) {
58-
key = "Linux-aarch64";
59-
} else {
60-
key = "Linux-x64";
61-
}
62-
}
63-
64-
if (LatestFromGithubLaunchUI.isMac()) {
65-
if (LatestFromGithubLaunchUI.isArm()) {
66-
key = "Mac-aarch64";
67-
} else {
68-
key = "Mac-x64";
69-
}
70-
}
71-
if (LatestFromGithubLaunchUI.isWin()) {
72-
if (LatestFromGithubLaunchUI.isArm()) {
73-
key = "UNKNOWN";
74-
} else {
75-
key = "Windows-x64";
76-
}
77-
}
65+
key = discoverKey(key);
7866
Map<String, Object> vm = (Map<String, Object>) database.get(key);
7967
String baseURL = vm.get("url").toString();
8068
String type = vm.get("type").toString();
@@ -87,16 +75,16 @@ public static String getCommandString(String project, String repo, String versio
8775
jvmargs = new ArrayList<String>();
8876
String jvmURL = baseURL + name + "." + type;
8977
File jvmArchive = download("", jvmURL, 185000000, progress, bindir, name + "." + type);
90-
File dest = new File(bindir+name);
91-
if(!dest.exists()) {
78+
File dest = new File(bindir + name);
79+
if (!dest.exists()) {
9280
if (type.toLowerCase().contains("zip")) {
9381
unzip(jvmArchive, bindir);
9482
}
9583
if (type.toLowerCase().contains("tar.gz")) {
9684
untar(jvmArchive, bindir);
9785
}
98-
}else {
99-
System.out.println("Not extraction, VM exists "+dest.getAbsolutePath());
86+
} else {
87+
System.out.println("Not extraction, VM exists " + dest.getAbsolutePath());
10088
}
10189
String cmd = bindir + name + "/bin/java" + (LatestFromGithubLaunchUI.isWin() ? ".exe" : "") + " ";
10290
for (String s : jvmargs) {
@@ -105,24 +93,75 @@ public static String getCommandString(String project, String repo, String versio
10593
return cmd + " -jar ";
10694
}
10795

96+
private static String discoverKey(String key) {
97+
if (LatestFromGithubLaunchUI.isLin()) {
98+
if (LatestFromGithubLaunchUI.isArm()) {
99+
key = "Linux-aarch64";
100+
} else {
101+
key = "Linux-x64";
102+
}
103+
}
104+
105+
if (LatestFromGithubLaunchUI.isMac()) {
106+
if (LatestFromGithubLaunchUI.isArm()) {
107+
key = "Mac-aarch64";
108+
} else {
109+
key = "Mac-x64";
110+
}
111+
}
112+
if (LatestFromGithubLaunchUI.isWin()) {
113+
if (LatestFromGithubLaunchUI.isArm()) {
114+
key = "UNKNOWN";
115+
} else {
116+
key = "Windows-x64";
117+
}
118+
}
119+
return key;
120+
}
121+
122+
public static boolean isExecutable(ZipArchiveEntry entry) {
123+
int unixMode = entry.getUnixMode();
124+
// Check if any of the executable bits are set for user, group, or others.
125+
// User executable: 0100 (0x40), Group executable: 0010 (0x10), Others
126+
// executable: 0001 (0x01)
127+
return (unixMode & 0x49) != 0;
128+
}
129+
108130
private static void unzip(File path, String dir) throws Exception {
109131
String fileBaseName = FilenameUtils.getBaseName(path.getName().toString());
110132
Path destFolderPath = new File(dir).toPath();
111133

112-
try (ZipFile zipFile = new ZipFile(path, ZipFile.OPEN_READ, Charset.defaultCharset())) {
113-
Enumeration<? extends ZipEntry> entries = zipFile.entries();
134+
try (ZipFile zipFile = ZipFile.builder().setFile(path).get()) {
135+
Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
114136
while (entries.hasMoreElements()) {
115-
ZipEntry entry = entries.nextElement();
137+
ZipArchiveEntry entry = entries.nextElement();
116138
Path entryPath = destFolderPath.resolve(entry.getName());
117139
if (entryPath.normalize().startsWith(destFolderPath.normalize())) {
118140
if (entry.isDirectory()) {
119141
Files.createDirectories(entryPath);
120142
} else {
121143
Files.createDirectories(entryPath.getParent());
122144
try (InputStream in = zipFile.getInputStream(entry)) {
145+
try {
146+
// ar.setExternalAttributes(entry.extraAttributes);
147+
if (entry.isUnixSymlink()) {
148+
String text = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
149+
.lines().collect(Collectors.joining("\n"));
150+
Path target = Paths.get(".", text);
151+
System.out.println("Creating symlink " + entryPath + " with " + target);
152+
153+
Files.createSymbolicLink(entryPath, target);
154+
continue;
155+
}
156+
} catch (Exception ex) {
157+
ex.printStackTrace();
158+
}
123159
try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
124160
IOUtils.copy(in, out);
125161
}
162+
if (isExecutable(entry)) {
163+
entryPath.toFile().setExecutable(true);
164+
}
126165
}
127166
}
128167
}
@@ -141,7 +180,7 @@ private static void untar(File tarFile, String dir) throws Exception {
141180
// tarIn is a TarArchiveInputStream
142181
while (tarEntry != null) {// create a file with the same name as the tarEntry
143182
File destPath = new File(dest.toString() + System.getProperty("file.separator") + tarEntry.getName());
144-
//System.out.println("working: " + destPath.getCanonicalPath());
183+
// System.out.println("working: " + destPath.getCanonicalPath());
145184
if (tarEntry.isDirectory()) {
146185
destPath.mkdirs();
147186
} else {
@@ -152,54 +191,60 @@ private static void untar(File tarFile, String dir) throws Exception {
152191
fout.write(b);
153192
fout.close();
154193
int mode = tarEntry.getMode();
155-
b= new byte[5];
194+
b = new byte[5];
156195
TarUtils.formatUnsignedOctalString(mode, b, 0, 4);
157-
if(bits(b[1]).endsWith("1")) {
196+
if (bits(b[1]).endsWith("1")) {
158197
destPath.setExecutable(true);
159198
}
160199
}
161200
tarEntry = tarIn.getNextTarEntry();
162201
}
163202
tarIn.close();
164203
}
204+
165205
private static String bits(byte b) {
166206
return String.format("%6s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
167207
}
168208

169209
private static File download(String version, String downloadJsonURL, long sizeOfJson, ProgressBar progress,
170210
String bindir, String filename) throws MalformedURLException, IOException, FileNotFoundException {
171-
URL url = new URL(downloadJsonURL);
172-
URLConnection connection = url.openConnection();
173-
InputStream is = connection.getInputStream();
174-
ProcessInputStream pis = new ProcessInputStream(is, (int) sizeOfJson);
175-
pis.addListener(new Listener() {
176-
@Override
177-
public void process(double percent) {
178-
System.out.println("Download percent " + percent);
179-
Platform.runLater(() -> {
180-
progress.setProgress(percent);
181-
});
182-
}
183-
});
184211
File folder = new File(bindir + version + "/");
185212
File exe = new File(bindir + version + "/" + filename);
213+
try {
214+
URL url = new URL(downloadJsonURL);
215+
URLConnection connection = url.openConnection();
216+
InputStream is = connection.getInputStream();
217+
ProcessInputStream pis = new ProcessInputStream(is, (int) sizeOfJson);
218+
pis.addListener(new Listener() {
219+
@Override
220+
public void process(double percent) {
221+
System.out.println("Download percent " + percent);
222+
Platform.runLater(() -> {
223+
progress.setProgress(percent);
224+
});
225+
}
226+
});
186227

187-
if (!folder.exists() || !exe.exists()) {
188-
System.out.println("Start Downloading " + filename);
189-
folder.mkdirs();
190-
exe.createNewFile();
191-
byte dataBuffer[] = new byte[1024];
192-
int bytesRead;
193-
FileOutputStream fileOutputStream = new FileOutputStream(exe.getAbsoluteFile());
194-
while ((bytesRead = pis.read(dataBuffer, 0, 1024)) != -1) {
195-
fileOutputStream.write(dataBuffer, 0, bytesRead);
228+
if (!folder.exists() || !exe.exists()) {
229+
System.out.println("Start Downloading " + filename);
230+
folder.mkdirs();
231+
exe.createNewFile();
232+
byte dataBuffer[] = new byte[1024];
233+
int bytesRead;
234+
FileOutputStream fileOutputStream = new FileOutputStream(exe.getAbsoluteFile());
235+
while ((bytesRead = pis.read(dataBuffer, 0, 1024)) != -1) {
236+
fileOutputStream.write(dataBuffer, 0, bytesRead);
237+
}
238+
fileOutputStream.close();
239+
pis.close();
240+
System.out.println("Finished downloading " + filename);
241+
} else {
242+
System.out.println("Not downloadeing, it existst " + filename);
196243
}
197-
fileOutputStream.close();
198-
pis.close();
199-
System.out.println("Finished downloading " + filename);
200-
} else {
201-
System.out.println("Not downloadeing, it existst " + filename);
244+
} catch (Throwable t) {
245+
t.printStackTrace();
202246
}
247+
System.out.println("Using JVM "+exe.getAbsolutePath());
203248
return exe;
204249
}
205250
}

0 commit comments

Comments
 (0)