use of org.apache.sling.ide.transport.FileInfo in project sling by apache.
the class ResourceChangeCommandFactory method removeFileCommand.
private Command<?> removeFileCommand(Repository repository, IResource resource) throws CoreException, IOException {
if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
Activator.getDefault().getPluginLogger().trace("Skipping team-private resource {0}", resource);
return null;
}
if (ignoredFileNames.contains(resource.getName())) {
return null;
}
IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
Filter filter = ProjectUtil.loadFilter(syncDirectory.getProject());
FilterResult filterResult = getFilterResult(resource, null, filter);
if (filterResult == FilterResult.DENY || filterResult == FilterResult.PREREQUISITE) {
return null;
}
String resourceLocation = getRepositoryPathForDeletedResource(resource, ProjectUtil.getSyncDirectoryFile(resource.getProject()));
// verify whether a resource being deleted does not signal that the content structure
// was rearranged under a covering parent aggregate
IPath serializationFilePath = Path.fromOSString(serializationManager.getSerializationFilePath(resourceLocation, SerializationKind.FOLDER));
ResourceProxy coveringParentData = findSerializationDataFromCoveringParent(resource, syncDirectory, resourceLocation, serializationFilePath);
if (coveringParentData != null) {
Activator.getDefault().getPluginLogger().trace("Found covering resource data ( repository path = {0} ) for resource at {1}, skipping deletion and performing an update instead", coveringParentData.getPath(), resource.getFullPath());
FileInfo info = createFileInfo(resource);
return repository.newAddOrUpdateNodeCommand(new CommandContext(filter), info, coveringParentData);
}
return repository.newDeleteNodeCommand(serializationManager.getRepositoryPath(resourceLocation));
}
use of org.apache.sling.ide.transport.FileInfo in project sling by apache.
the class ResourceChangeCommandFactory method createFileInfo.
private FileInfo createFileInfo(IResource resource) throws CoreException {
if (resource.getType() != IResource.FILE) {
return null;
}
IProject project = resource.getProject();
IFolder syncFolder = project.getFolder(ProjectUtil.getSyncDirectoryValue(project));
IPath relativePath = resource.getFullPath().makeRelativeTo(syncFolder.getFullPath());
FileInfo info = new FileInfo(resource.getLocation().toOSString(), relativePath.toOSString(), resource.getName());
Activator.getDefault().getPluginLogger().trace("For {0} built fileInfo {1}", resource, info);
return info;
}
use of org.apache.sling.ide.transport.FileInfo in project sling by apache.
the class ResourceChangeCommandFactory method buildResourceAndInfo.
/**
* Convenience method which builds a <tt>ResourceAndInfo</tt> info for a specific <tt>IResource</tt>
*
* @param resource the resource to process
* @param repository the repository, used to extract serialization information for different resource types
* @return the build object, or null if one could not be built
* @throws CoreException
* @throws SerializationException
* @throws IOException
*/
public ResourceAndInfo buildResourceAndInfo(IResource resource, Repository repository) throws CoreException, IOException {
if (ignoredFileNames.contains(resource.getName())) {
return null;
}
Long modificationTimestamp = (Long) resource.getSessionProperty(ResourceUtil.QN_IMPORT_MODIFICATION_TIMESTAMP);
if (modificationTimestamp != null && modificationTimestamp >= resource.getModificationStamp()) {
Activator.getDefault().getPluginLogger().trace("Change for resource {0} ignored as the import timestamp {1} >= modification timestamp {2}", resource, modificationTimestamp, resource.getModificationStamp());
return null;
}
if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
Activator.getDefault().getPluginLogger().trace("Skipping team-private resource {0}", resource);
return null;
}
FileInfo info = createFileInfo(resource);
Activator.getDefault().getPluginLogger().trace("For {0} built fileInfo {1}", resource, info);
File syncDirectoryAsFile = ProjectUtil.getSyncDirectoryFullPath(resource.getProject()).toFile();
IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
Filter filter = ProjectUtil.loadFilter(resource.getProject());
ResourceProxy resourceProxy = null;
if (serializationManager.isSerializationFile(resource.getLocation().toOSString())) {
IFile file = (IFile) resource;
try (InputStream contents = file.getContents()) {
String resourceLocation = file.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).toPortableString();
resourceProxy = serializationManager.readSerializationData(resourceLocation, contents);
normaliseResourceChildren(file, resourceProxy, syncDirectory, repository);
// TODO - not sure if this 100% correct, but we definitely should not refer to the FileInfo as the
// .serialization file, since for nt:file/nt:resource nodes this will overwrite the file contents
String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
if (Repository.NT_FILE.equals(primaryType)) {
// TODO move logic to serializationManager
File locationFile = new File(info.getLocation());
String locationFileParent = locationFile.getParent();
int endIndex = locationFileParent.length() - ".dir".length();
File actualFile = new File(locationFileParent.substring(0, endIndex));
String newLocation = actualFile.getAbsolutePath();
String newName = actualFile.getName();
String newRelativeLocation = actualFile.getAbsolutePath().substring(syncDirectoryAsFile.getAbsolutePath().length());
info = new FileInfo(newLocation, newRelativeLocation, newName);
Activator.getDefault().getPluginLogger().trace("Adjusted original location from {0} to {1}", resourceLocation, newLocation);
}
} catch (IOException e) {
Status s = new Status(Status.WARNING, Activator.PLUGIN_ID, "Failed reading file at " + resource.getFullPath(), e);
StatusManager.getManager().handle(s, StatusManager.LOG | StatusManager.SHOW);
return null;
}
} else {
// possible .dir serialization holder
if (resource.getType() == IResource.FOLDER && resource.getName().endsWith(".dir")) {
IFolder folder = (IFolder) resource;
IResource contentXml = folder.findMember(".content.xml");
// .dir serialization holder ; nothing to process here, the .content.xml will trigger the actual work
if (contentXml != null && contentXml.exists() && serializationManager.isSerializationFile(contentXml.getLocation().toOSString())) {
return null;
}
}
resourceProxy = buildResourceProxyForPlainFileOrFolder(resource, syncDirectory, repository);
}
FilterResult filterResult = getFilterResult(resource, resourceProxy, filter);
switch(filterResult) {
case ALLOW:
return new ResourceAndInfo(resourceProxy, info);
case PREREQUISITE:
// never try to 'create' the root node, we assume it exists
if (!resourceProxy.getPath().equals("/")) {
// suited one ( typically nt:unstructured )
return new ResourceAndInfo(new ResourceProxy(resourceProxy.getPath()), null, true);
}
// falls through
case DENY:
default:
return null;
}
}
Aggregations