use of org.apache.jackrabbit.vault.packaging.ExportOptions in project sling by apache.
the class FileVaultContentSerializerTest method testExportToStream.
@Test
public void testExportToStream() throws Exception {
Packaging packaging = mock(Packaging.class);
ImportMode importMode = ImportMode.REPLACE;
AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
String[] packageRoots = new String[] { "/etc/packages" };
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
boolean useReferences = false;
int threshold = 1024;
FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, threshold);
ResourceResolver sessionResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
PackageManager pm = mock(PackageManager.class);
when(packaging.getPackageManager()).thenReturn(pm);
OutputStream outputStream = new ByteArrayOutputStream();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(pm).assemble(same(session), any(ExportOptions.class), same(outputStream));
Workspace workspace = mock(Workspace.class);
ObservationManager observationManager = mock(ObservationManager.class);
when(workspace.getObservationManager()).thenReturn(observationManager);
when(session.getWorkspace()).thenReturn(workspace);
when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
DistributionExportFilter filter = mock(DistributionExportFilter.class);
DistributionRequest request = mock(DistributionRequest.class);
when(request.getPaths()).thenReturn(new String[] { "/libs" });
when(request.getFilters("/libs")).thenReturn(new String[0]);
DistributionExportOptions exportOptions = new DistributionExportOptions(request, filter);
fileVaultContentSerializer.exportToStream(sessionResolver, exportOptions, outputStream);
}
use of org.apache.jackrabbit.vault.packaging.ExportOptions in project sling by apache.
the class VltUtils method getExportOptions.
public static ExportOptions getExportOptions(WorkspaceFilter filter, String[] packageRoots, String packageGroup, String packageName, String packageVersion, boolean useBinaryReferences) {
DefaultMetaInf inf = new DefaultMetaInf();
ExportOptions opts = new ExportOptions();
inf.setFilter(filter);
Properties props = new Properties();
props.setProperty(VaultPackage.NAME_GROUP, packageGroup);
props.setProperty(VaultPackage.NAME_NAME, packageName);
props.setProperty(VaultPackage.NAME_VERSION, packageVersion);
props.setProperty(PackageProperties.NAME_USE_BINARY_REFERENCES, String.valueOf(useBinaryReferences));
inf.setProperties(props);
opts.setMetaInf(inf);
String root = getPackageRoot(filter.getFilterSets(), packageRoots);
opts.setRootPath(root);
opts.setMountPath(root);
return opts;
}
use of org.apache.jackrabbit.vault.packaging.ExportOptions in project sling by apache.
the class FileVaultContentSerializer method exportToStream.
@Override
public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions exportOptions, OutputStream outputStream) throws DistributionException {
Session session = null;
try {
session = getSession(resourceResolver);
String packageGroup = PACKAGE_GROUP;
String packageName = TYPE + "_" + System.currentTimeMillis() + "_" + UUID.randomUUID();
WorkspaceFilter filter = VltUtils.createFilter(exportOptions.getRequest(), nodeFilters, propertyFilters);
ExportOptions opts = VltUtils.getExportOptions(filter, packageRoots, packageGroup, packageName, VERSION, useBinaryReferences);
log.debug("assembling package {} user {}", packageGroup + '/' + packageName + "-" + VERSION, resourceResolver.getUserID());
packaging.getPackageManager().assemble(session, opts, outputStream);
} catch (Exception e) {
throw new DistributionException(e);
} finally {
ungetSession(session);
}
}
Aggregations