use of org.apache.sling.ide.serialization.SerializationKindManager in project sling by apache.
the class ResourceChangeCommandFactory method normaliseResourceChildren.
/**
* Normalises the of the specified <tt>resourceProxy</tt> by comparing the serialization data and the filesystem
* data
*
* @param serializationFile the file which contains the serialization data
* @param resourceProxy the resource proxy
* @param syncDirectory the sync directory
* @param repository TODO
* @throws CoreException
*/
private void normaliseResourceChildren(IFile serializationFile, ResourceProxy resourceProxy, IFolder syncDirectory, Repository repository) throws CoreException {
// TODO - this logic should be moved to the serializationManager
try {
SerializationKindManager skm = new SerializationKindManager();
skm.init(repository);
String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
List<String> mixinTypesList = getMixinTypes(resourceProxy);
SerializationKind serializationKind = skm.getSerializationKind(primaryType, mixinTypesList);
if (serializationKind == SerializationKind.METADATA_FULL) {
return;
}
} catch (RepositoryException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed creating a " + SerializationDataBuilder.class.getName(), e));
}
IPath serializationDirectoryPath = serializationFile.getFullPath().removeLastSegments(1);
Iterator<ResourceProxy> childIterator = resourceProxy.getChildren().iterator();
Map<String, IResource> extraChildResources = new HashMap<>();
for (IResource member : serializationFile.getParent().members()) {
if (member.equals(serializationFile)) {
continue;
}
extraChildResources.put(member.getName(), member);
}
while (childIterator.hasNext()) {
ResourceProxy child = childIterator.next();
String childName = PathUtil.getName(child.getPath());
String osPath = serializationManager.getOsPath(childName);
// covered children might have a FS representation, depending on their child nodes, so
// accept a directory which maps to their name
extraChildResources.remove(osPath);
// covered children do not need a filesystem representation
if (resourceProxy.covers(child.getPath())) {
continue;
}
IPath childPath = serializationDirectoryPath.append(osPath);
IResource childResource = ResourcesPlugin.getWorkspace().getRoot().findMember(childPath);
if (childResource == null) {
Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the serialized child resource at {1} does not exist in the filesystem and will be ignored", serializationFile, childPath);
childIterator.remove();
}
}
for (IResource extraChildResource : extraChildResources.values()) {
IPath extraChildResourcePath = extraChildResource.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).makeAbsolute();
resourceProxy.addChild(new ResourceProxy(serializationManager.getRepositoryPath(extraChildResourcePath.toPortableString())));
Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the found a child resource at {1} which is not listed in the serialized child resources and will be added", serializationFile, extraChildResource);
}
}
use of org.apache.sling.ide.serialization.SerializationKindManager in project sling by apache.
the class ImportRepositoryContentAction method run.
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, SerializationException, CoreException {
// TODO: We should try to make this give 'nice' progress feedback (aka here's what I'm processing)
monitor.beginTask("Repository import", IProgressMonitor.UNKNOWN);
this.monitor = monitor;
repository = ServerUtil.getConnectedRepository(server, monitor);
this.builder = serializationManager.newBuilder(repository, ProjectUtil.getSyncDirectoryFile(project));
SerializationKindManager skm;
try {
skm = new SerializationKindManager();
skm.init(repository);
} catch (RepositoryException e1) {
throw new InvocationTargetException(e1);
}
filter = ProjectUtil.loadFilter(project);
ProgressUtils.advance(monitor, 1);
try {
contentSyncRootDir = ProjectUtil.getSyncDirectory(project);
repositoryImportRoot = projectRelativePath.makeRelativeTo(contentSyncRootDir.getProjectRelativePath()).makeAbsolute();
contentSyncRoot = ProjectUtil.getSyncDirectoryFullPath(project).toFile();
readVltIgnoresNotUnderImportRoot(contentSyncRootDir, repositoryImportRoot);
ProgressUtils.advance(monitor, 1);
Activator.getDefault().getPluginLogger().trace("Starting import; repository start point is {0}, workspace start point is {1}", repositoryImportRoot, projectRelativePath);
recordNotIgnoredResources();
ProgressUtils.advance(monitor, 1);
crawlChildrenAndImport(repositoryImportRoot.toPortableString());
removeNotIgnoredAndNotUpdatedResources(new NullProgressMonitor());
ProgressUtils.advance(monitor, 1);
} catch (OperationCanceledException e) {
throw e;
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
if (builder != null) {
builder.destroy();
builder = null;
}
monitor.done();
}
}
use of org.apache.sling.ide.serialization.SerializationKindManager in project sling by apache.
the class JcrNode method getSerializationKind.
private SerializationKind getSerializationKind(String nodeType) {
final SerializationKindManager skm = new SerializationKindManager();
final Repository repo = ServerUtil.getDefaultRepository(getProject());
if (repo == null) {
return getFallbackSerializationKind(nodeType);
}
try {
skm.init(repo);
//TODO: mixins not yet supported
return skm.getSerializationKind(nodeType, new ArrayList<String>());
} catch (RepositoryException e) {
e.printStackTrace();
return getFallbackSerializationKind(nodeType);
}
}
use of org.apache.sling.ide.serialization.SerializationKindManager in project sling by apache.
the class VltSerializationDataBuilder method init.
public void init(org.apache.sling.ide.transport.Repository repository, File contentSyncRoot) throws SerializationException {
this.repo = repository;
try {
this.skm = new SerializationKindManager();
this.skm.init(repository);
if (!contentSyncRoot.exists()) {
throw new IllegalArgumentException("contentSyncRoot does not exist: " + contentSyncRoot);
}
Repository jcrRepo = RepositoryUtils.getRepository(repo.getRepositoryInfo());
Credentials credentials = RepositoryUtils.getCredentials(repo.getRepositoryInfo());
session = jcrRepo.login(credentials);
RepositoryAddress address = RepositoryUtils.getRepositoryAddress(repo.getRepositoryInfo());
fs = fsLocator.getFileSystem(address, contentSyncRoot, session);
} catch (org.apache.sling.ide.transport.RepositoryException e) {
throw new SerializationException(e);
} catch (RepositoryException e) {
throw new SerializationException(e);
} catch (IOException e) {
throw new SerializationException(e);
} catch (ConfigurationException e) {
throw new SerializationException(e);
}
}
Aggregations