Package com.deltawalker.script
Interface FolderComparison
- All Superinterfaces:
Comparison,HistoryEntry
A
Comparison of folder hierarchies. Its results are a tree of
DeltaNodes, one per file or folder, each holding the
Resource found at every Role.
const Comparison = Java.type('com.deltawalker.script.Comparison');
const ReportKind = Java.type('com.deltawalker.script.ReportKind');
const Role = Java.type('com.deltawalker.script.Role');
const TEST_DIR = App.getProperty('user.home') + '/test';
const IN = TEST_DIR + '/samples';
const comp = App.getComparisons().create(Comparison.Type.FOLDER,
[IN + '/f0', IN + '/f1'], null);
await comp.compare();
const nodes = comp.getAllDeltas();
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if (!node.isSame()) {
const res = node.resource(Role.REF) || node.resource(Role.ONE);
console.log(res.getPath() + ' differs');
}
}
await comp.report(TEST_DIR + '/folder-report.html', ReportKind.HTML, null, null);
- Since:
- 2.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.deltawalker.script.Comparison
Comparison.Method, Comparison.State, Comparison.Type -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteResource(DeltaNode[] deltas, Role[] roles, SyncProgressListener spm) Returns all nodes of this comparison that are not excluded by filters, whether their resources are identical or different.intReturns the number of nodes in this comparison, the same as the length ofgetAllDeltas().Returns the rootDeltaNodeof this comparison.voidRe-compares the specified nodes, updating their results as well as the results of the nodes that depend on them, such as their parent folders.report(String pathname, ReportKind kind, PatchFormat format, Role[] roles) Writes a report of the results of this comparison to a file, and returns an operation that settles when the report has been written.reportEx(UriInfo uriInfo, ReportKind kind, PatchFormat format, ReportLink link, Role[] roles) Likereport(String, ReportKind, PatchFormat, Role[]), but takes aUriInfofor the report file, so that, for example, a remote location, a user name and password, a character encoding or a line ending can be specified, and can create linked reports.voidsort(Role role, SortBy sortBy, SortDirection sortOrder) Sorts the folder hierarchy with the specified role by the specified column and direction.Methods inherited from interface com.deltawalker.script.Comparison
addListener, close, compare, hasDifferences, isClosed, print, removeListenerMethods inherited from interface com.deltawalker.script.HistoryEntry
getCreationTime, getDisplayCreationTime, getName, getPaths, getRoles, getSettings, getType, getUriInfos, setName
-
Method Details
-
deleteResource
Deletes theResources with the specifiedRoles from the specifiedDeltaNodes. This deletes files and folders on disk.Each deletion triggers a partial re-comparison, which can be expensive. When deleting several resources, gather them and pass them in a single call rather than calling this method repeatedly.
When the last resource of a node is deleted, the node itself is removed. Nodes that have no resource at a specified role are left unchanged for that role.
// Delete the Role.ONE copy of a file comp.deleteResource([node], [Role.ONE], null);- Parameters:
deltas- the nodes to delete resources from; cannot benullor emptyroles- the roles of the resources to delete; cannot benullor empty, and must all be roles of this comparisonspm- an optionalSyncProgressListenerto track the progress of this operation and to cancel it; can benull- Throws:
NullPointerException- ifdeltasorrolesisnullIllegalArgumentException- ifdeltasorrolesis empty, or if a role is not a role of this comparison, for instanceRole.TWOin a two-way comparisonIOException- if deleting fails- Since:
- 2.0
-
getAllDeltas
DeltaNode[] getAllDeltas()Returns all nodes of this comparison that are not excluded by filters, whether their resources are identical or different. UseDelta.isSame()and the otheris...()methods ofDeltato tell them apart.- Returns:
- an array of this comparison's
DeltaNodes - Since:
- 2.0
-
getDeltaCount
int getDeltaCount()Returns the number of nodes in this comparison, the same as the length ofgetAllDeltas().- Returns:
- the number of nodes
- Since:
- 2.0
-
getRootDelta
DeltaNode getRootDelta()Returns the rootDeltaNodeof this comparison. The root reports a difference when any node below it differs.- Returns:
- the root node of this comparison
- Since:
- 2.0
-
recompare
Re-compares the specified nodes, updating their results as well as the results of the nodes that depend on them, such as their parent folders.- Parameters:
nodes- the nodes to re-compare; cannot benull. When empty, this method does nothing.- Throws:
NullPointerException- ifnodesisnull- Since:
- 2.0
-
report
Writes a report of the results of this comparison to a file, and returns an operation that settles when the report has been written.await comp.report('/path/to/report.html', ReportKind.HTML, null, null); // A JSON snapshot of the Role.REF hierarchy await comp.report('/path/to/snapshot.json', ReportKind.JSON, null, [Role.REF]);Patch reports (
ReportKind.PATCH) are not implemented for folder comparisons: no file is written and the returned operation resolves immediately.- Parameters:
pathname- the path of the report file; cannot benullor emptykind- the kind of report; cannot benull. SeeReportKind.format- the format of a patch report; required only whenkindisReportKind.PATCH, otherwise can benull. SeePatchFormat.roles- the roles of the folder hierarchies to include in a snapshot; required, and cannot be empty, only whenkindisReportKind.JSON. Can benullfor other kinds of reports.- Returns:
- an operation that resolves when the report has been written
- Throws:
NullPointerException- ifpathnameisnullor empty, ifkindisnull, ifformatis missing for a patch report, or ifrolesis missing or empty for a JSON snapshot- Since:
- 2.1.0
- See Also:
-
reportEx
ScriptOperation reportEx(UriInfo uriInfo, ReportKind kind, PatchFormat format, ReportLink link, Role[] roles) Likereport(String, ReportKind, PatchFormat, Role[]), but takes aUriInfofor the report file, so that, for example, a remote location, a user name and password, a character encoding or a line ending can be specified, and can create linked reports. When theUriInfospecifies no character encoding, UTF-8 is used.- Parameters:
uriInfo- the location of the report file; cannot benulland must have a non-empty URIkind- the kind of report; cannot benull. SeeReportKind.format- the format of a patch report; required only whenkindisReportKind.PATCH, otherwise can benull. SeePatchFormat.link- for HTML reports, which linked file comparison reports to create; can benull. SeeReportLink.roles- the roles of the folder hierarchies to include in a snapshot; required, and cannot be empty, only whenkindisReportKind.JSON. Can benullfor other kinds of reports.- Returns:
- an operation that resolves when the report has been written
- Throws:
NullPointerException- ifuriInfoisnullor has an empty URI, ifkindisnull, ifformatis missing for a patch report, or ifrolesis missing or empty for a JSON snapshot- Since:
- 2.0.02
-
sort
Sorts the folder hierarchy with the specified role by the specified column and direction.- Parameters:
role- theRoleof the folder hierarchy to sortsortBy- the column to sort bysortOrder- the direction to sort in- Since:
- 2.0
-
sync
ScriptOperation sync(SyncOp syncOp, DeltaNode[] nodes, Role src, Role dst, SyncProgressListener spl) throws IOException Applies the specifiedSyncOpto the specifiedDeltaNodes, from the source role to the destination role, and returns an operation that settles when synchronization completes. This changes files and folders on disk.const SyncOp = Java.type('com.deltawalker.script.SyncOp'); // Two-way: copy the selected nodes from Role.ONE to Role.REF await comp.sync(SyncOp.COPY, nodes, Role.ONE, Role.REF, null); // Three-way: bring non-conflicting changes into Role.REF; no source role await comp.sync(SyncOp.SYNC, comp.getAllDeltas(), null, Role.REF, null);- Parameters:
syncOp- the operation to perform; cannot benullnodes- the nodes to synchronize; cannot benull. When empty, nothing is done and the returned operation is already resolved.src- the source role. Cannot be the same asdst. PassnullforSyncOp.SYNC, which takes its sources from bothRole.ONEandRole.TWO.dst- the destination role; cannot benullspl- an optionalSyncProgressListenerto track the progress of this operation and to cancel it; can benull- Returns:
- an operation that resolves when synchronization completes
- Throws:
IOException- if the synchronization failsNullPointerException- ifsyncOp,nodesordstisnullIllegalArgumentException- ifsrcanddstare the same, ifRole.TWOis used in a two-way comparison, or ifSyncOp.SYNCis used in a two-way comparison- Since:
- 2.0
-