diff --git a/README.md b/README.md index 17de824..7af9b78 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,12 @@ Gradle Compatibility Tested | 2.5 | no | | 2.6 | yes - must force to 'org.spockframework:spock-core:1.0-groovy-2.3' | | 2.7 | yes - must force to 'org.spockframework:spock-core:1.0-groovy-2.3' | -| 2.8-rc-1 | yes | +| 2.8 | yes | LICENSE ======= -Copyright 2014-2015 Netflix, Inc. +Copyright 2014-2016 Netflix, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9fb521f..7ae94c1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Thu Nov 17 11:27:41 PST 2016 +#Mon Nov 14 15:10:56 PST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/groovy/nebula/test/dependencies/ivy/Descriptor.groovy b/src/main/groovy/nebula/test/dependencies/ivy/Descriptor.groovy new file mode 100644 index 0000000..c1c149c --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/ivy/Descriptor.groovy @@ -0,0 +1,7 @@ +package nebula.test.dependencies.ivy + +/** + * Created by rspieldenner on 11/14/16. + */ +class Descriptor { +} diff --git a/src/main/groovy/nebula/test/dependencies/maven/Artifact.groovy b/src/main/groovy/nebula/test/dependencies/maven/Artifact.groovy new file mode 100644 index 0000000..00bc0df --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/maven/Artifact.groovy @@ -0,0 +1,34 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 + * + * http://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 nebula.test.dependencies.maven + +import groovy.transform.Canonical +import groovy.transform.Sortable + +@Canonical +@Sortable +class Artifact { + String group + String artifact + String version + ArtifactType type = ArtifactType.JAR + + Artifact(String group, String artifact, String version) { + this.group = group + this.artifact = artifact + this.version = version + } +} diff --git a/src/main/groovy/nebula/test/dependencies/maven/ArtifactType.groovy b/src/main/groovy/nebula/test/dependencies/maven/ArtifactType.groovy new file mode 100644 index 0000000..91ad226 --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/maven/ArtifactType.groovy @@ -0,0 +1,27 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 + * + * http://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 nebula.test.dependencies.maven + +enum ArtifactType { + POM('pom'), + JAR('jar') + + ArtifactType(String packaging) { + this.packaging = packaging + } + + String packaging +} diff --git a/src/main/groovy/nebula/test/dependencies/maven/Pom.groovy b/src/main/groovy/nebula/test/dependencies/maven/Pom.groovy new file mode 100644 index 0000000..d315a53 --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/maven/Pom.groovy @@ -0,0 +1,101 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 + * + * http://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 nebula.test.dependencies.maven + +import groovy.xml.MarkupBuilder + +class Pom { + Artifact artifact + Set dependencies = new TreeSet<>() + Set dependencyManagementArtifacts = new TreeSet<>() + + Pom(String group, String artifact, String version) { + this.artifact = new Artifact(group, artifact, version) + } + + Pom(String group, String artifact, String version, ArtifactType type) { + this(group, artifact, version) + this.artifact.type = type + } + + Pom addDependency(Artifact artifact) { + dependencies.add(artifact) + + this + } + + Pom addDependency(String group, String name, String version) { + dependencies.add(new Artifact(group, name, version)) + + this + } + + Pom addManagementDependency(Artifact artifact) { + dependencyManagementArtifacts.add(artifact) + + this + } + + Pom addManagementDependency(String group, String name, String version) { + dependencyManagementArtifacts.add(new Artifact(group, name, version)) + + this + } + + String getFilename() { + "${artifact.artifact}-${artifact.version}.pom" + } + + String generate() { + def writer = new StringWriter() + def pom = new MarkupBuilder(writer) + pom.setDoubleQuotes(true) + pom.mkp.xmlDeclaration(version: '1.0', encoding: 'UTF-8') + pom.project('xsi:schemaLocation' : 'http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd', 'xmlns' : 'http://maven.apache.org/POM/4.0.0', 'xmlns:xsi' : 'http://www.w3.org/2001/XMLSchema-instance') { + modelVersion('4.0.0') + groupId(artifact.group) + artifactId(artifact.artifact) + version(artifact.version) + if (artifact.type != ArtifactType.JAR) { + packaging(artifact.type.packaging) + } + if (dependencyManagementArtifacts) { + dependencyManagement { + dependencyManagementArtifacts.each { Artifact a -> + dependency { + groupId(a.group) + artifactId(a.artifact) + version(a.version) + } + } + } + } + if (dependencies) { + dependencies { + dependencies.each { Artifact a -> + dependency { + groupId(a.group) + artifactId(a.artifact) + version(a.version) + } + } + } + } + } + + writer.toString() + } +} diff --git a/src/main/groovy/nebula/test/dependencies/repositories/IvyRepo.groovy b/src/main/groovy/nebula/test/dependencies/repositories/IvyRepo.groovy new file mode 100644 index 0000000..5560e94 --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/repositories/IvyRepo.groovy @@ -0,0 +1,19 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 + * + * http://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 nebula.test.dependencies.repositories + +class IvyRepo { +} diff --git a/src/main/groovy/nebula/test/dependencies/repositories/MavenRepo.groovy b/src/main/groovy/nebula/test/dependencies/repositories/MavenRepo.groovy new file mode 100644 index 0000000..c91e28f --- /dev/null +++ b/src/main/groovy/nebula/test/dependencies/repositories/MavenRepo.groovy @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Netflix, Inc. + * + * 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 + * + * http://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 nebula.test.dependencies.repositories + +import nebula.test.dependencies.maven.Pom + +class MavenRepo { + Set poms = new HashSet<>() + File root + + String repoString() { + """\ + maven { url '${root.absolutePath}' } + """.stripIndent() + } + + void generate() { + if (!root.exists()) { + root.mkdirs() + } + poms.each { Pom pom -> + def path = "${pom.artifact.group.replaceAll(/\./, '/')}/${pom.artifact.artifact}/${pom.artifact.version}" + def dir = new File(root, path) + dir.mkdirs() + new File(dir, pom.filename).text = pom.generate() + } + } +} diff --git a/src/test/groovy/nebula/test/ChangingTestDirSpec.groovy b/src/test/groovy/nebula/test/ChangingTestDirSpec.groovy index 69ddf84..12447f7 100644 --- a/src/test/groovy/nebula/test/ChangingTestDirSpec.groovy +++ b/src/test/groovy/nebula/test/ChangingTestDirSpec.groovy @@ -5,7 +5,7 @@ import com.energizedwork.spock.extensions.TempDirectory class ChangingTestDirSpec extends IntegrationSpec { - @TempDirectory(clean = false, baseDir = 'test/build1') File projectDir + @TempDirectory(clean = false, baseDir = 'build/test/build1') File projectDir def 'can change name of project dir'() { expect: diff --git a/src/test/groovy/nebula/test/dependencies/GradleDependencyGeneratorSpec.groovy b/src/test/groovy/nebula/test/dependencies/GradleDependencyGeneratorSpec.groovy index 5db97c6..a58c1cb 100644 --- a/src/test/groovy/nebula/test/dependencies/GradleDependencyGeneratorSpec.groovy +++ b/src/test/groovy/nebula/test/dependencies/GradleDependencyGeneratorSpec.groovy @@ -15,6 +15,7 @@ */ package nebula.test.dependencies +import spock.lang.Ignore import spock.lang.Specification class GradleDependencyGeneratorSpec extends Specification { @@ -61,6 +62,33 @@ class GradleDependencyGeneratorSpec extends Specification { new File(ivyRepo, 'test/ivy/foo/1.0.0/foo-1.0.0.jar').exists() } + def 'check ivy status'() { + def directory = 'build/testdependencies/ivyxml' + def graph = ['test.ivy:foo:1.0.0'] + def generator = new GradleDependencyGenerator(new DependencyGraph(graph), directory) + + when: + generator.generateTestIvyRepo() + + then: + def repo = new File(directory) + new File(repo, 'ivyrepo/test/ivy/foo/1.0.0/foo-1.0.0-ivy.xml').text.contains 'status="integration"' + } + + @Ignore + def 'allow different ivy status'() { + def directory = 'build/testdependencies/ivyxml' + def graph = ['test.ivy:foo:1.0.0'] + def generator = new GradleDependencyGenerator(new DependencyGraph(graph), directory) + + when: + generator.generateTestIvyRepo('release') + + then: + def repo = new File(directory) + new File(repo, 'ivyrepo/test/ivy/foo/1.0.0/foo-1.0.0-ivy.xml').text.contains 'status="release"' + } + def 'check ivy xml'() { def directory = 'build/testdependencies/ivyxml' def graph = ['test.ivy:foo:1.0.0 -> test.ivy:bar:1.1.0'] diff --git a/src/test/groovy/nebula/test/dependencies/maven/PomSpec.groovy b/src/test/groovy/nebula/test/dependencies/maven/PomSpec.groovy new file mode 100644 index 0000000..b599363 --- /dev/null +++ b/src/test/groovy/nebula/test/dependencies/maven/PomSpec.groovy @@ -0,0 +1,82 @@ +package nebula.test.dependencies.maven + +import spock.lang.Specification + +class PomSpec extends Specification { + def 'generate basic pom'() { + def pom = new Pom('nebula.test', 'basic', '0.1.0') + + when: + def pomXml = pom.generate() + + then: + def expected = '''\ + + + 4.0.0 + nebula.test + basic + 0.1.0 + '''.stripIndent() + pomXml == expected + } + + def 'generate bom'() { + def pom = new Pom('nebula.test', 'basic', '0.1.0', ArtifactType.POM) + pom.addManagementDependency('foo', 'bar', '1.2.3') + + when: + def pomXml = pom.generate() + + then: + def expected = '''\ + + + 4.0.0 + nebula.test + basic + 0.1.0 + pom + + + foo + bar + 1.2.3 + + + '''.stripIndent() + pomXml == expected + } + + def 'generate pom with dependency'() { + def pom = new Pom('nebula.test', 'basic', '0.1.0') + pom.addDependency('foo', 'bar', '1.2.3') + pom.addDependency(new Artifact('baz', 'qux', '2.0.1')) + + when: + def pomXml = pom.generate() + + then: + def expected = '''\ + + + 4.0.0 + nebula.test + basic + 0.1.0 + + + baz + qux + 2.0.1 + + + foo + bar + 1.2.3 + + + '''.stripIndent() + pomXml == expected + } +} diff --git a/src/test/groovy/nebula/test/dependencies/repositories/MavenRepoSpec.groovy b/src/test/groovy/nebula/test/dependencies/repositories/MavenRepoSpec.groovy new file mode 100644 index 0000000..0f3694a --- /dev/null +++ b/src/test/groovy/nebula/test/dependencies/repositories/MavenRepoSpec.groovy @@ -0,0 +1,25 @@ +package nebula.test.dependencies.repositories + +import nebula.test.dependencies.maven.ArtifactType +import nebula.test.dependencies.maven.Pom +import spock.lang.Specification + +class MavenRepoSpec extends Specification { + def 'create repo'() { + def repo = new MavenRepo() + final String rootDir = 'build/test/nebula.test.dependencies.repositories.MavenRepoSpec/create_repo/mavenrepo' + repo.root = new File(rootDir) + if (repo.root.exists()) { + repo.root.deleteDir() + } + def example = new Pom('test.nebula', 'ourbom', '0.1.0', ArtifactType.POM) + repo.poms.add(example) + + when: + repo.generate() + + then: + def pom = new File("${rootDir}/test/nebula/ourbom/0.1.0/ourbom-0.1.0.pom") + pom.exists() + } +}