forked from I2P_Developers/i2p.i2p
Merge branch 'wrapper-3560' into 'master'
Build: Update wrapper to 3.5.60 See merge request i2p-hackers/i2p.i2p!237
This commit is contained in:
@ -182,10 +182,10 @@ Launchers:
|
||||
Copyright (c) 2002-2018 EPFL, Lausanne / Lightbend, Inc. , unless otherwise specified.
|
||||
See licenses/LICENSE-Scala.md
|
||||
|
||||
Java Service Wrapper Community Edition 3.5.44:
|
||||
Java Service Wrapper Community Edition 3.5.60:
|
||||
(Windows: 3.5.25)
|
||||
(not included in most distribution packages)
|
||||
Copyright (C) 1999-2020 Tanuki Software, Ltd. All Rights Reserved.
|
||||
Copyright (C) 1999-2024 Tanuki Software, Ltd. All Rights Reserved.
|
||||
See licenses/LICENSE-Wrapper.txt
|
||||
|
||||
|
||||
|
39
build.xml
39
build.xml
@ -427,6 +427,10 @@
|
||||
<copy file="apps/jrobin/java/build/jrobin.jar" todir="build/" />
|
||||
</target>
|
||||
|
||||
<target name="buildWrapperJar" >
|
||||
<ant dir="installer/lib/wrapper" target="jar" />
|
||||
</target>
|
||||
|
||||
<target name="buildProperties" depends="getGitRev, getReleaseNumber, getBuildNumber, setBuildTimestamp, disableManifestClasspath" >
|
||||
<antversion property="antversion"/>
|
||||
<fail message="FATAL: Minimum Ant version is ${ant.minimumVersion} - your Ant version is ${antversion}">
|
||||
@ -1269,6 +1273,7 @@
|
||||
<delete dir="core/c/jbigi/bin" />
|
||||
<delete dir="core/c/jbigi/lib" />
|
||||
<delete dir="core/c/jcpuid/lib" />
|
||||
<ant dir="installer/lib/wrapper" target="distclean" />
|
||||
<ant dir="installer/resources/locale" target="distclean" />
|
||||
<ant dir="installer/tools/java" target="distclean" />
|
||||
<delete dir="installer/lib/izpack5/patches/java/build" quiet="true" />
|
||||
@ -1337,34 +1342,40 @@
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="preppkg" depends="preppkg-linux, preppkg-freebsd, preppkg-osx, preppkg-windows, jbigi">
|
||||
<target name="preppkg" depends="preppkg-linux, preppkg-freebsd, preppkg-osx, preppkg-windows, jbigi, buildWrapperJar">
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<!--
|
||||
<copy todir="pkg-temp/lib/wrapper/solaris/">
|
||||
<fileset dir="installer/lib/wrapper/solaris/" excludes="*.txt" />
|
||||
</copy>
|
||||
-->
|
||||
<!-- Force using the new wrapper.jar.
|
||||
The new jar with the old windows binaries will output a warning on windows.
|
||||
We do not generate release files from this target.
|
||||
See preppkg-windows-only target below.
|
||||
-->
|
||||
<copy overwrite="true" file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy overwrite="true" file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<target name="preppkg-nowindows" depends="preppkg-linux, preppkg-freebsd, preppkg-osx, jbigi-nowindows">
|
||||
<target name="preppkg-nowindows" depends="preppkg-linux, preppkg-freebsd, preppkg-osx, jbigi-nowindows, buildWrapperJar">
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<!--
|
||||
<copy todir="pkg-temp/lib/wrapper/solaris/">
|
||||
<fileset dir="installer/lib/wrapper/solaris/" excludes="*.txt" />
|
||||
</copy>
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
-->
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<target name="preppkgRepack" depends="preppkg-linux, preppkg-freebsd, preppkg-osx, preppkg-windows, jbigi">
|
||||
<ant target="repack200" />
|
||||
<!-- no use doing repack200 on jbigi.jar -->
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<!--
|
||||
<copy todir="pkg-temp/lib/wrapper/solaris/">
|
||||
<fileset dir="installer/lib/wrapper/solaris/" excludes="*.txt" />
|
||||
</copy>
|
||||
-->
|
||||
</target>
|
||||
|
||||
<target name="preppkg-freebsd" depends="preppkg-unix">
|
||||
@ -1376,15 +1387,15 @@
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="preppkg-freebsd-only" depends="preppkg-freebsd, jbigi-freebsd-only" >
|
||||
<target name="preppkg-freebsd-only" depends="preppkg-freebsd, jbigi-freebsd-only, buildWrapperJar" >
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<!-- only what is needed for debian, etc. -->
|
||||
<target name="preppkg-linux-only" depends="preppkg-linux, jbigi-linux-only" >
|
||||
<target name="preppkg-linux-only" depends="preppkg-linux, jbigi-linux-only, buildWrapperJar" >
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<!-- This is the target called by debian/rules -->
|
||||
@ -1411,9 +1422,11 @@
|
||||
</target>
|
||||
|
||||
<target name="preppkg-linux-nonx86" depends="preppkg-unix">
|
||||
<!--
|
||||
<copy todir="pkg-temp/lib/wrapper/linux-ppc/">
|
||||
<fileset dir="installer/lib/wrapper/linux-ppc/" excludes="*.txt" />
|
||||
</copy>
|
||||
-->
|
||||
<copy todir="pkg-temp/lib/wrapper/linux-armv5/">
|
||||
<fileset dir="installer/lib/wrapper/linux-armv5/" excludes="*.txt" />
|
||||
</copy>
|
||||
@ -1441,9 +1454,9 @@
|
||||
<copy file="installer/resources/uninstall_i2p_service_osx.command" todir="pkg-temp/" />
|
||||
</target>
|
||||
|
||||
<target name="preppkg-osx-only" depends="preppkg-osx, jbigi-osx-only" >
|
||||
<target name="preppkg-osx-only" depends="preppkg-osx, jbigi-osx-only, buildWrapperJar" >
|
||||
<copy file="build/jbigi.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<target name="preppkg-windows" depends="preppkg-base, preplicenses-windows, buildUtilityJar, buildexe">
|
||||
@ -1469,9 +1482,9 @@
|
||||
This will not overwrite, so preppkg (for all OSes) will get the new jar with
|
||||
the old binaries, which will probably work but will output a warning.
|
||||
The windows-only installer will get the correct jar.
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
-->
|
||||
<copy overwrite="true" file="installer/lib/wrapper/win-all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy overwrite="true" file="installer/lib/wrapper/win-build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
</target>
|
||||
|
||||
<!-- see targets below for conditional copying -->
|
||||
@ -3197,7 +3210,7 @@
|
||||
<target name = "preppkg-portable-win32" depends="preppkg-portable-win32-jbigi,preppkg-portable-basic">
|
||||
<!--wrapper - dont even think about it. i2p cosumes appreantly more mem without it on win32-->
|
||||
<copy file="installer/lib/wrapper/win32/wrapper.dll" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/all/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/build/wrapper.jar" todir="pkg-temp/lib" />
|
||||
<copy file="installer/lib/wrapper/win32/I2Psvc.exe" tofile="pkg-temp/i2psvc.ex_" />
|
||||
<!-- copy the unpack/start batchfiles -->
|
||||
<copy todir="pkg-temp">
|
||||
|
@ -26,6 +26,9 @@ For armv6, build from source following the instructions
|
||||
in linux-armv6/README.txt.
|
||||
Don't forget to strip the binaries and disable the execute bit.
|
||||
|
||||
From the source, copy WrapperBootstrap.java to patches/
|
||||
and merge in our changes.
|
||||
|
||||
For macosx, combine (if possible) the universal-32 and universal-64 files
|
||||
from the delta pack (each is a 2-architecture fat file)
|
||||
into a "quad-fat" binary. Instructions can be found in
|
||||
|
Binary file not shown.
79
installer/lib/wrapper/build.xml
Normal file
79
installer/lib/wrapper/build.xml
Normal file
@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="wrapper">
|
||||
|
||||
<property name="javac.compilerargs" value="" />
|
||||
<property name="javac.version" value="1.8" />
|
||||
<property name="javac.release" value="8" />
|
||||
<property name="build.built-by" value="unknown" />
|
||||
<property name="build.timestamp" value="unknown" />
|
||||
<property name="workspace.version" value="unknown" />
|
||||
<property name="wrapper.version" value="3.5.60" />
|
||||
|
||||
<target name="all" depends="jar" />
|
||||
|
||||
<condition property="depend.available">
|
||||
<typefound name="depend" />
|
||||
</condition>
|
||||
|
||||
<target name="depend" if="depend.available">
|
||||
<depend
|
||||
cache="../../build"
|
||||
srcdir="./patches"
|
||||
destdir="./build/obj" >
|
||||
<classpath>
|
||||
<pathelement location="all/wrapper.jar" />
|
||||
</classpath>
|
||||
</depend>
|
||||
</target>
|
||||
|
||||
<target name="compilePatches" depends="depend" >
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<javac
|
||||
srcdir="./patches"
|
||||
debug="true" deprecation="on" source="${javac.version}" target="${javac.version}"
|
||||
release="${javac.release}"
|
||||
destdir="./build/obj"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false" >
|
||||
<classpath>
|
||||
<pathelement location="all/wrapper.jar" />
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!--
|
||||
- We have to make a new jar because the tanuki one is signed
|
||||
-->
|
||||
<target name="jar" depends="compilePatches, jarUpToDate" unless="jar.uptodate" >
|
||||
<jar destfile="./build/wrapper.jar" basedir="./build/obj" includes="**/*.class">
|
||||
<manifest>
|
||||
<attribute name="Specification-Title" value="Java Service Wrapper" />
|
||||
<attribute name="Specification-Vendor" value="Tanuki Software, Ltd." />
|
||||
<attribute name="Specification-Version" value="${wrapper.version}" />
|
||||
<attribute name="Implementation-Title" value="org.tanukisoftware.wrapper" />
|
||||
<attribute name="Implementation-Vendor" value="Tanuki Software, Ltd." />
|
||||
<attribute name="Implementation-Version" value="${wrapper.version}" />
|
||||
<attribute name="Built-By" value="${build.built-by}" />
|
||||
<attribute name="Build-Date" value="${build.timestamp}" />
|
||||
<attribute name="Base-Revision" value="${workspace.version}" />
|
||||
<attribute name="X-Compile-Source-JDK" value="${javac.version}" />
|
||||
<attribute name="X-Compile-Target-JDK" value="${javac.version}" />
|
||||
</manifest>
|
||||
<zipfileset excludes="META-INF/* org/tanukisoftware/wrapper/bootstrap/WrapperBootstrap.class" src="all/wrapper.jar"/>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="jarUpToDate">
|
||||
<uptodate property="jar.uptodate" targetfile="build/wrapper.jar" >
|
||||
<srcfiles dir= "build/obj" includes="**/*.class" />
|
||||
<srcfiles dir= "all" />
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="clean" >
|
||||
<delete dir="./build" />
|
||||
</target>
|
||||
<target name="distclean" depends="clean" />
|
||||
</project>
|
@ -1,22 +1,45 @@
|
||||
#
|
||||
# copy the files out of the unzipped delta pack
|
||||
#
|
||||
V=3.5.44
|
||||
V=3.5.60
|
||||
D=wrapper-delta-pack-$V
|
||||
T=$D.tar.gz
|
||||
U=https://download.tanukisoftware.com/wrapper/$V/$T
|
||||
if [ ! -f $T ]
|
||||
then
|
||||
echo "Downloading delta pack from $U"
|
||||
wget $U
|
||||
fi
|
||||
if [ ! -d $D ]
|
||||
then
|
||||
echo "Untarring $T"
|
||||
tar xzf $T
|
||||
fi
|
||||
|
||||
B=$D/bin
|
||||
L=$D/lib
|
||||
|
||||
cp $L/wrapper.jar all
|
||||
|
||||
#
|
||||
# In delta pack but not used:
|
||||
#
|
||||
# AIX
|
||||
# FreeBSD ARM
|
||||
# HPUX
|
||||
# Linux PPC
|
||||
# Solaris
|
||||
#
|
||||
# You must update postinstall.sh to add support for new architectures.
|
||||
#
|
||||
set -x
|
||||
cp $L/libwrapper-freebsd-x86-32.so freebsd/libwrapper.so
|
||||
cp $L/libwrapper-freebsd-x86-64.so freebsd64/libwrapper.so
|
||||
cp $L/libwrapper-linux-x86-32.so linux/libwrapper.so
|
||||
cp $L/libwrapper-linux-x86-64.so linux64/libwrapper.so
|
||||
#cp $L/libwrapper-linux-ppcbe-32.so linux-ppc/libwrapper.so
|
||||
cp $L/libwrapper-linux-armel-32.so linux-armv5/libwrapper.so
|
||||
cp $L/libwrapper-linux-armhf-32.so linux-armv7/libwrapper.so
|
||||
cp $L/libwrapper-linux-armhf-64.so linux64-armv8/libwrapper.so
|
||||
cp $L/libwrapper-solaris-sparc-32.so solaris/libwrapper.so
|
||||
cp $L/libwrapper-linux-arm-64.so linux64-armv8/libwrapper.so
|
||||
cp $L/libwrapper-macosx-universal-32.jnilib macosx/libwrapper-macosx-universal-32.jnilib
|
||||
cp $L/libwrapper-macosx-universal-64.jnilib macosx/libwrapper-macosx-universal-64.jnilib
|
||||
|
||||
@ -24,13 +47,12 @@ cp $B/wrapper-freebsd-x86-32 freebsd/i2psvc
|
||||
cp $B/wrapper-freebsd-x86-64 freebsd64/i2psvc
|
||||
cp $B/wrapper-linux-x86-32 linux/i2psvc
|
||||
cp $B/wrapper-linux-x86-64 linux64/i2psvc
|
||||
#cp $B/wrapper-linux-ppcbe-32 linux-ppc/i2psvc
|
||||
cp $B/wrapper-linux-armel-32 linux-armv5/i2psvc
|
||||
cp $B/wrapper-linux-armhf-32 linux-armv7/i2psvc
|
||||
cp $B/wrapper-linux-armhf-64 linux64-armv8/i2psvc
|
||||
cp $B/wrapper-solaris-sparc-32 solaris/i2psvc
|
||||
cp $B/wrapper-linux-arm-64 linux64-armv8/i2psvc
|
||||
cp $B/wrapper-macosx-universal-32 macosx/i2psvc-macosx-universal-32
|
||||
cp $B/wrapper-macosx-universal-64 macosx/i2psvc-macosx-universal-64
|
||||
set +x
|
||||
|
||||
for i in freebsd freebsd64 linux linux64
|
||||
do
|
||||
@ -38,7 +60,7 @@ do
|
||||
chmod -x $i/i2psvc $i/libwrapper.so
|
||||
done
|
||||
|
||||
for i in linux-ppc linux-armv5 linux-armv7 linux64-armv8 solaris
|
||||
for i in linux-armv5 linux-armv7 linux64-armv8
|
||||
do
|
||||
chmod -x $i/i2psvc $i/libwrapper.so
|
||||
done
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
Wrapper build instructions (Ubuntu or Raspbian):
|
||||
|
||||
apt-get install default-jdk ant
|
||||
export JAVA_HOME=/usr/lib/jvm/default-java
|
||||
apt-get install openjdk-8-jdk-headless ant
|
||||
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-armhf
|
||||
ant -Dbits=32 compile-c-unix
|
||||
mv bin/wrapper bin/i2psvc
|
||||
strip --strip-unneeded bin/i2psvc lib/libwrapper.so
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,533 @@
|
||||
package org.tanukisoftware.wrapper.bootstrap;
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2023 Tanuki Software, Ltd.
|
||||
* http://www.tanukisoftware.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is the proprietary information of Tanuki Software.
|
||||
* You shall use it only in accordance with the terms of the
|
||||
* license agreement you entered into with Tanuki Software.
|
||||
* http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.tanukisoftware.wrapper.WrapperInfo;
|
||||
|
||||
public class WrapperBootstrap
|
||||
{
|
||||
private static boolean c_bootstrapInstance;
|
||||
|
||||
private static final int ENTRYPOINT_MAINCLASS = 1;
|
||||
/* private static final int ENTRYPOINT_MODULE = 2;*/
|
||||
private static final int ENTRYPOINT_JAR = 3;
|
||||
|
||||
private static boolean m_debug;
|
||||
|
||||
public static boolean isBootstrapInstance()
|
||||
{
|
||||
return c_bootstrapInstance;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
* Main Method
|
||||
*-------------------------------------------------------------*/
|
||||
/**
|
||||
* In general, this method should avoid failing with exit code 1 and
|
||||
* instead print tokens that can be parsed by native code.
|
||||
* Exit code 1 will cause to not parse the output at all, not even the
|
||||
* version number.
|
||||
* For some critical errors, it can be useful to print error messages or
|
||||
* call stacks from this function and then return. This can be achieved
|
||||
* with special tokens to inform the Wrapper to raise the loglevel.
|
||||
*
|
||||
* @param args arg1: 1: 'mainclass', 2: 'module' or 3: 'jar'
|
||||
* arg2: name of the element which type is specified by arg1
|
||||
* arg3: debug
|
||||
*/
|
||||
public static void main( String args[] )
|
||||
{
|
||||
c_bootstrapInstance = true;
|
||||
|
||||
HashMap tm = new LinkedHashMap();
|
||||
|
||||
tm.put( "wrapper_version", WrapperInfo.getVersion() );
|
||||
|
||||
if ( args.length < 3 )
|
||||
{
|
||||
// This output will cause the error after to be printed at loglevel ERROR.
|
||||
tm.put( "wrong_argument_number", Integer.toString( args.length ) );
|
||||
printParseInformation( tm );
|
||||
System.err.println( "WrapperBootstrap Error: Wrong argument number." );
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if ( Integer.parseInt( args[2] ) != 0 )
|
||||
{
|
||||
m_debug = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_debug = false;
|
||||
}
|
||||
}
|
||||
catch ( NumberFormatException e )
|
||||
{
|
||||
m_debug = false;
|
||||
}
|
||||
|
||||
Class mainClassClass = null;
|
||||
|
||||
boolean findMainModule = false;
|
||||
|
||||
int javaVersion = getJavaVersion();
|
||||
|
||||
int id = Integer.parseInt( args[0] );
|
||||
if ( id == ENTRYPOINT_MAINCLASS )
|
||||
{
|
||||
/**
|
||||
* Output:
|
||||
* ------------------------------
|
||||
* mainclass: not found
|
||||
* or (Java >= 9)
|
||||
* mainmodule: not found
|
||||
* package: <package>
|
||||
* or (Java >= 9)
|
||||
* mainmodule: <modulename>
|
||||
* package: <package>
|
||||
* or (Java >= 9)
|
||||
* mainmodule: unnamed
|
||||
* package: <package>
|
||||
*/
|
||||
try
|
||||
{
|
||||
mainClassClass = Class.forName( args[1] );
|
||||
}
|
||||
catch ( ClassNotFoundException e )
|
||||
{
|
||||
tm.put( "mainclass", "not found" );
|
||||
mainClassClass = null;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
// This output will cause the stack below to be printed at loglevel ERROR.
|
||||
tm.put( "mainclass", "load failed" );
|
||||
printParseInformation( tm );
|
||||
t.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if ( javaVersion >= 9 )
|
||||
{
|
||||
findMainModule = true;
|
||||
}
|
||||
}
|
||||
// else if ( id == ENTRYPOINT_MODULE )
|
||||
// {
|
||||
// if ( javaVersion >= 9 )
|
||||
// {
|
||||
// /**
|
||||
// * Output (Java >= 9):
|
||||
// * ------------------------------
|
||||
// * mainmodule: not found
|
||||
// * or
|
||||
// * mainmodule: no main class
|
||||
// * or
|
||||
// * mainclass: not found
|
||||
// * or
|
||||
// * mainclass: <mainclass>
|
||||
// * package: <package>
|
||||
// */
|
||||
// Object module = getModuleByName( args[1] );
|
||||
// if ( module != null )
|
||||
// {
|
||||
// Object mainClass = null;
|
||||
// try
|
||||
// {
|
||||
// Method m = module.getClass().getMethod( "getDescriptor", new Class[] { } );
|
||||
// Object descriptor = m.invoke( module, new Object[] { } );
|
||||
// if ( descriptor != null )
|
||||
// {
|
||||
// m = descriptor.getClass().getMethod( "mainClass", new Class[] { } );
|
||||
// Object optional = m.invoke( descriptor, new Object[] { } );
|
||||
// m = optional.getClass().getMethod( "get", new Class[] { });
|
||||
// try
|
||||
// {
|
||||
// mainClass = m.invoke( optional, new Object[] { } );
|
||||
// }
|
||||
// catch ( InvocationTargetException e ) {
|
||||
// if ( m_debug && e.getCause() instanceof NoSuchElementException ) {
|
||||
// printDebug( "Failed to find main class." );
|
||||
// }
|
||||
// }
|
||||
// if ( mainClass != null )
|
||||
// {
|
||||
// tm.put( "mainclass", mainClass );
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tm.put( "mainmodule", "no main class" );
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // unnamed module (but should not happen because we retrieved the module by its name)
|
||||
// }
|
||||
// }
|
||||
// catch ( Exception e )
|
||||
// {
|
||||
// if ( m_debug )
|
||||
// {
|
||||
// printDebug( "Failed to retrieve main class - " + e.getMessage() );
|
||||
// }
|
||||
// tm.put( "mainclass", "not found" );
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// tm.put( "mainmodule", "not found" );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
else if ( id == ENTRYPOINT_JAR )
|
||||
{
|
||||
/**
|
||||
* Output:
|
||||
* ------------------------------
|
||||
* mainjar: not found
|
||||
* or
|
||||
* mainjar: can't open
|
||||
* or
|
||||
* mainjar: no manifest
|
||||
* or
|
||||
* [
|
||||
* mainjar: no mainclass
|
||||
* or
|
||||
* mainclass: not found - <classname>
|
||||
* or
|
||||
* mainclass: <classname>
|
||||
* mainmodule: <mainmodule>
|
||||
* package: <package>
|
||||
* ]
|
||||
* and
|
||||
* [
|
||||
* mainjar: no classpath
|
||||
* or
|
||||
* classpath: <classpath>
|
||||
* ]
|
||||
*/
|
||||
// Look for the specified jar file.
|
||||
File file = new File( args[1] );
|
||||
if ( !file.exists() )
|
||||
{
|
||||
tm.put( "mainjar", "not found" );
|
||||
}
|
||||
else
|
||||
{
|
||||
JarFile jarFile;
|
||||
try
|
||||
{
|
||||
jarFile = new JarFile( file );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Can't open jar file - " + e.getMessage() );
|
||||
}
|
||||
tm.put( "mainjar", "can't open" );
|
||||
jarFile = null;
|
||||
}
|
||||
catch ( SecurityException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Can't open jar file - " + e.getMessage() );
|
||||
}
|
||||
tm.put( "mainjar", "access denied" );
|
||||
jarFile = null;
|
||||
}
|
||||
if ( jarFile != null )
|
||||
{
|
||||
Manifest manifest;
|
||||
try
|
||||
{
|
||||
manifest = jarFile.getManifest();
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Jar file doesn't have a manifest - " + e.getMessage() );
|
||||
}
|
||||
tm.put( "mainjar", "no manifest" );
|
||||
manifest = null;
|
||||
}
|
||||
|
||||
if ( manifest != null )
|
||||
{
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
|
||||
String mainClassName = attributes.getValue( "Main-Class" );
|
||||
if ( mainClassName == null )
|
||||
{
|
||||
tm.put( "mainjar", "no mainclass" );
|
||||
}
|
||||
else
|
||||
{
|
||||
URLClassLoader cl;
|
||||
|
||||
// Store the main jar in the classpath.
|
||||
try
|
||||
{
|
||||
URL[] classURLs = new URL[1];
|
||||
classURLs[0] = new URL( "file:" + file.getAbsolutePath() );
|
||||
cl = URLClassLoader.newInstance( classURLs, WrapperBootstrap.class.getClassLoader() );
|
||||
}
|
||||
catch ( MalformedURLException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Unable to add jar to classpath: " + e.getMessage() );
|
||||
}
|
||||
cl = null;
|
||||
}
|
||||
try
|
||||
{
|
||||
if ( cl == null )
|
||||
{
|
||||
mainClassClass = Class.forName( mainClassName );
|
||||
}
|
||||
else
|
||||
{
|
||||
mainClassClass = Class.forName( mainClassName, false, cl );
|
||||
}
|
||||
if ( javaVersion >= 9 )
|
||||
{
|
||||
findMainModule = true;
|
||||
}
|
||||
}
|
||||
catch ( ClassNotFoundException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Failed to retrieve main class - " + e.getMessage() );
|
||||
}
|
||||
mainClassClass = null;
|
||||
}
|
||||
catch ( Throwable t )
|
||||
{
|
||||
// This output will cause the stack below to be printed at loglevel ERROR.
|
||||
tm.put( "mainclass", "load failed - " + mainClassName );
|
||||
printParseInformation( tm );
|
||||
t.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mainClassClass != null )
|
||||
{
|
||||
tm.put( "mainclass", mainClassName );
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.put( "mainclass", "not found - " + mainClassName );
|
||||
}
|
||||
}
|
||||
|
||||
String classPath = attributes.getValue( "Class-Path" );
|
||||
if ( classPath == null )
|
||||
{
|
||||
tm.put( "mainjar", "no classpath" );
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.put( "classpath", classPath );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// This output will cause the error after to be printed at loglevel ERROR.
|
||||
tm.put( "invalid_argument", "" );
|
||||
printParseInformation( tm );
|
||||
System.err.println( "WrapperBootstrap Error: Invalid argument(s)." );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mainClassClass != null )
|
||||
{
|
||||
if ( findMainModule )
|
||||
{
|
||||
Object moduleName = null;
|
||||
try
|
||||
{
|
||||
// use reflection as this requires java 9
|
||||
Method m = Class.class.getMethod( "getModule", new Class[] { } );
|
||||
Object module = m.invoke( mainClassClass, new Object[] { } );
|
||||
m = module.getClass().getMethod( "getName", new Class[] { } );
|
||||
moduleName = (String)m.invoke( module, new Object[] { } );
|
||||
if ( moduleName != null )
|
||||
{
|
||||
tm.put( "mainmodule", moduleName );
|
||||
}
|
||||
else
|
||||
{
|
||||
tm.put( "mainmodule", "unnamed" );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Failed to retrieve main module - " + e.getMessage() );
|
||||
}
|
||||
tm.put( "mainmodule", "not found" );
|
||||
}
|
||||
}
|
||||
|
||||
Package pkg = mainClassClass.getPackage();
|
||||
if ( pkg != null )
|
||||
{
|
||||
tm.put( "package", pkg.getName() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// should not happen because the class was retrieved using the fully qualified name.
|
||||
tm.put( "package", "not found" );
|
||||
}
|
||||
}
|
||||
|
||||
// check that modules used by the Wrapper are available (might not be the case if running with a custom image)
|
||||
if ( javaVersion >= 9 )
|
||||
{
|
||||
if ( getModuleByName( "java.management" ) == null )
|
||||
{
|
||||
tm.put( "java.management", "not available" );
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Make sure that the method is public and static?
|
||||
|
||||
printParseInformation( tm );
|
||||
}
|
||||
|
||||
private static void printParseInformation( HashMap tm )
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for ( Iterator iter = tm.keySet().iterator(); iter.hasNext(); )
|
||||
{
|
||||
String name = (String)iter.next();
|
||||
sb.append( "WrapperBootstrap: " );
|
||||
sb.append( name );
|
||||
sb.append( ": " );
|
||||
sb.append( (String)tm.get( name ) );
|
||||
if ( iter.hasNext() )
|
||||
{
|
||||
sb.append( System.getProperty( "line.separator" ) );
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println( sb.toString() );
|
||||
}
|
||||
|
||||
private static void printDebug( String message )
|
||||
{
|
||||
System.out.println( "WrapperBootstrap Debug: " + message );
|
||||
}
|
||||
|
||||
private static int getJavaVersion()
|
||||
{
|
||||
String version = System.getProperty( "java.version" );
|
||||
if ( version.startsWith( "1." ) )
|
||||
{
|
||||
// Java 8 or lower
|
||||
version = version.substring( 2, 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Java 9 or higher
|
||||
int i = version.indexOf( "." );
|
||||
if ( i != -1 )
|
||||
{
|
||||
version = version.substring( 0, i );
|
||||
}
|
||||
// I2P 24-ea
|
||||
i = version.indexOf( "-" );
|
||||
if ( i != -1 )
|
||||
{
|
||||
version = version.substring( 0, i );
|
||||
}
|
||||
}
|
||||
return Integer.parseInt( version );
|
||||
}
|
||||
|
||||
private static Object getModuleByName( String moduleName )
|
||||
{
|
||||
Object module = null;
|
||||
Class moduleLayerClass;
|
||||
try
|
||||
{
|
||||
moduleLayerClass = Class.forName( "java.lang.ModuleLayer" );
|
||||
}
|
||||
catch ( ClassNotFoundException e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "java.lang.ModuleLayer not found" );
|
||||
}
|
||||
moduleLayerClass = null;
|
||||
}
|
||||
if ( moduleLayerClass != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
Method m = moduleLayerClass.getMethod( "boot", new Class[] { } );
|
||||
Object boot = m.invoke( null, new Object[] { } );
|
||||
if ( boot != null )
|
||||
{
|
||||
m = moduleLayerClass.getMethod( "findModule", new Class[] { String.class } );
|
||||
Object optional = m.invoke( boot, new Object[] { moduleName } );
|
||||
m = optional.getClass().getMethod( "get", new Class[] { });
|
||||
try
|
||||
{
|
||||
module = m.invoke( optional, new Object[] { } );
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
if ( m_debug && e.getCause() instanceof NoSuchElementException ) {
|
||||
printDebug( "Failed to find module." );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// boot layer not initialized (should not happen)
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
if ( m_debug )
|
||||
{
|
||||
printDebug( "Failed to retrieve " + moduleName + " module - " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
}
|
||||
return module;
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user