Skip to content

Commit

Permalink
Fix tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans committed Dec 24, 2024
1 parent ef82082 commit 88ab508
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ldtteam.tableau.neoforge.metadata.components.model;

import java.util.ArrayList;

import javax.inject.Inject;

import org.gradle.api.Project;
Expand All @@ -16,16 +18,21 @@
/**
* Represents the dependencies of a mod.
* <p>
* Mod dependencies can either be added to the required or optional dependencies collection, which is wired to the source sets implementation or api configuration.
* Mod dependencies can either be added to the required or optional dependencies
* collection, which is wired to the source sets implementation or api
* configuration.
* <p>
* Alternatively, a dependency can directly be added as a model component to the mod metadata.
* Alternatively, a dependency can directly be added as a model component to the
* mod metadata.
*/
public abstract class ModDependencies extends DelegatingNamedDomainObjectContainer<ModDependency> implements Dependencies {

public abstract class ModDependencies extends DelegatingNamedDomainObjectContainer<ModDependency>
implements Dependencies {

/**
* Creates a new ModDependencies instance.
*
* @param project The project.
* @param project The project.
* @param sourceSetConfiguration The source set configuration.
*/
@Inject
public ModDependencies(final Project project, final SourceSetConfiguration sourceSetConfiguration) {
Expand All @@ -34,29 +41,43 @@ public ModDependencies(final Project project, final SourceSetConfiguration sourc
}));

this.addAllLater(getRequired().getDependencies().flatMap(dependencies -> {
final Configuration resolveTarget = project.getConfigurations().detachedConfiguration(dependencies.toArray(Dependency[]::new));
if (dependencies.isEmpty()) {
return project.provider(() -> new ArrayList<>());
}

final Configuration resolveTarget = project.getConfigurations()
.detachedConfiguration(dependencies.toArray(Dependency[]::new));
resolveTarget.getDependencyConstraints().addAllLater(getRequired().getDependencyConstraints());
return DependencyResolver.resolveDependencies(project, getProblems(), resolveTarget, true);
}));
this.addAllLater(getOptional().getDependencies().flatMap(dependencies -> {
final Configuration resolveTarget = project.getConfigurations().detachedConfiguration(dependencies.toArray(Dependency[]::new));
if (dependencies.isEmpty()) {
return project.provider(() -> new ArrayList<>());
}

final Configuration resolveTarget = project.getConfigurations()
.detachedConfiguration(dependencies.toArray(Dependency[]::new));
resolveTarget.getDependencyConstraints().addAllLater(getOptional().getDependencyConstraints());
return DependencyResolver.resolveDependencies(project, getProblems(), resolveTarget, false);
}));

final Configuration runtimeClasspath = project.getConfigurations().maybeCreate(sourceSetConfiguration.getSourceSet().getRuntimeClasspathConfigurationName());
final Configuration api = project.getConfigurations().maybeCreate(sourceSetConfiguration.getSourceSet().getApiConfigurationName());
final Configuration runtimeClasspath = project.getConfigurations()
.maybeCreate(sourceSetConfiguration.getSourceSet().getRuntimeClasspathConfigurationName());
final Configuration api = project.getConfigurations()
.maybeCreate(sourceSetConfiguration.getSourceSet().getApiConfigurationName());

runtimeClasspath.fromDependencyCollector(getOptional());
api.fromDependencyCollector(getRequired());

}

/**
* Problem reporter used to report dependency resolution and metadata extraction issues.
* Problem reporter used to report dependency resolution and metadata extraction
* issues.
*
* @return the problem reporter
*/
@Inject
@Inject
protected abstract Problems getProblems();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ private DependencyResolver() {
/**
* Find all the resolved dependencies.
*
* @param project The project in which dependencies are being resolved.
* @param problems The problems handler.
* @param configuration The configuration to look for dependencies in.
* @param required Whether this dependency is required or not.
* @return The set provider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void setUp() {
sourceSetConfiguration = mock(SourceSetConfiguration.class);
sourceSet = mock(SourceSet.class);
when(sourceSetConfiguration.getSourceSet()).thenReturn(sourceSet);
when(sourceSet.getRuntimeClasspathConfigurationName()).thenReturn("runtimeClasspath");
when(sourceSet.getApiConfigurationName()).thenReturn("api");
mod = project.getObjects().newInstance(Mod.class, project, sourceSetConfiguration, "testMod");
}

Expand Down

0 comments on commit 88ab508

Please sign in to comment.