Skip to content

Commit

Permalink
fix: Extension register
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-siebert committed Dec 31, 2024
1 parent 8675d2c commit b837ff3
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ dependencies {

compileOnly(gradleApi())
testImplementation(gradleTestKit())

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}

gradlePlugin {
Expand All @@ -34,6 +37,10 @@ gradlePlugin {
}
}

tasks.test {
useJUnitPlatform()
}

publishing {
repositories {
mavenLocal()
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/studio/o7/remora/RemoraPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void apply(Project project) {
applyNecessaryPlugins(logger, project);
applyNecessaryRepositories(logger, project);

RemoraExtension extension = setupExtension(logger, project.getExtensions());
RemoraExtension extension = setupExtension(logger, project);

applyNecessaryProjectConfiguration(logger, project, extension);
applyJavaPluginConfiguration(logger, project, extension);
Expand All @@ -36,9 +36,9 @@ public void apply(Project project) {
// applyPlaceholderConfiguration(logger, project, extension);
}

public static RemoraExtension setupExtension(@NonNull Logger logger, @NonNull ExtensionContainer extensions) {
public static RemoraExtension setupExtension(@NonNull Logger logger, @NonNull Project project) {
logger.info("Setting up the `remora` extension");
return extensions.create("remora", RemoraExtension.class);
return project.getExtensions().create("remora", RemoraExtension.class, project.getObjects());
}

public static void applyNecessaryProjectConfiguration(@NonNull Logger logger, @NonNull Project project, @NonNull RemoraExtension extension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;
import org.gradle.jvm.toolchain.JavaLanguageVersion;
import studio.o7.remora.extensions.framework.FrameworkExtension;
Expand All @@ -26,4 +27,8 @@ public class RemoraExtension {
public RemoraExtension(ObjectFactory factory) {
this.framework = factory.newInstance(FrameworkExtension.class);
}

public void framework(Action<? super FrameworkExtension> action) {
action.execute(this.framework);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Getter;
import lombok.Setter;
import org.gradle.api.Action;
import org.gradle.api.model.ObjectFactory;

import javax.inject.Inject;
Expand All @@ -15,4 +16,8 @@ public class FrameworkExtension {
public FrameworkExtension(ObjectFactory factory) {
lombok = factory.newInstance(LombokExtension.class);
}

public void lombok(Action<? super LombokExtension> action) {
action.execute(this.lombok);
}
}
8 changes: 8 additions & 0 deletions src/test/java/studio/o7/remora/RemoraPluginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package studio.o7.remora;


import static org.junit.jupiter.api.Assertions.*;

class RemoraPluginTest {

}
32 changes: 32 additions & 0 deletions src/test/java/studio/o7/remora/extensions/RemoraExtensionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package studio.o7.remora.extensions;

import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import studio.o7.remora.RemoraPlugin;
import studio.o7.remora.extensions.framework.FrameworkExtension;
import studio.o7.remora.extensions.framework.LombokExtension;

import static org.junit.jupiter.api.Assertions.*;

class RemoraExtensionTest {

@Test
public void testExtension() {
Project project = ProjectBuilder.builder().build();
project.getPlugins().apply(RemoraPlugin.class);

RemoraExtension extension = project.getExtensions().findByType(RemoraExtension.class);
assertNotNull(extension);

FrameworkExtension framework = extension.getFramework();
assertNotNull(framework);

LombokExtension lombok = framework.getLombok();
assertNotNull(lombok);

String version = lombok.getVersion();
assertNotNull(version);
assertEquals("1.18.36", version);
}
}

0 comments on commit b837ff3

Please sign in to comment.