Skip to content

Commit

Permalink
Merge pull request #69 from rspieldenner/repogeneration
Browse files Browse the repository at this point in the history
Repogeneration
  • Loading branch information
rspieldenner authored Dec 7, 2016
2 parents 5ae7c2b + 7689f8e commit b6dfc70
Show file tree
Hide file tree
Showing 12 changed files with 368 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package nebula.test.dependencies.ivy

/**
* Created by rspieldenner on 11/14/16.
*/
class Descriptor {
}
34 changes: 34 additions & 0 deletions src/main/groovy/nebula/test/dependencies/maven/Artifact.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}
27 changes: 27 additions & 0 deletions src/main/groovy/nebula/test/dependencies/maven/ArtifactType.groovy
Original file line number Diff line number Diff line change
@@ -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
}
101 changes: 101 additions & 0 deletions src/main/groovy/nebula/test/dependencies/maven/Pom.groovy
Original file line number Diff line number Diff line change
@@ -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<Artifact> dependencies = new TreeSet<>()
Set<Artifact> 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()
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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<Pom> 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()
}
}
}
2 changes: 1 addition & 1 deletion src/test/groovy/nebula/test/ChangingTestDirSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package nebula.test.dependencies

import spock.lang.Ignore
import spock.lang.Specification

class GradleDependencyGeneratorSpec extends Specification {
Expand Down Expand Up @@ -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']
Expand Down
82 changes: 82 additions & 0 deletions src/test/groovy/nebula/test/dependencies/maven/PomSpec.groovy
Original file line number Diff line number Diff line change
@@ -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 = '''\
<?xml version="1.0" encoding="UTF-8"?>
<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</modelVersion>
<groupId>nebula.test</groupId>
<artifactId>basic</artifactId>
<version>0.1.0</version>
</project>'''.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 = '''\
<?xml version="1.0" encoding="UTF-8"?>
<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</modelVersion>
<groupId>nebula.test</groupId>
<artifactId>basic</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<dependencyManagement>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.2.3</version>
</dependency>
</dependencyManagement>
</project>'''.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 = '''\
<?xml version="1.0" encoding="UTF-8"?>
<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</modelVersion>
<groupId>nebula.test</groupId>
<artifactId>basic</artifactId>
<version>0.1.0</version>
<dependencies>
<dependency>
<groupId>baz</groupId>
<artifactId>qux</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>foo</groupId>
<artifactId>bar</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>'''.stripIndent()
pomXml == expected
}
}
Loading

0 comments on commit b6dfc70

Please sign in to comment.