A
Andrew Thompson
This is a repost from a JDIC forum message from Oct. 2nd.
<https://screensavers.dev.java.net/servlets/ProjectForumMessageView?forumID=698&messageID=4325>
The forum (for the 'Saverbeans' Java based screensavers) is a
bit quiet and I have got no responses, so I am reposting here
in the hope of getting some.
Here is the problem..
I intend to make an installer for screen savers. While
installation on Win is pretty straightforward, *nix boxes
(Solaris, Unix, Linux) are more complicated, primarily
because of the inconsistencies in the set-up.
As such, I intend to use a simple class to attempt to detect
the appropriate paths, and I figure that if I can detect the
presence of 'libXm.so', that will get me %90 of the way.
I have hacked out some crude code to begin testing this
theory, it is below. I would appreciate if some *nix
enabled devlopers could run it on their boxes and paste
the results back for me.
Please note that if the code fails to find the file on any
of the paths defined for the java.library.path, it will then
revert to a 'brute force' search of the local disks
returned by File.listRoots(), so it might take 'a few
moments'..
Suggestions for improvement are welcome. I do not have
a *nix box on which to test, and I would not be surprised
if many of my naiive assumptions are wrong, we'll start
fixing them here.
<sscce>
import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
/** This class searches for the existence of the libXm.so file
that is indicative of the installation of XScreensaver on *nix
based systems. */
class XScreensaverPath {
/** Array of directories that form a path to the libXm.so file */
public final String[] pathToLibXm = {
"usr", "X11R6", "lib",
"libXm.so" // for the real test on *nix boxes
// "tomcat.ico" // for testing on a Win box w/Tomcat
};
/** Path to the libXm.so file, built from the pathToLibXm array
using the platform path separator. */
String relativePath;
/** Flag to indicate the libXm.so file has been located. */
boolean found = false;
/** The file object that represents the libXm.so file. */
File libXmSo = null;
/** Compile true for debugging output. */
public static final boolean TEST = false;
/** The XScreensaverPath constructor. Automatically searches for
the XScreensaver existence by detecting the path to a crucial
file. */
XScreensaverPath() {
File f = getXScreensaverPath();
String result = "not found";
if (f!=null) {
result = f.toString();
}
System.out.println( "libXm.so - Search (1): " + result );
if (f==null) {
searchRoots();
if (f!=null) {
result = f.toString();
}
System.out.println( "libXm.so - Search (2): " + libXmSo );
}
}
/** Build the pathToLibXm into the relativePath. */
public void initializePathString() {
String sep = System.getProperty( "file.separator" );
relativePath = "";
for( int ii=0; ii<pathToLibXm.length; ii++ ) {
relativePath += pathToLibXm[ii] + sep;
}
relativePath = relativePath.substring(0,
relativePath.length()-1);
if (TEST) System.out.println("XSP.XSP: " + relativePath);
}
/** Searches the java library path to ascertain if the
libXm.so file is on it.*/
public File getXScreensaverPath() {
initializePathString();
String s = System.getProperty("java.library.path");
String[] paths = s.split(
System.getProperty("path.separator") );
Arrays.sort(paths);
ArrayList uniquePath = new ArrayList();
for (int ii=0; ii<paths.length; ii++) {
if (ii>0 && !paths[ii].equals(paths[ii-1]) ) {
uniquePath.add( paths[ii] );
System.out.println( "paths: " + paths[ii] );
}
}
File f = null;
for (int ii=0; ii<uniquePath.size(); ii++) {
File f1 = new File(
(String)uniquePath.get(ii), relativePath );
if (TEST) System.out.println( "XSP.gXSP: " + f1 );
if ( f1.exists() ) {
f = f1;
break;
}
}
return f;
}
/** Searches the 'roots' for the 'libXm.so' file.
A brute force method used if the targetted search fails. */
public void searchRoots() {
File[] roots = File.listRoots();
File libXm = null;
int ii = 0;
while ( ii<roots.length && !found ) {
searchDirectory(roots[ii]);
ii++;
}
}
/** Searches a directory and all it's subdirectories for
the 'libXm.so' file. */
public void searchDirectory(File f) {
if (TEST) System.out.println("XSP.sD: " + f);
File[] files;
File libXm = null;
if (!found) {
try {
File libXmTest = new File(f,
pathToLibXm[pathToLibXm.length-1]);
if (TEST) System.out.println("XSP.sD: " +
libXmTest + "/" + libXmTest.exists() );
if ( libXmTest.exists() ) {
found = true;
libXm = libXmTest;
libXmSo = libXmTest;
} else {
// search the sub-directories.
files = f.listFiles();
int ii = 0;
while ( ii<files.length && !found ) {
if ( files[ii].isDirectory() ) {
searchDirectory( files[ii] );
}
ii++;
}
}
} catch (NullPointerException npe) {
// empty/inaccessible disk
}
}
}
/** Create an XScreenaverPath instance and let it do it's stuff. */
public static void main(String args[]) {
new XScreensaverPath();
}
}
</sscce>
<https://screensavers.dev.java.net/servlets/ProjectForumMessageView?forumID=698&messageID=4325>
The forum (for the 'Saverbeans' Java based screensavers) is a
bit quiet and I have got no responses, so I am reposting here
in the hope of getting some.
Here is the problem..
I intend to make an installer for screen savers. While
installation on Win is pretty straightforward, *nix boxes
(Solaris, Unix, Linux) are more complicated, primarily
because of the inconsistencies in the set-up.
As such, I intend to use a simple class to attempt to detect
the appropriate paths, and I figure that if I can detect the
presence of 'libXm.so', that will get me %90 of the way.
I have hacked out some crude code to begin testing this
theory, it is below. I would appreciate if some *nix
enabled devlopers could run it on their boxes and paste
the results back for me.
Please note that if the code fails to find the file on any
of the paths defined for the java.library.path, it will then
revert to a 'brute force' search of the local disks
returned by File.listRoots(), so it might take 'a few
moments'..
Suggestions for improvement are welcome. I do not have
a *nix box on which to test, and I would not be surprised
if many of my naiive assumptions are wrong, we'll start
fixing them here.
<sscce>
import java.io.File;
import java.util.Arrays;
import java.util.ArrayList;
/** This class searches for the existence of the libXm.so file
that is indicative of the installation of XScreensaver on *nix
based systems. */
class XScreensaverPath {
/** Array of directories that form a path to the libXm.so file */
public final String[] pathToLibXm = {
"usr", "X11R6", "lib",
"libXm.so" // for the real test on *nix boxes
// "tomcat.ico" // for testing on a Win box w/Tomcat
};
/** Path to the libXm.so file, built from the pathToLibXm array
using the platform path separator. */
String relativePath;
/** Flag to indicate the libXm.so file has been located. */
boolean found = false;
/** The file object that represents the libXm.so file. */
File libXmSo = null;
/** Compile true for debugging output. */
public static final boolean TEST = false;
/** The XScreensaverPath constructor. Automatically searches for
the XScreensaver existence by detecting the path to a crucial
file. */
XScreensaverPath() {
File f = getXScreensaverPath();
String result = "not found";
if (f!=null) {
result = f.toString();
}
System.out.println( "libXm.so - Search (1): " + result );
if (f==null) {
searchRoots();
if (f!=null) {
result = f.toString();
}
System.out.println( "libXm.so - Search (2): " + libXmSo );
}
}
/** Build the pathToLibXm into the relativePath. */
public void initializePathString() {
String sep = System.getProperty( "file.separator" );
relativePath = "";
for( int ii=0; ii<pathToLibXm.length; ii++ ) {
relativePath += pathToLibXm[ii] + sep;
}
relativePath = relativePath.substring(0,
relativePath.length()-1);
if (TEST) System.out.println("XSP.XSP: " + relativePath);
}
/** Searches the java library path to ascertain if the
libXm.so file is on it.*/
public File getXScreensaverPath() {
initializePathString();
String s = System.getProperty("java.library.path");
String[] paths = s.split(
System.getProperty("path.separator") );
Arrays.sort(paths);
ArrayList uniquePath = new ArrayList();
for (int ii=0; ii<paths.length; ii++) {
if (ii>0 && !paths[ii].equals(paths[ii-1]) ) {
uniquePath.add( paths[ii] );
System.out.println( "paths: " + paths[ii] );
}
}
File f = null;
for (int ii=0; ii<uniquePath.size(); ii++) {
File f1 = new File(
(String)uniquePath.get(ii), relativePath );
if (TEST) System.out.println( "XSP.gXSP: " + f1 );
if ( f1.exists() ) {
f = f1;
break;
}
}
return f;
}
/** Searches the 'roots' for the 'libXm.so' file.
A brute force method used if the targetted search fails. */
public void searchRoots() {
File[] roots = File.listRoots();
File libXm = null;
int ii = 0;
while ( ii<roots.length && !found ) {
searchDirectory(roots[ii]);
ii++;
}
}
/** Searches a directory and all it's subdirectories for
the 'libXm.so' file. */
public void searchDirectory(File f) {
if (TEST) System.out.println("XSP.sD: " + f);
File[] files;
File libXm = null;
if (!found) {
try {
File libXmTest = new File(f,
pathToLibXm[pathToLibXm.length-1]);
if (TEST) System.out.println("XSP.sD: " +
libXmTest + "/" + libXmTest.exists() );
if ( libXmTest.exists() ) {
found = true;
libXm = libXmTest;
libXmSo = libXmTest;
} else {
// search the sub-directories.
files = f.listFiles();
int ii = 0;
while ( ii<files.length && !found ) {
if ( files[ii].isDirectory() ) {
searchDirectory( files[ii] );
}
ii++;
}
}
} catch (NullPointerException npe) {
// empty/inaccessible disk
}
}
}
/** Create an XScreenaverPath instance and let it do it's stuff. */
public static void main(String args[]) {
new XScreensaverPath();
}
}
</sscce>