Skip to content

Commit

Permalink
remove duplicate dependency and use toml4j
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlongbrother committed Feb 26, 2024
1 parent 8a82499 commit f4a0a30
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 96 deletions.
11 changes: 2 additions & 9 deletions integration-test/rust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.uniffle</groupId>
<artifactId>shuffle-server</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.uniffle</groupId>
<artifactId>rss-client</artifactId>
<scope>test</scope>
<type>test-jar</type>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,18 @@

package org.apache.uniffle.test;

import com.moandjiezana.toml.TomlWriter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RustShuffleServerConf {

private static final Logger LOG = LoggerFactory.getLogger(RustShuffleServerConf.class);

private final Map<String, Object> conf;

private final File tempDir;

private final File tempFile;

public RustShuffleServerConf(File tempDir) {
Expand All @@ -57,78 +50,9 @@ public void set(String key, Object value) {
}

public void generateTomlConf() throws IOException {
writeToFile(toTomlString(conf), tempFile.getPath());
}

public String toTomlString(Map<String, Object> tomlData) {
StringBuilder tomlBuilder = new StringBuilder();

for (Map.Entry<String, Object> entry : tomlData.entrySet()) {
if (!(entry.getValue() instanceof Map)) {
appendEntry(tomlBuilder, entry);
}
}

for (Map.Entry<String, Object> entry : tomlData.entrySet()) {
if (entry.getValue() instanceof Map) {
tomlBuilder.append("\n[").append(entry.getKey()).append("]\n");
Map<?, ?> nestedMap = (Map<?, ?>) entry.getValue();
for (Map.Entry<?, ?> nestedEntry : nestedMap.entrySet()) {
appendEntry(tomlBuilder, nestedEntry);
}
}
}

return tomlBuilder.toString();
}

private void appendEntry(StringBuilder builder, Map.Entry<?, ?> entry) {
if (entry.getValue() instanceof List) {
builder
.append(entry.getKey())
.append(" = ")
.append(listToString((List<?>) entry.getValue()))
.append("\n");
} else {
builder
.append(entry.getKey())
.append(" = ")
.append(valueToString(entry.getValue()))
.append("\n");
}
}

private String mapToString(Map<?, ?> map) {
StringBuilder mapBuilder = new StringBuilder();
for (Map.Entry<?, ?> entry : map.entrySet()) {
mapBuilder
.append(entry.getKey())
.append(" = ")
.append(valueToString(entry.getValue()))
.append("\n");
}
return mapBuilder.toString();
}

private String listToString(List<?> list) {
StringBuilder listBuilder = new StringBuilder("[");
boolean first = true;
for (Object item : list) {
if (!first) {
listBuilder.append(", ");
}
listBuilder.append(valueToString(item));
first = false;
}
listBuilder.append("]");
return listBuilder.toString();
}

private String valueToString(Object value) {
if (value instanceof String) {
return "\"" + value + "\"";
}
return value.toString();
TomlWriter tomlWriter = new TomlWriter();
String toml = tomlWriter.write(conf);
writeToFile(toml, tempFile.getPath());
}

private void writeToFile(String content, String filePath) throws IOException {
Expand Down
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<skipITs>${skipTests}</skipITs>
<skipBuildImage>true</skipBuildImage>
<snakeyaml.version>2.2</snakeyaml.version>
<toml4j.version>0.7.2</toml4j.version>
</properties>

<repositories>
Expand Down Expand Up @@ -2358,13 +2359,6 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.uniffle</groupId>
<artifactId>shuffle-server</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.uniffle</groupId>
<artifactId>rss-client</artifactId>
Expand All @@ -2377,6 +2371,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.moandjiezana.toml</groupId>
<artifactId>toml4j</artifactId>
<version>${toml4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Expand Down

0 comments on commit f4a0a30

Please sign in to comment.