diff --git a/core b/core index 8da01bc..3013394 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8da01bc09c704aaeaa7c6ad1aa671dd4913c0276 +Subproject commit 301339449ec290cf118d969ef2b51ee02b8b83b7 diff --git a/src/main/java/rife/bld/operations/PublishOperation.java b/src/main/java/rife/bld/operations/PublishOperation.java index 9385fb9..0acde72 100644 --- a/src/main/java/rife/bld/operations/PublishOperation.java +++ b/src/main/java/rife/bld/operations/PublishOperation.java @@ -45,6 +45,7 @@ public class PublishOperation extends AbstractOperation { private final List repositories_ = new ArrayList<>(); private final DependencyScopes dependencies_ = new DependencyScopes(); private PublishInfo info_ = new PublishInfo(); + private PublishProperties properties_ = new PublishProperties(); private final List artifacts_ = new ArrayList<>(); /** @@ -190,7 +191,7 @@ protected void executePublishPom(Repository repository, VersionNumber actualVers // 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 @@ protected void executeUploadArtifact(Repository repository, HttpRequest.BodyPubl * @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 PublishOperation dependencies(DependencyScopes dependencies) { 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 DependencyScopes dependencies() { return dependencies_; } + /** + * Retrieves the publication properties. + *

+ * 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. *

diff --git a/src/main/java/rife/bld/publish/PomBuilder.java b/src/main/java/rife/bld/publish/PomBuilder.java index 8df677b..5cb3db4 100644 --- a/src/main/java/rife/bld/publish/PomBuilder.java +++ b/src/main/java/rife/bld/publish/PomBuilder.java @@ -22,6 +22,7 @@ */ public class PomBuilder { private PublishInfo info_ = null; + private PublishProperties properties_ = new PublishProperties(); private DependencyScopes dependencies_ = new DependencyScopes(); /** @@ -46,6 +47,28 @@ public PublishInfo info() { 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 String build() { } } + 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); diff --git a/src/main/java/rife/bld/publish/PublishInfo.java b/src/main/java/rife/bld/publish/PublishInfo.java index e2d8c64..07a8337 100644 --- a/src/main/java/rife/bld/publish/PublishInfo.java +++ b/src/main/java/rife/bld/publish/PublishInfo.java @@ -163,7 +163,7 @@ public String url() { } /** - * Provides the custompath to the {@code gpg} executable used for signing. + * Provides the custom path to the {@code gpg} executable used for signing. *

* By default, {@code gpg} will be used. * diff --git a/src/main/java/rife/bld/publish/PublishProperties.java b/src/main/java/rife/bld/publish/PublishProperties.java new file mode 100644 index 0000000..bc6fd6d --- /dev/null +++ b/src/main/java/rife/bld/publish/PublishProperties.java @@ -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 { + 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); + } +} \ No newline at end of file diff --git a/src/main/resources/templates/bld/pom_blueprint.xml b/src/main/resources/templates/bld/pom_blueprint.xml index eabcdad..154a90c 100644 --- a/src/main/resources/templates/bld/pom_blueprint.xml +++ b/src/main/resources/templates/bld/pom_blueprint.xml @@ -22,6 +22,16 @@ + + + + + + <{{v property-key/}}> + + + + diff --git a/src/test/java/rife/bld/operations/TestPublishOperation.java b/src/test/java/rife/bld/operations/TestPublishOperation.java index d4f9d63..90a6437 100644 --- a/src/test/java/rife/bld/operations/TestPublishOperation.java +++ b/src/test/java/rife/bld/operations/TestPublishOperation.java @@ -50,12 +50,20 @@ static void deleteReposilite() } } + 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 @@ void testPopulation() { .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 @@ void testPublishRelease() // 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 @@ void testPublishReleaseLocal() // 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 @@ void testPublishSnapshot() // 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 @@ protected Project createProjectBlueprint() { // 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 @@ void testPublishSnapshotLocal() // 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 @@ protected Project createProjectBlueprint() { // 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) diff --git a/src/test/java/rife/bld/publish/TestPomBuilder.java b/src/test/java/rife/bld/publish/TestPomBuilder.java index 582cbaa..cb4371f 100644 --- a/src/test/java/rife/bld/publish/TestPomBuilder.java +++ b/src/test/java/rife/bld/publish/TestPomBuilder.java @@ -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 @@ void testScmInfoBuild() { """, builder.build()); } + @Test + void testCompilerPropertiesBuild() { + var builder = new PomBuilder() + .properties(new PublishProperties().mavenCompilerSource(22).mavenCompilerTarget(19)); + assertEquals(""" + + + 4.0.0 + + + + + + + + 22 + 19 + + + """, builder.build()); + } + @Test void testFullInfoBuild() { var builder = new PomBuilder() @@ -486,7 +510,8 @@ void testComplete() { .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 @@ void testComplete() { https://license2.com + + 22 + 19 + com.uwyn.rife2 diff --git a/src/test/java/rife/bld/publish/TestPublishProperties.java b/src/test/java/rife/bld/publish/TestPublishProperties.java new file mode 100644 index 0000000..12a0ad3 --- /dev/null +++ b/src/test/java/rife/bld/publish/TestPublishProperties.java @@ -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); + } +} \ No newline at end of file