Skip to content

Commit

Permalink
feat: New Extension
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-siebert committed Dec 31, 2024
1 parent 8d8da7b commit d74aebe
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 48 deletions.
35 changes: 22 additions & 13 deletions src/main/java/studio/o7/remora/RemoraPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.dsl.RepositoryHandler;
import org.gradle.api.logging.Logger;
import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.JavaLibraryPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.plugins.PluginManager;
import org.gradle.api.provider.Property;
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin;
import org.gradle.plugins.signing.SigningPlugin;
import studio.o7.remora.extensions.DefaultRemoraExtension;
import studio.o7.remora.extensions.FrameworkExtension;
import studio.o7.remora.extensions.RemoraExtension;

Expand All @@ -24,21 +27,30 @@ public void apply(Project project) {
applyNecessaryPlugins(logger, project);
applyNecessaryRepositories(logger, project);

RemoraExtension extension = project.getExtensions().create("remora", RemoraExtension.class);
RemoraExtension extension = setupExtension(logger, project.getExtensions());

applyNecessaryProjectConfiguration(logger, project, extension);
applyJavaPluginConfiguration(logger, project, extension);

applyDependencies(logger, project, extension);
//applyDependencies(logger, project, extension);

// todo
// applyPlaceholderConfiguration(logger, project, extension);
}

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

public static void applyNecessaryProjectConfiguration(@NonNull Logger logger, @NonNull Project project, @NonNull RemoraExtension extension) {
logger.info("Applying project `group` and `description` configuration");
project.setGroup(extension.getGroupId());
project.setDescription(extension.getDescription());
project.setGroup(extension.getGroupId().get());

Property<String> description = extension.getDescription();
if (description.isPresent()) {
project.setDescription(description.get());
}
}

public static void applyJavaPluginConfiguration(@NonNull Logger logger, @NonNull Project project, @NonNull RemoraExtension extension) {
Expand Down Expand Up @@ -69,23 +81,20 @@ public static void applyNecessaryRepositories(@NonNull Logger logger, @NonNull P
public static void applyDependencies(@NonNull Logger logger, @NonNull Project project, @NonNull RemoraExtension extension) {
DependencyHandler dependencies = project.getDependencies();

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

FrameworkExtension.Lombok lombok = framework.getLombok();
if (lombok.isEnabled()) {
logger.info("Adding dependency `lombok`");
logger.info("Adding dependency `lombok`");

String id = "org.projectlombok:lombok:" + lombok.getVersion();
String lombokId = "org.projectlombok:lombok:1.18.36";

dependencies.add("compileOnly", id);
dependencies.add("annotationProcessor", id);
}
dependencies.add("compileOnly", lombokId);
dependencies.add("annotationProcessor", lombokId);

FrameworkExtension.FastUtils fastUtils = framework.getFastUtils();
if (fastUtils.isEnabled()) {
logger.info("Adding dependency `fastUtils`");

String id = "it.unimi.dsi:fastutil:" + lombok.getVersion();
String id = "it.unimi.dsi:fastutil:" + fastUtils.getVersion();

dependencies.add(fastUtils.getScope().getConfigurationName(), id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package studio.o7.remora.extensions;

import org.gradle.api.reflect.HasPublicType;

public abstract class DefaultRemoraExtension implements RemoraExtension, HasPublicType {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@

@Data
public class FrameworkExtension {
@Optional
private Lombok lombok = new Lombok();
@Optional
private FastUtils fastUtils = new FastUtils();

@Data
public static class Lombok {
private boolean enabled = true;
private String version = "1.18.36";
}

@Data
public static class FastUtils {
private boolean enabled = true;
Expand Down
38 changes: 11 additions & 27 deletions src/main/java/studio/o7/remora/extensions/RemoraExtension.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
package studio.o7.remora.extensions;

import lombok.Data;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Optional;
import org.gradle.jvm.toolchain.JavaLanguageVersion;

@Data
public class RemoraExtension {
/**
* Project group id. Set as gradle group and publishing groupId.
*/
private String groupId;
/**
* Project artifact id. Set as publishing artifactId.
*/
private String artifactId;
/**
* Project description. Set as publishing description.
*/
private String description;
public interface RemoraExtension {

/**
* Java language version.
*/
private JavaLanguageVersion javaVersion = JavaLanguageVersion.of(23);
Property<String> getGroupId();

/**
* Configuration of included frameworks.
*/
private FrameworkExtension framework = new FrameworkExtension();
Property<String> getArtifactId();

@Optional
Property<String> getDescription();

@Optional
Property<JavaLanguageVersion> getJavaVersion();

/**
* Configuration of publishing strategies.
*/
private PublishingExtension publishing = new PublishingExtension();
}
41 changes: 41 additions & 0 deletions src/main/java/studio/o7/remora/extensions/RemoraOldExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package studio.o7.remora.extensions;

import lombok.Data;
import org.gradle.api.model.ObjectFactory;
import org.gradle.jvm.toolchain.JavaLanguageVersion;

@Data
public class RemoraOldExtension {
/**
* Project group id. Set as gradle group and publishing groupId.
*/
private String groupId;
/**
* Project artifact id. Set as publishing artifactId.
*/
private String artifactId;
/**
* Project description. Set as publishing description.
*/
private String description;

/**
* Java language version.
*/
private JavaLanguageVersion javaVersion = JavaLanguageVersion.of(23);

/**
* Configuration of included frameworks.
*/
private FrameworkExtension framework;

/**
* Configuration of publishing strategies.
*/
private PublishingExtension publishing = new PublishingExtension();


public RemoraOldExtension(ObjectFactory factory) {
this.framework = factory.newInstance(FrameworkExtension.class);
}
}

0 comments on commit d74aebe

Please sign in to comment.