Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamebuster19901 committed Aug 1, 2024
1 parent 5e99b26 commit e685372
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 8 deletions.
25 changes: 25 additions & 0 deletions src/main/java/com/wildermods/workspace/WWProjectContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@

import org.gradle.api.Project;

/**
* Represents the context of a WilderWorkspace project.
* <p>
* This class encapsulates the project and the WilderWorkspace extension
* to provide a unified interface for interacting with project-specific
* settings and configurations within the plugin.
* </p>
*/
public class WWProjectContext {

private final Project project;
private final WilderWorkspaceExtension extension;

/**
* Constructs a new {@code WWProjectContext} with the specified project
* and WilderWorkspace extension.
*
* @param project the Gradle project associated with this context
* @param extension the WilderWorkspace extension associated with this context
*/
public WWProjectContext(Project project, WilderWorkspaceExtension extension) {
this.project = project;
this.extension = extension;
}

/**
* Returns the Gradle project associated with this context.
*
* @return the Gradle project
*/
public Project getProject() {
return project;
}

/**
* Returns the WilderWorkspace extension associated with this context.
*
* @return the WilderWorkspace extension
*/
public WilderWorkspaceExtension getWWExtension() {
return extension;
}
Expand Down
57 changes: 52 additions & 5 deletions src/main/java/com/wildermods/workspace/WWProjectDependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@
* A WWProject dependency represents a dependency common to all projects made
* using WilderWorkspace.
* <p>
* For example, all projects made with the same WilderWorkspace version will
* should be compiled against the same version of SpongePowered Mixin.
* Each constant in this enum corresponds to a specific dependency required for projects
* using WilderWorkspace. These dependencies are essential for consistent compilation
* and execution of projects that share the same version of the WilderWorkspace plugin.
* <p>
* @see {@link PluginDependency} for dependencies the WilderWorkspace gradle
* plugin itself needs in order to be built and run.
* Dependencies are categorized into two types:
* <ul>
* <li>{@code fabricDep}: Dependencies that Fabric requires to be in the "fabricDependencyPath" at runtime.
* {@code ./bin/fabric/} is the default location where these dependencies are located.</li>
* <li>{@code fabricImpl}: Dependencies that are required to be in the "fabricPath" at runtime.
* {@code ./bin/} is the default location where these dependencies are located.</li>
* </ul>
* <p>
* The {@code gitRepo} field, if specified, indicates a Git repository URL from which
* the dependency can be obtained. This is used to set up source control repositories
* for project dependencies during plugin application. See the {@link WilderWorkspacePlugin#apply(Settings)}
* method for details on how these repositories are configured.
* <p>
* For additional information about the dependencies needed by the WilderWorkspace
* gradle plugin itself, see {@link PluginDependency}.
* </p>
*/
public enum WWProjectDependency implements Dependency {

Expand Down Expand Up @@ -46,11 +61,27 @@ public enum WWProjectDependency implements Dependency {
private final URI gitRepo;
private String reason;


/**
* Constructs a new {@code WWProjectDependency} with the specified parameters.
*
* @param type the type of the project dependency
* @param groupID the group ID of the dependency
* @param artifact the artifact ID of the dependency
* @param version the version of the dependency
*/
private WWProjectDependency(ProjectDependencyType type, String groupID, String artifact, String version) {
this(type, groupID, artifact, version, null);
}

/**
* Constructs a new {@code WWProjectDependency} with the specified parameters and optional Git repository.
*
* @param type the type of the project dependency
* @param groupID the group ID of the dependency
* @param artifact the artifact ID of the dependency
* @param version the version of the dependency
* @param gitRepo the URL of the Git repository associated with the dependency, or {@code null} if not applicable
*/
private WWProjectDependency(ProjectDependencyType type, String groupID, String artifact, String version, String gitRepo) {
this.type = type;
this.groupID = groupID;
Expand Down Expand Up @@ -88,6 +119,16 @@ public Dependency copy() {
throw new AssertionError();
}

/**
* Returns the type of the project dependency.
*
* The type indicates the category of the dependency is used to determine where it should be placed
* within the workspace.
*
* @see ProjectDependencyType
*
* @return the type of the dependency
*/
public ProjectDependencyType getType() {
return type;
}
Expand All @@ -107,6 +148,12 @@ public String getReason() {
return reason;
}

/**
* Returns the module string representation of the dependency in the format
* {@code group:artifact}.
*
* @return the module string representation
*/
public String getModule() {
return String.join(":", getGroup(), getName());
}
Expand Down
94 changes: 91 additions & 3 deletions src/main/java/com/wildermods/workspace/WilderWorkspacePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,34 @@

import org.gradle.api.Plugin;

/**
* A Gradle plugin for setting up and managing the WilderWorkspace development environment.
* <p>
* This plugin configures various tasks and settings required for working with the WilderWorkspace project,
* including setting up dependencies, configuring tasks, and integrating with IDEs like Eclipse and IntelliJ IDEA.
* </p>
* <p>
* It supports:
* <ul>
* <li>Adding plugin dependencies</li>
* <li>Setting up configurations and tasks</li>
* <li>Configuring IDE plugins (Eclipse and IntelliJ IDEA)</li>
* <li>Handling post-evaluation of the project for dependency management</li>
* </ul>
* </p>
*/

public class WilderWorkspacePlugin implements Plugin<Object> {

/** The version of the WilderWorkspace plugin. */
public static final String VERSION = "@workspaceVersion@";

/**
* Applies the plugin to either a {@link Project} or {@link Settings}.
*
* @param object the object to apply the plugin to
* @throws Error if the object is neither a {@link Project} nor a {@link Settings}
*/
public void apply(Object object) {
if(object instanceof Project) {
apply((Project)object);
Expand All @@ -43,10 +67,19 @@ else if (object instanceof Settings) {
apply((Settings)object);
}
else {
throw new Error();
throw new Error("WilderWorkspacePlugin can only be applied to projects and settings");
}
}

/**
* Applies the plugin to the project.
* <p>
* This method initializes the plugin, sets up dependencies, creates the WilderWorkspace extension,
* configures tasks, and handles post-evaluation tasks.
* </p>
*
* @param project the Gradle project to apply the plugin to
*/
public void apply(Project project) {

project.getLogger().log(LogLevel.INFO, "Initializing WilderWorkspace PROJECT plugin version " + VERSION);
Expand All @@ -73,9 +106,17 @@ public void apply(Project project) {
throw new LinkageError("Failed to initialize WilderWorkspace " + VERSION, t);
}

project.getLogger().log(LogLevel.INFO, "Initialized WilderWorkspace plugin version {$workspaceVersion}");
project.getLogger().log(LogLevel.INFO, "Initialized WilderWorkspace plugin version " + VERSION);
}

/**
* Applies the plugin to the given settings.
* <p>
* This method sets up source control repositories for project dependencies as defined in {@link WWProjectDependency}.
* </p>
*
* @param settings the Gradle settings to apply the plugin to
*/
public void apply(Settings settings) {
SourceControl sourceControl = settings.getSourceControl();
for(WWProjectDependency dependency : WWProjectDependency.values()) {
Expand All @@ -87,6 +128,14 @@ public void apply(Settings settings) {
}
}

/**
* Adds plugin dependencies to the project's build script classpath.
* <p>
* This method configures repositories and adds dependencies required for the plugin.
* </p>
*
* @param project the Gradle project
*/
private static void addPluginDependencies(Project project) {
ScriptHandler buildscript = project.getBuildscript();
{
Expand Down Expand Up @@ -116,12 +165,28 @@ private static void addPluginDependencies(Project project) {
}));
}

/**
* Sets up configurations required by the plugin.
* <p>
* This method creates configurations for Fabric dependencies and implementations.
* </p>
*
* @param context the project context
*/
private static void setupConfigurations(WWProjectContext context) {
Project project = context.getProject();
Configuration fabricDep = project.getConfigurations().create(ProjectDependencyType.fabricDep.name());
Configuration fabricImpl = project.getConfigurations().create(ProjectDependencyType.fabricImpl.name());
}

/**
* Sets up tasks for the plugin.
* <p>
* This method registers tasks for copying local dependencies, decompiling JARs, and configuring the workspace.
* </p>
*
* @param context the project context
*/
private static void setupTasks(WWProjectContext context) {
Project project = context.getProject();
WilderWorkspaceExtension extension = context.getWWExtension();
Expand Down Expand Up @@ -190,12 +255,27 @@ private static void setupTasks(WWProjectContext context) {
});
}


/**
* Sets up post-evaluation tasks for the plugin.
* <p>
* This method adds workspace dependencies and configures IDE plugins.
* </p>
*
* @param context the project context
*/
private static void setupPostEvaluations(WWProjectContext context) {
addWorkspaceDependencies(context);
setupEclipsePlugin(context);
}

/**
* Adds workspace dependencies to the project after evaluation.
* <p>
* This method ensures that project dependencies are added to the correct configurations.
* </p>
*
* @param context the project context
*/
private static void addWorkspaceDependencies(WWProjectContext context) {
Project project = context.getProject();
project.afterEvaluate((proj -> {
Expand All @@ -209,6 +289,14 @@ private static void addWorkspaceDependencies(WWProjectContext context) {
}));
}

/**
* Configures the Eclipse plugin after project evaluation.
* <p>
* This method integrates with the Eclipse plugin to set source paths for game JARs.
* </p>
*
* @param context the project context
*/
@SuppressWarnings({ "unchecked"})
private static void setupEclipsePlugin(WWProjectContext context) {
Project project = context.getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

import com.wildermods.workspace.util.FileHelper.IgnoreSymbolicVisitor;

/**
* Task to clear the workspace.
* <p>
* This task deletes the specified directories for dependencies and decompiled sources. By defualt, the entirety of './bin'
* </p>
*/
public class ClearLocalDependenciesTask extends DefaultTask {

@Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
import com.wildermods.workspace.util.OS;
import com.wildermods.workspace.util.Platform;

/**
* Task to copy local dependencies to the workspace.
* <p>
* This task copies the necessary files from the game installation directory to a specified workspace directory.
* It supports the game platforms as defined in {@link Platform} and allows for custom directories.
* </p>
*/
public class CopyLocalDependenciesToWorkspaceTask extends DefaultTask {

private static final Logger LOGGER = Logging.getLogger(CopyLocalDependenciesToWorkspaceTask.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
import net.fabricmc.loom.decompilers.ClassLineNumbers;
import net.fabricmc.loom.decompilers.LineNumberRemapper;

/**
* Task to decompile JAR files and remap their line numbers.
* <p>
* This task identifies specific JAR files to decompile, adds other JAR files as libraries, and processes
* line number mappings to produce decompiled sources with accurate line numbers.
* </p>
*/
public class DecompileJarsTask extends DefaultTask {

@Input
Expand Down Expand Up @@ -142,6 +149,14 @@ public FileVisitResult visitFile(Path linemap, BasicFileAttributes attrs) throws

}

/**
* Remaps the line numbers of the specified JAR file using the provided line map.
*
* @param linemap the path to the line map file
* @param jarToRemap the path to the JAR file to remap
* @param remappedJarDest the destination path for the remapped JAR file
* @throws Throwable if an error occurs during remapping
*/
private void remap(Path linemap, Path jarToRemap, Path remappedJarDest) throws Throwable {
System.out.println("Remapping " + jarToRemap + " to " + remappedJarDest);
ClassLineNumbers lineNumbers = ClassLineNumbers.readMappings(linemap);
Expand All @@ -152,18 +167,38 @@ private void remap(Path linemap, Path jarToRemap, Path remappedJarDest) throws T
remapper.process(jarToRemap, remappedJarDest);
}

/**
* Gets the directory containing the compiled JAR files.
*
* @return the compiled directory path as a string
*/
public String getCompiledDir() {
return compiledDir;
}

/**
* Sets the directory containing the compiled JAR files.
*
* @param compiledDir the compiled directory path as a string
*/
public void setCompiledDir(String compiledDir) {
this.compiledDir = compiledDir;
}

/**
* Gets the directory where the decompiled sources will be stored.
*
* @return the decompiled directory path as a string
*/
public String getDecompDir() {
return decompDir;
}

/**
* Sets the directory where the decompiled sources will be stored.
*
* @param decompDir the decompiled directory path as a string
*/
public void setDecompDir(String decompDir) {
this.decompDir = decompDir;
}
Expand Down
Loading

0 comments on commit e685372

Please sign in to comment.