Search in sources :

Example 1 with CleanupService

use of eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService in project hale by halestudio.

the class CoreBundle method start.

/**
 * @see BundleActivator#start(BundleContext)
 */
@Override
public void start(BundleContext context) throws Exception {
    CoreBundle.activated = true;
    this.context = context;
    // TODO register clean up service in a way that it is also available
    // in a non-OSGi context?
    cleanupService = new CleanupServiceImpl();
    cleanupServiceRef = context.registerService(CleanupService.class, cleanupService, new Hashtable<String, Object>());
    CoreBundle.instance = this;
}
Also used : CleanupServiceImpl(eu.esdihumboldt.hale.common.core.service.cleanup.impl.CleanupServiceImpl) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) Hashtable(java.util.Hashtable)

Example 2 with CleanupService

use of eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService in project hale by halestudio.

the class ArchiveProjectWriter method createProjectArchive.

/**
 * Creates the project archive.
 *
 * @param target {@link OutputStream} to write the archive to
 * @param reporter the reporter to use for the execution report
 * @param progress the progress indicator
 * @return the execution report
 * @throws IOException if an I/O operation fails
 * @throws IOProviderConfigurationException if the I/O provider was not
 *             configured properly
 */
public IOReport createProjectArchive(OutputStream target, IOReporter reporter, ProgressIndicator progress) throws IOException, IOProviderConfigurationException {
    ZipOutputStream zip = new ZipOutputStream(target);
    // all files related to the project are copied into a temporary
    // directory first and then packed into a zip file
    // create temporary directory and project file
    File tempDir = Files.createTempDir();
    File baseFile = new File(tempDir, "project.halex");
    // mark the temporary directory for clean-up if the project is closed
    CleanupService clean = HalePlatform.getService(CleanupService.class);
    if (clean != null) {
        clean.addTemporaryFiles(CleanupContext.PROJECT, tempDir);
    }
    LocatableOutputSupplier<OutputStream> out = new FileIOSupplier(baseFile);
    // false is correct if getParameter is null because false is default
    boolean includeWebresources = getParameter(INCLUDE_WEB_RESOURCES).as(Boolean.class, false);
    SubtaskProgressIndicator subtask = new SubtaskProgressIndicator(progress);
    // save old IO configurations
    List<IOConfiguration> oldResources = new ArrayList<IOConfiguration>();
    for (int i = 0; i < getProject().getResources().size(); i++) {
        // clone all IO configurations to work on different objects
        oldResources.add(getProject().getResources().get(i).clone());
    }
    IOConfiguration config = getProject().getSaveConfiguration();
    if (config == null) {
        config = new IOConfiguration();
    }
    IOConfiguration oldSaveConfig = config.clone();
    // copy resources to the temp directory and update xml schemas
    updateResources(tempDir, includeWebresources, subtask, reporter);
    // update target save configuration of the project
    config.getProviderConfiguration().put(PARAM_TARGET, Value.of(baseFile.toURI().toString()));
    // write project file via XMLProjectWriter
    XMLProjectWriter writer = new XMLProjectWriter();
    writer.setTarget(out);
    writer.setProject(getProject());
    writer.setProjectFiles(getProjectFiles());
    IOReport report = writer.execute(progress, reporter);
    // now after the project with its project files is written, look for the
    // alignment file and update it
    ProjectFileInfo newAlignmentInfo = getAlignmentFile(getProject());
    if (newAlignmentInfo != null) {
        URI newAlignment = tempDir.toURI().resolve(newAlignmentInfo.getLocation());
        XMLAlignmentUpdater.update(new File(newAlignment), newAlignment, includeWebresources, reporter);
    }
    // put the complete temp directory into a zip file
    IOUtils.zipDirectory(tempDir, zip);
    zip.close();
    // the files may not be deleted now as they will be needed if the
    // project is saved again w/o loading it first
    // update the relative resource locations
    LocationUpdater updater = new LocationUpdater(getProject(), out.getLocation());
    // resources are made absolute (else they can't be found afterwards),
    // e.g. when saving the project again before loading it
    updater.updateProject(false);
    // reset the save configurations that has been overridden by the XML
    // project writer
    getProject().setSaveConfiguration(oldSaveConfig);
    if (clean == null) {
        // if no clean service is available, assume the directory is not
        // needed anymore
        FileUtils.deleteDirectory(tempDir);
    }
    return report;
}
Also used : LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) SubtaskProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator) URI(java.net.URI) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) ZipOutputStream(java.util.zip.ZipOutputStream) ProjectFileInfo(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File)

Example 3 with CleanupService

use of eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService in project hale by halestudio.

the class ProjectServiceImpl method internalClean.

private boolean internalClean() {
    if (!changeCheck()) {
        return false;
    }
    // reset current session descriptor
    ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
    repService.updateCurrentSessionDescription();
    // clean
    final IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            ATransaction trans = log.begin("Clean project");
            CleanupService cs = HalePlatform.getService(CleanupService.class);
            if (cs != null) {
                cs.triggerProjectCleanup();
            }
            monitor.beginTask("Clean project", IProgressMonitor.UNKNOWN);
            try {
                synchronized (this) {
                    main = createDefaultProject();
                    projectFile = null;
                    projectLocation = null;
                    changed = false;
                    projectLoadContentType = null;
                    temporarySettings.clear();
                }
                updateWindowTitle();
                notifyClean();
                // schemas aren't valid anymore, clear property resolver
                // cache
                PropertyResolver.clearCache();
            } finally {
                monitor.done();
                trans.end();
            }
            // clean workbench history AFTER other cleans since they can
            // create operations
            IWorkbenchOperationSupport os = PlatformUI.getWorkbench().getOperationSupport();
            os.getOperationHistory().dispose(os.getUndoContext(), true, true, false);
            // suppress the status being set to changed by the clean
            synchronized (ProjectServiceImpl.this) {
                changed = false;
            }
            updateWindowTitle();
        }
    };
    try {
        ThreadProgressMonitor.runWithProgressDialog(op, false);
    } catch (Exception e) {
        log.error("Error cleaning the project.", e);
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) CleanupService(eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService) IWorkbenchOperationSupport(org.eclipse.ui.operations.IWorkbenchOperationSupport) ATransaction(de.fhg.igd.slf4jplus.ATransaction) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

CleanupService (eu.esdihumboldt.hale.common.core.service.cleanup.CleanupService)3 ATransaction (de.fhg.igd.slf4jplus.ATransaction)1 SubtaskProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.SubtaskProgressIndicator)1 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)1 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)1 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)1 CleanupServiceImpl (eu.esdihumboldt.hale.common.core.service.cleanup.impl.CleanupServiceImpl)1 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1