Scripting API Reference
The Scripting API Reference lists every object, method, and constant that a script can use. It is generated from the code of DeltaWalker Classic, so it is complete and exact, but it is written for Java programmers: methods appear as Java signatures. This page shows how to read those signatures from JavaScript, and which types to look at first.
The scripting types are all in one package, com.deltawalker.script, and its page lists every type mentioned below.
Start here
These are the types most scripts use. Each name links to its page in the reference.
| Type | What it is for |
|---|---|
App | The starting point, available in every script as App (and dw). It gives you getComparisons(), getSettings(), getWindow(), getVersion(), getEdition(), and getProperty(name). |
Comparisons | Creates comparisons with create(...) and lists the open ones and the comparison history. |
Comparison | What every comparison can do: compare(), hasDifferences(), print(), close(), and getSettings(). Its nested enum Comparison.Type (FOLDER, IMAGE, TEXT) says which kind of comparison to create. |
FileComparison | A comparison of two or three files, with save(...) and saveAll(...). Text and image comparisons are file comparisons. |
TextComparison | A text comparison: getAllDeltas(), getText(...), setText(...), merge(...), and report(...). It has no getDeltaCount(); count the deltas with getAllDeltas().length. |
FolderComparison | A folder comparison: getAllDeltas(), getDeltaCount(), getRootDelta(), sort(...), sync(...), deleteResource(...), and report(...). |
ImageComparison | An image comparison. It adds nothing to a file comparison. |
ScriptOperation | What a long-running method hands back. You await it. |
Settings | Reads and changes settings with get(...) and set(...), saves and loads them with save(...) and load(...), and gives access to page and printer settings. App.getSettings() returns the application’s; comparison.getSettings() returns a comparison’s. |
Window | The main window: its bounds, and whether it is full screen, maximized, minimized, or visible. |
Filters | The filters of a kind of comparison, from settings.filters(Comparison.Type.FOLDER). Add filters with addPathFilter(...), addSizeFilter(...), and the other add...Filter methods. |
ReportKind | The kind of report to write: HTML, JSON, or PATCH. |
Role | Which side of a comparison you mean: REF (the Reference), ONE (the first Modified side), or TWO (the second Modified side, in a three-way comparison). |
Reading a Java signature from JavaScript
The reference shows each method the way Java declares it. In JavaScript you call it like this:
- Interfaces are objects you get from
App.Comparisons,Comparison,Settings,Window, and the others are not constructors. You never writenew Comparison(). Start fromAppand follow the methods:App.getComparisons().create(...)gives you a comparison. - Getters are methods. The reference lists
getAllDeltas(), so you writecomparison.getAllDeltas(), with parentheses. There is nocomparison.allDeltas. The same goes forisClosed()andhasDifferences(), and for setters such assetBounds(...). - Enums and constants come from
Java.type. An enum such asRoleorReportKindis not predefined. Load it first:const Role = Java.type('com.deltawalker.script.Role');, and then useRole.REF. For an enum nested in an interface, load the interface and reach into it:Comparison.Type.TEXTandComparison.Method.SIZEafterJava.type('com.deltawalker.script.Comparison'). Constants used as setting names, such asSettingKey.D_COMP_METHOD, come fromJava.type('com.deltopia.io.SettingKey'), as the sample workflows show. - Strings, numbers, and booleans are the JavaScript ones. A Java
Stringis a JavaScript string,int,long, anddoubleare numbers, andbooleanistrueorfalse. - Arrays are arrays. Where the reference shows
String[], pass a JavaScript array such as['/path/old.txt', '/path/new.txt']. A method that returns an array, such asgetAllDeltas(), gives you something you can index and ask for.length. nullstands for an argument you don’t need. Many methods accept a listener or a format that is optional.create(Comparison.Type.TEXT, paths, null)makes a comparison without a listener, andreport(path, ReportKind.HTML, null)on a text comparison writes an HTML report without a patch format.- Operations are awaited. A method that takes time, such as
compare(),merge(...),sync(...),report(...), andprint(), returns straight away with an operation. The reference shows its type asScriptOperation, or asObject. Putawaitin front of the call to wait for it to finish. A failed operation throws at theawait, so you can catch it withtry/catch. throwsmeans a failure you can catch. A method declared withthrows IOExceptionorthrows IllegalArgumentExceptionraises an exception in your script when it fails. Wrap the call intry/catchif you want to handle it.
A short example puts these together:
const Comparison = Java.type('com.deltawalker.script.Comparison');
const ReportKind = Java.type('com.deltawalker.script.ReportKind');
const comparison = App.getComparisons().create(
Comparison.Type.TEXT, ['/path/to/old.txt', '/path/to/new.txt'], null);
await comparison.compare();
console.log('Deltas: ' + comparison.getAllDeltas().length);
await comparison.report('/path/to/report.html', ReportKind.HTML, null);See Also
Последна промяна на