-
Notifications
You must be signed in to change notification settings - Fork 170
performant multi-run support #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Any thoughts on this one? Would be really useful to know whether such functionality can be eventually accepted and whether this is the right approach for it. Thank you. |
Yes please. It is not just about comfort when reviewing diffs; if we ever need to |
| * You must have used {@link #createSecureCompilerConfiguration} to prepare the Groovy shell. | ||
| * @param script a script ready to {@link Script#run}, created for example by {@link GroovyShell#parse(String)} | ||
| * @param whitelist the whitelist to use, such as {@link Whitelist#all()} | ||
| * @return the sandbox for running this script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be helpful to @link to register and unregister so callers can see how to use it.
| } | ||
| } | ||
|
|
||
| public PreparedScript prepare(ClassLoader loader, Binding binding) throws IllegalAccessException, IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deserves Javadoc at least for the loader parameter, which in evaluate is nontrivial.
| } | ||
|
|
||
| } finally { | ||
| public void cleanUp() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better implement Closeable and make this the close method, so PreparedScript can be used in a Java 7+ try block.
| } catch (NoSuchFieldException nsme) { | ||
| LOGGER.log(Level.FINE, "GroovyShell fields have changed, field loader no longer exists -- memory leak fixes won't work"); | ||
| /** | ||
| * Allows access to execue a script multiple times without preparation and clean-up overhead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
|
|
||
| public Object run() throws Exception { | ||
| if (sandbox) { | ||
| scriptSandbox.register(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: register and unregister calls should be cheap enough that they contribute no significant overhead.
| assertTrue((int) res == 6); | ||
| assertTrue((int) b.getVariable("a") == 7); | ||
| } catch (Exception e) { | ||
| script.cleanUp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a finally block, not a catch block (or just use Closeable trick mentioned above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange that I did this, I'll check your Closeable suggestion
| assertTrue((int) res == 6); | ||
| assertTrue((int) b.getVariable("a") == 7); | ||
| } catch (Exception e) { | ||
| script.cleanUp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
|
Hello, updated according to your reasonable comments. Please let me know if you see further possible improvements (or if I missed anything). One question - would the automatic PR test job deploy a timestamped snapshot or does it have to be deployed in some other way? |
Afraid not.
IIRC you just need a jenkins.io account, then I use a helper script: mvn clean install source:jar deploy:deploy -DaltDeploymentRepository=maven.jenkins-ci.org::default::https://repo.jenkins-ci.org/snapshots/ -DskipTestsPlain |
BTW that has been superseded by JEP-305. Docs |
jglick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last I checked, the idea sounded fine but I have not looked at the details. Leaving it to plugin owners.
Hello, I want to be able to run a groovy script many times without needless overhead.
This is needed for me to implement custom log lines processing in Logstash plugin.
At the same time I'd like the convenience and safety of all the magic presently done
by the secure groovy script plugin. This modification is to allow that.
Sorry about white-space changes. It's because of the editor settings. If you don't
want them, I'll go ahead and revert them. Same about the EditorConfig file. Just
thought it is a useful addition.
If you like to keep the removed needless whilte spaces, you could add
?w=1to urlof the file diff to have them filtered out while reviewing:
https://github.com/jenkinsci/script-security-plugin/pull/169/files?w=1