Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/src/main/java/dev/streamx/cli/StreamxCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;
import jakarta.inject.Inject;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.jetbrains.annotations.Nullable;
import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
Expand All @@ -39,6 +41,10 @@
},
versionProvider = VersionProvider.class)
public class StreamxCommand implements QuarkusApplication {
private static final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("yyyy_MM_dd__HH_mm_ss_SSS");
private static final String LOG_FILE_PATH_PROPERTY_NAME = "%prod.quarkus.log.file.path";
private static final String STREAMX_LOG_FILE_NAME_PATTERN = "%s/.streamx/logs/streamx-%s.log";

@Inject
CommandLine.IFactory factory;
Expand Down Expand Up @@ -67,6 +73,8 @@ public class StreamxCommand implements QuarkusApplication {
public static void main(String... args) {
initializeArgumentConfigSource(args);

overrideLogFileName();

Quarkus.run(StreamxCommand.class, args);
}

Expand Down Expand Up @@ -121,6 +129,18 @@ private int executionStrategy(ParseResult parseResult) {
}
}

private static void overrideLogFileName() {
if (System.getProperty(LOG_FILE_PATH_PROPERTY_NAME) != null) {
return;
}

String userHome = System.getProperty("user.home");
String date = DATE_FORMAT.format(new Date());
String streamxLogPath = String.format(STREAMX_LOG_FILE_NAME_PATTERN, userHome, date);

System.setProperty(LOG_FILE_PATH_PROPERTY_NAME, streamxLogPath);
}

private void init() {
bannerPrinter.initialize(commandLine, args);

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ streamx.runner.generated-keys.location=${user.home}/.streamx/config/generated

%prod.quarkus.log.console.enable=false
%prod.quarkus.log.file.enable=true
# WARNING! %prod.quarkus.log.file.path is overridden by EntrypointMain
# WARNING! %prod.quarkus.log.file.path is overridden by StreamxCommand
# Log name is overriden to log to date-specific log to allow multiple commands to be run paralleled.
%prod.quarkus.log.file.path=${user.home}/.streamx/logs/streamx.log
%prod.quarkus.log.file.rotation.max-backup-index=10
Expand Down
43 changes: 43 additions & 0 deletions core/src/test/java/dev/streamx/cli/StreamxCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.streamx.cli;

import java.io.IOException;
import java.nio.file.Files;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class StreamxCommandTest {

public static final String TIMESTAMP_REGEX =
"[0-9]{4}_[0-9]{2}_[0-9]{2}__[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{3}";
private static final String STREAMX_LOG_REGEX =
".*/\\.streamx/logs/streamx-" + TIMESTAMP_REGEX + "\\.log";

@Test
void shouldOverrideProdFileLogName() throws IOException {
// given
String userHome = Files.createTempDirectory("").toFile().getAbsolutePath();
System.clearProperty("%prod.quarkus.log.file.path");
System.setProperty("user.home", userHome);

// when
StreamxCommand.main(new String[] {});

// then
String fileName = System.getProperty("%prod.quarkus.log.file.path");
Assertions.assertTrue(fileName.matches(STREAMX_LOG_REGEX));
Assertions.assertTrue(fileName.startsWith(userHome));
}

@Test
void shouldUseProvidedProdFileLogName() {
// given
System.setProperty("%prod.quarkus.log.file.path", ".streamx.log");

// when
StreamxCommand.main(new String[] {});

// then
String fileName = System.getProperty("%prod.quarkus.log.file.path");
Assertions.assertEquals(".streamx.log", fileName);
}
}
6 changes: 1 addition & 5 deletions distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
</properties>

<dependencies>
<dependency>
<groupId>dev.streamx.cli</groupId>
<artifactId>streamx-cli-entrypoint</artifactId>
</dependency>
<dependency>
<groupId>dev.streamx.cli</groupId>
<artifactId>streamx-cli-core</artifactId>
Expand All @@ -47,7 +43,7 @@
<archive>
<manifest>
<mainClass>
dev.streamx.cli.EntrypointMain
dev.streamx.cli.StreamxCommand
</mainClass>
</manifest>
</archive>
Expand Down
52 changes: 0 additions & 52 deletions entrypoint/pom.xml

This file was deleted.

61 changes: 0 additions & 61 deletions entrypoint/src/main/java/dev/streamx/cli/EntrypointMain.java

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions entrypoint/src/test/java/dev/streamx/cli/StreamxCommand.java

This file was deleted.

11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<name>StreamX Cli : Parent</name>

<modules>
<module>entrypoint</module>
<module>core</module>
<module>distribution</module>
<module>e2e-tests</module>
Expand Down Expand Up @@ -64,11 +63,6 @@
<scope>import</scope>
</dependency>

<dependency>
<groupId>dev.streamx.cli</groupId>
<artifactId>streamx-cli-entrypoint</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>dev.streamx.cli</groupId>
<artifactId>streamx-cli-core</artifactId>
Expand Down Expand Up @@ -234,6 +228,11 @@
<goal>check</goal>
</goals>
<configuration>
<excludes>
<!-- Temporary exclude StreamxCommand from test coverage.
Some tests were added in the scope of DXP-2558, but it's not enough to satisfy test coverage requirements. -->
<exclude>dev.streamx.cli/StreamxCommand.class</exclude>
</excludes>
<rules>
<rule>
<element>BUNDLE</element>
Expand Down