Search in sources :

Example 1 with SerializationException

use of org.apache.sling.ide.serialization.SerializationException in project sling by apache.

the class ImportWizard method performFinish.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
public boolean performFinish() {
    if (!mainPage.isPageComplete()) {
        return false;
    }
    final IServer server = mainPage.getServer();
    IResource resource = mainPage.getResource();
    final IProject project = resource.getProject();
    final IPath projectRelativePath = resource.getProjectRelativePath();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                // following this change ( see org.apache.sling.ide.core.ResourceUtil )
                try {
                    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            try {
                                new ImportRepositoryContentAction(server, projectRelativePath, project, serializationManager).run(monitor);
                            } catch (SerializationException e) {
                                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e));
                            } catch (InvocationTargetException e) {
                                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e.getCause()));
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            } finally {
                                serializationManager.destroy();
                            }
                        }
                    }, project, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        mainPage.setErrorMessage("Import error : " + cause.getMessage() + " . Please see the error log for details.");
        Activator.getDefault().getPluginLogger().error("Repository import failed", cause);
        return false;
    } catch (OperationCanceledException | InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    }
    return true;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IServer(org.eclipse.wst.server.core.IServer) SerializationException(org.apache.sling.ide.serialization.SerializationException) IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ImportRepositoryContentAction(org.apache.sling.ide.eclipse.ui.internal.ImportRepositoryContentAction) IResource(org.eclipse.core.resources.IResource)

Example 2 with SerializationException

use of org.apache.sling.ide.serialization.SerializationException in project sling by apache.

the class VltSerializationDataBuilder method buildSerializationData.

@Override
public SerializationData buildSerializationData(File contentSyncRoot, ResourceProxy resource) throws SerializationException {
    try {
        List<Aggregate> chain = findAggregateChain(resource);
        if (chain == null) {
            return null;
        }
        Aggregate aggregate = chain.get(chain.size() - 1);
        String fileOrFolderPathHint = calculateFileOrFolderPathHint(chain);
        String nameHint = PlatformNameFormat.getPlatformName(aggregate.getName());
        SerializationKind serializationKind = getSerializationKind(aggregate);
        if (resource.getPath().equals("/") || serializationKind == SerializationKind.METADATA_PARTIAL || serializationKind == SerializationKind.FILE || serializationKind == SerializationKind.FOLDER) {
            nameHint = Constants.DOT_CONTENT_XML;
        } else if (serializationKind == SerializationKind.METADATA_FULL) {
            nameHint += ".xml";
        }
        Activator.getDefault().getPluginLogger().trace("Got location {0} for path {1}", fileOrFolderPathHint, resource.getPath());
        if (!needsDir(aggregate)) {
            return SerializationData.empty(fileOrFolderPathHint, serializationKind);
        }
        DocViewSerializer s = new DocViewSerializer(aggregate);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        s.writeContent(out);
        byte[] result = out.toByteArray();
        return new SerializationData(fileOrFolderPathHint, nameHint, result, serializationKind);
    } catch (RepositoryException e) {
        throw new SerializationException(e);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
Also used : SerializationException(org.apache.sling.ide.serialization.SerializationException) SerializationData(org.apache.sling.ide.serialization.SerializationData) SerializationKind(org.apache.sling.ide.serialization.SerializationKind) DocViewSerializer(org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer) RepositoryException(javax.jcr.RepositoryException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Aggregate(org.apache.jackrabbit.vault.fs.api.Aggregate)

Example 3 with SerializationException

use of org.apache.sling.ide.serialization.SerializationException 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)

Example 4 with SerializationException

use of org.apache.sling.ide.serialization.SerializationException in project sling by apache.

the class SlingLaunchpadBehaviour method publishModule.

@Override
protected void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
    Logger logger = Activator.getDefault().getPluginLogger();
    if (commandFactory == null) {
        commandFactory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
    }
    logger.trace(traceOperation(kind, deltaKind, module));
    if (getServer().getServerState() == IServer.STATE_STOPPED) {
        logger.trace("Ignoring request to publish module when the server is stopped");
        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
        return;
    }
    if ((kind == IServer.PUBLISH_AUTO || kind == IServer.PUBLISH_INCREMENTAL) && deltaKind == ServerBehaviourDelegate.NO_CHANGE) {
        logger.trace("Ignoring request to publish the module when no resources have changed; most likely another module has changed");
        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
        return;
    }
    if (kind == IServer.PUBLISH_FULL && deltaKind == ServerBehaviourDelegate.REMOVED) {
        logger.trace("Ignoring request to unpublish all of the module resources");
        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
        return;
    }
    try {
        if (ProjectHelper.isBundleProject(module[0].getProject())) {
            String serverMode = getServer().getMode();
            if (!serverMode.equals(ILaunchManager.DEBUG_MODE) || kind == IServer.PUBLISH_CLEAN) {
                // in debug mode, we rely on the hotcode replacement feature of eclipse/jvm
                // otherwise, for run and profile modes we explicitly publish the bundle module
                // TODO: make this configurable as part of the server config
                // SLING-3655 : when doing PUBLISH_CLEAN, the bundle deployment mechanism should 
                // still be triggered
                publishBundleModule(module, monitor);
            }
        } else if (ProjectHelper.isContentProject(module[0].getProject())) {
            try {
                publishContentModule(kind, deltaKind, module, monitor);
            } catch (SerializationException e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Serialization error for " + traceOperation(kind, deltaKind, module).toString(), e));
            } catch (IOException e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "IO error for " + traceOperation(kind, deltaKind, module).toString(), e));
            }
        }
    } catch (CoreException e) {
        // in case of errors always require full redeployment of the whole module
        setModulePublishState(module, IServer.PUBLISH_STATE_FULL);
        throw e;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SerializationException(org.apache.sling.ide.serialization.SerializationException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) Logger(org.apache.sling.ide.log.Logger)

Example 5 with SerializationException

use of org.apache.sling.ide.serialization.SerializationException 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)

Aggregations

SerializationException (org.apache.sling.ide.serialization.SerializationException)5 IOException (java.io.IOException)4 CoreException (org.eclipse.core.runtime.CoreException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RepositoryException (javax.jcr.RepositoryException)2 SerializationKindManager (org.apache.sling.ide.serialization.SerializationKindManager)2 IStatus (org.eclipse.core.runtime.IStatus)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 Status (org.eclipse.core.runtime.Status)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Credentials (javax.jcr.Credentials)1 Repository (javax.jcr.Repository)1 Aggregate (org.apache.jackrabbit.vault.fs.api.Aggregate)1 RepositoryAddress (org.apache.jackrabbit.vault.fs.api.RepositoryAddress)1 ConfigurationException (org.apache.jackrabbit.vault.fs.config.ConfigurationException)1 DocViewSerializer (org.apache.jackrabbit.vault.fs.impl.io.DocViewSerializer)1 ImportRepositoryContentAction (org.apache.sling.ide.eclipse.ui.internal.ImportRepositoryContentAction)1 Logger (org.apache.sling.ide.log.Logger)1 SerializationData (org.apache.sling.ide.serialization.SerializationData)1 SerializationKind (org.apache.sling.ide.serialization.SerializationKind)1