Skip to content

Commit

Permalink
Added support for generating POM properties.
Browse files Browse the repository at this point in the history
Projects with javaRelease specified automatically set the maven compiler properties in their POM at generation.
  • Loading branch information
gbevin committed Jun 23, 2024
1 parent a30b290 commit ecb9289
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core
Submodule core updated 40 files
+15 −11 src/main/antlr/TemplateMainLexer.g4
+1 −1 src/main/resources/CORE_VERSION
+34 −2 src/test/java/rife/template/TestParser.java
+104 −8 src/test/java/rife/template/TestTemplate.java
+4 −0 src/test/resources/templates/values_long_in.html
+1 −0 src/test/resources/templates/values_long_out_content_10.html
+1 −0 src/test/resources/templates/values_long_out_content_11.html
+2 −0 src/test/resources/templates/values_long_out_content_12.html
+1 −0 src/test/resources/templates/values_long_out_content_13.html
+1 −0 src/test/resources/templates/values_long_out_content_14.html
+1 −0 src/test/resources/templates/values_long_out_content_15.html
+2 −0 src/test/resources/templates/values_long_out_content_16.html
+1 −0 src/test/resources/templates/values_long_out_content_17.html
+1 −0 src/test/resources/templates/values_long_out_content_18.html
+1 −0 src/test/resources/templates/values_long_out_content_19.html
+3 −0 src/test/resources/templates/values_long_out_content_20.html
+1 −2 src/test/resources/templates/values_long_out_content_4.html
+1 −0 src/test/resources/templates/values_long_out_content_5.html
+1 −0 src/test/resources/templates/values_long_out_content_6.html
+1 −0 src/test/resources/templates/values_long_out_content_7.html
+2 −0 src/test/resources/templates/values_long_out_content_8.html
+1 −0 src/test/resources/templates/values_long_out_content_9.html
+4 −0 src/test/resources/templates/values_short_in.html
+1 −0 src/test/resources/templates/values_short_out_content_10.html
+1 −0 src/test/resources/templates/values_short_out_content_11.html
+2 −0 src/test/resources/templates/values_short_out_content_12.html
+1 −0 src/test/resources/templates/values_short_out_content_13.html
+1 −0 src/test/resources/templates/values_short_out_content_14.html
+1 −0 src/test/resources/templates/values_short_out_content_15.html
+2 −0 src/test/resources/templates/values_short_out_content_16.html
+1 −0 src/test/resources/templates/values_short_out_content_17.html
+1 −0 src/test/resources/templates/values_short_out_content_18.html
+1 −0 src/test/resources/templates/values_short_out_content_19.html
+3 −0 src/test/resources/templates/values_short_out_content_20.html
+1 −2 src/test/resources/templates/values_short_out_content_4.html
+1 −0 src/test/resources/templates/values_short_out_content_5.html
+1 −0 src/test/resources/templates/values_short_out_content_6.html
+1 −0 src/test/resources/templates/values_short_out_content_7.html
+2 −0 src/test/resources/templates/values_short_out_content_8.html
+1 −0 src/test/resources/templates/values_short_out_content_9.html
32 changes: 31 additions & 1 deletion src/main/java/rife/bld/operations/PublishOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<>();

/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -667,6 +685,18 @@ public DependencyScopes dependencies() {
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>
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/rife/bld/publish/PomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
public class PomBuilder {
private PublishInfo info_ = null;
private PublishProperties properties_ = new PublishProperties();
private DependencyScopes dependencies_ = new DependencyScopes();

/**
Expand All @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/publish/PublishInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* By default, {@code gpg} will be used.
*
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/rife/bld/publish/PublishProperties.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
10 changes: 10 additions & 0 deletions src/main/resources/templates/bld/pom_blueprint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 15 additions & 6 deletions src/test/java/rife/bld/operations/TestPublishOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 30 additions & 1 deletion src/test/java/rife/bld/publish/TestPomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class TestPomBuilder {
void testInstantiation() {
var builder = new PomBuilder();
assertNull(builder.info());
assertTrue(builder.properties().isEmpty());
assertTrue(builder.dependencies().isEmpty());
}

Expand Down Expand Up @@ -197,6 +198,29 @@ void testScmInfoBuild() {
""", 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()
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -517,6 +542,10 @@ void testComplete() {
<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>
Expand Down
Loading

0 comments on commit ecb9289

Please sign in to comment.