mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 00:07:12 -07:00
Added support for generating POM properties.
Projects with javaRelease specified automatically set the maven compiler properties in their POM at generation.
This commit is contained in:
parent
a30b290c0d
commit
ecb9289001
9 changed files with 295 additions and 10 deletions
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit 8da01bc09c704aaeaa7c6ad1aa671dd4913c0276
|
||||
Subproject commit 301339449ec290cf118d969ef2b51ee02b8b83b7
|
|
@ -45,6 +45,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
private final List<Repository> repositories_ = new ArrayList<>();
|
||||
private final DependencyScopes dependencies_ = new DependencyScopes();
|
||||
private PublishInfo info_ = new PublishInfo();
|
||||
private PublishProperties properties_ = new PublishProperties();
|
||||
private final List<PublishArtifact> artifacts_ = new ArrayList<>();
|
||||
|
||||
/**
|
||||
|
@ -190,7 +191,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
// generate and upload pom
|
||||
executePublishStringArtifact(
|
||||
repository,
|
||||
new PomBuilder().info(info()).dependencies(dependencies()).build(),
|
||||
new PomBuilder().properties(properties()).info(info()).dependencies(dependencies()).build(),
|
||||
info().version() + "/" + info().artifactId() + "-" + actualVersion + ".pom", true);
|
||||
}
|
||||
|
||||
|
@ -496,6 +497,11 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
* @since 1.5.7
|
||||
*/
|
||||
public PublishOperation fromProject(BaseProject project) {
|
||||
if (project.javaRelease() != null) {
|
||||
properties()
|
||||
.mavenCompilerSource(project.javaRelease())
|
||||
.mavenCompilerTarget(project.javaRelease());
|
||||
}
|
||||
artifactRetriever(project.artifactRetriever());
|
||||
dependencies().include(project.dependencies());
|
||||
artifacts(List.of(
|
||||
|
@ -593,6 +599,18 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the publication properties.
|
||||
*
|
||||
* @param properties the publication properties
|
||||
* @return this operation instance
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PublishOperation properties(PublishProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the publication info structure.
|
||||
*
|
||||
|
@ -667,6 +685,18 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
|||
return dependencies_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the publication properties.
|
||||
* <p>
|
||||
* This is a modifiable structure that can be retrieved and changed.
|
||||
*
|
||||
* @return the publication properties
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PublishProperties properties() {
|
||||
return properties_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the publication info structure.
|
||||
* <p>
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Objects;
|
|||
*/
|
||||
public class PomBuilder {
|
||||
private PublishInfo info_ = null;
|
||||
private PublishProperties properties_ = new PublishProperties();
|
||||
private DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
||||
/**
|
||||
|
@ -46,6 +47,28 @@ public class PomBuilder {
|
|||
return info_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the properties to build the POM with.
|
||||
*
|
||||
* @param properties the properties to use
|
||||
* @return this {@code PomBuilder} instance
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PomBuilder properties(PublishProperties properties) {
|
||||
properties_ = properties;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the properties to build the POM with.
|
||||
*
|
||||
* @return the properties to use
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PublishProperties properties() {
|
||||
return properties_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the dependencies to build the POM for.
|
||||
*
|
||||
|
@ -115,6 +138,17 @@ public class PomBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
if (properties() != null && !properties().isEmpty()) {
|
||||
for (var entry : properties().entrySet()) {
|
||||
if (entry.getKey() != null) {
|
||||
t.setValueEncoded("property-key", entry.getKey());
|
||||
t.setValueEncoded("property-value", Objects.requireNonNullElse(entry.getValue(), ""));
|
||||
t.appendBlock("properties", "property");
|
||||
}
|
||||
}
|
||||
t.setBlock("properties-tag");
|
||||
}
|
||||
|
||||
if (dependencies() != null && !dependencies().isEmpty()) {
|
||||
addDependencies(t, Scope.compile);
|
||||
addDependencies(t, Scope.runtime);
|
||||
|
|
|
@ -163,7 +163,7 @@ public class PublishInfo {
|
|||
}
|
||||
|
||||
/**
|
||||
* Provides the custompath to the {@code gpg} executable used for signing.
|
||||
* Provides the custom path to the {@code gpg} executable used for signing.
|
||||
* <p>
|
||||
* By default, {@code gpg} will be used.
|
||||
*
|
||||
|
|
80
src/main/java/rife/bld/publish/PublishProperties.java
Normal file
80
src/main/java/rife/bld/publish/PublishProperties.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2001-2024 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.publish;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Provides the properties information for publication.
|
||||
*
|
||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public class PublishProperties extends LinkedHashMap<String, String> {
|
||||
private static final String MAVEN_COMPILER_SOURCE = "maven.compiler.source";
|
||||
private static final String MAVEN_COMPILER_TARGET = "maven.compiler.target";
|
||||
|
||||
/**
|
||||
* Sets the value of the 'maven.compiler.source' property.
|
||||
*
|
||||
* @param value the value to be set for the 'maven.compiler.source' property
|
||||
* @return this {@code PomProperties} instance
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PublishProperties mavenCompilerSource(Integer value) {
|
||||
if (value == null) {
|
||||
remove(MAVEN_COMPILER_SOURCE);
|
||||
}
|
||||
else {
|
||||
put(MAVEN_COMPILER_SOURCE, String.valueOf(value));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of the 'maven.compiler.source' property.
|
||||
*
|
||||
* @return the value of the 'maven.compiler.source' property
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public Integer mavenCompilerSource() {
|
||||
var value = get(MAVEN_COMPILER_SOURCE);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the 'maven.compiler.target' property.
|
||||
*
|
||||
* @param value the value to be set for the 'maven.compiler.target' property
|
||||
* @return this {@code PomProperties} instance
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public PublishProperties mavenCompilerTarget(Integer value) {
|
||||
if (value == null) {
|
||||
remove(MAVEN_COMPILER_TARGET);
|
||||
}
|
||||
else {
|
||||
put(MAVEN_COMPILER_TARGET, String.valueOf(value));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of the 'maven.compiler.target' property.
|
||||
*
|
||||
* @return the value of the 'maven.compiler.target' property
|
||||
* @since 1.9.2
|
||||
*/
|
||||
public Integer mavenCompilerTarget() {
|
||||
var value = get(MAVEN_COMPILER_TARGET);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,16 @@
|
|||
</licenses>
|
||||
<!--/b-->
|
||||
|
||||
<!--v properties-tag--><!--/v-->
|
||||
<!--b properties-tag-->
|
||||
<properties>
|
||||
<!--v properties--><!--/v-->
|
||||
<!--b property-->
|
||||
<{{v property-key/}}><!--v property-value--><!--/v--></{{v property-key/}}>
|
||||
<!--/b-->
|
||||
</properties>
|
||||
<!--/b-->
|
||||
|
||||
<!--v dependencies-tag--><!--/v-->
|
||||
<!--b dependencies-tag-->
|
||||
<dependencies>
|
||||
|
|
|
@ -50,12 +50,20 @@ public class TestPublishOperation {
|
|||
}
|
||||
}
|
||||
|
||||
static class PublishProject extends AppProjectBlueprint {
|
||||
public PublishProject(File work, String packageName, String projectName, VersionNumber versionNumber) {
|
||||
super(work, packageName, projectName, versionNumber);
|
||||
javaRelease = 19;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new PublishOperation();
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
assertNull(operation.moment());
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertTrue(operation.properties().isEmpty());
|
||||
assertNotNull(operation.info());
|
||||
assertNull(operation.info().groupId());
|
||||
assertNull(operation.info().artifactId());
|
||||
|
@ -105,6 +113,7 @@ public class TestPublishOperation {
|
|||
.repository(repository2)
|
||||
.moment(moment)
|
||||
.artifacts(List.of(artifact1, artifact2));
|
||||
operation3.properties().mavenCompilerSource(17).mavenCompilerTarget(19);
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
assertEquals(moment, operation3.moment());
|
||||
|
@ -195,7 +204,7 @@ public class TestPublishOperation {
|
|||
// created an updated publication
|
||||
var create_operation2 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
|
@ -328,7 +337,7 @@ public class TestPublishOperation {
|
|||
// created an updated publication
|
||||
var create_operation2 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
|
@ -405,7 +414,7 @@ public class TestPublishOperation {
|
|||
// create a first publication
|
||||
var create_operation1 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp1)
|
||||
|
@ -482,7 +491,7 @@ public class TestPublishOperation {
|
|||
// created an updated publication
|
||||
var create_operation2 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
|
@ -575,7 +584,7 @@ public class TestPublishOperation {
|
|||
// create a first publication
|
||||
var create_operation1 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp1)
|
||||
|
@ -631,7 +640,7 @@ public class TestPublishOperation {
|
|||
// created an updated publication
|
||||
var create_operation2 = new CreateAppOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new AppProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
return new PublishProject(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
|
|
|
@ -22,6 +22,7 @@ public class TestPomBuilder {
|
|||
void testInstantiation() {
|
||||
var builder = new PomBuilder();
|
||||
assertNull(builder.info());
|
||||
assertTrue(builder.properties().isEmpty());
|
||||
assertTrue(builder.dependencies().isEmpty());
|
||||
}
|
||||
|
||||
|
@ -197,6 +198,29 @@ public class TestPomBuilder {
|
|||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCompilerPropertiesBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.properties(new PublishProperties().mavenCompilerSource(22).mavenCompilerTarget(19));
|
||||
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></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<properties>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFullInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
|
@ -486,7 +510,8 @@ public class TestPomBuilder {
|
|||
.developer(new PublishDeveloper().id("id1").name("name1").email("email1").url("url1"))
|
||||
.developer(new PublishDeveloper().id("id2").name("name2"))
|
||||
.developer(new PublishDeveloper().id("id3").name("name3").url("url3"))
|
||||
.scm(new PublishScm().connection("conn1").developerConnection("devconn1").url("url1")));
|
||||
.scm(new PublishScm().connection("conn1").developerConnection("devconn1").url("url1")))
|
||||
.properties(new PublishProperties().mavenCompilerSource(22).mavenCompilerTarget(19));
|
||||
builder.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 5, 5), "bld", "zip"))
|
||||
|
@ -517,6 +542,10 @@ public class TestPomBuilder {
|
|||
<url>https://license2.com</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<properties>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
<maven.compiler.target>19</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
|
|
93
src/test/java/rife/bld/publish/TestPublishProperties.java
Normal file
93
src/test/java/rife/bld/publish/TestPublishProperties.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2001-2024 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.publish;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestPublishProperties {
|
||||
@Test
|
||||
public void testMavenCompilerSourceDefaultValue() {
|
||||
var publishProperties = new PublishProperties();
|
||||
var actualValue = publishProperties.mavenCompilerSource();
|
||||
assertNull(actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerSourceSetterWhenValueIsNotNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
Integer testValue = 15;
|
||||
publishProperties.mavenCompilerSource(testValue);
|
||||
Integer actualValue = Integer.parseInt(publishProperties.get("maven.compiler.source"));
|
||||
assertEquals(testValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerSourceSetterWhenValueIsNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
publishProperties.mavenCompilerSource(null);
|
||||
var actualValue = publishProperties.get("maven.compiler.source");
|
||||
assertNull(actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerSourceGetterWhenValueIsNotNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
Integer testValue = 8;
|
||||
publishProperties.put("maven.compiler.source", String.valueOf(testValue));
|
||||
var actualValue = publishProperties.mavenCompilerSource();
|
||||
assertEquals(testValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerSourceGetterWhenValueIsNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
publishProperties.put("maven.compiler.source", null);
|
||||
var actualValue = publishProperties.mavenCompilerSource();
|
||||
assertNull(actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerTargetDefaultValue() {
|
||||
var publishProperties = new PublishProperties();
|
||||
var actualValue = publishProperties.mavenCompilerTarget();
|
||||
assertNull(actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerTargetSetterWhenValueIsNotNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
Integer testValue = 15;
|
||||
publishProperties.mavenCompilerTarget(testValue);
|
||||
Integer actualValue = Integer.parseInt(publishProperties.get("maven.compiler.target"));
|
||||
assertEquals(testValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerTargetSetterWhenValueIsNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
publishProperties.mavenCompilerTarget(null);
|
||||
var actualValue = publishProperties.get("maven.compiler.target");
|
||||
assertNull(actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerTargetGetterWhenValueIsNotNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
Integer testValue = 8;
|
||||
publishProperties.put("maven.compiler.target", String.valueOf(testValue));
|
||||
var actualValue = publishProperties.mavenCompilerTarget();
|
||||
assertEquals(testValue, actualValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMavenCompilerTargetGetterWhenValueIsNull() {
|
||||
var publishProperties = new PublishProperties();
|
||||
publishProperties.put("maven.compiler.target", null);
|
||||
var actualValue = publishProperties.mavenCompilerTarget();
|
||||
assertNull(actualValue);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue