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