| 1 | package com.github.dakusui.actionunit.actions.cmd.unix; | |
| 2 | ||
| 3 | import com.github.dakusui.actionunit.actions.cmd.CommandLineComposer; | |
| 4 | import com.github.dakusui.actionunit.actions.cmd.Commander; | |
| 5 | import com.github.dakusui.actionunit.actions.cmd.CommanderConfig; | |
| 6 | import com.github.dakusui.actionunit.core.Context; | |
| 7 | import com.github.dakusui.actionunit.core.context.ContextFunction; | |
| 8 | import com.github.dakusui.printables.PrintableFunction; | |
| 9 | ||
| 10 | import java.util.ArrayList; | |
| 11 | import java.util.LinkedList; | |
| 12 | import java.util.List; | |
| 13 | import java.util.Objects; | |
| 14 | import java.util.Optional; | |
| 15 | import java.util.function.Function; | |
| 16 | ||
| 17 | import static com.github.dakusui.actionunit.core.context.ContextFunctions.immediateOf; | |
| 18 | import static com.github.dakusui.actionunit.utils.Checks.requireState; | |
| 19 | import static java.util.Objects.requireNonNull; | |
| 20 | ||
| 21 | public class Scp extends Commander<Scp> { | |
| 22 | private ContextFunction<Target> destination; | |
| 23 | private List<Function<Context, Target>> files; | |
| 24 | private Function<String, SshOptions> sshOptionsResolver; | |
| 25 | ||
| 26 | public Scp(CommanderConfig config) { | |
| 27 | super(config, "scp"); | |
| 28 | this.files = new LinkedList<>(); | |
| 29 | sshOptionsResolver(config.sshOptionsResolver()); | |
| 30 | } | |
| 31 | ||
| 32 | public Scp sshOptionsResolver(Function<String, SshOptions> resolver) { | |
| 33 | this.sshOptionsResolver = requireNonNull(resolver); | |
| 34 |
1
1. sshOptionsResolver : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::sshOptionsResolver → KILLED |
return this; |
| 35 | } | |
| 36 | ||
| 37 | public Scp recursive() { | |
| 38 |
1
1. recursive : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::recursive → NO_COVERAGE |
return this.addOption("-r"); |
| 39 | } | |
| 40 | ||
| 41 | public Scp file(Function<Context, Target> target) { | |
| 42 | this.files.add(requireNonNull(target)); | |
| 43 |
1
1. file : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::file → KILLED |
return this; |
| 44 | } | |
| 45 | ||
| 46 | public Scp file(Target target) { | |
| 47 |
1
1. file : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::file → KILLED |
return this.file(immediateOf(requireNonNull(target))); |
| 48 | } | |
| 49 | ||
| 50 | public Scp to(Target target) { | |
| 51 | this.destination = immediateOf(requireNonNull(target)); | |
| 52 |
1
1. to : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::to → KILLED |
return this; |
| 53 | } | |
| 54 | ||
| 55 | @Override | |
| 56 | public CommandLineComposer buildCommandLineComposer() { | |
| 57 | Scp cloned = this.clone(); | |
| 58 | CommandLineComposer.Builder commandLineComposerBuilder = cloned.commandLineComposerBuilderIfSet(); | |
| 59 | Function<Target, String> formatTarget = PrintableFunction.of(Target::format).describe("Target::format"); | |
| 60 | for (Function<Context, Target> each : files) { | |
| 61 | commandLineComposerBuilder | |
| 62 | .append(" ", false) | |
| 63 | .append(each.andThen(formatTarget), true); | |
| 64 | } | |
| 65 |
1
1. buildCommandLineComposer : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::buildCommandLineComposer → KILLED |
return commandLineComposerBuilder |
| 66 | .append(" ", false) | |
| 67 | .append(requireState(Objects::nonNull, cloned.destination).andThen(formatTarget), true) | |
| 68 | .build(); | |
| 69 | } | |
| 70 | ||
| 71 | @Override | |
| 72 | public Scp clone() { | |
| 73 | Scp ret = super.clone(); | |
| 74 |
1
1. clone : removed call to java/util/List::forEach → KILLED |
ret.sshOptionsResolver.apply("{remotehost}").formatOptionsWith(SshOptions.Formatter.forScp()).forEach(ret::addOption); |
| 75 | ret.files = new ArrayList<>(ret.files); | |
| 76 |
1
1. clone : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp::clone → KILLED |
return ret; |
| 77 | } | |
| 78 | ||
| 79 | public interface Target { | |
| 80 | interface Account { | |
| 81 | Optional<String> user(); | |
| 82 | ||
| 83 | String host(); | |
| 84 | ||
| 85 | default String format() { | |
| 86 |
1
1. format : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account::format → KILLED |
return user() |
| 87 |
1
1. lambda$format$0 : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account::lambda$format$0 → KILLED |
.map(v -> String.format("%s@%s", v, host())) |
| 88 | .orElseGet(this::host); | |
| 89 | } | |
| 90 | ||
| 91 | static Account create(String user, String host) { | |
| 92 | requireNonNull(user); | |
| 93 | requireNonNull(host); | |
| 94 |
1
1. create : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account::create → KILLED |
return new Account() { |
| 95 | @Override | |
| 96 | public Optional<String> user() { | |
| 97 |
1
1. user : replaced return value with Optional.empty for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account$1::user → KILLED |
return Optional.of(user); |
| 98 | } | |
| 99 | ||
| 100 | @Override | |
| 101 | public String host() { | |
| 102 |
1
1. host : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account$1::host → KILLED |
return host; |
| 103 | } | |
| 104 | ||
| 105 | @Override | |
| 106 | public String toString() { | |
| 107 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account$1::toString → NO_COVERAGE |
return format(); |
| 108 | } | |
| 109 | }; | |
| 110 | } | |
| 111 | ||
| 112 | static Account create(String host) { | |
| 113 | requireNonNull(host); | |
| 114 |
1
1. create : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account::create → KILLED |
return new Account() { |
| 115 | @Override | |
| 116 | public Optional<String> user() { | |
| 117 | return Optional.empty(); | |
| 118 | } | |
| 119 | ||
| 120 | @Override | |
| 121 | public String host() { | |
| 122 |
1
1. host : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account$2::host → KILLED |
return host; |
| 123 | } | |
| 124 | ||
| 125 | @Override | |
| 126 | public String toString() { | |
| 127 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$Account$2::toString → NO_COVERAGE |
return format(); |
| 128 | } | |
| 129 | }; | |
| 130 | } | |
| 131 | } | |
| 132 | ||
| 133 | Optional<Account> account(); | |
| 134 | ||
| 135 | String path(); | |
| 136 | ||
| 137 | default String format() { | |
| 138 |
2
1. format : negated conditional → KILLED 2. format : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target::format → KILLED |
return account().isPresent() ? |
| 139 | String.format("%s:%s", account().get().format(), path()) : | |
| 140 | path(); | |
| 141 | } | |
| 142 | ||
| 143 | static Target of(String path) { | |
| 144 | requireNonNull(path); | |
| 145 |
1
1. of : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target::of → KILLED |
return new Target() { |
| 146 | @Override | |
| 147 | public Optional<Account> account() { | |
| 148 | return Optional.empty(); | |
| 149 | } | |
| 150 | ||
| 151 | @Override | |
| 152 | public String path() { | |
| 153 |
1
1. path : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$1::path → KILLED |
return path; |
| 154 | } | |
| 155 | ||
| 156 | @Override | |
| 157 | public String toString() { | |
| 158 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$1::toString → KILLED |
return format(); |
| 159 | } | |
| 160 | }; | |
| 161 | } | |
| 162 | ||
| 163 | static Target of(String host, String path) { | |
| 164 | requireNonNull(host); | |
| 165 | requireNonNull(path); | |
| 166 |
1
1. of : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target::of → KILLED |
return new Target() { |
| 167 | @Override | |
| 168 | public Optional<Account> account() { | |
| 169 |
1
1. account : replaced return value with Optional.empty for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$2::account → KILLED |
return Optional.of(Account.create(host)); |
| 170 | } | |
| 171 | ||
| 172 | @Override | |
| 173 | public String path() { | |
| 174 |
1
1. path : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$2::path → KILLED |
return path; |
| 175 | } | |
| 176 | ||
| 177 | @Override | |
| 178 | public String toString() { | |
| 179 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$2::toString → KILLED |
return format(); |
| 180 | } | |
| 181 | }; | |
| 182 | } | |
| 183 | ||
| 184 | static Target of(String user, String host, String path) { | |
| 185 | requireNonNull(user); | |
| 186 | requireNonNull(host); | |
| 187 | requireNonNull(path); | |
| 188 |
1
1. of : replaced return value with null for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target::of → KILLED |
return new Target() { |
| 189 | @Override | |
| 190 | public Optional<Account> account() { | |
| 191 |
1
1. account : replaced return value with Optional.empty for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$3::account → KILLED |
return Optional.of(Account.create(user, host)); |
| 192 | } | |
| 193 | ||
| 194 | @Override | |
| 195 | public String path() { | |
| 196 |
1
1. path : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$3::path → KILLED |
return path; |
| 197 | } | |
| 198 | ||
| 199 | @Override | |
| 200 | public String toString() { | |
| 201 |
1
1. toString : replaced return value with "" for com/github/dakusui/actionunit/actions/cmd/unix/Scp$Target$3::toString → KILLED |
return format(); |
| 202 | } | |
| 203 | }; | |
| 204 | } | |
| 205 | } | |
| 206 | } | |
Mutations | ||
| 34 |
1.1 |
|
| 38 |
1.1 |
|
| 43 |
1.1 |
|
| 47 |
1.1 |
|
| 52 |
1.1 |
|
| 65 |
1.1 |
|
| 74 |
1.1 |
|
| 76 |
1.1 |
|
| 86 |
1.1 |
|
| 87 |
1.1 |
|
| 94 |
1.1 |
|
| 97 |
1.1 |
|
| 102 |
1.1 |
|
| 107 |
1.1 |
|
| 114 |
1.1 |
|
| 122 |
1.1 |
|
| 127 |
1.1 |
|
| 138 |
1.1 2.2 |
|
| 145 |
1.1 |
|
| 153 |
1.1 |
|
| 158 |
1.1 |
|
| 166 |
1.1 |
|
| 169 |
1.1 |
|
| 174 |
1.1 |
|
| 179 |
1.1 |
|
| 188 |
1.1 |
|
| 191 |
1.1 |
|
| 196 |
1.1 |
|
| 201 |
1.1 |