Search in sources :

Example 1 with FileInfo

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));
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileInfo(org.apache.sling.ide.transport.FileInfo) CommandContext(org.apache.sling.ide.transport.CommandContext) Filter(org.apache.sling.ide.filter.Filter) FilterResult(org.apache.sling.ide.filter.FilterResult) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with FileInfo

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileInfo(org.apache.sling.ide.transport.FileInfo) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with FileInfo

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;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) FileInfo(org.apache.sling.ide.transport.FileInfo) Filter(org.apache.sling.ide.filter.Filter) FilterResult(org.apache.sling.ide.filter.FilterResult) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

FileInfo (org.apache.sling.ide.transport.FileInfo)3 IFolder (org.eclipse.core.resources.IFolder)3 Filter (org.apache.sling.ide.filter.Filter)2 FilterResult (org.apache.sling.ide.filter.FilterResult)2 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)2 IPath (org.eclipse.core.runtime.IPath)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CommandContext (org.apache.sling.ide.transport.CommandContext)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1