Skip to content
This repository was archived by the owner on Jan 17, 2024. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

import com.gpuopenanalytics.jenkins.remotedocker.AbstractDockerLauncher;
import com.gpuopenanalytics.jenkins.remotedocker.Utils;
import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -41,14 +39,15 @@ public abstract class CustomConfigItem extends ConfigItem {
public static final String CUSTOM_VALUE_INDICATOR = "custom";

private String value;
private Optional<String> customValue;
private transient Optional<String> customValue;
private String customVal;

public CustomConfigItem(String value, String customValue) {
this.value = value;
if (CUSTOM_VALUE_INDICATOR.equals(value)) {
this.customValue = Optional.ofNullable(customValue);
if (StringUtils.isEmpty(customValue)) {
this.customVal = null;
} else {
this.customValue = Optional.empty();
this.customVal = customValue;
}
}

Expand All @@ -58,7 +57,7 @@ public CustomConfigItem(String value, String customValue) {
* @return
*/
public boolean isCustom() {
return customValue.isPresent();
return CUSTOM_VALUE_INDICATOR.equals(value);
}

/**
Expand All @@ -76,7 +75,7 @@ public boolean isDefault() {
* @return
*/
public String getValue() {
return customValue.orElse(value);
return Optional.ofNullable(customVal).orElse(value);
}

public String getResolvedValue(AbstractDockerLauncher launcher) {
Expand All @@ -101,17 +100,13 @@ public String getRawValue() {
* Used to get the raw custom value. Prefer {@link #getValue()} over this.
*/
public Optional<String> getRawCustomValue() {
return customValue;
return Optional.ofNullable(customVal);
}

private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
value = (String) ois.readObject();
customValue = Optional.ofNullable((String) ois.readObject());
}

private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeObject(value);
oos.writeObject(customValue.orElse(null));
protected Object readResolve() {
if (customValue != null) {
customVal = customValue.orElse(null);
}
return this;
}

}