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

refactor ProcessFactory.java to put all process creations in one function. #188

Merged
merged 2 commits into from
Dec 3, 2022
Merged

Conversation

xu-chiheng
Copy link
Contributor

No description provided.

@jonahgraham
Copy link
Member

Prerequisite of #187

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

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

This change looks reasonable. I find it a little hard to read due to all the inline comments, a builder pattern would certainly be preferred over the overly long number of incompatible arguments, but is not required. For clarity, I gave some examples in the comments of what I mean.

Once build and test approves it I will check closer to see if the translation of each method is correct.

Comment on lines 66 to 143
Process p = doExec(true/*use_cmd*/, cmd, null/*cmdarray*/, null/*envp*/, null/*dir*/, false/*use_pty*/,
null/*pty*/, false/*has_gracefulExitTimeMs*/, 0/*gracefulExitTimeMs*/);
return p;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Process p = doExec(true/*use_cmd*/, cmd, null/*cmdarray*/, null/*envp*/, null/*dir*/, false/*use_pty*/,
null/*pty*/, false/*has_gracefulExitTimeMs*/, 0/*gracefulExitTimeMs*/);
return p;
return new Builder().setCmd(cmd).launch();

Comment on lines 147 to 216
Process p = doExec(false/*use_cmd*/, null/*cmd*/, cmdarray, envp, dir, true/*use_pty*/, pty,
true/*has_gracefulExitTimeMs*/, gracefulExitTimeMs);
return p;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Process p = doExec(false/*use_cmd*/, null/*cmd*/, cmdarray, envp, dir, true/*use_pty*/, pty,
true/*has_gracefulExitTimeMs*/, gracefulExitTimeMs);
return p;
return new Builder().setCmdArray(cmd).setEnvp(envp).setCwd(dir).setPty(pty).launch();

@github-actions
Copy link

github-actions bot commented Nov 30, 2022

Test Results

     594 files       594 suites   14m 20s ⏱️
10 127 tests 10 105 ✔️ 22 💤 0
10 143 runs  10 121 ✔️ 22 💤 0

Results for commit 9015944.

♻️ This comment has been updated with latest results.

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

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

On further consideration, please refactor the code for readability. My reasoning is that all day I have had this in my review queue, and every time I come back to it I look at it for a few minutes and move on to something else due to the lack of code readability here.

Comment on lines 166 to 175
if (use_cmd) {
if (cmd.isEmpty())
throw new IllegalArgumentException("Empty command");

StringTokenizer st = new StringTokenizer(cmd);
cmdarray = new String[st.countTokens()];
for (int i = 0; st.hasMoreTokens(); i++)
cmdarray[i] = st.nextToken();
}

Copy link
Member

Choose a reason for hiding this comment

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

Don't make the non-deprecated methods go through the deprecated code handling. i.e. the exec(String[] cmdarray) variant should not have to deal with the use_cmd flag. My reasoning is the intention is to mark these deprecated methods for deletion one day, and I don't want me or a future programmer to have to detangle this then.

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

jonahgraham commented Nov 30, 2022 via email

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

Precisely. But all methods are calling the method with two extra arguments.

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

Don't make the non-deprecated methods go through the deprecated code handling. i.e. the exec(String[] cmdarray) variant should not have to deal with the use_cmd flag. My reasoning is the intention is to mark these deprecated methods for deletion one day, and I don't want me or a future programmer to have to detangle this then.

In the future I want to delete the deprecated code, I don't want to have to modify non-deprecated code when I do that. I won't accept this change as is and I would appreciate it if you fixed it.

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

Thanks, but if you don't want to make this change, please close the PR.

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

The version of your code is hard to read, makes future maintenance harder. I don't mind how you fix it, I would use a builder pattern to make it easier. Having a method with 9+ command line arguments is excessive, as demonstrated by you needing to have comments on each line. Imagine in the future we need to add an additional argument to your new method, we then need to update many many places. I understand why you want to make this change, but the current version of the change is not good enough.

If you disagree with my assessment, I will add an additional CDT committer to the review list for a second opinion.

you can do whatever you want on that branch.

I don't know what this means? Do you want me to change your change?

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Nov 30, 2022 via email

@jonahgraham
Copy link
Member

Excellent. I am glad the change is simple for you to make. I look forward to a change that is readable, maintainable and adds the functionality you want.

Copy link
Member

@jonahgraham jonahgraham left a comment

Choose a reason for hiding this comment

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

That version is so much better. Very readable and looks like it will be easy to evolve in the future.

@jonahgraham
Copy link
Member

Because there were two unrelated topics in this PR I wasn't able to merge it directly from the web interface, so I squashed and forced pushed the main change, and put the other change in #190

@xu-chiheng
Copy link
Contributor Author

xu-chiheng commented Dec 3, 2022 via email

@jonahgraham
Copy link
Member

Our CI isn't setup to catch new warnings, so I didn't notice that. It would be great if you fixed it.

@jonahgraham jonahgraham merged commit 9114ac3 into eclipse-cdt:main Dec 3, 2022
@jonahgraham
Copy link
Member

Thanks for the improvement. I hope this refactor makes it easier for you to debug and develop the solution for #187

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.

2 participants