001/* 002 * JDrupes Builder 003 * Copyright (C) 2025 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.builder.core; 020 021import java.util.Objects; 022import org.jdrupes.builder.api.ExecResult; 023import org.jdrupes.builder.api.ResourceProvider; 024 025/// Default implementation of a test result. 026/// 027public class DefaultExecResult extends ResourceObject implements ExecResult { 028 029 private final ResourceProvider provider; 030 private final int exitValue; 031 032 /// Initializes a new default exec result. 033 /// 034 /// @param provider the provider 035 /// @param name the name 036 /// @param exitValue the exit value 037 /// 038 @SuppressWarnings("PMD.ConstructorCallsOverridableMethod") 039 protected DefaultExecResult(ResourceProvider provider, 040 String name, int exitValue) { 041 name(name); 042 this.provider = provider; 043 this.exitValue = exitValue; 044 } 045 046 @Override 047 public int exitValue() { 048 return exitValue; 049 } 050 051 @Override 052 public int hashCode() { 053 final int prime = 31; 054 int result = super.hashCode(); 055 result = prime * result + Objects.hash(exitValue, provider); 056 return result; 057 } 058 059 @Override 060 public boolean equals(Object obj) { 061 if (this == obj) { 062 return true; 063 } 064 if (!super.equals(obj)) { 065 return false; 066 } 067 if (!(obj instanceof DefaultExecResult)) { 068 return false; 069 } 070 DefaultExecResult other = (DefaultExecResult) obj; 071 return exitValue == other.exitValue 072 && Objects.equals(provider, other.provider); 073 } 074 075 /// To string. 076 /// 077 /// @return the string 078 /// 079 @Override 080 public String toString() { 081 return ExecResult.class.getSimpleName() 082 + name().map(n -> ":" + n).orElse("") 083 + " [exitValue=" + exitValue + "]"; 084 } 085}