Initial commit
This commit is contained in:
commit
fe3040fd8b
51 changed files with 1365 additions and 0 deletions
93
src/bld/java/rife/bld/extension/JReleaserExtensionBuild.java
Normal file
93
src/bld/java/rife/bld/extension/JReleaserExtensionBuild.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
|
||||
import rife.bld.Project;
|
||||
import rife.bld.publish.PublishDeveloper;
|
||||
import rife.bld.publish.PublishLicense;
|
||||
import rife.bld.publish.PublishScm;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static rife.bld.dependencies.Repository.*;
|
||||
import static rife.bld.dependencies.Scope.compile;
|
||||
import static rife.bld.dependencies.Scope.test;
|
||||
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
||||
|
||||
public class JReleaserExtensionBuild extends Project {
|
||||
public JReleaserExtensionBuild() {
|
||||
pkg = "rife.bld.extension";
|
||||
name = "JReleaserExtension";
|
||||
version = version(0, 9, 0, "SNAPSHOT");
|
||||
|
||||
javaRelease = 17;
|
||||
|
||||
downloadSources = true;
|
||||
autoDownloadPurge = true;
|
||||
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS);
|
||||
|
||||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 0)));
|
||||
scope(test)
|
||||
.include(dependency("org.jreleaser", "jreleaser", version(1,16,0)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 4)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 4)));
|
||||
|
||||
javadocOperation()
|
||||
.javadocOptions()
|
||||
.author()
|
||||
.docLint(NO_MISSING)
|
||||
.link("https://rife2.github.io/bld/")
|
||||
.link("https://rife2.github.io/rife2/");
|
||||
|
||||
publishOperation()
|
||||
.repository(version.isSnapshot() ? repository("rife2-snapshot") : repository("rife2"))
|
||||
.repository(repository("github"))
|
||||
.info()
|
||||
.groupId("com.uwyn.rife2")
|
||||
.artifactId("bld-jreleaser")
|
||||
.description("JReleaser Extension for bld")
|
||||
.url("https://github.com/rife2/bld-jreleaser")
|
||||
.developer(new PublishDeveloper()
|
||||
.id("aalmiray")
|
||||
.name("Andres Almiray")
|
||||
.url("https://andresalmiray.com/")
|
||||
).developer(new PublishDeveloper()
|
||||
.id("ethauvin")
|
||||
.name("Erik C. Thauvin")
|
||||
.email("erik@thauvin.net")
|
||||
.url("https://erik.thauvin.net/")
|
||||
)
|
||||
.license(new PublishLicense()
|
||||
.name("The Apache License, Version 2.0")
|
||||
.url("https://www.apache.org/licenses/LICENSE-2.0.txt")
|
||||
)
|
||||
.scm(new PublishScm()
|
||||
.connection("scm:git:https://github.com/rife2/bld-jreleaser.git")
|
||||
.developerConnection("scm:git:git@github.com:rife2/bld-jreleaser.git")
|
||||
.url("https://github.com/rife2/bld-jreleaser")
|
||||
)
|
||||
.signKey(property("sign.key"))
|
||||
.signPassphrase(property("sign.passphrase"));
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new JReleaserExtensionBuild().start(args);
|
||||
}
|
||||
}
|
258
src/main/java/rife/bld/extension/JReleaserInitOperation.java
Normal file
258
src/main/java/rife/bld/extension/JReleaserInitOperation.java
Normal file
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.operations.AbstractProcessOperation;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Create a JReleaser config file.
|
||||
*/
|
||||
public class JReleaserInitOperation extends AbstractProcessOperation<JReleaserInitOperation> {
|
||||
private static final String EMPTY = "";
|
||||
private static final Logger LOGGER = Logger.getLogger(JReleaserInitOperation.class.getName());
|
||||
private final Map<String, String> options_ = new ConcurrentHashMap<>();
|
||||
private BaseProject project_;
|
||||
|
||||
/**
|
||||
* Sets the base directory.
|
||||
*
|
||||
* @param directory the base directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation basedir(String directory) {
|
||||
options_.put("--basedir", directory);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base directory.
|
||||
*
|
||||
* @param directory the base directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation basedir(File directory) {
|
||||
return basedir(directory.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the base directory.
|
||||
*
|
||||
* @param directory the base directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation basedir(Path directory) {
|
||||
return basedir(directory.toFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set log level to debug.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation debug() {
|
||||
options_.put("--debug", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws IOException, InterruptedException, ExitStatusException {
|
||||
if (project_ == null) {
|
||||
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||
LOGGER.severe("A project must be specified.");
|
||||
}
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
} else {
|
||||
super.execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Part of the {@link #execute} operation, constructs the command list
|
||||
* to use for building the process.
|
||||
*/
|
||||
@Override
|
||||
protected List<String> executeConstructProcessCommandList() {
|
||||
List<String> args = new ArrayList<>();
|
||||
|
||||
if (project_ != null) {
|
||||
args.add(javaTool());
|
||||
args.add("-cp");
|
||||
args.add(String.format("%s:%s:%s:%s", new File(project_.libTestDirectory(), "*"),
|
||||
new File(project_.libCompileDirectory(), "*"), project_.buildMainDirectory(),
|
||||
project_.buildTestDirectory()));
|
||||
args.add("org.jreleaser.cli.Main");
|
||||
args.add("init");
|
||||
|
||||
options_.forEach((k, v) -> {
|
||||
if (!v.isEmpty()) {
|
||||
args.add(k + '=' + v);
|
||||
} else {
|
||||
args.add(k);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the operation from a {@link BaseProject}.
|
||||
*
|
||||
* @param project the project to configure the operation from
|
||||
*/
|
||||
@Override
|
||||
public JReleaserInitOperation fromProject(BaseProject project) {
|
||||
project_ = project;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the format.
|
||||
*
|
||||
* @param format the format
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation format(Format format) {
|
||||
options_.put("--format", format.getFormat());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the help message.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation help() {
|
||||
options_.put("--help", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set log level to info.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation info() {
|
||||
options_.put("--info", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output directory.
|
||||
*
|
||||
* @param directory the output directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation outputDirectory(String directory) {
|
||||
options_.put("-output-directory", directory);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output directory.
|
||||
*
|
||||
* @param directory the output directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation outputDirectory(File directory) {
|
||||
return outputDirectory(directory.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Output directory.
|
||||
*
|
||||
* @param directory the output directory
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation outputDirectory(Path directory) {
|
||||
return outputDirectory(directory.toFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite existing files.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation overwrite() {
|
||||
options_.put("--overwrite", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a System property.
|
||||
*
|
||||
* @param key the property key
|
||||
* @param value the property value
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation systemProperty(String key, String value) {
|
||||
options_.put("-D", key + '=' + value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print version information.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation version() {
|
||||
options_.put("--version", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set log level to warn.
|
||||
*
|
||||
* @return this operation instance
|
||||
*/
|
||||
public JReleaserInitOperation warn() {
|
||||
options_.put("--warn", EMPTY);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The currently supported formats.
|
||||
*/
|
||||
public enum Format {
|
||||
JSON("json"),
|
||||
TOML("toml"),
|
||||
YAML("yaml");
|
||||
|
||||
private final String format;
|
||||
|
||||
Format(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class JReleaserInitOperationTest {
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
var level = Level.ALL;
|
||||
var logger = Logger.getLogger("rife.bld.extension");
|
||||
var consoleHandler = new ConsoleHandler();
|
||||
consoleHandler.setLevel(level);
|
||||
logger.addHandler(consoleHandler);
|
||||
logger.setLevel(level);
|
||||
logger.setUseParentHandlers(false);
|
||||
}
|
||||
|
||||
static void deleteOnExit(File folder) {
|
||||
folder.deleteOnExit();
|
||||
for (var f : Objects.requireNonNull(folder.listFiles())) {
|
||||
if (f.isDirectory()) {
|
||||
deleteOnExit(f);
|
||||
} else {
|
||||
f.deleteOnExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFormat() throws IOException, ExitStatusException, InterruptedException {
|
||||
var tmpDir = Files.createTempDirectory("bld-jreleaser-testformat").toFile();
|
||||
tmpDir.deleteOnExit();
|
||||
|
||||
var op = new JReleaserInitOperation();
|
||||
|
||||
op.fromProject(new BaseProject()).basedir(tmpDir.getAbsolutePath());
|
||||
op.execute();
|
||||
assertTrue(new File(tmpDir, "jreleaser.yml").exists(), "jreleaser.yml not found");
|
||||
|
||||
op.format(JReleaserInitOperation.Format.JSON);
|
||||
op.execute();
|
||||
assertTrue(new File(tmpDir, "jreleaser.json").exists(), "jreleaser.json not found");
|
||||
|
||||
op.format(JReleaserInitOperation.Format.TOML);
|
||||
op.execute();
|
||||
assertTrue(new File(tmpDir, "jreleaser.toml").exists(), "jreleaser.toml not found");
|
||||
|
||||
deleteOnExit(tmpDir);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue