diff --git a/CHANGELOG.md b/CHANGELOG.md index de249f1..c3a286b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,19 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html) ## [Unreleased] +### Changed + +- Needs DirXMLDev 0.79.0 (was 0.78.0). **Reads of the vault take in other Libraries** + (PointBlueTechnology/DirXMLDev#115): Compare, Plan, Deploy and capture now see the objects the driver set's + links name outside it, as the LDIF and Designer imports do, so a tree read from the vault no longer reports + `link-unresolved` for them. Deploy's verify no longer fails on a trace size limit it leaves alone. The + simulator behind Simulate is 1.10.0: entitlements a user holds are seen, and Matching, Create and Placement + run only when the engine runs them. +- **Update this branch from ** keeps the tree's folder name for each other Library (a read could name + `Library@services` just `Library`). Updating chosen drivers brings in the other-Library objects they link + that the tree doesn't have yet, with the folder when the tree has none for that container; the tree's + other objects stay as they are. + ## [0.97.0] - 2026-11-23 ### Changed diff --git a/pom.xml b/pom.xml index a9a8243..372cdf0 100644 --- a/pom.xml +++ b/pom.xml @@ -23,8 +23,8 @@ - 0.78.0 - 1.9.0 + 0.79.0 + 1.10.0 0.4.11 diff --git a/src/main/java/com/pointblue/dirxml/web/TreeService.java b/src/main/java/com/pointblue/dirxml/web/TreeService.java index 3db4731..da3d6ae 100644 --- a/src/main/java/com/pointblue/dirxml/web/TreeService.java +++ b/src/main/java/com/pointblue/dirxml/web/TreeService.java @@ -26,6 +26,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * The tree, as the page needs it: the outline, an artifact with its source and references, a @@ -903,6 +904,59 @@ public synchronized String requireRevision(String revision) { return current; } + /** + * A partial pull swaps in the named drivers from {@code live}; their links into {@code libraries/} must still + * resolve. Each other-Library object those drivers link that {@code result} (the tree) lacks is added, with its + * folder when the tree has no Library for that DN. Objects the tree already has stay as they are: they are + * read-only references, refreshed by a whole-set pull. Returns the folders that got objects. + */ + static Set addLinkedLibraryObjects(DriverSet result, DriverSet live, List drivers, List notes) { + Set wanted = new java.util.TreeSet<>(String.CASE_INSENSITIVE_ORDER); + for (String name : drivers) { + Driver d = live.driver(name); + if (d != null) { + for (com.pointblue.dirxml.dev.model.PolicyLink l : d.links) { + if (l.ref != null && l.ref.startsWith("libraries/")) { + wanted.add(l.ref); + } + } + } + } + Set aliases = new java.util.TreeSet<>(); + for (Artifact a : live.library.artifacts()) { + if (a.library == null || !wanted.contains(a.path()) || result.resolve(a.path()) != null) { + continue; + } + String dn = live.libraries.get(a.library); + String have = result.libraries.get(a.library); + if (have == null && dn != null) { + result.libraries.put(a.library, dn); + notes.add("libraries/" + a.library + ": " + dn + " (another Library the update's drivers link)"); + } else if (have != null && dn != null + && !com.pointblue.dirxml.dev.model.Libraries.normDn(have).equals(com.pointblue.dirxml.dev.model.Libraries.normDn(dn))) { + notes.add(a.path() + ": the tree's folder " + a.library + " is " + have + ", the vault's object is in " + dn + "; left out"); + continue; + } + if (a instanceof Policy) { + result.library.policies.add((Policy) a); + } else if (a instanceof Resource) { + result.library.resources.add((Resource) a); + } else { + continue; + } + aliases.add(a.library); + } + Set dirs = new java.util.TreeSet<>(); + Map byAlias = AsCodeWriter.libraryDirs(result); + for (String alias : aliases) { + String dir = byAlias.get(alias); + if (dir != null) { + dirs.add(dir); + } + } + return dirs; + } + /** * Write the vault's state into this workspace's tree, as {@code idm import-live --env} does: the whole driver set, * or only the {@code drivers} named (the rest of the tree as it is); with an {@code overrides/} directory the @@ -951,8 +1005,11 @@ public synchronized Map pull(DriverSet live, String envName, Lis if (base != null) { notes.addAll(com.pointblue.dirxml.dev.deploy.Overrides.toTreeNames(live, base.overrides.get(envName))); notes.addAll(com.pointblue.dirxml.dev.deploy.ServerMap.toTree(live, base.overrides.get(envName), base)); + // a read sees only the Libraries its links name: give each the tree's folder name (DirXMLDev #115) + com.pointblue.dirxml.dev.model.Libraries.adoptAliases(live, base); } DriverSet result = live; + Set newLibraryDirs = new java.util.TreeSet<>(); if (drivers != null && !drivers.isEmpty()) { if (base == null) { throw new BadRequest("the workspace has no tree yet: take the whole driver set"); @@ -981,6 +1038,7 @@ public synchronized Map pull(DriverSet live, String envName, Lis } } result.overrides.clear(); + newLibraryDirs.addAll(addLinkedLibraryObjects(result, live, drivers, notes)); } notes.addAll(com.pointblue.dirxml.dev.deploy.DriverEnvironments.keepOnImport(result, envName, base, markNew, drivers != null && !drivers.isEmpty() ? drivers : null)); @@ -1013,6 +1071,19 @@ public synchronized Map pull(DriverSet live, String envName, Lis } roots.add(com.pointblue.dirxml.dev.deploy.Overrides.DIR); roots.add(".gitattributes"); + // the other-Library objects a partial pull brought in: their files and the folder's manifest, not the rest + for (String dir : newLibraryDirs) { + Path p = copy.resolve(dir); + names.add(dir + "/" + AsCodeWriter.LIBRARY_MANIFEST); + if (Files.isDirectory(p)) { + try (java.util.stream.Stream s = Files.walk(p)) { + s.filter(Files::isRegularFile) + .map(f -> copy.relativize(f).toString().replace('\\', '/')) + .filter(f -> !Files.exists(tree.resolve(f))) + .forEach(names::add); + } + } + } for (Path side : List.of(tree, copy)) { for (String r : roots) { Path p = side.resolve(r); diff --git a/src/test/java/com/pointblue/dirxml/web/PullOtherLibrariesTest.java b/src/test/java/com/pointblue/dirxml/web/PullOtherLibrariesTest.java new file mode 100644 index 0000000..40e4a98 --- /dev/null +++ b/src/test/java/com/pointblue/dirxml/web/PullOtherLibrariesTest.java @@ -0,0 +1,148 @@ +package com.pointblue.dirxml.web; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.pointblue.dirxml.dev.ascode.AsCodeReader; +import com.pointblue.dirxml.dev.ascode.AsCodeWriter; +import com.pointblue.dirxml.dev.model.Driver; +import com.pointblue.dirxml.dev.model.DriverSet; +import com.pointblue.dirxml.dev.model.DuplicateArtifacts; +import com.pointblue.dirxml.dev.model.Policy; +import com.pointblue.dirxml.dev.model.PolicyLink; +import com.pointblue.dirxml.dev.model.PolicySet; +import com.pointblue.dirxml.dev.model.Scope; +import com.pointblue.dirxml.dev.xml.CanonicalXml; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/** + * Update this branch from a vault whose drivers link Libraries outside the driver set (DirXMLDev #115): the tree keeps + * its folder names for them, and updating one driver brings in the other-Library objects it links that the tree lacks. + */ +public class PullOtherLibrariesTest { + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + private static final String DS_DN = "cn=Set,o=system"; + private static final String SHARED = "cn=Library,ou=shared,o=system"; + private static final String ODD = "ou=policies,o=x"; + + private static Policy policy(String name, String libraryDn, String alias) { + Policy p = new Policy(name, Scope.LIBRARY, null, CanonicalXml.parse( + "" + name + "").getDocumentElement()); + p.meta.put(DuplicateArtifacts.LIBRARY_DN, libraryDn); + p.library = alias; + return p; + } + + private static Driver driver(String name, String... refs) { + Driver d = new Driver(name); + d.dn = "cn=" + name + "," + DS_DN; + d.shimClass = "com.example.Shim"; + int order = 0; + for (String ref : refs) { + d.links.add(new PolicyLink(PolicySet.SUB_EVENT, ref, order++)); + } + return d; + } + + /** The tree: SHARED in the folder the LDIF import named it, Library@shared, with P; AD links P, Payroll nothing. */ + private Path tree() throws Exception { + DriverSet ds = new DriverSet("Set"); + ds.dn = DS_DN; + ds.libraries.put("Library@shared", SHARED); + ds.library.policies.add(policy("P", SHARED, "Library@shared")); + ds.drivers.add(driver("AD", "libraries/Library@shared/P")); + ds.drivers.add(driver("Payroll")); + Path tree = tmp.newFolder("tree").toPath(); + AsCodeWriter.write(ds, tree); + return tree; + } + + /** The vault as a read sees it: SHARED alone, so aliased Library, and AD now links Q there; Payroll links Odd in an ou. */ + private static DriverSet live() { + DriverSet live = new DriverSet("Set"); + live.dn = DS_DN; + live.libraries.put("Library", SHARED); + live.libraries.put("policies", ODD); + live.library.policies.add(policy("P", SHARED, "Library")); + live.library.policies.add(policy("Q", SHARED, "Library")); + live.library.policies.add(policy("Odd", ODD, "policies")); + live.drivers.add(driver("AD", "libraries/Library/P", "libraries/Library/Q")); + live.drivers.add(driver("Payroll", "libraries/policies/Odd")); + return live; + } + + @Test + @SuppressWarnings("unchecked") + public void aWholeUpdateKeepsTheTreesFolderNames() throws Exception { + Path tree = tree(); + try (Watcher w = new Watcher(tree, 10_000)) { + TreeService service = new TreeService(tree, w); + Map plan = service.pull(live(), "QA", List.of(), true, "", new ArrayList<>()); + List changed = (List) plan.get("changedFiles"); + List deleted = (List) plan.get("deletedFiles"); + assertFalse("no folder under the read's alias " + changed, changed.stream().anyMatch(f -> f.startsWith("libraries/Library/"))); + assertFalse("the tree's folder stays " + deleted, deleted.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/"))); + + service.pull(live(), "QA", List.of(), false, (String) plan.get("revision"), new ArrayList<>()); + DriverSet now = AsCodeReader.read(tree); + assertEquals(SHARED, now.libraries.get("Library@shared")); + assertNotNull(now.resolve("libraries/Library@shared/Q")); + assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty()); + } + } + + @Test + @SuppressWarnings("unchecked") + public void updatingOneDriverBringsInWhatItLinks() throws Exception { + Path tree = tree(); + byte[] p = Files.readAllBytes(tree.resolve(firstFile(tree, "libraries/Library@shared", "P"))); + try (Watcher w = new Watcher(tree, 10_000)) { + TreeService service = new TreeService(tree, w); + + // AD: Q joins the tree's folder for SHARED; P is left as it is + List notes = new ArrayList<>(); + Map plan = service.pull(live(), "QA", List.of("AD"), true, "", notes); + List changed = (List) plan.get("changedFiles"); + assertTrue(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/Q"))); + assertFalse(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/Library@shared/P"))); + assertFalse(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/policies/"))); + service.pull(live(), "QA", List.of("AD"), false, (String) plan.get("revision"), new ArrayList<>()); + DriverSet now = AsCodeReader.read(tree); + assertNotNull(now.resolve("libraries/Library@shared/Q")); + assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty()); + assertEquals(new String(p), new String(Files.readAllBytes(tree.resolve(firstFile(tree, "libraries/Library@shared", "P"))))); + + // Payroll: a container the tree has no folder for gets one, in the manifest too + notes.clear(); + plan = service.pull(live(), "QA", List.of("Payroll"), true, "", notes); + changed = (List) plan.get("changedFiles"); + assertTrue(changed.toString(), changed.stream().anyMatch(f -> f.startsWith("libraries/policies/Odd"))); + assertTrue(notes.toString(), notes.stream().anyMatch(n -> n.startsWith("libraries/policies: " + ODD))); + service.pull(live(), "QA", List.of("Payroll"), false, (String) plan.get("revision"), new ArrayList<>()); + now = AsCodeReader.read(tree); + assertEquals(ODD, now.libraries.get("policies")); + assertNotNull(now.resolve("libraries/policies/Odd")); + assertTrue(now.unresolvedLinks().toString(), now.unresolvedLinks().isEmpty()); + } + } + + /** The file an artifact named {@code name} was written to in {@code dir}, relative to the tree. */ + private static String firstFile(Path tree, String dir, String name) throws Exception { + try (java.util.stream.Stream s = Files.list(tree.resolve(dir))) { + return tree.relativize(s.filter(f -> f.getFileName().toString().startsWith(name + ".")) + .findFirst().orElseThrow(() -> new AssertionError("no file for " + name + " in " + dir))).toString(); + } + } +}