-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
fj-core/src/main/java/org/fugerit/java/core/lang/LibHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.fugerit.java.core.lang; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.fugerit.java.core.cfg.ConfigRuntimeException; | ||
|
||
import java.io.File; | ||
import java.io.FilenameFilter; | ||
|
||
@Slf4j | ||
public class LibHelper { | ||
|
||
private LibHelper() {} | ||
|
||
private static final String LLP = "java.library.path"; | ||
|
||
private static final String OSN = "os.name"; | ||
|
||
public static int ll(String name ) { | ||
return ll( name, 1 ); | ||
} | ||
|
||
public static int ll(String name, int checkCount ) { | ||
return ll( name, (f, n) -> n.contains(name), checkCount ); | ||
} | ||
|
||
public static int ll(String name, FilenameFilter ffn, int checkCount ) { | ||
String libPath = System.getProperty( LLP ); | ||
log.info( "loading library path [{}]", libPath ); | ||
int count = 0; | ||
if ( libPath != null ) { | ||
String[] listPath = libPath.split(File.pathSeparator ); | ||
for ( int k=0; k<listPath.length; k++ ) { | ||
File folder = new File( listPath[k] ); | ||
if ( folder.isDirectory() ) { | ||
count+=folder.list(ffn).length; | ||
} | ||
} | ||
} | ||
log.info( "name : {}, checkCount : {}, count : {} ", name, checkCount, count ); | ||
if ( count > checkCount ) { | ||
throw new ConfigRuntimeException( String.format( "%s is too many library paths : %s", name, count ) ); | ||
} else if ( count > 1 ) { | ||
log.info( "loading library [{}]", name ); | ||
System.loadLibrary( name ); | ||
} else { | ||
log.info( "skip loading library [{}]", name ); | ||
} | ||
return count; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
fj-core/src/test/java/test/org/fugerit/java/core/lang/TestLibHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package test.org.fugerit.java.core.lang; | ||
|
||
import org.fugerit.java.core.cfg.ConfigRuntimeException; | ||
import org.fugerit.java.core.lang.LibHelper; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public class TestLibHelper { | ||
|
||
private static final String LLP = "java.library.path"; | ||
|
||
@Test | ||
public void testCount0() throws IOException { | ||
File libraryPath = new File( "src/test/resources/core/lang/lib_helper" ); | ||
String llPath = System.getProperty( LLP ); | ||
System.setProperty( LLP, llPath+File.pathSeparator+libraryPath.getCanonicalPath() ); | ||
int count1 = LibHelper.ll( "test_ll_fug1" ); | ||
Assert.assertEquals( 1, count1 ); | ||
Assert.assertThrows( ConfigRuntimeException.class, () -> LibHelper.ll( "test_ll_fug" ) ); | ||
Assert.assertEquals( 0, LibHelper.ll( "test_ll_not_found" ) ); | ||
} | ||
|
||
} |
Empty file.
Empty file.