Kaydet (Commit) e2b7ea63 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS sb87 (1.5.10); FILE MERGED

2008/05/07 11:34:25 sb 1.5.10.1: #i88687# let Loader call new unoinfo instead of old juh.jar UnoInfo.getJars
üst c4c10c17
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite * OpenOffice.org - a multi-platform office productivity suite
* *
* $RCSfile: Loader.java,v $ * $RCSfile: Loader.java,v $
* $Revision: 1.5 $ * $Revision: 1.6 $
* *
* This file is part of OpenOffice.org. * This file is part of OpenOffice.org.
* *
...@@ -32,6 +32,8 @@ package com.sun.star.lib.loader; ...@@ -32,6 +32,8 @@ package com.sun.star.lib.loader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.JarURLConnection; import java.net.JarURLConnection;
...@@ -166,18 +168,7 @@ public final class Loader { ...@@ -166,18 +168,7 @@ public final class Loader {
"java.class.path: " + e ); "java.class.path: " + e );
} }
if ( classpath != null ) { if ( classpath != null ) {
StringTokenizer tokens = new StringTokenizer( classpath, addUrls(vec, classpath, File.pathSeparator);
File.pathSeparator );
while ( tokens.hasMoreTokens() ) {
try {
vec.add( new File( tokens.nextToken() ).toURL() );
} catch ( MalformedURLException e ) {
// don't add this class path entry to the list of class
// loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: bad java.class.path: " + e );
}
}
} }
// get the urls from which to load classes and resources // get the urls from which to load classes and resources
...@@ -186,6 +177,7 @@ public final class Loader { ...@@ -186,6 +177,7 @@ public final class Loader {
if ( path != null ) { if ( path != null ) {
File fClassesDir = new File( path, CLASSESDIR ); File fClassesDir = new File( path, CLASSESDIR );
File fJuh = new File( fClassesDir, JUHJAR ); File fJuh = new File( fClassesDir, JUHJAR );
if ( fJuh.exists() ) {
URL[] clurls = new URL[1]; URL[] clurls = new URL[1];
try { try {
clurls[0] = fJuh.toURL(); clurls[0] = fJuh.toURL();
...@@ -193,36 +185,40 @@ public final class Loader { ...@@ -193,36 +185,40 @@ public final class Loader {
Class c = cl.loadClass( Class c = cl.loadClass(
"com.sun.star.comp.helper.UnoInfo" ); "com.sun.star.comp.helper.UnoInfo" );
Method m = c.getMethod( "getJars", (Class[]) null ); Method m = c.getMethod( "getJars", (Class[]) null );
URL[] jarurls = (URL[]) m.invoke( null, (Object[]) null ); URL[] jarurls = (URL[]) m.invoke(
null, (Object[]) null );
for ( int i = 0; i < jarurls.length; i++ ) { for ( int i = 0; i < jarurls.length; i++ ) {
vec.add( jarurls[i] ); vec.add( jarurls[i] );
} }
} catch ( MalformedURLException e ) { } catch ( MalformedURLException e ) {
// don't add the UNO jar files to the list of class loader // don't add the UNO jar files to the list of class
// URLs // loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: cannot add UNO jar files: " + e ); "getCustomLoader: cannot add UNO jar files: " + e );
} catch ( ClassNotFoundException e ) { } catch ( ClassNotFoundException e ) {
// don't add the UNO jar files to the list of class loader // don't add the UNO jar files to the list of class
// URLs // loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: cannot add UNO jar files: " + e ); "getCustomLoader: cannot add UNO jar files: " + e );
} catch ( NoSuchMethodException e ) { } catch ( NoSuchMethodException e ) {
// don't add the UNO jar files to the list of class loader // don't add the UNO jar files to the list of class
// URLs // loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: cannot add UNO jar files: " + e ); "getCustomLoader: cannot add UNO jar files: " + e );
} catch ( IllegalAccessException e ) { } catch ( IllegalAccessException e ) {
// don't add the UNO jar files to the list of class loader // don't add the UNO jar files to the list of class
// URLs // loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: cannot add UNO jar files: " + e ); "getCustomLoader: cannot add UNO jar files: " + e );
} catch ( InvocationTargetException e ) { } catch ( InvocationTargetException e ) {
// don't add the UNO jar files to the list of class loader // don't add the UNO jar files to the list of class
// URLs // loader URLs
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: cannot add UNO jar files: " + e ); "getCustomLoader: cannot add UNO jar files: " + e );
} }
} else {
callUnoinfo(path, vec);
}
} else { } else {
System.err.println( "com.sun.star.lib.loader.Loader::" + System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: no UNO installation found!" ); "getCustomLoader: no UNO installation found!" );
...@@ -239,6 +235,116 @@ public final class Loader { ...@@ -239,6 +235,116 @@ public final class Loader {
return m_Loader; return m_Loader;
} }
private static void addUrls(Vector urls, String data, String delimiter) {
StringTokenizer tokens = new StringTokenizer( data, delimiter );
while ( tokens.hasMoreTokens() ) {
try {
urls.add( new File( tokens.nextToken() ).toURL() );
} catch ( MalformedURLException e ) {
// don't add this class path entry to the list of class loader
// URLs
System.err.println( "com.sun.star.lib.loader.Loader::" +
"getCustomLoader: bad pathname: " + e );
}
}
}
private static void callUnoinfo(String path, Vector urls) {
Process p;
try {
p = Runtime.getRuntime().exec(
new String[] { new File(path, "unoinfo").getPath(), "java" });
} catch (IOException e) {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader: exec" +
" unoinfo: " + e);
return;
}
new Drain(p.getErrorStream()).start();
int code;
byte[] buf = new byte[1000];
int n = 0;
try {
InputStream s = p.getInputStream();
code = s.read();
for (;;) {
if (n == buf.length) {
if (n > Integer.MAX_VALUE / 2) {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader:" +
" too much unoinfo output");
return;
}
byte[] buf2 = new byte[2 * n];
for (int i = 0; i < n; ++i) {
buf2[i] = buf[i];
}
buf = buf2;
}
int k = s.read(buf, n, buf.length - n);
if (k == -1) {
break;
}
n += k;
}
} catch (IOException e) {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader: reading" +
" unoinfo output: " + e);
return;
}
int ev;
try {
ev = p.waitFor();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader: waiting for" +
" unoinfo: " + e);
return;
}
if (ev != 0) {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader: unoinfo"
+ " exit value " + n);
return;
}
String s;
if (code == '0') {
s = new String(buf);
} else if (code == '1') {
try {
s = new String(buf, "UTF-16LE");
} catch (UnsupportedEncodingException e) {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader:" +
" transforming unoinfo output: " + e);
return;
}
} else {
System.err.println(
"com.sun.star.lib.loader.Loader::getCustomLoader: bad unoinfo"
+ " output");
return;
}
addUrls(urls, s, "\0");
}
private static final class Drain extends Thread {
public Drain(InputStream stream) {
super("unoinfo stderr drain");
this.stream = stream;
}
public void run() {
try {
while (stream.read() != -1) {}
} catch (IOException e) { /* ignored */ }
}
private final InputStream stream;
}
/** /**
* A customized class loader which is used to load classes and resources * A customized class loader which is used to load classes and resources
* from a search path of user-defined URLs. * from a search path of user-defined URLs.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment