Skip to content

Commit

Permalink
Make extension extensions safer to use by not allowing them to instan…
Browse files Browse the repository at this point in the history
…tiate things
  • Loading branch information
lukebemish committed Jan 6, 2025
1 parent 5cb6996 commit cd71692
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/main/java/dev/lukebemish/crochet/model/CrochetExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public abstract class CrochetExtension implements ExtensionAware {
private final CrochetFeaturesContext features;
private final CrochetTasksContext tasks;
private final NamedDomainObjectContainer<SplitSourceSet> splitSourceSets;
private final NamedDomainObjectContainer<DependencySet> sharedDependencySets;
private final NamedDomainObjectContainer<FabricDependencyBundle> fabricDependencyBundles;
private final NamedDomainObjectContainer<SharedInstallation> sharedInstallations;

@Inject
Expand Down Expand Up @@ -75,13 +75,19 @@ public CrochetExtension(Project project) {
// Runs should also be non-lazy, to trigger task creation
this.getRuns().whenObjectAdded(o -> {});

this.splitSourceSets = objects.domainObjectContainer(SplitSourceSet.class);
this.sharedDependencySets = objects.domainObjectContainer(DependencySet.class);
this.sharedInstallations = objects.domainObjectContainer(SharedInstallation.class);
this.splitSourceSets = objects.domainObjectContainer(SplitSourceSet.class, name -> {
throw new UnsupportedOperationException("Cannot instantiate SplitSourceSet on this container.");
});
this.fabricDependencyBundles = objects.domainObjectContainer(FabricDependencyBundle.class, name -> {
throw new UnsupportedOperationException("Cannot instantiate FabricDependencyBundle on this container.");
});
this.sharedInstallations = objects.domainObjectContainer(SharedInstallation.class, name -> {
throw new UnsupportedOperationException("Cannot instantiate SharedInstallation on this container.");
});

this.getExtensions().add("installations", this.installations);
this.getExtensions().add("splitSourceSets", this.splitSourceSets);
this.getExtensions().add("sharedDependencySets", this.sharedDependencySets);
this.getExtensions().add("fabricDependencyBundles", this.fabricDependencyBundles);
this.getExtensions().add("sharedInstallations", this.sharedInstallations);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

import javax.inject.Inject;

public abstract class DependencySet implements Named {
public abstract class FabricDependencyBundle implements Named {
private final Action<FabricRemapDependencies> action;
private final String name;

@Inject
public DependencySet(String name, Action<FabricRemapDependencies> action) {
public FabricDependencyBundle(String name, Action<FabricRemapDependencies> action) {
this.action = action;
this.name = name;
}
Expand Down

0 comments on commit cd71692

Please sign in to comment.