View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.booter;
20  
21  import javax.annotation.Nonnull;
22  
23  import java.io.File;
24  
25  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
26  import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
27  import org.apache.maven.surefire.api.booter.DumpErrorSingleton;
28  import org.apache.maven.surefire.api.fork.ForkNodeArguments;
29  
30  public final class ForkedNodeArg implements ForkNodeArguments {
31      private final int forkChannelId;
32      private final ConsoleLogger logger;
33      private final boolean isDebug;
34  
35      public ForkedNodeArg(int forkChannelId, boolean isDebug) {
36          this.forkChannelId = forkChannelId;
37          logger = new NullConsoleLogger();
38          this.isDebug = isDebug;
39      }
40  
41      @Nonnull
42      @Override
43      public String getSessionId() {
44          throw new UnsupportedOperationException();
45      }
46  
47      @Override
48      public int getForkChannelId() {
49          return forkChannelId;
50      }
51  
52      @Override
53      @Nonnull
54      public File dumpStreamText(@Nonnull String text) {
55          return DumpErrorSingleton.getSingleton().dumpStreamText(text);
56      }
57  
58      @Nonnull
59      @Override
60      public File dumpStreamException(@Nonnull Throwable t) {
61          return DumpErrorSingleton.getSingleton().dumpStreamException(t, t.getLocalizedMessage());
62      }
63  
64      @Override
65      public void logWarningAtEnd(@Nonnull String text) {
66          // do nothing - the log message of forked VM already goes to the dump file
67      }
68  
69      @Nonnull
70      @Override
71      public ConsoleLogger getConsoleLogger() {
72          return logger;
73      }
74  
75      @Nonnull
76      @Override
77      public Object getConsoleLock() {
78          return logger;
79      }
80  
81      @Override
82      public File getEventStreamBinaryFile() {
83          throw new UnsupportedOperationException();
84      }
85  
86      @Override
87      public File getCommandStreamBinaryFile() {
88          return isDebug ? DumpErrorSingleton.getSingleton().getCommandStreamBinaryFile() : null;
89      }
90  }