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  /**
31   *
32   */
33  public final class ForkedNodeArg implements ForkNodeArguments {
34      private final int forkChannelId;
35      private final ConsoleLogger logger;
36      private final boolean isDebug;
37  
38      public ForkedNodeArg(int forkChannelId, boolean isDebug) {
39          this.forkChannelId = forkChannelId;
40          logger = new NullConsoleLogger();
41          this.isDebug = isDebug;
42      }
43  
44      @Nonnull
45      @Override
46      public String getSessionId() {
47          throw new UnsupportedOperationException();
48      }
49  
50      @Override
51      public int getForkChannelId() {
52          return forkChannelId;
53      }
54  
55      @Override
56      @Nonnull
57      public File dumpStreamText(@Nonnull String text) {
58          return DumpErrorSingleton.getSingleton().dumpStreamText(text);
59      }
60  
61      @Nonnull
62      @Override
63      public File dumpStreamException(@Nonnull Throwable t) {
64          return DumpErrorSingleton.getSingleton().dumpStreamException(t, t.getLocalizedMessage());
65      }
66  
67      @Override
68      public void logWarningAtEnd(@Nonnull String text) {
69          // do nothing - the log message of forked VM already goes to the dump file
70      }
71  
72      @Nonnull
73      @Override
74      public ConsoleLogger getConsoleLogger() {
75          return logger;
76      }
77  
78      @Nonnull
79      @Override
80      public Object getConsoleLock() {
81          return logger;
82      }
83  
84      @Override
85      public File getEventStreamBinaryFile() {
86          throw new UnsupportedOperationException();
87      }
88  
89      @Override
90      public File getCommandStreamBinaryFile() {
91          return isDebug ? DumpErrorSingleton.getSingleton().getCommandStreamBinaryFile() : null;
92      }
93  }