Skip to content

Commit

Permalink
Implement a clean up of the ivy repository (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored May 18, 2024
1 parent bbf7345 commit ff5c330
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private Dependency wrap(Dependency dependency) {

final String gav = ModuleDependencyUtils.format((ExternalModuleDependency) dependency);

return project.getDependencies().create("ng_dummy_ng." + gav);
return project.getDependencies().create(IvyRepository.GAV_PREFIX + gav);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,21 @@

import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

public abstract class IvyRepository implements ConfigurableDSLElement<Repository>, Repository
{
public static final String GAV_PREFIX_DIRECTORY = "ng_dummy_ng";
public static final String GAV_PREFIX = GAV_PREFIX_DIRECTORY + ".";
/**
* A version for stored metadata.
*/
Expand Down Expand Up @@ -95,6 +100,19 @@ private Action<IvyArtifactRepository> repositoryConfiguration(
//We primarily configure the metadata supplier here, but we also need to configure the repository itself.
//We follow standard IVY patterns, and we also set M2 compatibility to true.
return ivy -> {
final File rootDir = root.get().getAsFile();
if (!rootDir.exists() && !rootDir.mkdirs()) {
throw new IllegalStateException("Failed to create repository directory");
}

for (File file : Objects.requireNonNull(rootDir.listFiles(pathname -> pathname.isDirectory() && !pathname.getName().equals(GAV_PREFIX_DIRECTORY)))) {
try {
FileUtils.delete(file.toPath());
} catch (IOException e) {
throw new RuntimeException("Failed to delete old repository directory", e);
}
}

ivy.setName(name);
ivy.setUrl(root.get().getAsFile().toURI());
ivy.patternLayout(layout -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,15 @@ private static class RuntimeFindingTaskDependencyResolveContext extends Abstract
public RuntimeFindingTaskDependencyResolveContext(Project project) {
this.project = project;
this.sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
this.runtimes = project.getExtensions().getByType(RuntimesExtension.class).getAllDefinitions();
this.dependencies = project.getExtensions().getByType(RuntimesExtension.class).getAllDependencies();

final RuntimesExtension runtimesExtension = project.getExtensions().findByType(RuntimesExtension.class);
if (runtimesExtension == null) {
this.runtimes = Collections.emptyList();
this.dependencies = Collections.emptyMap();
} else {
this.runtimes = runtimesExtension.getAllDefinitions();
this.dependencies = runtimesExtension.getAllDependencies();
}
}

@Override
Expand All @@ -202,8 +209,9 @@ public void add(@NotNull Object dependency) {
private void processConfiguration(Configuration configuration) {
DependencySet dependencies = configuration.getDependencies();

final DependencyReplacement replacement = project.getExtensions().getByType(DependencyReplacement.class);
final Set<Dependency> operatingSet = dependencies.stream()
//Grab the original dependencies if we have a replacement extension
final DependencyReplacement replacement = project.getExtensions().findByType(DependencyReplacement.class);
final Set<Dependency> operatingSet = replacement == null ? dependencies : dependencies.stream()
.map(dependency -> replacement.optionallyConvertBackToOriginal(dependency, configuration))
.collect(Collectors.toSet());

Expand Down Expand Up @@ -238,7 +246,7 @@ private void processSourceSet(SourceSet sourceSet) {
Property<CommonRuntimeDefinition<?>> runtimeDefinition = (Property<CommonRuntimeDefinition<?>>) sourceSet.getExtensions().findByName("runtimeDefinition");
if (runtimeDefinition != null && runtimeDefinition.isPresent()) {
this.add(runtimeDefinition.get());
} else {
} else if (runtimeDefinition != null) {
Set<CommonRuntimeDefinition<?>> tmp = new HashSet<>(this.found);
this.found.clear();
this.add(sourceSet.getCompileClasspath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class FunctionalTests extends BuilderBasedTestSpecification {

then:
run.task(':dependencies').outcome == TaskOutcome.SUCCESS
run.output.contains("\\--- net.neoforged:neoforge:")
run.output.contains("\\--- ng_dummy_ng.net.neoforged:neoforge:")
}

def "userdev supports complex version resolution"() {
Expand Down Expand Up @@ -116,7 +116,7 @@ class FunctionalTests extends BuilderBasedTestSpecification {

then:
run.task(':dependencies').outcome == TaskOutcome.SUCCESS
run.output.contains("\\--- net.neoforged:neoforge:20.4.188")
run.output.contains("\\--- ng_dummy_ng.net.neoforged:neoforge:20.4.188")
}

def "a mod with userdev as dependency has a mixin-extra dependency on the compile classpath"() {
Expand Down

0 comments on commit ff5c330

Please sign in to comment.