DeltaGeneration - Get the generated or deleted Files

MichaelaReydt
Community Manager
Community Manager
3 18 6,554

As described in the first blogposting about the DeltaGeneration , FirstSpirit 5 introduces a new mechanism, called DeltaGeneration, which simplifies things a lot.

The DeltaGeneration makes it possible to find out and to generate just the elements, which were changed since the last successful generation. How a DeltaGeneration can be configured is explained in the linked blogposting. (It is recommended to read the linked blogposting to understand the current blogposting.)

The information, which files were changed or deleted since the last generation, could be necessary - for example - to inform search engines and to let them update their search indices. Another use case might be to replace the FullGeneration by the DeltaGeneration. In this case the webserver needs the information which files were changed or deleted, because the synchronization of all files (as in the FullGeneration) won't be executed.

The DeltaGeneration offers commands to find out these files. Therefore the schedule-script of the DeltaGeneration has to be extended.

Generated Files

To get a list of all generated files the following command has to be added at the end of the schedule-script after the execution of the generate task:

changeSet.configureGenerateTask();

generatedFilesList = DeploymentUtil.getGeneratedFiles(context);

Note


If the checkbox "Clear generation directory beforehand" inside the dialog of the generation task isn't activated, this command will return all files, which are currently located within the generation folder.

If the list should only contain the files, which has been generated during the DeltaGeneration, the checkbox has to be activated.

1.png

With an iteration over this list of generatedFiles the several entries can be separated and for example be printed to the logfile.

generatedFilesList = DeploymentUtil.getGeneratedFiles(context);
it =
generatedFilesList.iterator();


if(it.hasNext()) {
   context.logInfo("Generated files found.");
}
else {
   context.logInfo("No generated files found.");
}

while(it.hasNext()) {
   generatedFile = it.next();
   context.logInfo(" generatedFile: " + generatedFile);
}

Deleted Files

Such a list is also available for the deleted files. Therefore the following line has to be added to the script:

changeSet.configureGenerateTask();

deletedPageInfo = changeSet.getDeletedPageInfos();

Note

This line just works when persistent pages were deleted. So it is necessary to generate the paths for the pages inside the project by a SEO URL-Creator.

2.png

Further information to SEO URLs are available in the Release Notes for FirstSpirit 5.0.

The iteration in this step is equivalent to the iteration over the list of generatedFiles. Just the expression inside the loop isn't analog:

deletedPageInfos = changeSet.getDeletedPageInfos();
it = deletedPageInfos.iterator();

if(it.hasNext()) {
context.logInfo("Information for deleted Pages found.");
}
else {
  context.logInfo("No Information for deleted Pages found.");
}

while(it.hasNext()) {
  deletedPageInfo = it.next();
  context.logInfo("deletedPageInfo nodeId " + deletedPageInfo.getNodeId()
  + " path " + deletedPageInfo.getPath());
}

Logfile-Information

After elements were changed inside a project and the schedule-task was executed the information of the generated or deleted files are displayed in the script-logfile.

Exemplary the logfile-information for the generated files:

code-snippet from the schedule-script (see above):

if(it.hasNext()) {

context.logInfo("Generated files found.");

}

[...]

while(it.hasNext()) {

generatedFile = it.next();

context.logInfo(" generatedFile: " + generatedFile);

}

logfile-information:

INFO  04.04.2013 09:42:43.459 (de.espirit.firstspirit.impl.access.ScriptContextImpl): Generated files found.

INFO  04.04.2013 09:42:43.459 (de.espirit.firstspirit.impl.access.ScriptContextImpl): generatedFile: /de/example.html

INFO  04.04.2013 09:42:43.461 (de.espirit.firstspirit.impl.access.ScriptContextImpl): generatedFile: /en/example.html

API-Classes

The classes, which are needed for a DeltaGeneration, can be found inside the Developer-API.

Their names are:

18 Comments
Version history
Last update:
‎04-09-2013 03:42 AM
Updated by: