mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-26 00:37:10 -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
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue