Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
<artifactId>truth</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.file.Files.isDirectory;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Maybe;
Expand All @@ -37,6 +38,8 @@
/** Loads skills from the local file system. */
public final class LocalSkillSource extends AbstractSkillSource<Path> {

private static final Joiner PATH_JOINER = Joiner.on('/');

private final Path skillsBasePath;

public LocalSkillSource(Path skillsBasePath) {
Expand Down Expand Up @@ -71,7 +74,9 @@ public Single<ImmutableList<String>> listResources(String skillName, String reso
return paths
.filter(Files::isRegularFile)
.map(skillDir::relativize)
.map(Path::toString)
// Join the path's name elements with '/' on every OS, not the platform
// separator, to match ClassPathSkillSource and InMemorySkillSource.
.map(relativePath -> PATH_JOINER.join(relativePath))
.collect(toImmutableList());
}
})
Expand Down
24 changes: 24 additions & 0 deletions core/src/test/java/com/google/adk/skills/LocalSkillSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.Rule;
Expand Down Expand Up @@ -96,6 +99,27 @@ public void testListResources() throws IOException {
assertThat(resources).containsExactly("assets/file1.txt", "assets/subdir/file2.txt");
}

@Test
public void testListResources_windowsFileSystem() throws IOException {
// Use Windows paths on any host so Ubuntu CI covers separator normalization.
try (FileSystem fileSystem = Jimfs.newFileSystem(Configuration.windows())) {
Path skillsBase = fileSystem.getPath("C:\\skills");
Path assetsDir = skillsBase.resolve("my-skill").resolve("assets");
Files.createDirectories(assetsDir.resolve("subdir"));
Files.writeString(assetsDir.resolve("file1.txt"), "resource content");
Files.writeString(assetsDir.resolve("subdir").resolve("file2.txt"), "resource content");

SkillSource source = new LocalSkillSource(skillsBase);
ImmutableList<String> resources = source.listResources("my-skill", "assets").blockingGet();

assertThat(resources).containsExactly("assets/file1.txt", "assets/subdir/file2.txt");
for (String resourcePath : resources) {
ByteSource resource = source.loadResource("my-skill", resourcePath).blockingGet();
assertThat(new String(resource.read(), UTF_8)).isEqualTo("resource content");
}
}
}

@Test
public void testListResources_notDirectory() throws IOException {
Path skillsBase = tempFolder.getRoot().toPath().resolve("skills");
Expand Down
Loading