Skip to content

Commit 318fad3

Browse files
committed
Relativize config file path in errors
1 parent 35848c4 commit 318fad3

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersContainerImpl.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.gradle.api.attributes.HasConfigurableAttributes;
2424
import org.gradle.api.file.FileCollection;
2525
import org.gradle.api.file.FileSystemLocation;
26+
import org.gradle.api.file.ProjectLayout;
2627
import org.gradle.api.file.RegularFile;
2728
import org.gradle.api.file.RegularFileProperty;
2829
import org.gradle.api.logging.LogLevel;
@@ -38,6 +39,7 @@
3839
import java.io.FileNotFoundException;
3940
import java.io.IOException;
4041
import java.io.Serial;
42+
import java.nio.file.Paths;
4143
import java.util.ArrayList;
4244
import java.util.Objects;
4345

@@ -50,6 +52,7 @@ abstract class AccessTransformersContainerImpl implements AccessTransformersCont
5052
private final OptionsImpl options;
5153

5254
protected abstract @Inject ObjectFactory getObjects();
55+
protected abstract @Inject ProjectLayout getProjectLayout();
5356
protected abstract @Inject ProviderFactory getProviders();
5457

5558
@Inject
@@ -113,19 +116,20 @@ private void validateATFile(Attribute<Boolean> attribute, RegularFileProperty at
113116
}
114117

115118
// check that the file exists
116-
File atFile = atFileSource.getAsFile();
119+
var atFile = atFileSource.getAsFile();
120+
var atFilePath = this.getProjectLayout().getProjectDirectory().getAsFile().toPath().relativize(atFile.toPath()).toString();
117121
if (!atFile.exists())
118-
throw this.problems.accessTransformerConfigMissing(new RuntimeException(new FileNotFoundException("Config file does not exist at " + atFile)), attribute, atFile);
122+
throw this.problems.accessTransformerConfigMissing(new RuntimeException(new FileNotFoundException("Config file does not exist at " + atFilePath)), attribute, atFilePath);
119123

120124
// check that the file can be read and isn't empty
121125
String atFileContents;
122126
try {
123127
atFileContents = this.getProviders().fileContents(atFileSource).getAsText().get();
124128
} catch (Throwable e) {
125-
throw this.problems.accessTransformerConfigUnreadable(new RuntimeException(new IOException("Failed to read config file at " + atFile, e)), attribute, atFile);
129+
throw this.problems.accessTransformerConfigUnreadable(new RuntimeException(new IOException("Failed to read config file at " + atFilePath, e)), attribute, atFilePath);
126130
}
127131
if (atFileContents.isBlank())
128-
throw this.problems.accessTransformerConfigEmpty(new IllegalStateException("Config file must not be blank at " + atFile), attribute, atFile);
132+
throw this.problems.accessTransformerConfigEmpty(new IllegalStateException("Config file must not be blank at " + atFilePath), attribute, atFilePath);
129133
}
130134

131135
private void setAttributes(AttributeContainer attributes, boolean value) {

at-gradle/src/main/java/net/minecraftforge/accesstransformers/gradle/AccessTransformersProblems.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,36 @@ RuntimeException accessTransformerConfigNotDefined(Exception e, Attribute<Boolea
4747
.solution(HELP_MESSAGE));
4848
}
4949

50-
RuntimeException accessTransformerConfigMissing(Exception e, Attribute<Boolean> attribute, File atFile) {
50+
RuntimeException accessTransformerConfigMissing(Exception e, Attribute<Boolean> attribute, String atFilePath) {
5151
return this.getReporter().throwing(e, this.id("access-transformer-config-missing", "Access transformer config file not found"), spec -> spec
5252
.details("""
5353
The access transformer cannot transform the input artifact because the configuration file could not be found.
5454
Attribute: %s
55-
AccessTransformer Config: %s""".formatted(attribute, atFile))
55+
AccessTransformer Config: %s""".formatted(attribute, atFilePath))
5656
.severity(Severity.ERROR)
5757
.solution("Ensure your AccessTransformers configuration file exists.")
5858
.solution("Do not use AccessTransformers if you do not need to.")
5959
.solution(HELP_MESSAGE));
6060
}
6161

62-
RuntimeException accessTransformerConfigUnreadable(Throwable e, Attribute<Boolean> attribute, File atFile) {
62+
RuntimeException accessTransformerConfigUnreadable(Throwable e, Attribute<Boolean> attribute, String atFilePath) {
6363
return this.getReporter().throwing(e, this.id("access-transformer-config-unreadable", "Access transformer config file not read"), spec -> spec
6464
.details("""
6565
The access transformer cannot transform the input artifact because the configuration file could not be read.
6666
This may be due to insufficient file permissions or a corrupted file.
6767
Attribute: %s
68-
AccessTransformer Config: %s""".formatted(attribute, atFile))
68+
AccessTransformer Config: %s""".formatted(attribute, atFilePath))
6969
.severity(Severity.ERROR)
7070
.solution("Ensure you (and/or Gradle) have proper read/write permissions to the AccessTransformer config file.")
7171
.solution(HELP_MESSAGE));
7272
}
7373

74-
RuntimeException accessTransformerConfigEmpty(Exception e, Attribute<Boolean> attribute, File atFile) {
74+
RuntimeException accessTransformerConfigEmpty(Exception e, Attribute<Boolean> attribute, String atFilePath) {
7575
return this.getReporter().throwing(e, this.id("access-transformer-config-empty", "Access transformer config missing or empty"), spec -> spec
7676
.details("""
7777
The access transformer cannot transform the input artifact because the configuration file is empty or blank.
7878
Attribute: %s
79-
AccessTransformer Config: %s""".formatted(attribute, atFile))
79+
AccessTransformer Config: %s""".formatted(attribute, atFilePath))
8080
.severity(Severity.ERROR)
8181
.solution("Ensure your AccessTransformers configuration file contains definitions to be used.")
8282
.solution("Do not use AccessTransformers if you do not need to.")

0 commit comments

Comments
 (0)