fix(studio): keep project directory checks behind core services
This commit is contained in:
@@ -2,10 +2,14 @@ package p.studio.api.project;
|
|||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface ProjectCatalog {
|
public interface ProjectCatalog {
|
||||||
Path projectsRoot();
|
Path projectsRoot();
|
||||||
|
|
||||||
|
/** Returns the configured projects root only if it currently exists as a directory, without creating it. */
|
||||||
|
Optional<Path> existingProjectsRoot();
|
||||||
|
|
||||||
List<ProjectReference> listProjects();
|
List<ProjectReference> listProjects();
|
||||||
|
|
||||||
ProjectReference openProject(Path projectPath);
|
ProjectReference openProject(Path projectPath);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class ProjectCatalogService implements ProjectCatalog {
|
public final class ProjectCatalogService implements ProjectCatalog {
|
||||||
@@ -43,6 +44,11 @@ public final class ProjectCatalogService implements ProjectCatalog {
|
|||||||
return projectsRoot;
|
return projectsRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Path> existingProjectsRoot() {
|
||||||
|
return Files.isDirectory(projectsRoot) ? Optional.of(projectsRoot) : Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProjectReference> listProjects() {
|
public List<ProjectReference> listProjects() {
|
||||||
if (!Files.isDirectory(projectsRoot)) {
|
if (!Files.isDirectory(projectsRoot)) {
|
||||||
|
|||||||
+27
@@ -11,12 +11,39 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
class ProjectCatalogServiceTest {
|
class ProjectCatalogServiceTest {
|
||||||
@TempDir
|
@TempDir
|
||||||
Path tempDir;
|
Path tempDir;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void exposesExistingProjectsDirectoryWithoutChangingConfiguredRoot() {
|
||||||
|
final ProjectCatalogService service = service(tempDir.resolve("child/.."));
|
||||||
|
|
||||||
|
assertEquals(tempDir.toAbsolutePath().normalize(), service.existingProjectsRoot().orElseThrow());
|
||||||
|
assertEquals(service.projectsRoot(), service.existingProjectsRoot().orElseThrow());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void doesNotCreateMissingProjectsRootForDirectorySelection() {
|
||||||
|
final Path missing = tempDir.resolve("missing");
|
||||||
|
final ProjectCatalogService service = service(missing);
|
||||||
|
|
||||||
|
assertTrue(service.existingProjectsRoot().isEmpty());
|
||||||
|
assertEquals(missing.toAbsolutePath().normalize(), service.projectsRoot());
|
||||||
|
assertFalse(Files.exists(missing));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void doesNotOfferRegularFileAsProjectsDirectory() throws Exception {
|
||||||
|
final Path file = Files.writeString(tempDir.resolve("projects"), "not a directory");
|
||||||
|
|
||||||
|
assertTrue(service(file).existingProjectsRoot().isEmpty());
|
||||||
|
assertEquals("not a directory", Files.readString(file));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createsAndReopensAProjectWithLocalSetup() throws Exception {
|
void createsAndReopensAProjectWithLocalSetup() throws Exception {
|
||||||
final ProjectCatalogService service = service(tempDir);
|
final ProjectCatalogService service = service(tempDir);
|
||||||
|
|||||||
+1
-2
@@ -18,7 +18,6 @@ import p.studio.ui.javafx2.components.*;
|
|||||||
import p.studio.ui.javafx2.play.PlaybackViewport;
|
import p.studio.ui.javafx2.play.PlaybackViewport;
|
||||||
import p.studio.ui.javafx2.shell.MinimalShell;
|
import p.studio.ui.javafx2.shell.MinimalShell;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
@@ -141,7 +140,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
private void reloadProjects(Path selection){
|
private void reloadProjects(Path selection){
|
||||||
chooser.busy(true);
|
chooser.busy(true);
|
||||||
background(()->{var root=catalog.projectsRoot();return new ProjectList(known.listKnownProjects(),Files.isDirectory(root)?root:null);},(result,failure)->{
|
background(()->new ProjectList(known.listKnownProjects(),catalog.existingProjectsRoot().orElse(null)),(result,failure)->{
|
||||||
if(project!=null)return;
|
if(project!=null)return;
|
||||||
chooser.busy(busy||opening.busy());if(failure!=null){error(failure);return;}
|
chooser.busy(busy||opening.busy());if(failure!=null){error(failure);return;}
|
||||||
initialDirectory=result.root();chooser.projects(result.projects(),selection);
|
initialDirectory=result.root();chooser.projects(result.projects(),selection);
|
||||||
|
|||||||
+1
@@ -39,6 +39,7 @@ class ProjectOpeningTest {
|
|||||||
Fixture(){
|
Fixture(){
|
||||||
ProjectCatalog catalog=new ProjectCatalog(){
|
ProjectCatalog catalog=new ProjectCatalog(){
|
||||||
public Path projectsRoot(){return ROOT;}
|
public Path projectsRoot(){return ROOT;}
|
||||||
|
public Optional<Path> existingProjectsRoot(){return Optional.of(ROOT);}
|
||||||
public List<ProjectReference> listProjects(){return List.of(REF);}
|
public List<ProjectReference> listProjects(){return List.of(REF);}
|
||||||
public ProjectReference openProject(Path path){fail("catalog");return REF;}
|
public ProjectReference openProject(Path path){fail("catalog");return REF;}
|
||||||
public ProjectReference openProjectManifest(Path path){return openProject(path);}
|
public ProjectReference openProjectManifest(Path path){return openProject(path);}
|
||||||
|
|||||||
Reference in New Issue
Block a user