Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I356 #461

Merged
merged 2 commits into from
Sep 2, 2021
Merged

I356 #461

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
19 changes: 19 additions & 0 deletions common/src/main/java/org/mvndaemon/mvnd/common/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public abstract class Message {
public static final int TRANSFER_SUCCEEDED = 22;
public static final int TRANSFER_FAILED = 23;
public static final int EXECUTION_FAILURE = 24;
public static final int PRINT_OUT = 25;
public static final int PRINT_ERR = 26;

final int type;

Expand Down Expand Up @@ -106,6 +108,9 @@ public static Message read(DataInputStream input) throws IOException {
return TransferEvent.read(type, input);
case EXECUTION_FAILURE:
return ExecutionFailureEvent.read(input);
case PRINT_OUT:
case PRINT_ERR:
return StringMessage.read(type, input);
}
throw new IllegalStateException("Unexpected message type: " + type);
}
Expand All @@ -126,6 +131,8 @@ public static int getClassOrder(Message m) {
case PROMPT:
case PROMPT_RESPONSE:
case DISPLAY:
case PRINT_OUT:
case PRINT_ERR:
return 2;
case PROJECT_STARTED:
return 3;
Expand Down Expand Up @@ -703,6 +710,10 @@ private String mnemonic() {
return "BuildLogMessage";
case DISPLAY:
return "Display";
case PRINT_OUT:
return "PrintOut";
case PRINT_ERR:
return "PrintErr";
default:
throw new IllegalStateException("Unexpected type " + type);
}
Expand Down Expand Up @@ -1015,6 +1026,14 @@ public static StringMessage display(String message) {
return new StringMessage(DISPLAY, message);
}

public static StringMessage out(String message) {
return new StringMessage(PRINT_OUT, message);
}

public static StringMessage err(String message) {
return new StringMessage(PRINT_ERR, message);
}

public static StringMessage log(String message) {
return new StringMessage(BUILD_LOG_MESSAGE, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ private boolean doAccept(Message entry) {
terminal.writer().printf("%s%n", d.getMessage());
break;
}
case Message.PRINT_OUT: {
Message.StringMessage d = (Message.StringMessage) entry;
clearDisplay();
System.out.printf("%s%n", d.getMessage());
break;
}
case Message.PRINT_ERR: {
Message.StringMessage d = (Message.StringMessage) entry;
clearDisplay();
System.err.printf("%s%n", d.getMessage());
break;
}
case Message.PROMPT: {
Message.Prompt prompt = (Message.Prompt) entry;
if (dumb) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public class DaemonMavenCli {

public static final String RESUME = "r";

public static final String RAW_STREAMS = "raw-streams";

private final Slf4jLoggerManager plexusLoggerManager;

private final ILoggerFactory slf4jLoggerFactory;
Expand Down Expand Up @@ -323,6 +325,8 @@ private CLIManager newCLIManager() {
CLIManager cliManager = new CLIManager();
cliManager.options.addOption(Option.builder(RESUME).longOpt("resume").desc("Resume reactor from " +
"the last failed project, using the resume.properties file in the build directory").build());
cliManager.options.addOption(Option.builder().longOpt(RAW_STREAMS).desc("Do not decorate output and " +
"error streams").build());
return cliManager;
}

Expand Down Expand Up @@ -409,7 +413,7 @@ void logging(CliRequest cliRequest) {
// Ignore
//
}
} else {
} else if (!cliRequest.commandLine.hasOption(RAW_STREAMS)) {
ch.qos.logback.classic.Logger stdout = (ch.qos.logback.classic.Logger) slf4jLoggerFactory.getLogger("stdout");
ch.qos.logback.classic.Logger stderr = (ch.qos.logback.classic.Logger) slf4jLoggerFactory.getLogger("stderr");
stdout.setLevel(ch.qos.logback.classic.Level.INFO);
Expand Down
3 changes: 3 additions & 0 deletions daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.mvndaemon.mvnd.daemon.DaemonExpiration.DaemonExpirationResult;
import org.mvndaemon.mvnd.daemon.DaemonExpiration.DaemonExpirationStrategy;
import org.mvndaemon.mvnd.logging.smart.BuildEventListener;
import org.mvndaemon.mvnd.logging.smart.LoggingOutputStream;
import org.mvndaemon.mvnd.logging.smart.ProjectBuildLogAppender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -567,6 +568,8 @@ public <T extends Message> T request(Message request, Class<T> responseType, Pre
}
}
});
System.setOut(new LoggingOutputStream(s -> sendQueue.add(Message.out(s))).printStream());
System.setErr(new LoggingOutputStream(s -> sendQueue.add(Message.err(s))).printStream());
int exitCode = cli.main(
buildRequest.getArgs(),
buildRequest.getWorkingDir(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2019-2021 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
*
* http://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 org.mvndaemon.mvnd.it;

import java.io.IOException;
import javax.inject.Inject;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mvndaemon.mvnd.assertj.TestClientOutput;
import org.mvndaemon.mvnd.client.Client;
import org.mvndaemon.mvnd.client.DaemonParameters;
import org.mvndaemon.mvnd.junit.MvndTest;
import org.mvndaemon.mvnd.junit.TestRegistry;

import static org.junit.jupiter.api.Assertions.assertTrue;

@MvndTest(projectDir = "src/test/projects/raw-streams")
public class RawStreamsTest {

@Inject
Client client;

@Inject
DaemonParameters parameters;

@Inject
TestRegistry registry;

@Test
void version() throws IOException, InterruptedException {
registry.killAll();
assertDaemonRegistrySize(0);

final TestClientOutput o = new TestClientOutput();
client.execute(o, "validate", "--quiet", "--raw-streams").assertSuccess();
String expected = "PrintOut{payload='Hello'}";
o.getMessages().forEach(m -> System.out.println(m.toString()));
assertTrue(o.getMessages().stream()
.anyMatch(m -> m.toString().contains(expected)), "Output should contain " + expected);
assertDaemonRegistrySize(1);
}

private void assertDaemonRegistrySize(int size) {
Assertions.assertThat(registry.getAll().size())
.as("Daemon registry size should be " + size)
.isEqualTo(size);
}

}
50 changes: 50 additions & 0 deletions integration-tests/src/test/projects/raw-streams/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--

Copyright 2019-2021 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

http://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.

-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.mvndaemon.mvnd.test.raw-streams</groupId>
<artifactId>raw-streams</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>groovy-maven-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
println 'Hello'
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>