2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-26 00:37:10 -07:00

Added method to generate a POM into a given file

This commit is contained in:
Erik C. Thauvin 2023-08-16 05:17:45 -07:00
parent 17548f787c
commit 49243568c6
2 changed files with 526 additions and 473 deletions

View file

@ -7,8 +7,11 @@ package rife.bld.publish;
import rife.bld.dependencies.*;
import rife.template.Template;
import rife.template.TemplateFactory;
import rife.tools.FileUtils;
import rife.tools.StringUtils;
import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File;
import java.util.Objects;
/**
@ -121,6 +124,18 @@ public class PomBuilder {
return StringUtils.stripBlankLines(t.getContent());
}
/**
* Generates a POM into the given file.
*
* @since 1.7.1
*/
public void generateInto(PublishInfo info, DependencyScopes dependencies, File file)
throws FileUtilsErrorException {
info_ = info;
dependencies_ = dependencies;
FileUtils.writeString(build(), file);
}
private void addDependencies(Template t, Scope scope) {
var scoped_dependencies = dependencies().scope(scope);
if (!scoped_dependencies.isEmpty()) {

View file

@ -5,7 +5,14 @@
package rife.bld.publish;
import org.junit.jupiter.api.Test;
import rife.bld.dependencies.*;
import rife.bld.dependencies.Dependency;
import rife.bld.dependencies.DependencyScopes;
import rife.bld.dependencies.Scope;
import rife.bld.dependencies.VersionNumber;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.jupiter.api.Assertions.*;
@ -91,6 +98,37 @@ public class TestPomBuilder {
""", builder.build());
}
@Test
void testGenerateInto() throws IOException {
var temp = File.createTempFile("rife2-pom", "xml");
temp.deleteOnExit();
var deps = new DependencyScopes();
deps.scope(Scope.compile).include(new Dependency("com.uwyn.rife2", "rife2"));
new PomBuilder().generateInto(new PublishInfo().name("the thing"), deps, temp);
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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></groupId>
<artifactId></artifactId>
<version></version>
<name>the thing</name>
<description></description>
<url></url>
<dependencies>
<dependency>
<groupId>com.uwyn.rife2</groupId>
<artifactId>rife2</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>""", String.join(System.lineSeparator(), Files.readAllLines(temp.toPath())));
}
@Test
void testDevelopersInfoBuild() {
var builder = new PomBuilder()