Search in sources :

Example 1 with SerializationKindManager

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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) RepositoryException(org.apache.sling.ide.transport.RepositoryException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager) CoreException(org.eclipse.core.runtime.CoreException) SerializationKind(org.apache.sling.ide.serialization.SerializationKind) IResource(org.eclipse.core.resources.IResource)

Example 2 with SerializationKindManager

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();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RepositoryException(org.apache.sling.ide.transport.RepositoryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RepositoryException(org.apache.sling.ide.transport.RepositoryException) SerializationException(org.apache.sling.ide.serialization.SerializationException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager)

Example 3 with SerializationKindManager

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);
    }
}
Also used : Repository(org.apache.sling.ide.transport.Repository) RepositoryException(org.apache.sling.ide.transport.RepositoryException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager)

Example 4 with SerializationKindManager

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);
    }
}
Also used : RepositoryAddress(org.apache.jackrabbit.vault.fs.api.RepositoryAddress) SerializationException(org.apache.sling.ide.serialization.SerializationException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager) Repository(javax.jcr.Repository) ConfigurationException(org.apache.jackrabbit.vault.fs.config.ConfigurationException) Credentials(javax.jcr.Credentials)

Aggregations

SerializationKindManager (org.apache.sling.ide.serialization.SerializationKindManager)4 RepositoryException (org.apache.sling.ide.transport.RepositoryException)3 IOException (java.io.IOException)2 SerializationException (org.apache.sling.ide.serialization.SerializationException)2 CoreException (org.eclipse.core.runtime.CoreException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Credentials (javax.jcr.Credentials)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 RepositoryAddress (org.apache.jackrabbit.vault.fs.api.RepositoryAddress)1 ConfigurationException (org.apache.jackrabbit.vault.fs.config.ConfigurationException)1 SerializationKind (org.apache.sling.ide.serialization.SerializationKind)1 Repository (org.apache.sling.ide.transport.Repository)1 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1