forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-15053][runtime] Escape all dynamic property values for taskman…
…ager For unix-like OS(Linux, MacOS, FREE_BSD, etc.), each value will put in single quotes. This works for all chars except single quote itself. To escape the single quote, close the quoting before it, insert the escaped single quote, and then re-open the quoting. For example, the value is foo'bar and the escaped value is 'foo'\''bar'. For windows OS, each value will be surrounded with double quotes. The double quote itself needs to be escaped with back slash. Also the caret symbol need to be escaped with double carets since the window command uses it to escape characters. This closes apache#10532.
- Loading branch information
1 parent
f0fe365
commit 2ff1de7
Showing
6 changed files
with
343 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...t-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/ShellScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.test.util; | ||
|
||
import org.apache.flink.util.OperatingSystem; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
|
||
/** | ||
* ShellScript for creating shell script on linux and windows. | ||
*/ | ||
public class ShellScript { | ||
|
||
public static ShellScriptBuilder createShellScriptBuilder() { | ||
if (OperatingSystem.isWindows()) { | ||
return new WindowsShellScriptBuilder(); | ||
} | ||
return new UnixShellScriptBuilder(); | ||
} | ||
|
||
public static String getScriptExtension() { | ||
return OperatingSystem.isWindows() ? ".cmd" : ".sh"; | ||
} | ||
|
||
/** | ||
* Builder to create shell script. | ||
*/ | ||
public abstract static class ShellScriptBuilder { | ||
private static final String LINE_SEPARATOR = System.getProperty("line.separator"); | ||
private final StringBuilder sb = new StringBuilder(); | ||
|
||
void line(String... command) { | ||
for (String s : command) { | ||
sb.append(s); | ||
} | ||
sb.append(LINE_SEPARATOR); | ||
} | ||
|
||
public void write(File file) throws IOException { | ||
try (FileWriter fwrt = new FileWriter(file); PrintWriter out = new PrintWriter(fwrt)) { | ||
out.append(sb); | ||
} | ||
file.setExecutable(true, false); | ||
} | ||
|
||
public abstract void command(List<String> command); | ||
|
||
public abstract void env(String key, String value); | ||
} | ||
|
||
private static final class UnixShellScriptBuilder extends ShellScriptBuilder { | ||
|
||
UnixShellScriptBuilder(){ | ||
line("#!/usr/bin/env bash"); | ||
line(); | ||
} | ||
|
||
public void command(List<String> command) { | ||
line("exec ", String.join(" ", command)); | ||
} | ||
|
||
public void env(String key, String value) { | ||
line("export ", key, "=\"", value, "\""); | ||
} | ||
} | ||
|
||
private static final class WindowsShellScriptBuilder extends ShellScriptBuilder { | ||
|
||
WindowsShellScriptBuilder() { | ||
line("@setlocal"); | ||
line(); | ||
} | ||
|
||
public void command(List<String> command) { | ||
line("@call ", String.join(" ", command)); | ||
} | ||
|
||
public void env(String key, String value) { | ||
line("@set ", key, "=", value); | ||
} | ||
} | ||
} |
Oops, something went wrong.