-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
enigma-cli/src/main/java/org/quiltmc/enigma/command/PrintStatsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.quiltmc.enigma.command; | ||
|
||
import org.quiltmc.enigma.api.Enigma; | ||
import org.quiltmc.enigma.api.EnigmaPlugin; | ||
import org.quiltmc.enigma.api.EnigmaProfile; | ||
import org.quiltmc.enigma.api.stats.ProjectStatsResult; | ||
import org.quiltmc.enigma.api.stats.StatType; | ||
import org.quiltmc.enigma.api.stats.StatsGenerator; | ||
import org.tinylog.Logger; | ||
|
||
import javax.annotation.Nullable; | ||
import java.nio.file.Path; | ||
import java.util.Set; | ||
|
||
public class PrintStatsCommand extends Command { | ||
public PrintStatsCommand() { | ||
super(Argument.INPUT_JAR.required(), | ||
Argument.INPUT_MAPPINGS.required(), | ||
Argument.ENIGMA_PROFILE.optional()); | ||
} | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
Path inJar = getReadablePath(this.getArg(args, 0)); | ||
Path mappings = getReadablePath(this.getArg(args, 1)); | ||
Path profilePath = getReadablePath(this.getArg(args, 2)); | ||
|
||
run(inJar, mappings, profilePath, null); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "print-stats"; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Generates and prints out the statistics of how well the provided mappings cover the provided JAR file."; | ||
} | ||
|
||
public static void run(Path inJar, Path mappings, @Nullable Path profilePath, @Nullable Iterable<EnigmaPlugin> plugins) throws Exception { | ||
EnigmaProfile profile = EnigmaProfile.read(profilePath); | ||
Enigma enigma = createEnigma(profile, plugins); | ||
|
||
run(inJar, mappings, enigma); | ||
} | ||
|
||
public static void run(Path inJar, Path mappings, Enigma enigma) throws Exception { | ||
StatsGenerator generator = new StatsGenerator(openProject(inJar, mappings, enigma)); | ||
ProjectStatsResult result = generator.generate(new ConsoleProgressListener(), Set.of(StatType.values()), false); | ||
|
||
Logger.info(String.format("Overall mapped: %.2f%% (%s / %s)", result.getPercentage(), result.getMapped(), result.getMappable())); | ||
Logger.info(String.format("Classes: %.2f%% (%s / %s)", result.getPercentage(StatType.CLASSES), result.getMapped(StatType.CLASSES), result.getMappable(StatType.CLASSES))); | ||
Logger.info(String.format("Fields: %.2f%% (%s / %s)", result.getPercentage(StatType.FIELDS), result.getMapped(StatType.FIELDS), result.getMappable(StatType.FIELDS))); | ||
Logger.info(String.format("Methods: %.2f%% (%s / %s)", result.getPercentage(StatType.METHODS), result.getMapped(StatType.METHODS), result.getMappable(StatType.METHODS))); | ||
Logger.info(String.format("Parameters: %.2f%% (%s / %s)", result.getPercentage(StatType.PARAMETERS), result.getMapped(StatType.PARAMETERS), result.getMappable(StatType.PARAMETERS))); | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
enigma-cli/src/test/java/org/quiltmc/enigma/command/PrintStatsCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.quiltmc.enigma.command; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.quiltmc.enigma.TestUtil; | ||
|
||
import java.nio.file.Path; | ||
|
||
import static org.quiltmc.enigma.TestUtil.getResource; | ||
|
||
public class PrintStatsCommandTest { | ||
private static final Path JAR = TestUtil.obfJar("lone_class"); | ||
private static final Path MAPPINGS = getResource("/print_stats"); | ||
|
||
@Test | ||
public void test() throws Exception { | ||
PrintStatsCommand.run(JAR, MAPPINGS, null, null); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
enigma-cli/src/test/resources/print_stats/AwesomeClass.mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CLASS a AwesomeClass | ||
FIELD a gaming Ljava/lang/String; | ||
METHOD <init> (Ljava/lang/String;)V | ||
ARG 1 gaming | ||
METHOD a getGaming ()Ljava/lang/String; |