working jpackage build
This commit is contained in:
48
build.sh
Normal file
48
build.sh
Normal file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "${JAVA_HOME}" ]; then
|
||||
echo "JAVA_HOME needs to point to Java 14+"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "cleaning"
|
||||
rm -f *.jar
|
||||
rm -rf build
|
||||
rm -f *.exe
|
||||
rm -f *.dmg
|
||||
|
||||
|
||||
RES_DIR=../i2p.i2p/installer/resources
|
||||
I2P_JARS=../i2p.i2p/pkg-temp/lib
|
||||
HERE=$PWD
|
||||
|
||||
echo "preparing resources.csv"
|
||||
mkdir build
|
||||
cd $RES_DIR
|
||||
find certificates -name *.crt -exec echo '{},{}' >> $HERE/build/resources.csv \;
|
||||
cd $HERE
|
||||
echo "geoip/GeoLite2-Country.mmdb,geoip/GeoLite2-Country.mmdb" >> build/resources.csv
|
||||
|
||||
echo "copying certificates"
|
||||
cp -R $RES_DIR/certificates build/
|
||||
|
||||
echo "copying GeoIP"
|
||||
mkdir build/geoip
|
||||
cp $RES_DIR/GeoLite2-Country.mmdb.gz build/geoip
|
||||
gunzip build/geoip/GeoLite2-Country.mmdb.gz
|
||||
|
||||
echo "compiling custom launcher"
|
||||
cp $I2P_JARS/{i2p,router}.jar build
|
||||
cd java
|
||||
$JAVA_HOME/bin/javac -d ../build -classpath ../build/i2p.jar:../build/router.jar net/i2p/router/PackageLauncher.java
|
||||
cd ..
|
||||
|
||||
echo "building launcher.jar"
|
||||
#cp -R java/net build
|
||||
cd build
|
||||
$JAVA_HOME/bin/jar -cf launcher.jar net certificates geoip resources.csv
|
||||
cd ..
|
||||
|
||||
echo "preparing to invoke jpackage"
|
||||
cp $I2P_JARS/*.jar build
|
||||
$JAVA_HOME/bin/jpackage --name I2P --input build --main-jar launcher.jar --main-class net.i2p.router.PackageLaunch
|
82
java/net/i2p/router/PackageLauncher.java
Normal file
82
java/net/i2p/router/PackageLauncher.java
Normal file
@ -0,0 +1,82 @@
|
||||
package net.i2p.router;
|
||||
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class PackageLauncher {
|
||||
public static void main(String[]args) throws Exception {
|
||||
if (!(SystemVersion.isWindows() || SystemVersion.isMac())) {
|
||||
System.err.println("This launcher will work only on Windows or Mac");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// 1. Select home directory
|
||||
File home = selectHome();
|
||||
if (!home.exists())
|
||||
home.mkdirs();
|
||||
else if (!home.isDirectory()) {
|
||||
System.err.println(home + " exists but is not a directory. Please get it out of the way");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
// 2. Deploy resources
|
||||
var resourcesList = PackageLauncher.class.getClassLoader().getResourceAsStream("resources.csv");
|
||||
var reader = new BufferedReader(new InputStreamReader(resourcesList));
|
||||
|
||||
String line;
|
||||
while((line = reader.readLine()) != null) {
|
||||
deployResource(home, line);
|
||||
}
|
||||
|
||||
// 3. Set up environment vars
|
||||
System.setProperty("i2p.dir.base", home.getAbsolutePath());
|
||||
System.setProperty("i2p.dir.config", home.getAbsolutePath());
|
||||
System.setProperty("geoip.dir", home.getAbsolutePath() + File.separator + "geoip");
|
||||
// hmm what else?
|
||||
|
||||
// 4. Launch router
|
||||
RouterLaunch.main(args);
|
||||
}
|
||||
|
||||
|
||||
private static File selectHome() throws Exception {
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File i2p;
|
||||
if (SystemVersion.isMac()) {
|
||||
File library = new File(home, "Library");
|
||||
File appSupport = new File(library, "Application Support");
|
||||
i2p = new File(appSupport, "I2P");
|
||||
} else {
|
||||
// windows
|
||||
File appData = new File(home, "AppData");
|
||||
File roaming = new File(appData, "Roaming");
|
||||
i2p = new File(roaming, "I2P");
|
||||
}
|
||||
return i2p.getAbsoluteFile();
|
||||
}
|
||||
|
||||
private static void deployResource(File home, String description) throws Exception {
|
||||
String []split = description.split(",");
|
||||
String url = split[0];
|
||||
String target = split[1];
|
||||
|
||||
var resource = PackageLauncher.class.getClassLoader().getResourceAsStream(url);
|
||||
|
||||
File targetFile = home;
|
||||
for (String element : target.split("/")) {
|
||||
targetFile = new File(targetFile, element);
|
||||
}
|
||||
|
||||
File targetDir = targetFile.getParentFile();
|
||||
if (!targetDir.exists())
|
||||
targetDir.mkdirs();
|
||||
else if (!targetDir.isDirectory())
|
||||
throw new Exception(targetDir + " exists but not a directory. Please get it out of the way");
|
||||
|
||||
Files.copy(resource, targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user