Search in sources :

Example 1 with ResourceChangeCommandFactory

use of org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory in project sling by apache.

the class ExportWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
                final Repository[] selectedServer = new Repository[1];
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            selectedServer[0] = ServerUtil.getConnectedRepository(exportPage.getServer(), monitor);
                        } catch (CoreException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
                try {
                    syncStartPoint.accept(new IResourceVisitor() {

                        @Override
                        public boolean visit(IResource resource) throws CoreException {
                            Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
                            if (command == null) {
                                return true;
                            }
                            Result<?> result = command.execute();
                            if (!result.isSuccess()) {
                                throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed exporting: " + result.toString()));
                            }
                            return true;
                        }
                    });
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } catch (Throwable t) {
                    t.printStackTrace();
                    throw new InvocationTargetException(t);
                }
            }
        });
        return true;
    } catch (RuntimeException | InterruptedException e) {
        exportPage.setErrorMessage(e.getMessage());
        return false;
    } catch (InvocationTargetException e) {
        exportPage.setErrorMessage(e.getCause().getMessage());
        return false;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) IResource(org.eclipse.core.resources.IResource)

Example 2 with ResourceChangeCommandFactory

use of org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory in project sling by apache.

the class ResourceChangeCommandFactoryTest method setUp.

@Before
public void setUp() throws Exception {
    // create faceted project
    contentProject = projectRule.getProject();
    project = new ProjectAdapter(contentProject);
    project.addNatures("org.eclipse.wst.common.project.facet.core.nature");
    // install content facet
    project.installFacet("sling.content", "1.0");
    // create filter.xml
    project.createVltFilterWithRoots("/content");
    Set<String> ignoredFileNames = new HashSet<>();
    ignoredFileNames.add(".gitignore");
    factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), ignoredFileNames);
    spyRepo = new SpyRepository();
}
Also used : SpyRepository(org.apache.sling.ide.test.impl.helpers.SpyRepository) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) ProjectAdapter(org.apache.sling.ide.test.impl.helpers.ProjectAdapter) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 3 with ResourceChangeCommandFactory

use of org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory in project sling by apache.

the class ImportRepositoryContentAction method recordNotIgnoredResources.

private void recordNotIgnoredResources() throws CoreException {
    final ResourceChangeCommandFactory rccf = new ResourceChangeCommandFactory(serializationManager, Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
    IResource importStartingPoint = contentSyncRootDir.findMember(repositoryImportRoot);
    if (importStartingPoint == null) {
        return;
    }
    importStartingPoint.accept(new IResourceVisitor() {

        @Override
        public boolean visit(IResource resource) throws CoreException {
            try {
                ResourceAndInfo rai = rccf.buildResourceAndInfo(resource, repository);
                if (rai == null) {
                    // can be a prerequisite
                    return true;
                }
                String repositoryPath = rai.getResource().getPath();
                FilterResult filterResult = filter.filter(repositoryPath);
                if (ignoredResources.isIgnored(repositoryPath)) {
                    return false;
                }
                if (filterResult == FilterResult.ALLOW) {
                    currentResources.add(resource);
                    return true;
                }
                return false;
            } catch (IOException e) {
                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed reading current project's resources", e));
            }
        }
    });
    logger.trace("Found {0} not ignored local resources", currentResources.size());
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceAndInfo(org.apache.sling.ide.eclipse.core.internal.ResourceAndInfo) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) FilterResult(org.apache.sling.ide.filter.FilterResult) IOException(java.io.IOException) IResource(org.eclipse.core.resources.IResource)

Aggregations

ResourceChangeCommandFactory (org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory)3 IResource (org.eclipse.core.resources.IResource)2 IResourceVisitor (org.eclipse.core.resources.IResourceVisitor)2 CoreException (org.eclipse.core.runtime.CoreException)2 Status (org.eclipse.core.runtime.Status)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 ResourceAndInfo (org.apache.sling.ide.eclipse.core.internal.ResourceAndInfo)1 FilterResult (org.apache.sling.ide.filter.FilterResult)1 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)1 SpyRepository (org.apache.sling.ide.test.impl.helpers.SpyRepository)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Before (org.junit.Before)1