mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-18 05:39:53 +01:00
More unit tests.
This commit is contained in:
@@ -15,8 +15,8 @@ import net.sf.briar.util.ZipUtils;
|
|||||||
|
|
||||||
class SetupWorker implements Runnable {
|
class SetupWorker implements Runnable {
|
||||||
|
|
||||||
private static final String MAIN_CLASS =
|
// FIXME: Change this when we have a main class
|
||||||
"net.sf.briar.ui.invitation.InvitationMain";
|
private static final String MAIN_CLASS = "net.sf.briar.ui.FIXME";
|
||||||
|
|
||||||
private final SetupCallback callback;
|
private final SetupCallback callback;
|
||||||
private final SetupParameters parameters;
|
private final SetupParameters parameters;
|
||||||
@@ -38,6 +38,7 @@ class SetupWorker implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
// Don't try to proceed if we're running from Eclipse
|
||||||
if(!jar.isFile()) {
|
if(!jar.isFile()) {
|
||||||
callback.error("Not running from jar");
|
callback.error("Not running from jar");
|
||||||
return;
|
return;
|
||||||
@@ -57,6 +58,7 @@ class SetupWorker implements Runnable {
|
|||||||
callback.notAllowed(dir);
|
callback.notAllowed(dir);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// If the chosen directory isn't empty, install to a subdirectory
|
||||||
if(list.length != 0) {
|
if(list.length != 0) {
|
||||||
dir = new File(dir, "Briar");
|
dir = new File(dir, "Briar");
|
||||||
if(!dir.exists() && !dir.mkdir()) {
|
if(!dir.exists() && !dir.mkdir()) {
|
||||||
@@ -64,6 +66,7 @@ class SetupWorker implements Runnable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Everything but the launchers will go in the Data directory
|
||||||
File data = new File(dir, "Data");
|
File data = new File(dir, "Data");
|
||||||
if(!data.exists() && !data.mkdir()) {
|
if(!data.exists() && !data.mkdir()) {
|
||||||
callback.notAllowed(data);
|
callback.notAllowed(data);
|
||||||
@@ -73,12 +76,15 @@ class SetupWorker implements Runnable {
|
|||||||
if(callback.isCancelled()) return;
|
if(callback.isCancelled()) return;
|
||||||
copyInstaller(jar, data);
|
copyInstaller(jar, data);
|
||||||
if(callback.isCancelled()) return;
|
if(callback.isCancelled()) return;
|
||||||
|
// Only extract the Windows JRE, jars and fonts
|
||||||
extractFiles(jar, data, "^jre/.*|.*\\.jar$|.*\\.ttf$");
|
extractFiles(jar, data, "^jre/.*|.*\\.jar$|.*\\.ttf$");
|
||||||
if(callback.isCancelled()) return;
|
if(callback.isCancelled()) return;
|
||||||
createLaunchers(dir);
|
createLaunchers(dir);
|
||||||
if(callback.isCancelled()) return;
|
if(callback.isCancelled()) return;
|
||||||
|
// Save the chosen locale for the first launch
|
||||||
i18n.saveLocale(data);
|
i18n.saveLocale(data);
|
||||||
if(callback.isCancelled()) return;
|
if(callback.isCancelled()) return;
|
||||||
|
// Installation succeeded - delete the installer
|
||||||
jar.deleteOnExit();
|
jar.deleteOnExit();
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
callback.error(e.getMessage());
|
callback.error(e.getMessage());
|
||||||
@@ -88,12 +94,14 @@ class SetupWorker implements Runnable {
|
|||||||
callback.installed(dir);
|
callback.installed(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a copy of the installer for use in future invitations
|
||||||
private void copyInstaller(File jar, File dir) throws IOException {
|
private void copyInstaller(File jar, File dir) throws IOException {
|
||||||
File dest = new File(dir, "setup.dat");
|
File dest = new File(dir, "setup.dat");
|
||||||
callback.copyingFile(dest);
|
callback.copyingFile(dest);
|
||||||
FileUtils.copy(jar, dest);
|
FileUtils.copy(jar, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extract files matching the given regex from the jar
|
||||||
private void extractFiles(File jar, File dir, String regex)
|
private void extractFiles(File jar, File dir, String regex)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
FileInputStream in = new FileInputStream(jar);
|
FileInputStream in = new FileInputStream(jar);
|
||||||
@@ -101,10 +109,12 @@ class SetupWorker implements Runnable {
|
|||||||
ZipUtils.unzipStream(in, dir, regex, unzipCallback);
|
ZipUtils.unzipStream(in, dir, regex, unzipCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create launchers for Windows, Mac and Linux
|
||||||
private void createLaunchers(File dir) throws IOException {
|
private void createLaunchers(File dir) throws IOException {
|
||||||
createWindowsLauncher(dir);
|
createWindowsLauncher(dir);
|
||||||
File mac = createMacLauncher(dir);
|
File mac = createMacLauncher(dir);
|
||||||
File lin = createLinuxLauncher(dir);
|
File lin = createLinuxLauncher(dir);
|
||||||
|
// If the OS supports chmod, make the Mac and Linux launchers executable
|
||||||
if(!OsUtils.isWindows()) {
|
if(!OsUtils.isWindows()) {
|
||||||
String[] chmod = { "chmod", "u+x", mac.getName(), lin.getName() };
|
String[] chmod = { "chmod", "u+x", mac.getName(), lin.getName() };
|
||||||
ProcessBuilder p = new ProcessBuilder(chmod);
|
ProcessBuilder p = new ProcessBuilder(chmod);
|
||||||
|
|||||||
@@ -137,6 +137,9 @@ public class SetupWorkerTest extends TestCase {
|
|||||||
assertTrue(fooTtf.isFile());
|
assertTrue(fooTtf.isFile());
|
||||||
assertEquals("three three three".length(), fooTtf.length());
|
assertEquals("three three three".length(), fooTtf.length());
|
||||||
assertFalse(fooXyz.exists());
|
assertFalse(fooXyz.exists());
|
||||||
|
assertTrue(new File(testDir, "Briar/run-windows.vbs").exists());
|
||||||
|
assertTrue(new File(testDir, "Briar/run-mac.command").exists());
|
||||||
|
assertTrue(new File(testDir, "Briar/run-linux.sh").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createJar() throws IOException {
|
private void createJar() throws IOException {
|
||||||
|
|||||||
Reference in New Issue
Block a user