Skip to content

Commit a1b03d1

Browse files
committed
repository: init new plugin to declare sponge repositories
1 parent 87796b2 commit a1b03d1

File tree

12 files changed

+385
-1
lines changed

12 files changed

+385
-1
lines changed

repository/build.gradle.kts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
indraPluginPublishing {
2+
plugin(
3+
"repository",
4+
"org.spongepowered.gradle.repository.RepositoryPlugin",
5+
"SpongePowered Repository",
6+
"Configure the Sponge maven repository automatically on projects",
7+
listOf("maven", "repository", "project", "settings")
8+
)
9+
}
10+
11+
testing.suites.withType(JvmTestSuite::class).configureEach {
12+
useJUnitJupiter("5.9.0")
13+
}
14+
15+
val functionalTest = testing.suites.register("functionalTest", JvmTestSuite::class) {
16+
dependencies {
17+
implementation(project)
18+
implementation("net.kyori:mammoth-test:1.2.0")
19+
}
20+
}
21+
22+
tasks.check {
23+
dependsOn(functionalTest)
24+
}
25+
26+
gradlePlugin.testSourceSets(functionalTest.get().sources)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of spongegradle-repository, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.gradle.repository;
26+
27+
import net.kyori.mammoth.test.GradleFunctionalTest;
28+
import net.kyori.mammoth.test.TestContext;
29+
import org.junit.jupiter.api.Disabled;
30+
import org.junit.jupiter.api.DisplayName;
31+
32+
import java.io.IOException;
33+
34+
// These all essentially just test evaluation of the buildscript
35+
public class RepositoriesFunctionalTest {
36+
37+
@GradleFunctionalTest
38+
@DisplayName("project")
39+
void testProject(final TestContext ctx) throws IOException {
40+
ctx.copyInput("build.gradle");
41+
ctx.copyInput("settings.gradle");
42+
43+
ctx.build("help");
44+
}
45+
46+
@GradleFunctionalTest
47+
@DisplayName("settings")
48+
void testSettings(final TestContext ctx) throws IOException {
49+
ctx.copyInput("settings.gradle");
50+
51+
ctx.build("help");
52+
}
53+
54+
@GradleFunctionalTest
55+
@Disabled
56+
@DisplayName("kotlinProject")
57+
void testKotlinProject(final TestContext ctx) throws IOException {
58+
ctx.copyInput("build.gradle.kts");
59+
ctx.copyInput("settings.gradle.kts");
60+
61+
ctx.build("help");
62+
}
63+
64+
@GradleFunctionalTest
65+
@Disabled
66+
@DisplayName("kotlinSettings")
67+
void testKotlinSettings(final TestContext ctx) throws IOException {
68+
ctx.copyInput("settings.gradle.kts");
69+
70+
ctx.build("help");
71+
}
72+
73+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id("org.spongepowered.gradle.repository")
3+
}
4+
5+
repositories {
6+
sponge.all()
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "kotlinProject"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id("org.spongepowered.gradle.repository")
3+
}
4+
5+
dependencyResolutionManagement {
6+
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
7+
repositories {
8+
sponge.releases()
9+
sponge.snapshots()
10+
}
11+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id("org.spongepowered.gradle.repository")
3+
}
4+
5+
repositories {
6+
sponge.all()
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "project"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id("org.spongepowered.gradle.repository")
3+
}
4+
5+
dependencyResolutionManagement {
6+
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
7+
repositories {
8+
sponge.releases()
9+
sponge.snapshots()
10+
}
11+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* This file is part of spongegradle-repository, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.gradle.repository;
26+
27+
import org.checkerframework.checker.nullness.qual.NonNull;
28+
import org.gradle.api.GradleException;
29+
import org.gradle.api.Plugin;
30+
import org.gradle.api.Project;
31+
import org.gradle.api.artifacts.dsl.RepositoryHandler;
32+
import org.gradle.api.initialization.Settings;
33+
import org.gradle.api.invocation.Gradle;
34+
import org.gradle.api.plugins.ExtensionAware;
35+
36+
public class RepositoryPlugin implements Plugin<Object> {
37+
38+
@Override
39+
public void apply(final @NonNull Object target) {
40+
if (target instanceof Project) {
41+
this.applyToProject((Project) target);
42+
} else if (target instanceof Settings) {
43+
this.applyToSettings((Settings) target);
44+
} else if (target instanceof Gradle) {
45+
// no-op
46+
} else {
47+
throw new GradleException(
48+
"Sponge repository plugin target '" + target
49+
+ "' is of unexpected type " + target.getClass()
50+
+ ", expecting a Project or Settings instance"
51+
);
52+
}
53+
}
54+
55+
private void applyToProject(final Project project) {
56+
this.registerExtension(project.getRepositories());
57+
}
58+
59+
private void applyToSettings(final Settings settings) {
60+
settings.getGradle().getPlugins().apply(RepositoryPlugin.class);
61+
this.registerExtension(settings.getDependencyResolutionManagement().getRepositories());
62+
}
63+
64+
private void registerExtension(final RepositoryHandler repositories) {
65+
((ExtensionAware) repositories).getExtensions().create(
66+
SpongeRepositoryExtension.class,
67+
"sponge",
68+
SpongeRepositoryExtensionImpl.class,
69+
repositories
70+
);
71+
}
72+
73+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* This file is part of spongegradle-repository, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.gradle.repository;
26+
27+
import static java.util.Objects.requireNonNull;
28+
29+
import org.checkerframework.checker.nullness.qual.NonNull;
30+
import org.gradle.api.Action;
31+
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
32+
33+
/**
34+
* Extension for configuring Sponge's repositories.
35+
*/
36+
public interface SpongeRepositoryExtension {
37+
38+
/**
39+
* Register the Maven repository group containing Sponge's own releases and snapshots, plus all proxied content.
40+
*
41+
* @return the created repository
42+
* @since 2.1.0
43+
*/
44+
MavenArtifactRepository all();
45+
46+
/**
47+
* Register the Maven repository group containing Sponge's own releases and snapshots, plus all proxied content.
48+
*
49+
* @param extraConfig an extra action to apply to the created repository
50+
* @return the created repository
51+
* @since 2.1.0
52+
*/
53+
default MavenArtifactRepository all(final @NonNull Action<MavenArtifactRepository> extraConfig) {
54+
final MavenArtifactRepository ret = all();
55+
requireNonNull(extraConfig, "extraConfig").execute(ret);
56+
return ret;
57+
}
58+
59+
/**
60+
* Register the Maven repository containing Sponge's own published releases.
61+
*
62+
* @return the created repository
63+
* @since 2.1.0
64+
*/
65+
MavenArtifactRepository releases();
66+
67+
/**
68+
* Register the Maven repository containing Sponge's own published releases.
69+
*
70+
* @param extraConfig an extra action to apply to the created repository
71+
* @return the created repository
72+
* @since 2.1.0
73+
*/
74+
default MavenArtifactRepository releases(final @NonNull Action<MavenArtifactRepository> extraConfig) {
75+
final MavenArtifactRepository ret = releases();
76+
requireNonNull(extraConfig, "extraConfig").execute(ret);
77+
return ret;
78+
}
79+
80+
/**
81+
* Register the Maven repository containing Sponge's own published snapshots.
82+
*
83+
* @return the created repository
84+
* @since 2.1.0
85+
*/
86+
MavenArtifactRepository snapshots();
87+
88+
/**
89+
* Register the Maven repository containing Sponge's own published snapshots.
90+
*
91+
* @param extraConfig an extra action to apply to the created repository
92+
* @return the created repository
93+
* @since 2.1.0
94+
*/
95+
default MavenArtifactRepository snapshots(final @NonNull Action<MavenArtifactRepository> extraConfig) {
96+
final MavenArtifactRepository ret = snapshots();
97+
requireNonNull(extraConfig, "extraConfig").execute(ret);
98+
return ret;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)