Add buildSrc
Closes gh-9539
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class IntegrationPluginTest {
|
||||
Project rootProject;
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
if (rootProject != null) {
|
||||
FileUtils.deleteDirectory(rootProject.getProjectDir());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenNoSourceThenIntegrationTestTaskNull() {
|
||||
rootProject = ProjectBuilder.builder().build();
|
||||
rootProject.getPlugins().apply(JavaPlugin.class);
|
||||
rootProject.getPlugins().apply(IntegrationTestPlugin.class);
|
||||
|
||||
assertThat(rootProject.getTasks().findByPath("integrationTest")).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.javadoc.Javadoc;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class JavadocApiPluginTest {
|
||||
Project rootProject;
|
||||
|
||||
@After
|
||||
public void cleanup() throws Exception {
|
||||
if (rootProject != null) {
|
||||
FileUtils.deleteDirectory(rootProject.getProjectDir());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenNotOverrideThenPropertiesDefaulted() {
|
||||
rootProject = ProjectBuilder.builder().build();
|
||||
rootProject.getPlugins().apply(JavadocApiPlugin.class);
|
||||
|
||||
Javadoc apiTask = (Javadoc) rootProject.getTasks().getByPath("api");
|
||||
|
||||
assertThat(apiTask).isNotNull();
|
||||
assertThat(apiTask.getGroup()).isEqualTo("Documentation");
|
||||
assertThat(apiTask.getDescription()).isEqualTo("Generates aggregated Javadoc API documentation.");
|
||||
assertThat(apiTask.getMaxMemory()).isEqualTo("1024m");
|
||||
assertThat(apiTask.getDestinationDir()).isEqualTo(new File(rootProject.getBuildDir(), "api"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2016-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package io.spring.gradle.convention;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.dsl.RepositoryHandler;
|
||||
import org.gradle.api.artifacts.repositories.ArtifactRepository;
|
||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
|
||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||
import org.gradle.testfixtures.ProjectBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RepositoryConventionPlugin}.
|
||||
*/
|
||||
public class RepositoryConventionPluginTests {
|
||||
|
||||
private Project project = ProjectBuilder.builder().build();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.project.getProperties().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsReleaseThenShouldIncludeReleaseRepo() {
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertReleaseRepository(repositories);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsMilestoneThenShouldIncludeMilestoneRepo() {
|
||||
this.project.setVersion("1.0.0.M1");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertMilestoneRepository(repositories); // milestone
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsSnapshotThenShouldIncludeSnapshotRepo() {
|
||||
this.project.setVersion("1.0.0.BUILD-SNAPSHOT");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertSnapshotRepository(repositories);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsSnapshotWithForceReleaseThenShouldOnlyIncludeReleaseRepo() {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("forceMavenRepositories", "release");
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertReleaseRepository(repositories);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsReleaseWithForceMilestoneThenShouldIncludeMilestoneRepo() {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("forceMavenRepositories", "milestone");
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertMilestoneRepository(repositories);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsReleaseWithForceSnapshotThenShouldIncludeSnapshotRepo() {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("forceMavenRepositories", "snapshot");
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertSnapshotRepository(repositories);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsReleaseWithForceLocalThenShouldIncludeReleaseAndLocalRepos() {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("forceMavenRepositories", "local");
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertThat(repositories).hasSize(4);
|
||||
assertThat((repositories.get(0)).getName()).isEqualTo("MavenLocal");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenIsReleaseWithForceMilestoneAndLocalThenShouldIncludeMilestoneAndLocalRepos() {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("forceMavenRepositories", "milestone,local");
|
||||
this.project.setVersion("1.0.0.RELEASE");
|
||||
this.project.getPluginManager().apply(RepositoryConventionPlugin.class);
|
||||
|
||||
RepositoryHandler repositories = this.project.getRepositories();
|
||||
assertThat(repositories).hasSize(5);
|
||||
assertThat((repositories.get(0)).getName()).isEqualTo("MavenLocal");
|
||||
}
|
||||
|
||||
private void assertSnapshotRepository(RepositoryHandler repositories) {
|
||||
assertThat(repositories).extracting(ArtifactRepository::getName).hasSize(5);
|
||||
assertThat(((MavenArtifactRepository) repositories.get(0)).getUrl().toString())
|
||||
.isEqualTo("https://repo.maven.apache.org/maven2/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(1)).getUrl().toString())
|
||||
.isEqualTo("https://jcenter.bintray.com/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(2)).getUrl().toString())
|
||||
.isEqualTo("https://repo.spring.io/snapshot/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(3)).getUrl().toString())
|
||||
.isEqualTo("https://repo.spring.io/milestone/");
|
||||
}
|
||||
|
||||
private void assertMilestoneRepository(RepositoryHandler repositories) {
|
||||
assertThat(repositories).extracting(ArtifactRepository::getName).hasSize(4);
|
||||
assertThat(((MavenArtifactRepository) repositories.get(0)).getUrl().toString())
|
||||
.isEqualTo("https://repo.maven.apache.org/maven2/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(1)).getUrl().toString())
|
||||
.isEqualTo("https://jcenter.bintray.com/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(2)).getUrl().toString())
|
||||
.isEqualTo("https://repo.spring.io/milestone/");
|
||||
}
|
||||
|
||||
private void assertReleaseRepository(RepositoryHandler repositories) {
|
||||
assertThat(repositories).extracting(ArtifactRepository::getName).hasSize(3);
|
||||
assertThat(((MavenArtifactRepository) repositories.get(0)).getUrl().toString())
|
||||
.isEqualTo("https://repo.maven.apache.org/maven2/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(1)).getUrl().toString())
|
||||
.isEqualTo("https://jcenter.bintray.com/");
|
||||
assertThat(((MavenArtifactRepository) repositories.get(2)).getUrl().toString())
|
||||
.isEqualTo("https://repo.spring.io/release/");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package io.spring.gradle.convention;
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UtilsTest {
|
||||
@Mock
|
||||
Project project;
|
||||
@Mock
|
||||
Project rootProject;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
when(project.getRootProject()).thenReturn(rootProject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProjectName() {
|
||||
when(rootProject.getName()).thenReturn("spring-security");
|
||||
|
||||
assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProjectNameWhenEndsWithBuildThenStrippedOut() {
|
||||
when(rootProject.getName()).thenReturn("spring-security-build");
|
||||
|
||||
assertThat(Utils.getProjectName(project)).isEqualTo("spring-security");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSnapshotValidWithDot() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.BUILD-SNAPSHOT");
|
||||
|
||||
assertThat(Utils.isSnapshot(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSnapshotValidWithNoBuild() {
|
||||
when(project.getVersion()).thenReturn("1.0.0-SNAPSHOT");
|
||||
|
||||
assertThat(Utils.isSnapshot(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSnapshotValidWithDash() {
|
||||
when(project.getVersion()).thenReturn("Theme-BUILD-SNAPSHOT");
|
||||
|
||||
assertThat(Utils.isSnapshot(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSnapshotInvalid() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.SNAPSHOT");
|
||||
|
||||
assertThat(Utils.isSnapshot(project)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMilestoneValidWithDot() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.M1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMilestoneValidWithDash() {
|
||||
when(project.getVersion()).thenReturn("Theme-M1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMilestoneValidWithNumberDash() {
|
||||
when(project.getVersion()).thenReturn("1.0.0-M1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMilestoneInvalid() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.M");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseCandidateValidWithDot() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.RC1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseCandidateValidWithNumberDash() {
|
||||
when(project.getVersion()).thenReturn("1.0.0-RC1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseCandidateValidWithDash() {
|
||||
when(project.getVersion()).thenReturn("Theme-RC1");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseCandidateInvalid() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.RC");
|
||||
|
||||
assertThat(Utils.isMilestone(project)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseValidWithDot() {
|
||||
when(project.getVersion()).thenReturn("1.0.0.RELEASE");
|
||||
|
||||
assertThat(Utils.isRelease(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseValidWithNoRelease() {
|
||||
when(project.getVersion()).thenReturn("1.0.0");
|
||||
|
||||
assertThat(Utils.isRelease(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReleaseValidWithDash() {
|
||||
when(project.getVersion()).thenReturn("Theme-RELEASE");
|
||||
|
||||
assertThat(Utils.isRelease(project)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isServiceReleaseValid() {
|
||||
when(project.getVersion()).thenReturn("Theme-SR1");
|
||||
|
||||
assertThat(Utils.isRelease(project)).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user