mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 16:27:11 -07:00
Merge pull request #4 from ethauvin/main
Added support for run arguments
This commit is contained in:
commit
5f619ce188
4 changed files with 550 additions and 480 deletions
|
@ -5,7 +5,7 @@
|
|||
package rife.bld.help;
|
||||
|
||||
import rife.bld.CommandHelp;
|
||||
import rife.tools.StringUtils;
|
||||
import rife.bld.operations.RunOperation;
|
||||
|
||||
/**
|
||||
* Provides help for the run command.
|
||||
|
@ -15,13 +15,13 @@ import rife.tools.StringUtils;
|
|||
*/
|
||||
public class RunHelp implements CommandHelp {
|
||||
public String getSummary() {
|
||||
return "Runs the project";
|
||||
return "Runs the project (take option)";
|
||||
}
|
||||
|
||||
public String getDescription(String topic) {
|
||||
return StringUtils.replace("""
|
||||
return String.format("""
|
||||
Runs the project.
|
||||
|
||||
Usage : ${topic}""", "${topic}", topic);
|
||||
Usage : %s [%sARG...]""", topic, RunOperation.ARGS_OPTION);
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import rife.bld.BaseProject;
|
|||
import rife.tools.FileUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -17,6 +18,7 @@ import java.util.List;
|
|||
* @since 1.5
|
||||
*/
|
||||
public class RunOperation extends AbstractProcessOperation<RunOperation> {
|
||||
public static final String ARGS_OPTION = "--args=";
|
||||
protected final List<String> runOptions_ = new ArrayList<>();
|
||||
|
||||
/**
|
||||
|
@ -52,6 +54,22 @@ public class RunOperation extends AbstractProcessOperation<RunOperation> {
|
|||
if (project.usesRife2Agent()) {
|
||||
operation.javaOptions().javaAgent(project.getRife2AgentFile());
|
||||
}
|
||||
|
||||
// parse the run arguments if any
|
||||
var args = project.arguments();
|
||||
while (!args.isEmpty()) {
|
||||
var arg = args.get(0);
|
||||
if (arg.startsWith("-")) {
|
||||
args.remove(0);
|
||||
if (arg.startsWith(ARGS_OPTION)) {
|
||||
var runArgs = arg.substring(ARGS_OPTION.length());
|
||||
if (!runArgs.isBlank()) {
|
||||
runOptions_.addAll(0, Arrays.asList(runArgs.split(" ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,11 @@ package rife.bld.publish;
|
|||
import rife.bld.dependencies.*;
|
||||
import rife.template.Template;
|
||||
import rife.template.TemplateFactory;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.StringUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
|
@ -121,6 +124,17 @@ public class PomBuilder {
|
|||
return StringUtils.stripBlankLines(t.getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a POM into the given file.
|
||||
*
|
||||
* @since 1.7.1
|
||||
*/
|
||||
public static void generateInto(PublishInfo info, DependencyScopes dependencies, File file)
|
||||
throws FileUtilsErrorException {
|
||||
var pomBuilder = new PomBuilder().info(info).dependencies(dependencies);
|
||||
FileUtils.writeString(pomBuilder.build(), file);
|
||||
}
|
||||
|
||||
private void addDependencies(Template t, Scope scope) {
|
||||
var scoped_dependencies = dependencies().scope(scope);
|
||||
if (!scoped_dependencies.isEmpty()) {
|
||||
|
|
|
@ -5,7 +5,14 @@
|
|||
package rife.bld.publish;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.bld.dependencies.Dependency;
|
||||
import rife.bld.dependencies.DependencyScopes;
|
||||
import rife.bld.dependencies.Scope;
|
||||
import rife.bld.dependencies.VersionNumber;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -91,6 +98,37 @@ public class TestPomBuilder {
|
|||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateInto() throws IOException {
|
||||
var temp = File.createTempFile("rife2-pom", "xml");
|
||||
temp.deleteOnExit();
|
||||
|
||||
var deps = new DependencyScopes();
|
||||
deps.scope(Scope.compile).include(new Dependency("com.uwyn.rife2", "rife2"));
|
||||
|
||||
PomBuilder.generateInto(new PublishInfo().name("the thing"), deps, temp);
|
||||
|
||||
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>the thing</name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>""", String.join(System.lineSeparator(), Files.readAllLines(temp.toPath())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDevelopersInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue