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

Major refactor to Java launcher library #291

Merged
merged 39 commits into from Nov 19, 2022

Conversation

TheKodeToad
Copy link
Member

@TheKodeToad TheKodeToad commented Oct 24, 2022

solonovamax helped a lot with this. Thank you!

Changes:

  • Rename enums to SHOUTING_SNAKE_CASE.
  • Add more exit codes.
  • Switch back from java.util.Logger to a custom one, this time with better code using an enum. The reason for this is the launcher did not colourise the logs like with the old behaviour. While JUL is better in terms of OOP, it doesn't have all the necessary log levels and in the end would require more code to make the log messages look nice. The API is also not the best. Using logging frameworks would just create bloat for no reason and probably create issues.
  • Split the onesix launcher into standard and legacy (Standard, Legacy and AbstractLauncher were introduced).
  • Reintroduce MultiMC's printing the chosen launcher, but from the C++ code instead.
  • Reformat the code using Eclipse. It has a good formatter, okay.
  • Updated license headers.
  • Split Utils into different classes.
  • Use MethodHandle instead of reflection where possible and practical.
  • Fix warnings instead of ignoring them. If you use the correct JDK none will be created (for the source code - there is one unrelated one).
  • Removed LauncherFactory again. Sorry icelimetea, but I personally think a factory is not needed for two launcher types.
  • Remove constructor in NewLaunch. Why have a field when you can have a local variable? I generally also like to avoid instances of the main class.
  • Remove feeding the classpath through stdin to the Java launcher. It's already passed into the java executable with the -cp flag, and NewLaunch completely ignores it.

@txtsd txtsd self-requested a review October 24, 2022 19:40
Copy link
Contributor

@flowln flowln left a comment

Choose a reason for hiding this comment

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

this creates a few new warnings:

org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked method invocation: method allSafe in class Parameters is applied to given types
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                 ^
  required: String,List<String>
  found: String,List
org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked conversion
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                                      ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked conversion
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                 ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked method invocation: method allSafe in class Parameters is applied to given types
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                               ^
  required: String,List<String>
  found: String,List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked conversion
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                                                     ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked conversion
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                               ^
  required: List<String>
  found:    List

they should probably be fixed, even if it incurs in some performance overhead. this isn't exactly a hot path anyways :3

@flowln flowln added the enhancement New feature or request label Oct 24, 2022
@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 25, 2022

this creates a few new warnings:

org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked method invocation: method allSafe in class Parameters is applied to given types
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                 ^
  required: String,List<String>
  found: String,List
org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked conversion
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                                      ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:63: warning: [unchecked] unchecked conversion
        mcParams = params.allSafe("param", Collections.EMPTY_LIST);
                                 ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked method invocation: method allSafe in class Parameters is applied to given types
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                               ^
  required: String,List<String>
  found: String,List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked conversion
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                                                     ^
  required: List<String>
  found:    List
org/prismlauncher/impl/OneSixLauncher.java:66: warning: [unchecked] unchecked conversion
        traits = params.allSafe("traits", Collections.EMPTY_LIST);
                               ^
  required: List<String>
  found:    List

they should probably be fixed, even if it incurs in some performance overhead. this isn't exactly a hot path anyways :3

I have fixed this now. Even if the performance impact is nothing to lose sleep about (well, it is for me), it's still generally preferred to use emptyList when you want an immutable empty list. Fortunately I managed to keep using this method in a safer way.

Anyway, does anyone have any idea of what I should change with the license headers, if anything?

@txtsd
Copy link
Member

txtsd commented Oct 25, 2022

java.applet.Applet is deprecated in newer Java versions. Is this required for older modloaders? And can it be replaced with whatever the modern alternative for applets is?

@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 25, 2022

java.applet.Applet is deprecated in newer Java versions. Is this required for older modloaders? And can it be replaced with whatever the modern alternative for applets is?

Old versions of Minecraft used Java applets so they could be run in web browsers. I think there is a standalone main class though. However, since there are other compatibility issues with newer versions of Java, I can't see many reasons to replace it.

@solonovamax
Copy link
Contributor

solonovamax commented Oct 26, 2022

Perhaps it might be better to split the applet/legacy launcher and the default launcher into separate classes?

There already exists support for different launcher types, so why not use it?

That way you can @Suppress all instances of deprecated for the entire class, while only affecting the applet code.

@solonovamax
Copy link
Contributor

Also, in the line of some improvements to the java code, why not use the ParseException class here instead of IllegalStateException?

throw new IllegalArgumentException("Unexpected window size parameter value: " + windowParams);

@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 26, 2022

Okay, I will try to improve the code more - maybe more of a refactor. I was trying to avoid it because other projects (it was mainly one though) didn't like it when I kept adding to my pull requests.

Time to fire up an IDE that isn't totally terrible ;)

@txtsd
Copy link
Member

txtsd commented Oct 26, 2022

Okay, I will try to improve the code more - maybe more of a refactor. I was trying to avoid it because other projects (it was mainly one though) didn't like it when I kept adding to my pull requests.

Time to fire up an IDE that isn't totally terrible ;)

Take your time and make your changes. We won't merge it until it's deemed ready.

@solonovamax
Copy link
Contributor

Okay, I will try to improve the code more - maybe more of a refactor. I was trying to avoid it because other projects (it was mainly one though) didn't like it when I kept adding to my pull requests.

I was gonna make my own pr with a bunch of code cleanup changes later as well, bc I noticed quite a few things that could be changed

@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 26, 2022

I think I've done enough for this pull request. I've implemented #291 (comment), as well as replaced some string splitting with substringing (just personal preference, but I think it's best to avoid regex when searching for single characters - and it can have side-effects if the character appears more times than you want). Maybe I'll open one aimed at improving the legacy launcher.

Also, somebody's been here before.

image

I reverted the change only for one of the fields which is changed.

No idea why re-requesting a review removed txtsd's.

@TheKodeToad TheKodeToad requested review from flowln and removed request for txtsd October 26, 2022 15:15
@txtsd txtsd self-requested a review October 26, 2022 16:26
@solonovamax
Copy link
Contributor

solonovamax commented Oct 26, 2022

few things I just noticed:

  1. The license header
    /*
     *  PolyMC - Minecraft Launcher
     *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
     *  Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
     *  Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
    
    should be changed for
    /*
     *  Prism Launcher - Minecraft Launcher
     *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
     *  Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
     *  Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
    
  2. You removed OneSixLauncher.java from the launcher code, however, I'm pretty sure that the "onesix launcher" is referenced in many other places in the codebase. May want to change that to just reference the "launcher". (Search for "onesix" or "one six" in the codebase)

Also, I'd very much like to contribute some of my own changes to this, but I want to commit them myself, so they're under my name (As they're slightly more significant than the previous changes I suggested). Would that be possible? If so, how do you want me to do that? I could make a fork of your fork, then PR to it, so that way it can be merged into this branch.

@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 27, 2022

few things I just noticed:

1. The license header
   ```
   /*
    *  PolyMC - Minecraft Launcher
    *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
    *  Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
    *  Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
   ```
   
   
       
         
       
   
         
       
   
       
     
   should be changed for
   ```
   /*
    *  Prism Launcher - Minecraft Launcher
    *  Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
    *  Copyright (C) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
    *  Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
   ```

2. You removed `OneSixLauncher.java` from the launcher code, however, I'm pretty sure that the "onesix launcher" is referenced in many other places in the codebase. May want to change that to just reference the "launcher". (Search for "onesix" or "one six" in the codebase)

Also, I'd very much like to contribute some of my own changes to this, but I want to commit them myself, so they're under my name (As they're slightly more significant than the previous changes I suggested). Would that be possible? If so, how do you want me to do that? I could make a fork of your fork, then PR to it, so that way it can be merged into this branch.

Oh dear, this is getting confusing. I'll give you push access. I'm not sure if people normally do that, but since you're not part of the Prism Launcher organisation it would be that or a fork fork (and this repo is already a fork fork).

@solonovamax
Copy link
Contributor

solonovamax commented Oct 27, 2022

👍 alright

I pinky promise not to git push --force

@Scrumplex
Copy link
Member

Scrumplex commented Oct 27, 2022

emptyList when you want an immutable empty list

We used to use emptyList() for everything but some lists can be modified conditionally so it should actually all be mutable.

EDIT: nvm you already saw my commit :D

@TheKodeToad TheKodeToad changed the title A few improvements to the Java code Rework Java code Oct 29, 2022
@solonovamax
Copy link
Contributor

@TheKodeToad I was going to keep LegacyUtils, because I wanted to move a bit of the messy logic happening in the LegacyLauncher into that, to clean it up.

You alright if I revert that commit later?

@solonovamax
Copy link
Contributor

Also, avoid force pushes if possible, because it forces me to have to rebase/re-clone my entire branch

@TheKodeToad
Copy link
Member Author

TheKodeToad commented Oct 30, 2022

@TheKodeToad I was going to keep LegacyUtils, because I wanted to move a bit of the messy logic happening in the LegacyLauncher into that, to clean it up.

You alright if I revert that commit later?

It seems weird to couple a class with a utils one. I feel like it would be more logical to move some of the messy logic into other methods.

Also, avoid force pushes if possible, because it forces me to have to rebase/re-clone my entire branch

Oops, sorry. I had to because I forgot signing off. I think I've got the hang of it now.

Edit: OMG I keep pushing and then realising my mistake. Still, it shouldn't make a difference unless you already have the commits on your local copy - rebasing is normally required even without force pushing.

@solonovamax
Copy link
Contributor

solonovamax commented Oct 31, 2022

Edit: OMG I keep pushing and then realising my mistake. Still, it shouldn't make a difference unless you already have the commits on your local copy - rebasing is normally required even without force pushing.

If you want to make sure to sign every single commit, add the following to your .gitconfig:

[user]
    name = [YOUR NAME HERE]
    email = [YOUR EMAIL HERE]
    signingkey = [YOUR SIGNING KEY HERE]
[commit]
    gpgsign = true

Then, it will sign every single one of your commits by default (so you don't need to specify -S on the git commit command.)

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Factories in OOP are a classic example of over-enginneering. When you only have two launchers I personally think that it's not very useful.

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Passing the classpath into stdin has no effect. Java is already provided the classpath with -cp, which pretty much takes up the largest part of the arguments anyway, which leads me to wonder, what's the point of stdin arguments at all?

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
@TheKodeToad
Copy link
Member Author

TheKodeToad commented Nov 8, 2022

I have managed to squash and drop a lot of commits. It should be ready for review now. The code is at a stage where to see something wrong with it you'd have to be not me.

@TheKodeToad TheKodeToad marked this pull request as ready for review November 8, 2022 16:41
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
@TheKodeToad TheKodeToad changed the title Rework Java launcher library Major refactor to Java launcher library Nov 12, 2022
@Scrumplex Scrumplex added this to the 6.0 milestone Nov 18, 2022
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
Copy link
Member

@Scrumplex Scrumplex left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@Scrumplex Scrumplex merged commit 30607c3 into PrismLauncher:develop Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants