Skip to content

Commit

Permalink
- improve readability and semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
kkriske committed Nov 18, 2023
1 parent b7e5cdf commit 0d815ec
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.gluonhq.substrate.model.Triplet;
import com.gluonhq.substrate.util.FileDeps;
import com.gluonhq.substrate.util.FileOps;
import com.gluonhq.substrate.util.JavaLib;
import com.gluonhq.substrate.util.Lib;
import com.gluonhq.substrate.util.Logger;
import com.gluonhq.substrate.util.ProcessRunner;
import com.gluonhq.substrate.util.Strings;
Expand Down Expand Up @@ -101,20 +101,11 @@ public abstract class AbstractTargetConfiguration implements TargetConfiguration
protected final boolean crossCompile;

private final List<String> defaultAdditionalSourceFiles = Collections.singletonList("launcher.c");
private final List<JavaLib> defaultStaticJavaLibs = List.of(
JavaLib.of("java"),
JavaLib.of("nio"),
JavaLib.of("zip"),
JavaLib.of("net"),
JavaLib.of("prefs"),
JavaLib.of("jvm"),
JavaLib.upto(20, "fdlibm"),
JavaLib.of("z"),
JavaLib.of("dl"),
JavaLib.of("j2pkcs11"),
JavaLib.upto(11, "sunec"),
JavaLib.of("jaas"),
JavaLib.of("extnet")
private final List<Lib> defaultStaticJavaLibs = List.of(
Lib.of("java"), Lib.of("nio"), Lib.of("zip"), Lib.of("net"),
Lib.of("prefs"), Lib.of("jvm"), Lib.upTo(20, "fdlibm"), Lib.of("z"),
Lib.of("dl"), Lib.of("j2pkcs11"), Lib.upTo(11, "sunec"), Lib.of("jaas"),
Lib.of("extnet")
);

AbstractTargetConfiguration(ProcessPaths paths, InternalProjectConfiguration configuration) {
Expand Down Expand Up @@ -957,14 +948,14 @@ List<String> getOtherStaticLibs() {

/**
* Return the list of library names applicable to the used java version.
* @param libs List to validate based on {@link JavaLib#inRange(int)}.
* @param libs List to validate based on {@link Lib#inRange(int)}.
* @return The list of library names applicable to the used java version.
*/
List<String> filterApplicableLibs(List<JavaLib> libs) {
final List<String> filterApplicableLibs(List<Lib> libs) {
int major = projectConfiguration.getJavaVersion().getMajor();
return libs.stream()
.filter(l -> l.inRange(major))
.map(JavaLib::getLibName)
.map(Lib::getLibName)
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.gluonhq.substrate.model.InternalProjectConfiguration;
import com.gluonhq.substrate.model.ProcessPaths;
import com.gluonhq.substrate.util.FileOps;
import com.gluonhq.substrate.util.JavaLib;
import com.gluonhq.substrate.util.Lib;
import com.gluonhq.substrate.util.Logger;
import com.gluonhq.substrate.util.ProcessRunner;
import com.gluonhq.substrate.util.Version;
Expand Down Expand Up @@ -60,21 +60,11 @@ public class LinuxTargetConfiguration extends PosixTargetConfiguration {

private static final List<String> linuxLibs = Arrays.asList("z", "dl", "stdc++", "pthread");

private static final List<JavaLib> staticJavaLibs = List.of(
JavaLib.of("java"),
JavaLib.of("nio"),
JavaLib.of("zip"),
JavaLib.of("net"),
JavaLib.of("prefs"),
JavaLib.of("j2pkcs11"),
JavaLib.upto(11, "sunec"),
JavaLib.of("extnet"),
JavaLib.upto(20, "fdlibm"),
JavaLib.of("fontmanager"),
JavaLib.of("javajpeg"),
JavaLib.of("lcms"),
JavaLib.of("awt_headless"),
JavaLib.of("awt")
private static final List<Lib> staticJavaLibs = List.of(
Lib.of("java"), Lib.of("nio"), Lib.of("zip"), Lib.of("net"),
Lib.of("prefs"), Lib.of("j2pkcs11"), Lib.upTo(11, "sunec"), Lib.of("extnet"),
Lib.upTo(20, "fdlibm"), Lib.of("fontmanager"), Lib.of("javajpeg"), Lib.of("lcms"),
Lib.of("awt_headless"), Lib.of("awt")
);
private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.gluonhq.substrate.model.InternalProjectConfiguration;
import com.gluonhq.substrate.model.ProcessPaths;
import com.gluonhq.substrate.util.FileOps;
import com.gluonhq.substrate.util.JavaLib;
import com.gluonhq.substrate.util.Lib;
import com.gluonhq.substrate.util.Logger;
import com.gluonhq.substrate.util.XcodeUtils;
import com.gluonhq.substrate.util.macos.CodeSigning;
Expand All @@ -57,16 +57,10 @@ public class MacOSTargetConfiguration extends DarwinTargetConfiguration {
"ApplicationServices", "OpenGL", "QuartzCore", "Security", "Accelerate"
);

private static final List<JavaLib> staticJavaLibs = Arrays.asList(
JavaLib.of("java"),
JavaLib.of("nio"),
JavaLib.of("zip"),
JavaLib.of("net"),
JavaLib.of("prefs"),
JavaLib.of("j2pkcs11"),
JavaLib.upto(20, "fdlibm"),
JavaLib.upto(11, "sunec"),
JavaLib.of("extnet")
private static final List<Lib> staticJavaLibs = Arrays.asList(
Lib.of("java"), Lib.of("nio"), Lib.of("zip"), Lib.of("net"),
Lib.of("prefs"), Lib.of("j2pkcs11"), Lib.upTo(20, "fdlibm"), Lib.upTo(11, "sunec"),
Lib.of("extnet")
);
private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper", "darwin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.gluonhq.substrate.model.InternalProjectConfiguration;
import com.gluonhq.substrate.model.ProcessPaths;
import com.gluonhq.substrate.util.FileOps;
import com.gluonhq.substrate.util.JavaLib;
import com.gluonhq.substrate.util.Lib;
import com.gluonhq.substrate.util.Logger;
import com.gluonhq.substrate.util.ProcessRunner;
import com.gluonhq.substrate.util.windows.MSIBundler;
Expand All @@ -47,29 +47,15 @@

public class WindowsTargetConfiguration extends AbstractTargetConfiguration {

private static final List<JavaLib> javaWindowsLibs = List.of(
JavaLib.of("advapi32"),
JavaLib.of("iphlpapi"),
JavaLib.of("secur32"),
JavaLib.of("userenv"),
JavaLib.of("version"),
JavaLib.of("ws2_32"),
JavaLib.of("winhttp"),
JavaLib.of("ncrypt"),
JavaLib.of("crypt32"),
JavaLib.from(20, "mswsock")
private static final List<Lib> javaWindowsLibs = List.of(
Lib.of("advapi32"), Lib.of("iphlpapi"), Lib.of("secur32"), Lib.of("userenv"),
Lib.of("version"), Lib.of("ws2_32"), Lib.of("winhttp"), Lib.of("ncrypt"),
Lib.of("crypt32"), Lib.from(20, "mswsock")
);
private static final List<JavaLib> staticJavaLibs = List.of(
JavaLib.of("j2pkcs11"),
JavaLib.of("java"),
JavaLib.of("net"),
JavaLib.of("nio"),
JavaLib.of("prefs"),
JavaLib.upto(20, "fdlibm"),
JavaLib.upto(11, "sunec"),
JavaLib.of("zip"),
JavaLib.of("sunmscapi"),
JavaLib.from(21, "extnet")
private static final List<Lib> staticJavaLibs = List.of(
Lib.of("j2pkcs11"), Lib.of("java"), Lib.of("net"), Lib.of("nio"),
Lib.of("prefs"), Lib.upTo(20, "fdlibm"), Lib.upTo(11, "sunec"), Lib.of("zip"),
Lib.of("sunmscapi"), Lib.from(21, "extnet")
);
private static final List<String> staticJvmLibs = Arrays.asList(
"jvm", "libchelper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* This class represents a java library constrained to the optional lower and upper bounds.
*/
public class JavaLib {
public class Lib {
/**
* lower bound of the applicable version range, inclusive
*/
Expand All @@ -41,7 +41,7 @@ public class JavaLib {
private final Integer upperBound;
private final String libName;

private JavaLib(Integer lowerBound, Integer upperBound, String libName) {
private Lib(Integer lowerBound, Integer upperBound, String libName) {
this.lowerBound = lowerBound;
this.upperBound = upperBound;
this.libName = libName;
Expand All @@ -59,19 +59,19 @@ public boolean inRange(int javaMajorVersion) {
return true;
}

public static JavaLib of(String libName) {
return new JavaLib(null, null, libName);
public static Lib of(String libName) {
return new Lib(null, null, libName);
}

public static JavaLib range(int lowerBound, int upperBound, String libName) {
return new JavaLib(lowerBound, upperBound, libName);
public static Lib range(int lowerBound, int upperBound, String libName) {
return new Lib(lowerBound, upperBound, libName);
}

public static JavaLib from(int lowerBound, String libName) {
return new JavaLib(lowerBound, null, libName);
public static Lib from(int lowerBound, String libName) {
return new Lib(lowerBound, null, libName);
}

public static JavaLib upto(int upperBound, String libName) {
return new JavaLib(null, upperBound, libName);
public static Lib upTo(int upperBound, String libName) {
return new Lib(null, upperBound, libName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@

import static org.junit.jupiter.api.Assertions.*;

class JavaLibTest {
class LibTest {
@Test
void testNoBound() {
JavaLib lib = JavaLib.of("");
Lib lib = Lib.of("");
assertTrue(lib.inRange(0));
assertTrue(lib.inRange(100));
}

@Test
void testLowerBound() {
JavaLib lib = JavaLib.from(10, "");
Lib lib = Lib.from(10, "");
assertFalse(lib.inRange(9));
assertTrue(lib.inRange(10));
assertTrue(lib.inRange(11));
}

@Test
void testUpperBound() {
JavaLib lib = JavaLib.upto(10, "");
Lib lib = Lib.upTo(10, "");
assertTrue(lib.inRange(9));
assertTrue(lib.inRange(10));
assertFalse(lib.inRange(11));
}

@Test
void testRange() {
JavaLib lib = JavaLib.range(10, 12, "");
Lib lib = Lib.range(10, 12, "");
assertFalse(lib.inRange(9));
assertTrue(lib.inRange(10));
assertTrue(lib.inRange(11));
Expand Down

0 comments on commit 0d815ec

Please sign in to comment.