-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from rspieldenner/repogeneration
Repogeneration
- Loading branch information
Showing
12 changed files
with
368 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/groovy/nebula/test/dependencies/ivy/Descriptor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
src/main/groovy/nebula/test/dependencies/maven/Artifact.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/main/groovy/nebula/test/dependencies/maven/ArtifactType.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
101
src/main/groovy/nebula/test/dependencies/maven/Pom.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/groovy/nebula/test/dependencies/repositories/IvyRepo.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/groovy/nebula/test/dependencies/repositories/MavenRepo.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/groovy/nebula/test/dependencies/maven/PomSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.