Skip to content

Commit dc0f5fa

Browse files
committed
Added debug messages and comments
1 parent 19b9717 commit dc0f5fa

5 files changed

Lines changed: 248 additions & 34 deletions

File tree

src/main/java/io/github/intisy/gradle/github/GithubExtension.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,52 @@
33
import java.io.File;
44
import java.nio.file.Path;
55

6+
/**
7+
* Extension for configuring GitHub integration.
8+
*/
69
@SuppressWarnings("unused")
710
public class GithubExtension {
811
private String accessToken;
912
private boolean debug;
1013

14+
/**
15+
* @param debug Whether to enable debug logging.
16+
*/
1117
public void setDebug(boolean debug) {
1218
this.debug = debug;
1319
}
1420

21+
/**
22+
* @return Whether debug logging is enabled.
23+
*/
1524
public boolean isDebug() {
1625
return debug;
1726
}
1827

28+
/**
29+
* @param accessToken The path to the access token.
30+
*/
1931
public void setAccessToken(Path accessToken) {
2032
this.accessToken = accessToken.toString();
2133
}
2234

35+
/**
36+
* @param accessToken The file containing the access token.
37+
*/
2338
public void setAccessToken(File accessToken) {
2439
this.accessToken = accessToken.toString();
2540
}
2641

42+
/**
43+
* @param accessToken The access token.
44+
*/
2745
public void setAccessToken(String accessToken) {
2846
this.accessToken = accessToken;
2947
}
3048

49+
/**
50+
* @return The access token.
51+
*/
3152
public String getAccessToken() {
3253
return accessToken;
3354
}
Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,91 @@
11
package io.github.intisy.gradle.github;
22

33
import org.gradle.api.Project;
4-
import org.gradle.api.logging.LogLevel;
54

5+
/**
6+
* A logger for the GitHub plugin.
7+
*/
68
public class Logger {
9+
private static final String PREFIX = "[GitHub] ";
710
private final GithubExtension extension;
8-
private final Project project;
11+
private final org.gradle.api.logging.Logger gradleLogger;
912

13+
/**
14+
* Creates a new logger.
15+
* @param project The project.
16+
*/
1017
public Logger(Project project) {
1118
this(project.getExtensions().getByType(GithubExtension.class), project);
1219
}
1320

21+
/**
22+
* Creates a new logger.
23+
* @param extension The GitHub extension.
24+
* @param project The project.
25+
*/
1426
public Logger(GithubExtension extension, Project project) {
1527
if (extension == null || project == null) {
1628
throw new NullPointerException("extension and project cannot be null");
1729
}
1830
this.extension = extension;
19-
this.project = project;
31+
this.gradleLogger = project.getLogger();
2032
}
2133

34+
/**
35+
* Logs a standard lifecycle message, visible in the default Gradle output.
36+
* @param message The message to log.
37+
*/
2238
public void log(String message) {
23-
project.getLogger().lifecycle(message);
39+
gradleLogger.lifecycle(PREFIX + message);
2440
}
2541

42+
/**
43+
* Logs an error message.
44+
* @param message The message to log.
45+
*/
2646
public void error(String message) {
27-
project.getLogger().error(message);
47+
gradleLogger.error(PREFIX + message);
2848
}
2949

50+
/**
51+
* Logs an error message along with an exception's stack trace.
52+
* @param message The message to log.
53+
* @param throwable The exception to log.
54+
*/
55+
public void error(String message, Throwable throwable) {
56+
gradleLogger.error(PREFIX + message, throwable);
57+
}
58+
59+
/**
60+
* Logs a debug message.
61+
* <p>
62+
* This message will be shown at the LIFECYCLE level (visible by default) only if
63+
* the user sets `github.debug = true` in their build script, providing an easy
64+
* way to enable verbose logging for this plugin specifically.
65+
* @param message The message to log.
66+
*/
3067
public void debug(String message) {
31-
LogLevel logLevel = project.getGradle().getStartParameter().getLogLevel();
32-
if (extension.isDebug() || logLevel.equals(LogLevel.INFO) || logLevel.equals(LogLevel.DEBUG)) {
33-
project.getLogger().lifecycle(message);
68+
if (extension.isDebug()) {
69+
gradleLogger.lifecycle(PREFIX + "[DEBUG] " + message);
70+
} else {
71+
gradleLogger.debug(PREFIX + message);
3472
}
3573
}
3674

75+
/**
76+
* Logs a warning message.
77+
* @param message The message to log.
78+
*/
3779
public void warn(String message) {
38-
project.getLogger().warn(message);
80+
gradleLogger.warn(PREFIX + message);
81+
}
82+
83+
/**
84+
* Logs a warning message along with an exception's stack trace.
85+
* @param message The message to log.
86+
* @param throwable The exception to log.
87+
*/
88+
public void warn(String message, Throwable throwable) {
89+
gradleLogger.warn(PREFIX + message, throwable);
3990
}
40-
}
91+
}

src/main/java/io/github/intisy/gradle/github/ResourcesExtension.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,76 @@
11
package io.github.intisy.gradle.github;
22

3+
/**
4+
* Extension for configuring external resources to be used in the project.
5+
*/
36
@SuppressWarnings("unused")
47
public class ResourcesExtension {
58
private String branch = "main";
69
private String path = "/";
710
private String repoUrl;
811
private boolean buildOnly;
912

13+
/**
14+
* @return Whether to only build the resources without including them in the project.
15+
*/
1016
public boolean isBuildOnly() {
1117
return buildOnly;
1218
}
1319

20+
/**
21+
* @param buildOnly Whether to only build the resources without including them in the project.
22+
*/
1423
public void setBuildOnly(boolean buildOnly) {
1524
this.buildOnly = buildOnly;
1625
}
1726

27+
/**
28+
* @param repoUrl The URL of the repository.
29+
* @deprecated Use {@link #setRepoUrl(String)} instead.
30+
*/
1831
@Deprecated
1932
public void setRepo(String repoUrl) {
2033
setRepoUrl(repoUrl);
2134
}
2235

36+
/**
37+
* @param repoUrl The URL of the repository.
38+
*/
2339
public void setRepoUrl(String repoUrl) {
2440
this.repoUrl = repoUrl;
2541
}
2642

43+
/**
44+
* @return The URL of the repository.
45+
*/
2746
public String getRepoUrl() {
2847
return repoUrl;
2948
}
3049

50+
/**
51+
* @return The branch of the repository to use.
52+
*/
3153
public String getBranch() {
3254
return branch;
3355
}
3456

57+
/**
58+
* @param branch The branch of the repository to use.
59+
*/
3560
public void setBranch(String branch) {
3661
this.branch = branch;
3762
}
3863

64+
/**
65+
* @return The path within the repository to the resources.
66+
*/
3967
public String getPath() {
4068
return path;
4169
}
4270

71+
/**
72+
* @param path The path within the repository to the resources.
73+
*/
4374
public void setPath(String path) {
4475
this.path = path;
4576
}

0 commit comments

Comments
 (0)