[MNG-6115] prevent JAnsi from writing temp native files to lib/ext

This commit is contained in:
Hervé Boutemy 2017-03-05 00:39:31 +01:00
parent 809ba34055
commit 181b0215aa
6 changed files with 91 additions and 2 deletions

View File

@ -128,6 +128,22 @@ under the License.
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<includeArtifactIds>jansi</includeArtifactIds>
<includes>META-INF/native/**</includes>
</configuration>
<executions>
<execution>
<id>unpack-jansi-native</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
@ -215,6 +231,7 @@ under the License.
<id>clean-target-dir</id>
<phase>prepare-package</phase>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${distributionTargetDir}</directory>

View File

@ -191,5 +191,4 @@ exec "$JAVACMD" \
-classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmaven.home=${MAVEN_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/ext" \
${CLASSWORLDS_LAUNCHER} "$@"

View File

@ -178,7 +178,6 @@ set CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
"-Dclassworlds.conf=%MAVEN_HOME%\bin\m2.conf" ^
"-Dmaven.home=%MAVEN_HOME%" ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\ext" ^
%CLASSWORLDS_LAUNCHER% %MAVEN_CMD_LINE_ARGS%
if ERRORLEVEL 1 goto error
goto end

View File

@ -0,0 +1,7 @@
This directory contains Jansi native libraries, extracted from Jansi jar.
You can add your own extensions for platforms not natively supported by
Jansi: the libraries follow HawtJNI directory and filename conventions.
See http://fusesource.github.io/hawtjni/documentation/api/org/fusesource/hawtjni/runtime/Library.html
See https://github.com/fusesource/jansi-native for native lib source.

View File

@ -55,6 +55,14 @@ under the License.
<include>**</include>
</includes>
</fileSet>
<fileSet>
<directory>target/dependency/META-INF/native</directory>
<outputDirectory>lib/jansi-native</outputDirectory>
<includes>
<include>**</include>
</includes>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>src/bin</directory>
<outputDirectory>bin</outputDirectory>

View File

@ -185,6 +185,7 @@ public static int main( String[] args, ClassWorld classWorld )
{
MavenCli cli = new MavenCli();
prepareJansiNative();
MessageUtils.systemInstall();
int result = cli.doMain( new CliRequest( args, classWorld ) );
MessageUtils.systemUninstall();
@ -192,6 +193,64 @@ public static int main( String[] args, ClassWorld classWorld )
return result;
}
/**
* temporary method while improvement reported to JAnsi+HawtJNI and integrated:
* library.jansi.path should point to lib/jansi-native and HawtJNI should be able to detect
* the platform instead of forcing the user having to point library.jansi.path to
* lib/jansi-native/[platform]
*/
private static void prepareJansiNative()
{
if ( System.getProperty( "library.jansi.path" ) == null )
{
String mavenHome = System.getProperty( "maven.home" );
if ( mavenHome != null )
{
File jansiNative = new File( mavenHome, "lib/jansi-native/" + hawtJNIgetPlatform() );
System.setProperty( "library.jansi.path", jansiNative.getAbsolutePath() );
}
}
}
private static String hawtJNIgetOperatingSystem()
{
String name = System.getProperty( "os.name" ).toLowerCase().trim();
if ( name.startsWith( "linux" ) )
{
return "linux";
}
if ( name.startsWith( "mac os x" ) )
{
return "osx";
}
if ( name.startsWith( "win" ) )
{
return "windows";
}
return name.replaceAll( "\\W+", "_" );
}
private static String hawtJNIgetPlatform()
{
return hawtJNIgetOperatingSystem() + hawtJNIgetBitModel();
}
private static int hawtJNIgetBitModel()
{
String prop = System.getProperty( "sun.arch.data.model" );
if ( prop == null )
{
prop = System.getProperty( "com.ibm.vm.bitmode" );
}
if ( prop != null )
{
return Integer.parseInt( prop );
}
return -1; // we don't know..
}
// TODO need to externalize CliRequest
public static int doMain( String[] args, ClassWorld classWorld )
{