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 abstract model of the Gradle Plugin development. #95

Merged
merged 7 commits into from
Jul 28, 2021
1 change: 1 addition & 0 deletions depclean-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repositories {
dependencies {
implementation(gradleApi())
implementation('se.kth.castor:depclean-core:2.0.2-SNAPSHOT')
implementation('se.kth.castor:depclean-maven-plugin:2.0.2-SNAPSHOT')
compileOnly('org.projectlombok:lombok:1.18.20')
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package se.kth.depclean;

import lombok.SneakyThrows;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.jetbrains.annotations.NotNull;


/**
* Depclean default and only action.
*/
public class DepCleanGradleAction implements Action<Project> {

@SneakyThrows
@Override
public void execute(@NotNull Project project) {
// To be continued.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package se.kth.depclean;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.jetbrains.annotations.NotNull;

/**
* This plugin checks the bytecode of a gradle project and configure out whether a dependency
* is used in that project or not. After analysis, it also configures out the source of that
* dependency i.e. whether <br>
* <b>1)</b> It is declared directly in your build.gradle file or, <br>
* <b>2)</b> Inherited from any direct dependency or, <br>
* <b>3)</b> Just a transitive dependency.
*/
public class DepCleanGradlePlugin implements Plugin<Project> {

@Override
public void apply(@NotNull Project project) {
// Creating the default task.
createTask(project);
}

/**
* Creating a task that performs the DepClean default action.
*
* @param project The Gradle project.
*/
public void createTask(final Project project) {
final String depCleanTaskName = "debloat";
DepCleanGradleTask task = project.getTasks().create(depCleanTaskName, DepCleanGradleTask.class);
task.setGroup("dependency management");
task.setDescription("Analyze the project byte-code and configure out the debloated dependencies.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package se.kth.depclean;

import org.gradle.api.Action;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;

/**
* Task that configures out the bloated dependencies.
*/
public class DepCleanGradleTask extends DefaultTask {

/**
* Action that analyzes the project dependencies and show the results.
*/
@TaskAction
public void analyzeProject() {

getProject().getLogger().lifecycle("Starting DepClean dependency analysis");

// Applying the only default action on the project and it's sub-projects (if any).
Action<Project> defaultAction = new DepCleanGradleAction();
getProject().allprojects(defaultAction);

}

}