Skip to content
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

Add a ProcessUtils Class #2044

Merged
merged 4 commits into from
Aug 22, 2019
Merged

Conversation

madoar
Copy link
Collaborator

@madoar madoar commented Jul 12, 2019

This PR adds a new ProcessUtils class which can be used as a Bean from the scripts to start new processes (see also #2015)

Copy link
Collaborator Author

@madoar madoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note:
I haven't tested this class yet from the scripts so take the implementation with a grain of salt. The intention for sharing this beforehand is to discuss about the API, whether it needs additional changes.

/**
* A wrapper class around the Java {@link Process} class allowing for a save access to the underlying process from the scripts
*/
public class PhoenicisProcess {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could think about moving this whole class to JS. This would mean that ProcessUtils#startProcess would return a Java Process object, which is then wrapped inside a JSObject in a proxy script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, is better to have our own class because it makes us sure that there are no unsafe things that are exposed. So I like your implementation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal dilemma is the assessment between safety (like you mentioned) and ease of use.

If we implement this on the Java side we have full control over how things are processed and whether something should be prevented/disallowed for certain input.

If we implement this on the JavaScript side, we lose a lot of control because scripts can change or reload other scripts without Phoenicis being aware of this. On the other hand it is more more clear what functionality is available from inside the Scripts and how it needs to be accessed syntactically.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I would vote for safety. Actually, this might not even be safe enough because it still allows you to spawn random processes (not that I would know any alternative to that in our special case).
One other point to consider: returning a Java object ties the scripts to Java whereas a Bean could be implemented in any language.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@madoar madoar changed the title Add a PhoenicisUtils Class Add a ProcessUtils Class Jul 12, 2019
@qparis
Copy link
Member

qparis commented Jul 21, 2019

Well not necessarily because we could generate a documentation from our @safe annotated classes. This would help a lot.
Also, one day, we could try to use typescript

@qparis
Copy link
Member

qparis commented Jul 27, 2019

It depends on how many parameter you have. More than 5-6 is enough to justify a builder

@plata
Copy link
Collaborator

plata commented Jul 27, 2019

Additionally, many of these parameters (like environment) are optional so I think a builder would be good.

- apply formatting
@madoar
Copy link
Collaborator Author

madoar commented Jul 29, 2019

Ok, I have changed the implementation and added a PhoenicisProcessBuilder to set the parameters.


processBuilder.environment().putAll(environment);

if (outputPath != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add some more optional parameters which we may need later on?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that is why I'm asking :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of anything currently.

@madoar madoar requested review from qparis and plata August 11, 2019 10:03
/**
* A process builder to be used from inside the scripts
*/
public class PhoenicisProcessBuilder {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the DTO's, the DTO and the builder are in the same file. Should it be the same here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is better readable if we split both classes in two separate files. But I'm fine either way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't care too much but it might make sense to be consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking some more about this I'm not sure this would work, because I don't know if it is possible to access inner Java classes from JavaScript.

@madoar
Copy link
Collaborator Author

madoar commented Aug 22, 2019

@plata I would suggest to add this class for now. We can still adjust it later on if we discover some hard edges.

@madoar madoar merged commit 964ad59 into PhoenicisOrg:master Aug 22, 2019
@madoar madoar deleted the add-phoenicis-utils branch August 22, 2019 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants