Passes JVM user.language arg to application.. This is important
Hook battery / PR-target hook battery (push) Successful in 11s

This commit is contained in:
Hammer
2026-07-21 15:19:51 -04:00
parent 2e892c4ef4
commit 15b81a210f
34 changed files with 133 additions and 1405 deletions
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="getdown-core" />
<module name="getdown-ant" />
<module name="getdown-launcher" />
</profile>
</annotationProcessing>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="getdown-ant" options="-Xlint -Xlint:-serial -Xlint:-path" />
<module name="getdown-core" options="-Xlint -Xlint:-serial -Xlint:-path" />
<module name="getdown-launcher" options="-Xlint -Xlint:-serial -Xlint:-path" />
</option>
</component>
</project>
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ant/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/ant/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/launcher/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/launcher/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="lib-repo" />
<option name="name" value="lib-repo" />
<option name="url" value="file://F:\projects\bang-mods\getdown\launcher/../lib" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_25" default="true" project-jdk-name="openjdk-25" project-jdk-type="JavaSDK" />
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
+3 -3
View File
@@ -2,9 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown</artifactId> <artifactId>getdown</artifactId>
<version>1.8.11-SNAPSHOT</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>getdown-ant</artifactId> <artifactId>getdown-ant</artifactId>
@@ -14,7 +14,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown-core</artifactId> <artifactId>getdown-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
+2 -2
View File
@@ -2,9 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown</artifactId> <artifactId>getdown</artifactId>
<version>1.8.11-SNAPSHOT</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>getdown-core</artifactId> <artifactId>getdown-core</artifactId>
@@ -1,54 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.tests;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import com.threerings.getdown.tools.Digester;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DigesterIT {
@Test
public void testDigester () throws Exception {
Path appdir = Paths.get("src/it/resources/testapp");
Digester.createDigests(appdir.toFile(), null, null, null);
Path digest = appdir.resolve("digest.txt");
List<String> digestLines = Files.readAllLines(digest, StandardCharsets.UTF_8);
Files.delete(digest);
Path digest2 = appdir.resolve("digest2.txt");
List<String> digest2Lines = Files.readAllLines(digest2, StandardCharsets.UTF_8);
Files.delete(digest2);
assertEquals(Arrays.asList(
"getdown.txt = 9c9b2494929c99d44ae51034d59e1a1b",
"testapp.jar = 404dafa55e78b25ec0e3a936357b1883",
"funny%test dir/some=file.txt = d8e8fca2dc0f896fd7cb4cb0031ba249",
"crazyhashfile#txt = f29d23fd5ab1781bd8d0760b3a516f16",
"foo.jar = 46ca4cc9079d9d019bb30cd21ebbc1ec",
"script.sh = f66e8ea25598e67e99c47d9b0b2a2cdf",
"digest.txt = 11f9ba349cf9edacac4d72a3158447e5"
), digestLines);
assertEquals(Arrays.asList(
"getdown.txt = 1efecfae2a189002a6658f17d162b1922c7bde978944949276dc038a0df2461f",
"testapp.jar = c9cb1906afbf48f8654b416c3f831046bd3752a76137e5bf0a9af2f790bf48e0",
"funny%test dir/some=file.txt = f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2",
"crazyhashfile#txt = 6816889f922de38f145db215a28ad7c5e1badf7354b5cdab225a27486789fa3b",
"foo.jar = ea188b872e0496debcbe00aaadccccb12a8aa9b025bb62c130cd3d9b8540b062",
"script.sh = cca1c5c7628d9bf7533f655a9cfa6573d64afb8375f81960d1d832dc5135c988",
"digest2.txt = 41eacdabda8909bdbbf61e4f980867f4003c16a12f6770e6fc619b6af100e05b"
), digest2Lines);
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 KiB

@@ -1 +0,0 @@
Hello crazy world.
Binary file not shown.
@@ -1 +0,0 @@
test
-40
View File
@@ -1,40 +0,0 @@
# where our app is hosted on the internets
appbase = http://notused.com/testapp
# the jar file that contains our code
code = testapp.jar
# the main entry point of our app
class = com.threerings.testapp.TestApp
# we pass the appdir to our app so that it can upgrade getdown
apparg = %APPDIR%
# test the %env% mechanism
jvmarg = -Dusername=\%ENV.USER%
# test various java_*** configs, they are not interesting for digester
java_local_dir = jre
java_max_version = 1089999
java_min_version = [windows] 1080111
java_min_version = [!windows] 1080192
java_exact_version_required = [linux] true
java_location = [linux-amd64] /files/java/java_linux_64.zip
java_location = [linux-i386] /files/java/java_linux_32.zip
java_location = [mac] /files/java/java_mac_64.zip
java_location = [windows-amd64] /files/java/java_windows_64.zip
java_location = [windows-x86] /files/java/java_windows_32.zip
strict_comments = true
resource = funny%test dir/some=file.txt
resource = crazyhashfile#txt
uresource = foo.jar
xresource = script.sh
ui.name = Getdown Test App
ui.background_image = background.png
ui.progress = 17, 321, 458, 22
ui.progress_bar = 336600
ui.progress_text = FFFFFF
ui.status = 57, 245, 373, 68
ui.status_text = 000000
-3
View File
@@ -1,3 +0,0 @@
#!/bin/sh
echo "Hello world!"
Binary file not shown.
@@ -1027,6 +1027,12 @@ public class Application
// add the marker indicating the app is running in getdown // add the marker indicating the app is running in getdown
args.add("-D" + Properties.GETDOWN + "=true"); args.add("-D" + Properties.GETDOWN + "=true");
// forward the current JVM's language setting to the launched app
String userLanguage = System.getProperty("user.language");
if (!StringUtil.isBlank(userLanguage)) {
args.add("-Duser.language=" + userLanguage);
}
// set the native library path if we have native resources // set the native library path if we have native resources
// @TODO optional getdown.txt parameter to set addCurrentLibraryPath to true or false? // @TODO optional getdown.txt parameter to set addCurrentLibraryPath to true or false?
ClassPath javaLibPath = PathBuilder.buildLibsPath(this, true); ClassPath javaLibPath = PathBuilder.buildLibsPath(this, true);
@@ -1715,7 +1721,15 @@ public class Application
} }
for (String rsrc : rsrcs) { for (String rsrc : rsrcs) {
try { try {
list.add(createResource(rsrc, attrs)); Resource res = createResource(rsrc, attrs);
// skip duplicate entries: a config publisher bug once stacked the code list 11x,
// and on Windows the duplicated -classpath blew past the 32,767-char
// CreateProcess limit (error=206); duplicates also multiply download/verify work
if (list.contains(res)) {
log.warning("Skipping duplicate resource '" + rsrc + "'.");
continue;
}
list.add(res);
} catch (Exception e) { } catch (Exception e) {
log.warning("Invalid resource '" + rsrc + "'. " + e); log.warning("Invalid resource '" + rsrc + "'. " + e);
} }
@@ -1,84 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.cache;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue;
/**
* Validates that cache garbage is collected and deleted correctly.
*/
@RunWith(Parameterized.class)
public class GarbageCollectorTest
{
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{ ".jar" }, { ".zip" }});
}
@Parameterized.Parameter
public String extension;
@Before public void setupFiles () throws IOException
{
_cachedFile = _folder.newFile("abc123" + extension);
_lastAccessedFile = _folder.newFile(
"abc123" + extension + ResourceCache.LAST_ACCESSED_FILE_SUFFIX);
}
@Test public void shouldDeleteCacheEntryIfRetentionPeriodIsReached ()
{
gcNow();
assertFalse(_cachedFile.exists());
assertFalse(_lastAccessedFile.exists());
}
@Test public void shouldDeleteCacheFolderIfFolderIsEmpty ()
{
gcNow();
assertFalse(_folder.getRoot().exists());
}
private void gcNow() {
GarbageCollector.collect(_folder.getRoot(), -1);
}
@Test public void shouldKeepFilesInCacheIfRententionPeriodIsNotReached ()
{
GarbageCollector.collect(_folder.getRoot(), TimeUnit.DAYS.toMillis(1));
assertTrue(_cachedFile.exists());
assertTrue(_lastAccessedFile.exists());
}
@Test public void shouldDeleteCachedFileIfLastAccessedFileIsMissing ()
{
assumeTrue(_lastAccessedFile.delete());
gcNow();
assertFalse(_cachedFile.exists());
}
@Test public void shouldDeleteLastAccessedFileIfCachedFileIsMissing ()
{
assumeTrue(_cachedFile.delete());
gcNow();
assertFalse(_lastAccessedFile.exists());
}
@Rule public final TemporaryFolder _folder = new TemporaryFolder();
private File _cachedFile;
private File _lastAccessedFile;
}
@@ -1,84 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.cache;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.Assert.*;
/**
* Asserts the correct functionality of the {@link ResourceCache}.
*/
@RunWith(Parameterized.class)
public class ResourceCacheTest
{
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{ ".jar" }, { ".zip" }});
}
@Parameterized.Parameter
public String extension;
@Before public void setupCache () throws IOException {
_fileToCache = _folder.newFile("filetocache" + extension);
_cache = new ResourceCache(_folder.newFolder(".cache"));
}
@Test public void shouldCacheFile () throws IOException
{
assertEquals("abc123" + extension, cacheFile().getName());
}
private File cacheFile() throws IOException
{
return _cache.cacheFile(_fileToCache, "abc123", "abc123");
}
@Test public void shouldTrackFileUsage () throws IOException
{
String name = "abc123" + extension + ResourceCache.LAST_ACCESSED_FILE_SUFFIX;
File lastAccessedFile = new File(cacheFile().getParentFile(), name);
assertTrue(lastAccessedFile.exists());
}
@Test public void shouldNotCacheTheSameFile () throws Exception
{
File cachedFile = cacheFile();
cachedFile.setLastModified(YESTERDAY);
long expectedLastModified = cachedFile.lastModified();
// caching it another time
File sameCachedFile = cacheFile();
assertEquals(expectedLastModified, sameCachedFile.lastModified());
}
@Test public void shouldRememberWhenFileWasRequested () throws Exception
{
File cachedFile = cacheFile();
String name = cachedFile.getName() + ResourceCache.LAST_ACCESSED_FILE_SUFFIX;
File lastAccessedFile = new File(cachedFile.getParentFile(), name);
lastAccessedFile.setLastModified(YESTERDAY);
long lastAccessed = lastAccessedFile.lastModified();
// caching it another time
cacheFile();
assertTrue(lastAccessedFile.lastModified() > lastAccessed);
}
@Rule public final TemporaryFolder _folder = new TemporaryFolder();
private File _fileToCache;
private ResourceCache _cache;
private static final long YESTERDAY = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1);
}
@@ -1,75 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.data;
import java.io.IOException;
import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.junit.*;
import static org.junit.Assert.*;
import com.threerings.getdown.util.Config;
public class ApplicationTest {
Application createApp () {
List<EnvConfig.Note> notes = new ArrayList<>();
EnvConfig env = EnvConfig.create(new String[0], notes);
EnvConfigTest.checkNoNotes(notes);
return new Application(env);
}
@Test public void testBaseConfig () throws Exception {
Application app = createApp();
URL appbase = new URL("https://test.com/foo/bar/");
Config config = new Config(Config.parseData(toReader(
"appbase", appbase.toString()
), Config.createOpts(true)));
app.initBase(config);
assertEquals(appbase, app.getRemoteURL(""));
}
@Test public void testVersionedBase () throws Exception {
Application app = createApp();
String rootAppbase = "https://test.com/foo/bar/";
Config config = new Config(Config.parseData(toReader(
"appbase", rootAppbase + "%VERSION%",
"version", "42"
), Config.createOpts(true)));
app.initBase(config);
assertEquals(new URL(rootAppbase + "42/"), app.getRemoteURL(""));
}
@Test public void testEnvVarBase () throws Exception {
// fiddling to make test work on Windows or Unix
String evar = System.getenv("USER") == null ? "USERNAME" : "USER";
Application app = createApp();
String rootAppbase = "https://test.com/foo/%ENV." + evar + "%/";
Config config = new Config(Config.parseData(toReader(
"appbase", rootAppbase + "%VERSION%",
"version", "42"
), Config.createOpts(true)));
app.initBase(config);
String expectAppbase = "https://test.com/foo/" + System.getenv(evar) + "/42/";
assertEquals(new URL(expectAppbase), app.getRemoteURL(""));
}
protected static StringReader toReader (String... pairs)
{
StringBuilder builder = new StringBuilder();
for (int ii = 0; ii < pairs.length; ii += 2) {
builder.append(pairs[ii]).append("=").append(pairs[ii+1]).append("\n");
}
return new StringReader(builder.toString());
}
}
@@ -1,54 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.data;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.LinkedHashSet;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link ClassPath}.
*/
public class ClassPathTest
{
@Before public void createJarsAndSetupClassPath () throws IOException
{
_firstJar = _folder.newFile("a.jar");
_secondJar = _folder.newFile("b.jar");
LinkedHashSet<File> classPathEntries = new LinkedHashSet<>();
classPathEntries.add(_firstJar);
classPathEntries.add(_secondJar);
_classPath = new ClassPath(classPathEntries);
}
@Test public void shouldCreateValidArgumentString ()
{
assertEquals(
"a.jar:b.jar",
_classPath.asArgumentString(_folder.getRoot()));
}
@Test public void shouldProvideJarUrls () throws URISyntaxException
{
URL[] actualUrls = _classPath.asUrls();
assertEquals(_firstJar, new File(actualUrls[0].toURI()));
assertEquals(_secondJar, new File(actualUrls[1].toURI()));
}
@Rule public final TemporaryFolder _folder = new TemporaryFolder();
private File _firstJar, _secondJar;
private ClassPath _classPath;
}
@@ -1,142 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.File;
import org.junit.*;
import static org.junit.Assert.*;
public class EnvConfigTest {
static final String CWD = System.getProperty("user.dir");
static final String TESTID = "testid";
static final String TESTBASE = "https://test.com/test";
private void debugNotes (List<EnvConfig.Note> notes) {
for (EnvConfig.Note note : notes) {
System.out.println(note.message);
}
}
static void checkNoNotes (List<EnvConfig.Note> notes) {
StringBuilder msg = new StringBuilder();
for (EnvConfig.Note note : notes) {
if (note.level != EnvConfig.Note.Level.INFO) {
msg.append("\n").append(note.message);
}
}
if (msg.length() > 0) {
fail("Unexpected notes:" + msg);
}
}
private void checkDir (EnvConfig cfg) {
assertTrue(cfg != null);
assertEquals(new File(CWD), cfg.appDir);
}
private void checkNoAppId (EnvConfig cfg) {
assertNull(cfg.appId);
}
private void checkAppId (EnvConfig cfg, String appId) {
assertEquals(appId, cfg.appId);
}
private void checkAppBase (EnvConfig cfg, String appBase) {
assertEquals(appBase, cfg.appBase);
}
private void checkNoAppBase (EnvConfig cfg) {
assertNull(cfg.appBase);
}
private void checkNoAppArgs (EnvConfig cfg) {
assertTrue(cfg.appArgs.isEmpty());
}
private void checkAppArgs (EnvConfig cfg, String... args) {
assertEquals(Arrays.asList(args), cfg.appArgs);
}
@Test public void testArgvDir () {
List<EnvConfig.Note> notes = new ArrayList<>();
String[] args = { CWD };
EnvConfig cfg = EnvConfig.create(args, notes);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkNoAppId(cfg);
checkNoAppBase(cfg);
checkNoAppArgs(cfg);
}
@Test public void testArgvDirId () {
List<EnvConfig.Note> notes = new ArrayList<>();
String[] args = { CWD, TESTID };
EnvConfig cfg = EnvConfig.create(args, notes);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkAppId(cfg, TESTID);
checkNoAppBase(cfg);
checkNoAppArgs(cfg);
}
@Test public void testArgvDirArgs () {
List<EnvConfig.Note> notes = new ArrayList<>();
String[] args = { CWD, "", "one", "two" };
EnvConfig cfg = EnvConfig.create(args, notes);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkNoAppId(cfg);
checkNoAppBase(cfg);
checkAppArgs(cfg, "one", "two");
}
@Test public void testArgvDirIdArgs () {
List<EnvConfig.Note> notes = new ArrayList<>();
String[] args = { CWD, TESTID, "one", "two" };
EnvConfig cfg = EnvConfig.create(args, notes);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkAppId(cfg, TESTID);
checkNoAppBase(cfg);
checkAppArgs(cfg, "one", "two");
}
private EnvConfig sysPropsConfig (List<EnvConfig.Note> notes, String... keyVals) {
for (int ii = 0; ii < keyVals.length; ii += 2) {
System.setProperty(keyVals[ii], keyVals[ii+1]);
}
EnvConfig cfg = EnvConfig.create(new String[0], notes);
for (int ii = 0; ii < keyVals.length; ii += 2) {
System.clearProperty(keyVals[ii]);
}
return cfg;
}
@Test public void testSysPropsDir () {
List<EnvConfig.Note> notes = new ArrayList<>();
EnvConfig cfg = sysPropsConfig(notes, "appdir", CWD);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkNoAppId(cfg);
checkNoAppBase(cfg);
checkNoAppArgs(cfg);
}
@Test public void testSysPropsDirIdBase () {
List<EnvConfig.Note> notes = new ArrayList<>();
EnvConfig cfg = sysPropsConfig(notes, "appdir", CWD, "appid", TESTID, "appbase", TESTBASE);
// debugNotes(notes);
checkNoNotes(notes);
checkDir(cfg);
checkAppId(cfg, TESTID);
checkAppBase(cfg, TESTBASE);
checkNoAppArgs(cfg);
}
}
@@ -1,58 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.data;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class PathBuilderTest
{
@Before public void setupFilesAndResources () throws IOException
{
_firstJarFile = _appdir.newFile("a.jar");
_secondJarFile = _appdir.newFile("b.jar");
when(_firstJar.getFinalTarget()).thenReturn(_firstJarFile);
when(_secondJar.getFinalTarget()).thenReturn(_secondJarFile);
when(_application.getActiveCodeResources()).thenReturn(Arrays.asList(_firstJar, _secondJar));
when(_application.getAppDir()).thenReturn(_appdir.getRoot());
}
@Test public void shouldBuildDefaultClassPath () throws IOException
{
ClassPath classPath = PathBuilder.buildDefaultClassPath(_application);
assertEquals("a.jar:b.jar", classPath.asArgumentString(_appdir.getRoot()));
}
@Test public void shouldBuildCachedClassPath () throws IOException
{
when(_application.getDigest(_firstJar)).thenReturn("first");
when(_application.getDigest(_secondJar)).thenReturn("second");
when(_application.getCodeCacheRetentionDays()).thenReturn(1);
ClassPath classPath = PathBuilder.buildCachedClassPath(_application);
assertEquals(".cache/fi/first.jar:.cache/se/second.jar", classPath.asArgumentString(_appdir.getRoot()));
}
@Mock protected Application _application;
@Mock protected Resource _firstJar;
@Mock protected Resource _secondJar;
protected File _firstJarFile, _secondJarFile;
@Rule public final TemporaryFolder _appdir = new TemporaryFolder();
}
@@ -1,63 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.data;
import org.junit.*;
import static org.junit.Assert.*;
public class SysPropsTest {
@After public void clearProps () {
System.clearProperty("delay");
System.clearProperty("appbase_domain");
System.clearProperty("appbase_override");
}
private static final String[] APPBASES = {
"http://foobar.com/myapp",
"https://foobar.com/myapp",
"http://foobar.com:8080/myapp",
"https://foobar.com:8080/myapp"
};
@Test public void testStartDelay () {
assertEquals(0, SysProps.startDelay());
System.setProperty("delay", "x");
assertEquals(0, SysProps.startDelay());
System.setProperty("delay", "-7");
assertEquals(0, SysProps.startDelay());
System.setProperty("delay", "7");
assertEquals(7, SysProps.startDelay());
System.setProperty("delay", "1440");
assertEquals(1440, SysProps.startDelay());
System.setProperty("delay", "1441");
assertEquals(1440, SysProps.startDelay());
}
@Test public void testAppbaseDomain () {
System.setProperty("appbase_domain", "https://barbaz.com");
for (String appbase : APPBASES) {
assertEquals("https://barbaz.com/myapp", SysProps.overrideAppbase(appbase));
}
System.setProperty("appbase_domain", "http://barbaz.com");
for (String appbase : APPBASES) {
assertEquals("http://barbaz.com/myapp", SysProps.overrideAppbase(appbase));
}
}
@Test public void testAppbaseOverride () {
System.setProperty("appbase_override", "https://barbaz.com/newapp");
for (String appbase : APPBASES) {
assertEquals("https://barbaz.com/newapp", SysProps.overrideAppbase(appbase));
}
}
}
@@ -1,23 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Tests {@link Color}.
*/
public class ColorTest
{
@Test
public void testBrightness() {
assertEquals(0, Color.brightness(0xFF000000), 0.0000001);
assertEquals(1, Color.brightness(0xFFFFFFFF), 0.0000001);
assertEquals(0.0117647, Color.brightness(0xFF010203), 0.0000001);
assertEquals(1, Color.brightness(0xFF00FFC8), 0.0000001);
}
}
@@ -1,171 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import java.util.Random;
import org.junit.*;
import static org.junit.Assert.*;
/**
* Tests {@link Config}.
*/
public class ConfigTest
{
public static class Pair {
public final String key;
public final String value;
public Pair (String key, String value) {
this.key = key;
this.value = value;
}
}
public static final Pair[] SIMPLE_PAIRS = {
new Pair("one", "two"),
new Pair("three", "four"),
new Pair("five", "six"),
new Pair("seven", "eight"),
new Pair("nine", "ten"),
};
@Test public void testSimplePairs () throws IOException
{
List<String[]> pairs = Config.parsePairs(
toReader(SIMPLE_PAIRS), Config.createOpts(true));
for (int ii = 0; ii < SIMPLE_PAIRS.length; ii++) {
assertEquals(SIMPLE_PAIRS[ii].key, pairs.get(ii)[0]);
assertEquals(SIMPLE_PAIRS[ii].value, pairs.get(ii)[1]);
}
}
@Test public void testQualifiedPairs () throws IOException
{
Pair linux = new Pair("one", "[linux] two");
Pair mac = new Pair("three", "[mac os x] four");
Pair linuxAndMac = new Pair("five", "[linux, mac os x] six");
Pair linux64 = new Pair("seven", "[linux-x86_64] eight");
Pair linux64s = new Pair("nine", "[linux-x86_64, linux-amd64] ten");
Pair mac64 = new Pair("eleven", "[mac os x-x86_64] twelve");
Pair win64 = new Pair("thirteen", "[windows-x86_64] fourteen");
Pair notWin = new Pair("fifteen", "[!windows] sixteen");
Pair[] pairs = { linux, mac, linuxAndMac, linux64, linux64s, mac64, win64, notWin };
Config.ParseOpts opts = Config.createOpts(false);
opts.osname = "linux";
opts.osarch = "i386";
List<String[]> parsed = Config.parsePairs(toReader(pairs), opts);
assertTrue(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertTrue(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertFalse(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertTrue(exists(parsed, notWin.key));
opts.osarch = "x86_64";
parsed = Config.parsePairs(toReader(pairs), opts);
assertTrue(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertTrue(exists(parsed, linuxAndMac.key));
assertTrue(exists(parsed, linux64.key));
assertTrue(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertTrue(exists(parsed, notWin.key));
opts.osarch = "amd64";
parsed = Config.parsePairs(toReader(pairs), opts);
assertTrue(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertTrue(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertTrue(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertTrue(exists(parsed, notWin.key));
opts.osname = "mac os x";
opts.osarch = "x86_64";
parsed = Config.parsePairs(toReader(pairs), opts);
assertFalse(exists(parsed, linux.key));
assertTrue(exists(parsed, mac.key));
assertTrue(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertFalse(exists(parsed, linux64s.key));
assertTrue(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertTrue(exists(parsed, notWin.key));
opts.osname = "windows";
opts.osarch = "i386";
parsed = Config.parsePairs(toReader(pairs), opts);
assertFalse(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertFalse(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertFalse(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertFalse(exists(parsed, notWin.key));
opts.osarch = "x86_64";
parsed = Config.parsePairs(toReader(pairs), opts);
assertFalse(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertFalse(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertFalse(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertTrue(exists(parsed, win64.key));
assertFalse(exists(parsed, notWin.key));
opts.osarch = "amd64";
parsed = Config.parsePairs(toReader(pairs), opts);
assertFalse(exists(parsed, linux.key));
assertFalse(exists(parsed, mac.key));
assertFalse(exists(parsed, linuxAndMac.key));
assertFalse(exists(parsed, linux64.key));
assertFalse(exists(parsed, linux64s.key));
assertFalse(exists(parsed, mac64.key));
assertFalse(exists(parsed, win64.key));
assertFalse(exists(parsed, notWin.key));
}
protected static boolean exists (List<String[]> pairs, String key)
{
for (String[] pair : pairs) {
if (pair[0].equals(key)) {
return true;
}
}
return false;
}
protected static StringReader toReader (Pair[] pairs)
{
StringBuilder builder = new StringBuilder();
for (Pair pair : pairs) {
// throw some whitespace in to ensure it's trimmed
builder.append(whitespace()).append(pair.key).
append(whitespace()).append("=").
append(whitespace()).append(pair.value).
append(whitespace()).append("\n");
}
return new StringReader(builder.toString());
}
protected static String whitespace ()
{
return _rando.nextBoolean() ? " " : "";
}
protected static final Random _rando = new Random();
}
@@ -1,60 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import org.junit.*;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.*;
/**
* Tests {@link FileUtil}.
*/
public class FileUtilTest
{
@Test public void testReadLines () throws IOException
{
String data = "This is a test\nof a file with\na few lines\n";
List<String> lines = FileUtil.readLines(new StringReader(data));
String[] linesBySplit = data.split("\n");
assertEquals(linesBySplit.length, lines.size());
for (int ii = 0; ii < lines.size(); ii++) {
assertEquals(linesBySplit[ii], lines.get(ii));
}
}
@Test public void shouldCopyFile () throws IOException
{
File source = _folder.newFile("source.txt");
File target = new File(_folder.getRoot(), "target.txt");
assertFalse(target.exists());
FileUtil.copy(source, target);
assertTrue(target.exists());
}
@Test public void shouldRecursivelyWalkOverFilesAndFolders () throws IOException
{
_folder.newFile("a.txt");
new File(_folder.newFolder("b"), "b.txt").createNewFile();
class CountingVisitor implements FileUtil.Visitor {
int fileCount = 0;
@Override public void visit(File file) {
fileCount++;
}
}
CountingVisitor visitor = new CountingVisitor();
FileUtil.walkTree(_folder.getRoot(), visitor);
assertEquals(3, visitor.fileCount);
}
@Rule public final TemporaryFolder _folder = new TemporaryFolder();
}
@@ -1,159 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import static org.junit.Assert.assertEquals;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
/**
* Tests {@link HostWhitelist}.
*/
public class HostWhitelistTest
{
@Test
public void testVerify () throws MalformedURLException
{
checkCanVerify("foo.com", "http://foo.com", true);
checkCanVerify("foo.com", "http://foo.com/", true);
checkCanVerify("foo.com", "http://foo.com/x/y/z", true);
checkCanVerify("foo.com", "http://www.foo.com", false);
checkCanVerify("foo.com", "http://www.foo.com/", false);
checkCanVerify("foo.com", "http://www.foo.com/x/y/z", false);
checkCanVerify("foo.com", "http://a.b.foo.com", false);
checkCanVerify("foo.com", "http://a.b.foo.com/", false);
checkCanVerify("foo.com", "http://a.b.foo.com/x/y/z", false);
checkCanVerify("foo.com", "http://oo.com", false);
checkCanVerify("foo.com", "http://f.oo.com", false);
checkCanVerify("foo.com", "http://a.f.oo.com", false);
checkCanVerify("*.foo.com", "http://foo.com", false);
checkCanVerify("*.foo.com", "http://foo.com/", false);
checkCanVerify("*.foo.com", "http://foo.com/x/y/z", false);
checkCanVerify("*.foo.com", "http://www.foo.com", true);
checkCanVerify("*.foo.com", "http://www.foo.com/", true);
checkCanVerify("*.foo.com", "http://www.foo.com/x/y/z", true);
checkCanVerify("*.foo.com", "http://a.b.foo.com", true);
checkCanVerify("*.foo.com", "http://a.b.foo.com/", true);
checkCanVerify("*.foo.com", "http://a.b.foo.com/x/y/z", true);
checkCanVerify("*.foo.com", "http://oo.com", false);
checkCanVerify("*.foo.com", "http://f.oo.com", false);
checkCanVerify("*.foo.com", "http://a.f.oo.com", false);
checkCanVerify("*.com", "http://foo.com", true);
checkCanVerify("*.com", "http://foo.com/", true);
checkCanVerify("*.com", "http://foo.com/x/y/z", true);
checkCanVerify("*.com", "http://www.foo.com", true);
checkCanVerify("*.com", "http://www.foo.com/", true);
checkCanVerify("*.com", "http://www.foo.com/x/y/z", true);
checkCanVerify("*.com", "http://a.b.foo.com", true);
checkCanVerify("*.com", "http://a.b.foo.com/", true);
checkCanVerify("*.com", "http://a.b.foo.com/x/y/z", true);
checkCanVerify("*.com", "http://oo.com", true);
checkCanVerify("*.com", "http://f.oo.com", true);
checkCanVerify("*.com", "http://a.f.oo.com", true);
checkCanVerify("*.net", "http://foo.com", false);
checkCanVerify("*.net", "http://foo.com/", false);
checkCanVerify("*.net", "http://foo.com/x/y/z", false);
checkCanVerify("*.net", "http://www.foo.com", false);
checkCanVerify("*.net", "http://www.foo.com/", false);
checkCanVerify("*.net", "http://www.foo.com/x/y/z", false);
checkCanVerify("*.net", "http://a.b.foo.com", false);
checkCanVerify("*.net", "http://a.b.foo.com/", false);
checkCanVerify("*.net", "http://a.b.foo.com/x/y/z", false);
checkCanVerify("*.net", "http://oo.com", false);
checkCanVerify("*.net", "http://f.oo.com", false);
checkCanVerify("*.net", "http://a.f.oo.com", false);
checkCanVerify("www.*.com", "http://foo.com", false);
checkCanVerify("www.*.com", "http://foo.com/", false);
checkCanVerify("www.*.com", "http://foo.com/x/y/z", false);
checkCanVerify("www.*.com", "http://www.foo.com", true);
checkCanVerify("www.*.com", "http://www.foo.com/", true);
checkCanVerify("www.*.com", "http://www.foo.com/x/y/z", true);
checkCanVerify("www.*.com", "http://a.b.foo.com", false);
checkCanVerify("www.*.com", "http://a.b.foo.com/", false);
checkCanVerify("www.*.com", "http://a.b.foo.com/x/y/z", false);
checkCanVerify("www.*.com", "http://oo.com", false);
checkCanVerify("www.*.com", "http://f.oo.com", false);
checkCanVerify("www.*.com", "http://a.f.oo.com", false);
checkCanVerify("www.*.com", "http://www.a.f.oo.com", true);
checkCanVerify("foo.*", "http://foo.com", true);
checkCanVerify("foo.*", "http://foo.com/", true);
checkCanVerify("foo.*", "http://foo.com/x/y/z", true);
checkCanVerify("foo.*", "http://www.foo.com", false);
checkCanVerify("foo.*", "http://www.foo.com/", false);
checkCanVerify("foo.*", "http://www.foo.com/x/y/z", false);
checkCanVerify("foo.*", "http://a.b.foo.com", false);
checkCanVerify("foo.*", "http://a.b.foo.com/", false);
checkCanVerify("foo.*", "http://a.b.foo.com/x/y/z", false);
checkCanVerify("foo.*", "http://oo.com", false);
checkCanVerify("foo.*", "http://f.oo.com", false);
checkCanVerify("foo.*", "http://a.f.oo.com", false);
checkCanVerify("*.foo.*", "http://foo.com", false);
checkCanVerify("*.foo.*", "http://foo.com/", false);
checkCanVerify("*.foo.*", "http://foo.com/x/y/z", false);
checkCanVerify("*.foo.*", "http://www.foo.com", true);
checkCanVerify("*.foo.*", "http://www.foo.com/", true);
checkCanVerify("*.foo.*", "http://www.foo.com/x/y/z", true);
checkCanVerify("*.foo.*", "http://a.b.foo.com", true);
checkCanVerify("*.foo.*", "http://a.b.foo.com/", true);
checkCanVerify("*.foo.*", "http://a.b.foo.com/x/y/z", true);
checkCanVerify("*.foo.*", "http://oo.com", false);
checkCanVerify("*.foo.*", "http://f.oo.com", false);
checkCanVerify("*.foo.*", "http://a.f.oo.com", false);
checkCanVerify("127.0.0.1", "http://127.0.0.1", true);
checkCanVerify("127.0.0.1", "http://127.0.0.1/", true);
checkCanVerify("127.0.0.1", "http://127.0.0.1/x/y/z", true);
checkCanVerify("*.0.0.1", "http://127.0.0.1/abc", true);
checkCanVerify("127.*.0.1", "http://127.0.0.1/abc", true);
checkCanVerify("127.0.*.1", "http://127.0.0.1/abc", true);
checkCanVerify("127.0.0.*", "http://127.0.0.1/abc", true);
checkCanVerify("127.*.1", "http://127.0.0.1/abc", true);
checkCanVerify("*.0.1", "http://127.0.0.1/abc", true);
checkCanVerify("127.0.*", "http://127.0.0.1/abc", true);
checkCanVerify("*", "http://127.0.0.1/abc", true);
checkCanVerify("127.0.0.2", "http://127.0.0.1", false);
checkCanVerify("127.0.2.1", "http://127.0.0.1", false);
checkCanVerify("127.2.0.1", "http://127.0.0.1", false);
checkCanVerify("222.0.0.1", "http://127.0.0.1", false);
checkCanVerify("", "http://foo.com", true);
checkCanVerify("", "http://aaa.bbb.net/xyz", true);
checkCanVerify("", "https://127.0.0.1/abc", true);
checkCanVerify("aaa.bbb.com,xxx.yyy.com, *.jjj.net", "http://aaa.bbb.com/m", true);
checkCanVerify("aaa.bbb.com, xxx.yyy.com,*.jjj.net", "http://xxx.yyy.com/n", true);
checkCanVerify("aaa.bbb.com,xxx.yyy.com, *.jjj.net", "http://www.jjj.net/o", true);
}
private static void checkCanVerify (String whitelist, String url, boolean expectedToPass)
throws MalformedURLException
{
List<String> w = Arrays.asList(StringUtil.parseStringArray(whitelist));
URL u = new URL(url);
boolean passed;
try {
HostWhitelist.verify(w, u);
passed = true;
} catch (MalformedURLException e) {
passed = false;
}
assertEquals("with whitelist '" + whitelist + "' and URL '" + url + "'",
expectedToPass, passed);
}
}
@@ -1,28 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import org.junit.Test;
import static com.threerings.getdown.util.StringUtil.couldBeValidUrl;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests {@link StringUtil}.
*/
public class StringUtilTest
{
@Test public void testCouldBeValidUrl ()
{
assertTrue(couldBeValidUrl("http://www.foo.com/"));
assertTrue(couldBeValidUrl("http://www.foo.com/A-B-C/1_2_3/~bar/q.jsp?x=u+i&y=2;3;4#baz%20baz"));
assertTrue(couldBeValidUrl("https://user:secret@www.foo.com/"));
assertFalse(couldBeValidUrl("http://www.foo.com & echo hello"));
assertFalse(couldBeValidUrl("http://www.foo.com\""));
}
}
@@ -1,53 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class VersionUtilTest {
@Test
public void shouldParseJavaVersion ()
{
long version = VersionUtil.parseJavaVersion(
"(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(_\\d+)?)?)?", "1.8.0_152");
assertEquals(1_080_152, version);
}
@Test
public void shouldParseJavaVersion8 ()
{
long version = VersionUtil.parseJavaVersion(
"(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(_\\d+)?)?)?", "1.8");
assertEquals(1_080_000, version);
}
@Test
public void shouldParseJavaVersion9 ()
{
long version = VersionUtil.parseJavaVersion(
"(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(_\\d+)?)?)?", "9");
assertEquals(9_000_000, version);
}
@Test
public void shouldParseJavaVersion10 ()
{
long version = VersionUtil.parseJavaVersion(
"(\\d+)(?:\\.(\\d+)(?:\\.(\\d+)(_\\d+)?)?)?", "10");
assertEquals(10_000_000, version);
}
@Test
public void shouldParseJavaRuntimeVersion ()
{
long version = VersionUtil.parseJavaVersion(
"(\\d+)\\.(\\d+)\\.(\\d+)(_\\d+)?(-b\\d+)?", "1.8.0_131-b11");
assertEquals(108_013_111, version);
}
}
@@ -1 +0,0 @@
mock-maker-inline
+30 -94
View File
@@ -2,9 +2,9 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown</artifactId> <artifactId>getdown</artifactId>
<version>1.8.11-SNAPSHOT</version> <version>1.0.0</version>
</parent> </parent>
<artifactId>getdown-launcher</artifactId> <artifactId>getdown-launcher</artifactId>
@@ -21,7 +21,7 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown-core</artifactId> <artifactId>getdown-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<optional>true</optional> <optional>true</optional>
@@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.samskivert</groupId> <groupId>com.samskivert</groupId>
<artifactId>samskivert</artifactId> <artifactId>samskivert</artifactId>
<version>1.12-SNAPSHOT</version> <version>1.13</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@@ -82,79 +82,6 @@
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-base</artifactId>
<version>${proguard.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.guardsquare</groupId>
<artifactId>proguard-core</artifactId>
<version>${proguard-core.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<configuration>
<proguardVersion>${proguard.version}</proguardVersion>
<outputDirectory>${project.build.directory}</outputDirectory>
<outjar>${project.build.finalName}.jar</outjar>
<injar>${project.build.finalName}.jar</injar>
<assembly>
<inclusions>
<inclusion>
<groupId>com.threerings.getdown</groupId>
<artifactId>getdown-core</artifactId>
</inclusion>
<inclusion>
<groupId>com.samskivert</groupId>
<artifactId>samskivert</artifactId>
<filter>
!**/*.java,
!**/swing/RuntimeAdjust*,
!**/swing/util/ButtonUtil*,
!**/util/CalendarUtil*,
!**/util/Calendars*,
!**/util/Log4JLogger*,
!**/util/PrefsConfig*,
!**/util/SignalUtil*,
com/samskivert/Log.class,
**/samskivert/io/**,
**/samskivert/swing/**,
**/samskivert/text/**,
**/samskivert/util/**
</filter>
</inclusion>
<inclusion>
<groupId>jregistrykey</groupId>
<artifactId>jregistrykey</artifactId>
</inclusion>
</inclusions>
</assembly>
<obfuscate>true</obfuscate>
<options>
<option>-keep public class com.threerings.getdown.** { *; }</option>
<option>-keep public class ca.beq.util.win32.registry.** { *; }</option>
<option>-keepattributes Exceptions, InnerClasses, Signature</option>
</options>
<libs>
<lib>${rt.jar.path}</lib>
</libs>
<addMavenDescriptor>false</addMavenDescriptor>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
@@ -175,6 +102,32 @@
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<!-- Shadow (fat) jar plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.threerings.getdown.launcher.GetdownApp</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<finalName>${project.artifactId}-all</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@@ -203,23 +156,6 @@
<activation> <activation>
<file><exists>${java.home}/jmods/java.base.jmod</exists></file> <file><exists>${java.home}/jmods/java.base.jmod</exists></file>
</activation> </activation>
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<configuration>
<libs>
<lib>${java.home}/jmods/java.base.jmod</lib>
<lib>${java.home}/jmods/java.desktop.jmod</lib>
<lib>${java.home}/jmods/java.logging.jmod</lib>
<lib>${java.home}/jmods/java.scripting.jmod</lib>
<lib>${java.home}/jmods/jdk.jsobject.jmod</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</profile> </profile>
</profiles> </profiles>
</project> </project>
@@ -1,149 +0,0 @@
//
// Getdown - application installer, patcher and launcher
// Copyright (C) 2004-2018 Getdown authors
// https://github.com/threerings/getdown/blob/master/LICENSE
package com.threerings.getdown.launcher;
import java.io.StringReader;
import java.net.InetAddress;
import java.net.URL;
import org.junit.Test;
import static org.junit.Assert.*;
public class ProxyUtilTest {
static String[] strs (String... strs) { return strs; }
static String[] findPAC (String code, String url) throws Exception {
return ProxyUtil.findPACProxiesForURL(new StringReader(code), new URL(url));
}
static void testPAC (String code, String url, String... expectedProxies) throws Exception {
assertArrayEquals(expectedProxies, findPAC(code, url));
}
@Test public void testPACProxy () throws Exception {
// we use the Graal JavaScrip VM for testing, because JDK15 no longer bundles Nashorn, but
// it does not support calling back into Java unless we set this compatibility property
System.setProperty("polyglot.js.nashorn-compat", "true");
String EXAMPLE0 =
"function FindProxyForURL(url, host) {\n" +
" if (shExpMatch(host, '*.example.com')) { return 'DIRECT'; }\n" +
" if (isInNet(host, '10.0.0.0', '255.255.248.0')) {\n" +
" return 'PROXY fastproxy.example.com:8080';\n" +
" }\n" +
" return 'PROXY proxy.example.com:8080; DIRECT';\n" +
"}\n";
testPAC(EXAMPLE0, "http://test.example.com/", "DIRECT");
testPAC(EXAMPLE0, "http://10.0.1.1/", "PROXY fastproxy.example.com:8080");
testPAC(EXAMPLE0, "http://chicken.gov/", "PROXY proxy.example.com:8080", "DIRECT");
String EXAMPLE1 =
"function FindProxyForURL(url, host) {" +
" if (isPlainHostName(host) || dnsDomainIs(host, '.mozilla.org')) {" +
" return 'DIRECT';" +
" } else {" +
" return 'PROXY w3proxy.mozilla.org:8080; DIRECT';" +
" }" +
"}";
testPAC(EXAMPLE1, "http://test.example.com/", "PROXY w3proxy.mozilla.org:8080", "DIRECT");
testPAC(EXAMPLE1, "http://www.mozilla.org/", "DIRECT");
testPAC(EXAMPLE1, "http://foo.mozilla.org/", "DIRECT");
testPAC(EXAMPLE1, "http://localhost/", "DIRECT");
String EXAMPLE2 =
" function FindProxyForURL(url, host) {\n" +
" if ((isPlainHostName(host) || dnsDomainIs(host, '.mozilla.org')) &&\n" +
" !localHostOrDomainIs(host, 'www.mozilla.org') &&\n" +
" !localHostOrDomainIs(host, 'merchant.mozilla.org')) {\n" +
" return 'DIRECT';\n" +
" } else {\n" +
" return 'PROXY w3proxy.mozilla.org:8080; DIRECT';\n" +
" }\n" +
" }";
testPAC(EXAMPLE2, "http://test.example.com/", "PROXY w3proxy.mozilla.org:8080", "DIRECT");
testPAC(EXAMPLE2, "http://www.mozilla.org/", "PROXY w3proxy.mozilla.org:8080", "DIRECT");
testPAC(EXAMPLE2, "http://www/", "PROXY w3proxy.mozilla.org:8080", "DIRECT");
testPAC(EXAMPLE2, "http://foo.mozilla.org/", "DIRECT");
testPAC(EXAMPLE2, "http://localhost/", "DIRECT");
String EXAMPLE3A =
"function FindProxyForURL(url, host) {\n" +
" if (isResolvable(host)) return 'DIRECT';\n" +
" else return 'PROXY proxy.mydomain.com:8080';\n" +
"}";
testPAC(EXAMPLE3A, "http://www.mozilla.org/", "DIRECT");
testPAC(EXAMPLE3A, "http://doesnotexist.mozilla.org/", "PROXY proxy.mydomain.com:8080");
String EXAMPLE3B =
"function FindProxyForURL(url, host) {\n" +
" if (isPlainHostName(host) ||\n" +
" dnsDomainIs(host, '.mydomain.com') ||\n" +
" isResolvable(host)) {\n" +
" return 'DIRECT';\n" +
" } else {\n" +
" return 'PROXY proxy.mydomain.com:8080';\n" +
" }\n" +
"}";
testPAC(EXAMPLE3B, "http://plain/", "DIRECT");
testPAC(EXAMPLE3B, "http://foo.mydomain.com/", "DIRECT");
testPAC(EXAMPLE3B, "http://www.mozilla.org/", "DIRECT");
testPAC(EXAMPLE3B, "http://doesnotexist.mozilla.org/", "PROXY proxy.mydomain.com:8080");
// example 4
// function FindProxyForURL(url, host) {
// if (isInNet(host, '198.95.0.0', '255.255.0.0')) return 'DIRECT';
// else return 'PROXY proxy.mydomain.com:8080';
// }
// function FindProxyForURL(url, host) {
// if (isPlainHostName(host) ||
// dnsDomainIs(host, '.mydomain.com') ||
// isInNet(host, '198.95.0.0', '255.255.0.0')) {
// return 'DIRECT';
// } else {
// return 'PROXY proxy.mydomain.com:8080';
// }
// }
// example 5
// function FindProxyForURL(url, host) {
// if (isPlainHostName(host) || dnsDomainIs(host, '.mydomain.com')) return 'DIRECT';
// else if (shExpMatch(host, '*.com')) return 'PROXY proxy1.mydomain.com:8080; ' +
// 'PROXY proxy4.mydomain.com:8080';
// else if (shExpMatch(host, '*.edu')) return 'PROXY proxy2.mydomain.com:8080; ' +
// 'PROXY proxy4.mydomain.com:8080';
// else return 'PROXY proxy3.mydomain.com:8080; ' +
// 'PROXY proxy4.mydomain.com:8080';
// }
// example 6
// function FindProxyForURL(url, host) {
// if (url.substring(0, 5) == 'http:') {
// return 'PROXY http-proxy.mydomain.com:8080';
// }
// else if (url.substring(0, 4) == 'ftp:') {
// return 'PROXY ftp-proxy.mydomain.com:8080';
// }
// else if (url.substring(0, 7) == 'gopher:') {
// return 'PROXY gopher-proxy.mydomain.com:8080';
// }
// else if (url.substring(0, 6) == 'https:' ||
// url.substring(0, 6) == 'snews:') {
// return 'PROXY security-proxy.mydomain.com:8080';
// } else {
// return 'DIRECT';
// }
// }
String MYIP =
"function FindProxyForURL(url, host) {\n" +
" return 'PROXY ' + myIpAddress() + ':8080';\n" +
"}";
String myIp = InetAddress.getLocalHost().getHostAddress();
testPAC(MYIP, "http://testurl.com/", "PROXY " + myIp + ":8080");
}
}
+2 -2
View File
@@ -2,10 +2,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.threerings.getdown</groupId> <groupId>net.affliction</groupId>
<artifactId>getdown</artifactId> <artifactId>getdown</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.8.11-SNAPSHOT</version> <version>1.0.0</version>
<name>getdown</name> <name>getdown</name>
<description>An application installer and updater.</description> <description>An application installer and updater.</description>