1 |
From cabcfa6732224ad36db52e33fb96f1d776c43f2d Mon Sep 17 00:00:00 2001 |
2 |
From: Stephan Bergmann <sbergman@redhat.com> |
3 |
Date: Fri, 26 Oct 2012 16:22:16 +0200 |
4 |
Subject: [PATCH] fdo#49517: Revert "fdo#46102: Load Java scripts with class |
5 |
loaders [...]" |
6 |
|
7 |
This reverts commit dd6c4f4db1d62268d73e09ae52d23f760a967dcc "fdo#46102: Load |
8 |
Java scripts with class loaders that actually find them." That commit broke |
9 |
support for macros embedded in documents (as |
10 |
new java.net.URL("vnd.sun.star.tdoc:...") throws a MalformedURLExcetpion), and |
11 |
it looks like that commit was not necessary after all -- or rather that what it |
12 |
tried to work around must have been some other problem that has been fixed |
13 |
meanwhile. "It is unclear to me how the Java script provider shall ever have |
14 |
found the script jars in the past" indicates that something must have been |
15 |
fishy, and what I failed to notice back then is that createURL creates |
16 |
java.net.URL instances with a UCBStreamHandler that does allow to obtain content |
17 |
from weird-looking URLs. |
18 |
|
19 |
Anyway, with that reverted, all three following scenarios work on both current |
20 |
master (towards LO 3.7) and libreoffice-3-6 (towards LO 3.6.4); I haven't yet |
21 |
come around to test on libreoffice-3-5: |
22 |
|
23 |
1 Stock macros, "Tools - Macros - Run Macro... - LibreOffice Macros - |
24 |
HelloWorld", running all of the four "helloworld.bsh", "helloworld.js", |
25 |
"HelloWorldPyhton", and |
26 |
"org.libreoffice.example.java_scripts.HelloWorld.printHW". |
27 |
|
28 |
2 Per-document macros, loading test.odt attached to fdo#49517, then "Tools - |
29 |
Macros - Run Macro... - test.odt - HelloWorld", running |
30 |
"org.libreoffice.example.java_scripts.HelloWorld.printHW". |
31 |
|
32 |
3 Extension macros, installing ScriptDispatch.oxt attached to fdo#46012 as |
33 |
shared extension, then loading StartScriptDispatch.odt attached to fdo#46012 and |
34 |
pressing the "Start Java via ScriptProvider" button. |
35 |
|
36 |
Change-Id: I31cd16b3720ffeb1058722d4d1fdffb773f8a067 |
37 |
(cherry picked from commit 7ea7fb009ddcfb0723e88ba0c5778b5fdbe2b553) |
38 |
--- |
39 |
.../script/framework/container/ScriptMetaData.java | 46 ++-------------------- |
40 |
.../framework/provider/ClassLoaderFactory.java | 6 +-- |
41 |
.../beanshell/ScriptEditorForBeanShell.java | 3 +- |
42 |
.../beanshell/ScriptProviderForBeanShell.java | 3 +- |
43 |
.../provider/java/ScriptProviderForJava.java | 2 +- |
44 |
.../javascript/ScriptProviderForJavaScript.java | 3 +- |
45 |
6 files changed, 9 insertions(+), 54 deletions(-) |
46 |
|
47 |
diff --git a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java |
48 |
index 178f480..1cf99d7 100755 |
49 |
--- a/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java |
50 |
+++ b/scripting/java/com/sun/star/script/framework/container/ScriptMetaData.java |
51 |
@@ -50,14 +50,7 @@ import com.sun.star.script.framework.io.UCBStreamHandler; |
52 |
|
53 |
import com.sun.star.ucb.XSimpleFileAccess2; |
54 |
|
55 |
-import com.sun.star.uno.AnyConverter; |
56 |
import com.sun.star.uno.UnoRuntime; |
57 |
-import com.sun.star.uno.XComponentContext; |
58 |
- |
59 |
-import com.sun.star.uri.UriReferenceFactory; |
60 |
-import com.sun.star.uri.XVndSunStarExpandUrl; |
61 |
- |
62 |
-import com.sun.star.util.XMacroExpander; |
63 |
|
64 |
public class ScriptMetaData extends ScriptEntry implements Cloneable { |
65 |
private boolean hasSource = false; |
66 |
@@ -253,8 +246,7 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { |
67 |
return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " + locationPlaceHolder + super.toString(); |
68 |
} |
69 |
|
70 |
- public URL[] getClassPath(XComponentContext context) |
71 |
- throws java.net.MalformedURLException |
72 |
+ public URL[] getClassPath() throws java.net.MalformedURLException |
73 |
{ |
74 |
try |
75 |
{ |
76 |
@@ -282,7 +274,7 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { |
77 |
{ |
78 |
String relativeClasspath = (String)stk.nextElement(); |
79 |
String pathToProcess = PathUtils.make_url( parcelPath, relativeClasspath); |
80 |
- URL url = expandURL( context, pathToProcess ); |
81 |
+ URL url = createURL( pathToProcess ); |
82 |
if ( url != null ) |
83 |
{ |
84 |
classPathVec.add ( url ); |
85 |
@@ -291,7 +283,7 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { |
86 |
} |
87 |
if ( classPathVec.size() == 0) |
88 |
{ |
89 |
- URL url = expandURL( context, parcelPath ); |
90 |
+ URL url = createURL( parcelPath ); |
91 |
if ( url != null ) |
92 |
{ |
93 |
classPathVec.add(url); |
94 |
@@ -308,38 +300,6 @@ public class ScriptMetaData extends ScriptEntry implements Cloneable { |
95 |
} |
96 |
|
97 |
} |
98 |
- |
99 |
- private URL expandURL(XComponentContext context, String url) |
100 |
- throws java.net.MalformedURLException |
101 |
- { |
102 |
- XVndSunStarExpandUrl exp = UnoRuntime.queryInterface( |
103 |
- XVndSunStarExpandUrl.class, |
104 |
- UriReferenceFactory.create(context).parse(url)); |
105 |
- String expurl; |
106 |
- if (exp == null) { |
107 |
- expurl = url; |
108 |
- } else { |
109 |
- XMacroExpander expander; |
110 |
- try { |
111 |
- expander = (XMacroExpander) AnyConverter.toObject( |
112 |
- XMacroExpander.class, |
113 |
- context.getValueByName( |
114 |
- "/singletons/com.sun.star.util.theMacroExpander")); |
115 |
- } catch (com.sun.star.lang.IllegalArgumentException e) { |
116 |
- throw new RuntimeException(e); |
117 |
- } |
118 |
- try { |
119 |
- expurl = exp.expand(expander); |
120 |
- } catch (com.sun.star.lang.IllegalArgumentException e) { |
121 |
- java.net.MalformedURLException e2 = |
122 |
- new java.net.MalformedURLException(e.toString()); |
123 |
- e2.initCause(e); |
124 |
- throw e2; |
125 |
- } |
126 |
- } |
127 |
- return new URL(expurl); |
128 |
- } |
129 |
- |
130 |
private URL createURL( String path ) throws java.net.MalformedURLException |
131 |
{ |
132 |
URL url = null; |
133 |
diff --git a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java |
134 |
index 081204f..641ca58 100755 |
135 |
--- a/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java |
136 |
+++ b/scripting/java/com/sun/star/script/framework/provider/ClassLoaderFactory.java |
137 |
@@ -31,7 +31,6 @@ import java.net.*; |
138 |
|
139 |
import com.sun.star.script.framework.log.LogUtils; |
140 |
import com.sun.star.script.framework.container.ScriptMetaData; |
141 |
-import com.sun.star.uno.XComponentContext; |
142 |
|
143 |
/** |
144 |
* Class Loader Factory |
145 |
@@ -43,12 +42,11 @@ public class ClassLoaderFactory |
146 |
{ |
147 |
private ClassLoaderFactory() {} |
148 |
|
149 |
- public static ClassLoader getURLClassLoader( |
150 |
- XComponentContext context, ScriptMetaData scriptData ) |
151 |
+ public static ClassLoader getURLClassLoader( ScriptMetaData scriptData ) |
152 |
throws NoSuitableClassLoaderException, MalformedURLException |
153 |
{ |
154 |
ClassLoader parent = scriptData.getClass().getClassLoader(); |
155 |
- URL[] classPath = scriptData.getClassPath(context); |
156 |
+ URL[] classPath = scriptData.getClassPath(); |
157 |
LogUtils.DEBUG("Classpath has length " + classPath.length ); |
158 |
for ( int i=0; i < classPath.length; i++ ) |
159 |
{ |
160 |
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java |
161 |
index 9f6739d..cbbcfc3 100755 |
162 |
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java |
163 |
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptEditorForBeanShell.java |
164 |
@@ -202,8 +202,7 @@ public class ScriptEditorForBeanShell |
165 |
try { |
166 |
ClassLoader cl = null; |
167 |
try { |
168 |
- cl = ClassLoaderFactory.getURLClassLoader( |
169 |
- context.getComponentContext(), entry ); |
170 |
+ cl = ClassLoaderFactory.getURLClassLoader( entry ); |
171 |
} |
172 |
catch (Exception ignore) // TODO re-examine error handling |
173 |
{ |
174 |
diff --git a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java |
175 |
index 22a9ea8..95c7278 100755 |
176 |
--- a/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java |
177 |
+++ b/scripting/java/com/sun/star/script/framework/provider/beanshell/ScriptProviderForBeanShell.java |
178 |
@@ -196,8 +196,7 @@ class ScriptImpl implements XScript |
179 |
ClassLoader cl = null; |
180 |
URL sourceUrl = null; |
181 |
try { |
182 |
- cl = ClassLoaderFactory.getURLClassLoader( |
183 |
- m_xContext, metaData ); |
184 |
+ cl = ClassLoaderFactory.getURLClassLoader( metaData ); |
185 |
sourceUrl = metaData.getSourceURL(); |
186 |
} |
187 |
catch ( java.net.MalformedURLException mfu ) |
188 |
diff --git a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java |
189 |
index 3f392f7..707ea05 100755 |
190 |
--- a/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java |
191 |
+++ b/scripting/java/com/sun/star/script/framework/provider/java/ScriptProviderForJava.java |
192 |
@@ -205,7 +205,7 @@ class ScriptImpl implements XScript |
193 |
try { |
194 |
LogUtils.DEBUG( "Classloader starting..." ); |
195 |
scriptLoader = ClassLoaderFactory.getURLClassLoader( |
196 |
- m_xContext, metaData ); |
197 |
+ metaData ); |
198 |
LogUtils.DEBUG( "Classloader finished..." ); |
199 |
} |
200 |
catch (MalformedURLException mfe ) |
201 |
diff --git a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java |
202 |
index 39205d4..9f04d91 100755 |
203 |
--- a/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java |
204 |
+++ b/scripting/java/com/sun/star/script/framework/provider/javascript/ScriptProviderForJavaScript.java |
205 |
@@ -195,8 +195,7 @@ class ScriptImpl implements XScript |
206 |
ClassLoader cl = null; |
207 |
URL sourceUrl = null; |
208 |
try { |
209 |
- cl = ClassLoaderFactory.getURLClassLoader( |
210 |
- m_xContext, metaData ); |
211 |
+ cl = ClassLoaderFactory.getURLClassLoader( metaData ); |
212 |
sourceUrl = metaData.getSourceURL(); |
213 |
} |
214 |
catch ( java.net.MalformedURLException mfu ) |
215 |
-- |
216 |
1.7.11.7 |
217 |
|