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

Added logging for non-fabric mods with tests. #907

Merged
merged 6 commits into from
Jul 9, 2024

Conversation

Acuadragon100
Copy link
Contributor

Added functionality to log all non-fabric-mod jar files, along with some tests.
Closes #644

Co-authored-by: Douglas Fischer <[email protected]>
Co-authored-by: Robin Claesson <[email protected]>
Co-authored-by: Acuadragon100 <[email protected]>
Co-authored-by: Erik Vinblad <[email protected]>
StringBuilder outputText = new StringBuilder();

for (Path nonFabricMod : nonFabricMods) {
outputText.append("\n\t- ").append(nonFabricMod.getFileName());
Copy link
Member

Choose a reason for hiding this comment

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

Question: Whats the behaviour when a mod has a none fabric mod contained within?

E.g you have mods/mymod.jar/notamod.jar where mymod.jar is a valid fabric mod, and within its fabric.mod.json file it points to nodamod.jar

I think it might be confusing for it to print out that it found a none mod jar notamod.jar

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It only adds to the non-fabric-mod list from ModScanTask::computeJarFile, so it will ignore any embedded mods as well as directory mods which do not seem to load anyways.

Copy link
Member

Choose a reason for hiding this comment

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

Great thanks.

Mockito.when(launcher.getEnvironmentType()).thenReturn(EnvType.CLIENT);
Mockito.when(launcher.isDevelopment()).thenReturn(false);

Method setLauncher = FabricLauncherBase.class.getDeclaredMethod("setLauncher", FabricLauncher.class);
Copy link
Member

Choose a reason for hiding this comment

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

I dont think using reflection is tests is a good idea especially against code that can be changed, this makes the tests harder to maintain and more likely to break with future changes.

You can use the @VisibleForTesting annotation if needed.

You have done a really good job writing unit tests for this, considering that the original code was never desgined to be unit tested. If this was new code that I was writing it would likely be written with unit testing in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now.

Comment on lines 41 to 42
* Calls dumpNonFabricMods using reflection, so we don't need to make the class
* and method public.
Copy link
Member

Choose a reason for hiding this comment

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

As above, I would make it public and mark it with @VisibleForTesting, its all within the impl package so we dont expect anyone to even attempt to use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now.

@BeforeEach
public void setUp() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
GameProvider provider = mock();
Mockito.when(provider.getBuiltinMods()).thenReturn(Collections.emptyList());
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Static import Mockito.when so this can just become when(provider. You already do it for mock()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should be fixed now.

@Acuadragon100
Copy link
Contributor Author

Just realised that the fact that the non-fabric mod list is not synchronised might cause issues, will commit a fix shortly.

DouglasFischer and others added 2 commits March 1, 2024 10:11
* feat(FabricMC#644): add @VisibleForTesting for the feat impl method

* Use static import for Mockito::when.

* Use @VisibleForTesting instead of reflection.

Co-authored-by: Douglas Fischer <[email protected]>
Co-authored-by: wenqic <[email protected]>
Co-authored-by: Acuadragon100 <[email protected]>
Co-authored-by: Douglas Fischer <[email protected]>
@DouglasFischer
Copy link
Contributor

We're done for now. Ready for another review :)

@@ -35,6 +35,7 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import com.google.common.annotations.VisibleForTesting;
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
import com.google.common.annotations.VisibleForTesting;
import org.jetbrains.annotations.VisibleForTesting;

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

StringBuilder outputText = new StringBuilder();

for (Path nonFabricMod : nonFabricMods) {
outputText.append("\n\t- ").append(nonFabricMod.getFileName());
Copy link
Member

Choose a reason for hiding this comment

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

Great thanks.

@modmuss50 modmuss50 added this to the 0.16.0 milestone Jun 8, 2024
@modmuss50 modmuss50 merged commit ae9a5f0 into FabricMC:master Jul 9, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Incompatible jar list in log
3 participants