Skip to content

Commit

Permalink
Merge branch 'NG_7.0' into feature/no-metadata-download
Browse files Browse the repository at this point in the history
  • Loading branch information
marchermans authored Apr 27, 2024
2 parents 458c34c + 993b9c3 commit e301768
Show file tree
Hide file tree
Showing 24 changed files with 823 additions and 525 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# File generated by the GradleUtils `setupGitHubActionsWorkflows` task, avoid modifying it directly
# The template can be found at https://github.com/neoforged/GradleUtils/blob/287df22f683ed8422bc93deb9eb4a62099cc061f/src/actionsTemplate/resources/.github/workflows/build-prs.yml

name: Build PRs

on:
pull_request:
types:
- synchronize
- opened
- ready_for_review
- reopened
push:
branches:
- 'feature/**'
workflow_dispatch:

jobs:
build:
uses: neoforged/actions/.github/workflows/build-prs.yml@main
with:
java: 8
gradle_tasks: assemble
4 changes: 2 additions & 2 deletions .github/workflows/publish-prs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Publish PRs to GitHub Packages

on:
workflow_run:
workflows: ['Build Pull Request']
workflows: ['Build PRs']
types:
- completed
issue_comment:
Expand All @@ -24,7 +24,7 @@ jobs:
uses: neoforged/actions/.github/workflows/publish-prs.yml@main
with:
artifact_base_path: net/neoforged/gradle/
uploader_workflow_name: 'Build Pull Request'
uploader_workflow_name: 'Build PRs'
secrets:
PR_PUBLISHING_GH_APP_ID: ${{ secrets.PR_PUBLISHING_GH_APP_ID }}
PR_PUBLISHING_GH_APP_KEY: ${{ secrets.PR_PUBLISHING_GH_APP_KEY }}
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/pr.yml → .github/workflows/test-prs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Build Pull Request'
run-name: Build for PR ${{ github.event.pull_request.number }}
name: Test PRs
run-name: Tests for PR ${{ github.event.pull_request.number }}

on:
pull_request:
Expand Down Expand Up @@ -61,9 +61,6 @@ jobs:
- name: Build
run: ./gradlew --info -s -x assemble

- name: Publish artifacts
uses: neoforged/action-pr-publishing/upload@v1

test:
name: Test
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-report.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Test Report'
on:
workflow_run:
workflows: ['Build Pull Request']
workflows: ['Test PRs']
types:
- completed
permissions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,60 @@
import net.neoforged.gradle.dsl.common.dependency.DependencyManagementObject;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.artifacts.dsl.DependencyFactory;
import org.gradle.api.specs.Spec;
import org.gradle.api.specs.Specs;
import org.jetbrains.annotations.Nullable;

import java.util.regex.Pattern;
import javax.inject.Inject;
import java.util.Objects;

public class AbstractDependencyManagementObject implements DependencyManagementObject {
@SuppressWarnings("UnstableApiUsage")
public abstract class AbstractDependencyManagementObject implements DependencyManagementObject {
@Inject
protected abstract DependencyFactory getDependencyFactory();

protected final Project project;

public AbstractDependencyManagementObject(Project project) {
this.project = project;
protected static ArtifactIdentifier createArtifactIdentifier(final Dependency dependency) {
return new ArtifactIdentifier(dependency.getGroup(), dependency.getName(), dependency.getVersion());
}

protected static ArtifactIdentifier createArtifactIdentifier(final ResolvedDependency dependency) {
return new ArtifactIdentifier(dependency.getModuleGroup(), dependency.getModuleName(), dependency.getModuleVersion());
@Override
public Spec<? super ArtifactIdentifier> dependency(Project project) {
return dependency(getDependencyFactory().create(project));
}

protected static ArtifactIdentifier createArtifactIdentifier(final ModuleDependency dependency) {
return new ArtifactIdentifier(dependency.getGroup(), dependency.getName(), dependency.getVersion());
@Override
public Spec<? super ArtifactIdentifier> dependency(CharSequence dependencyNotation) {
return dependency(getDependencyFactory().create(dependencyNotation));
}

public Spec<? super ArtifactIdentifier> dependency(Object notation) {
return dependency(project.getDependencies().create(notation));
@Override
public Spec<? super ArtifactIdentifier> dependency(@Nullable String group, String name, @Nullable String version) {
return dependency(getDependencyFactory().create(group, name, version));
}

@Override
public Spec<? super ArtifactIdentifier> dependency(Dependency dependency) {
ArtifactIdentifier identifier = createArtifactIdentifier(dependency);

return this.dependency(new Closure<Boolean>(null) {

@SuppressWarnings("ConstantConditions")
@Override
public Boolean call(final Object it) {
if (it instanceof DependencyManagementObject.ArtifactIdentifier) {
final DependencyManagementObject.ArtifactIdentifier identifier = (DependencyManagementObject.ArtifactIdentifier) it;
return (dependency.getGroup() == null || Pattern.matches(dependency.getGroup(), identifier.getGroup())) &&
(dependency.getName() == null || Pattern.matches(dependency.getName(), identifier.getName())) &&
(dependency.getVersion() == null || Pattern.matches(dependency.getVersion(), identifier.getVersion()));
final DependencyManagementObject.ArtifactIdentifier id = (DependencyManagementObject.ArtifactIdentifier) it;
return (identifier.getGroup() == null || id.getGroup() == null || Objects.equals(identifier.getGroup(), id.getGroup())) &&
(identifier.getName() == null || id.getName() == null || Objects.equals(identifier.getName(), id.getName())) &&
(identifier.getVersion() == null || id.getVersion() == null || Objects.equals(identifier.getVersion(), id.getVersion()));
}

return false;
}
});
}

@Override
public Spec<? super ArtifactIdentifier> dependency(Closure<Boolean> spec) {
return Specs.convertClosureToSpec(spec);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package net.neoforged.gradle.common.dependency;

import net.neoforged.gradle.dsl.common.dependency.DependencyFilter;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ResolvedDependency;
import org.gradle.api.specs.Spec;

import java.util.ArrayList;
import java.util.List;

public class DefaultDependencyFilter extends AbstractDependencyManagementObject implements DependencyFilter {
public abstract class DefaultDependencyFilter extends AbstractDependencyManagementObject implements DependencyFilter {
protected final List<Spec<? super ArtifactIdentifier>> includeSpecs = new ArrayList<>();
protected final List<Spec<? super ArtifactIdentifier>> excludeSpecs = new ArrayList<>();

public DefaultDependencyFilter(Project project) {
super(project);
}

@Override
public DependencyFilter exclude(Spec<? super ArtifactIdentifier> spec) {
excludeSpecs.add(spec);
Expand All @@ -29,16 +22,6 @@ public DependencyFilter include(Spec<? super ArtifactIdentifier> spec) {
return this;
}

@Override
public boolean isIncluded(ResolvedDependency dependency) {
return isIncluded(createArtifactIdentifier(dependency));
}

@Override
public boolean isIncluded(ModuleDependency dependency) {
return isIncluded(createArtifactIdentifier(dependency));
}

@Override
public boolean isIncluded(ArtifactIdentifier dependency) {
boolean include = includeSpecs.isEmpty() || includeSpecs.stream().anyMatch(spec -> spec.isSatisfiedBy(dependency));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,16 @@
import net.neoforged.gradle.dsl.common.dependency.DependencyVersionInformationHandler;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.specs.Spec;

import java.util.Map;
import java.util.Optional;

public class DefaultDependencyVersionInformationHandler extends AbstractDependencyManagementObject implements DependencyVersionInformationHandler {
public abstract class DefaultDependencyVersionInformationHandler extends AbstractDependencyManagementObject implements DependencyVersionInformationHandler {

private final Map<Spec<? super ArtifactIdentifier>, String> rangedVersions = Maps.newHashMap();
private final Map<Spec<? super ArtifactIdentifier>, String> pinnedVersions = Maps.newHashMap();

public DefaultDependencyVersionInformationHandler(final Project project) {
super(project);
}

@Override
public void ranged(final Spec<? super ArtifactIdentifier> spec, final String range) {
rangedVersions.put(spec, range);
Expand All @@ -46,17 +40,15 @@ public void pin(final Spec<? super ArtifactIdentifier> spec, final ArtifactVersi
}

@Override
public Optional<String> getVersionRange(final ModuleDependency dependency) {
final ArtifactIdentifier identifier = createArtifactIdentifier(dependency);
public Optional<String> getVersionRange(final ArtifactIdentifier identifier) {
return rangedVersions.entrySet().stream()
.filter(entry -> entry.getKey().isSatisfiedBy(identifier))
.map(Map.Entry::getValue)
.findFirst();
}

@Override
public Optional<String> getVersion(final ModuleDependency dependency) {
final ArtifactIdentifier identifier = createArtifactIdentifier(dependency);
public Optional<String> getVersion(final ArtifactIdentifier identifier) {
return pinnedVersions.entrySet().stream()
.filter(entry -> entry.getKey().isSatisfiedBy(identifier))
.map(Map.Entry::getValue)
Expand Down
Loading

0 comments on commit e301768

Please sign in to comment.