Search in sources :

Example 36 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project bndtools by bndtools.

the class OSGiRunLaunchDelegate method launch.

@Override
public void launch(final ILaunchConfiguration configuration, String mode, final ILaunch launch, IProgressMonitor monitor) throws CoreException {
    SubMonitor progress = SubMonitor.convert(monitor, 2);
    try {
        boolean dynamic = configuration.getAttribute(LaunchConstants.ATTR_DYNAMIC_BUNDLES, LaunchConstants.DEFAULT_DYNAMIC_BUNDLES);
        if (dynamic)
            registerLaunchPropertiesRegenerator(run, launch);
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error obtaining OSGi project launcher.", e));
    }
    display = Workbench.getInstance().getDisplay();
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            dialog = new PopupDialog(new Shell(display), PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, false, true, true, true, false, "Errors in running OSGi Framework", "") {

                @Override
                protected Control createDialogArea(Composite parent) {
                    textArea = new Text(parent, SWT.LEAD | SWT.READ_ONLY | SWT.WRAP);
                    return textArea;
                }

                @Override
                protected void fillDialogMenu(IMenuManager dialogMenu) {
                    super.fillDialogMenu(dialogMenu);
                    Action dismissAction = new Action("Close") {

                        @Override
                        public void run() {
                            close();
                        }
                    };
                    dialogMenu.add(dismissAction);
                }

                @Override
                protected Control createInfoTextArea(Composite parent) {
                    Link link = new Link(parent, SWT.NONE);
                    link.setText("<a>Dismiss…</a> ");
                    link.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            close();
                        }
                    });
                    GridDataFactory.fillDefaults().grab(true, false).align(SWT.END, SWT.FILL).applyTo(link);
                    return link;
                }

                @Override
                protected Point getDefaultSize() {
                    Point p = getShell().getSize();
                    p.x = Math.max(400, p.x / 2);
                    p.y = Math.max(200, p.y / 2);
                    return p;
                }

                @Override
                protected Point getInitialLocation(Point initialSize) {
                    Rectangle r = getShell().getBounds();
                    return new Point(r.x + r.width - initialSize.x, r.y + r.height - initialSize.y);
                }

                @Override
                public boolean close() {
                    if (textArea != null) {
                        textArea.setText("");
                    }
                    return super.close();
                }
            };
        }
    });
    super.launch(configuration, mode, launch, progress.newChild(1, SubMonitor.SUPPRESS_NONE));
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Action(org.eclipse.jface.action.Action) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) Rectangle(org.eclipse.swt.graphics.Rectangle) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) PopupDialog(org.eclipse.jface.dialogs.PopupDialog) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMenuManager(org.eclipse.jface.action.IMenuManager) Link(org.eclipse.swt.widgets.Link)

Example 37 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project applause by applause.

the class ApplauseBuilderParticipant method build.

public void build(final IBuildContext context, IProgressMonitor monitor) throws CoreException {
    if (!isEnabled(context)) {
        return;
    }
    final List<IResourceDescription.Delta> deltas = getRelevantDeltas(context);
    if (deltas.isEmpty()) {
        return;
    }
    final int numberOfDeltas = deltas.size();
    // monitor handling
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    SubMonitor subMonitor = SubMonitor.convert(monitor, numberOfDeltas + 3);
    ApplauseEclipseResourceFileSystemAccess2 access = fileSystemAccessProvider.get();
    final IProject builtProject = context.getBuiltProject();
    access.setProject(builtProject);
    final Map<String, OutputConfiguration> outputConfigurations = getOutputConfigurations(context);
    refreshOutputFolders(context, outputConfigurations, subMonitor.newChild(1));
    access.setOutputConfigurations(outputConfigurations);
    if (context.getBuildType() == BuildType.CLEAN || context.getBuildType() == BuildType.RECOVERY) {
        SubMonitor cleanMonitor = SubMonitor.convert(subMonitor.newChild(1), outputConfigurations.size());
        for (OutputConfiguration config : outputConfigurations.values()) {
            cleanOutput(context, config, cleanMonitor.newChild(1));
        }
        if (context.getBuildType() == BuildType.CLEAN)
            return;
    }
    Map<OutputConfiguration, Iterable<IMarker>> generatorMarkers = getGeneratorMarkers(builtProject, outputConfigurations.values());
    for (int i = 0; i < numberOfDeltas; i++) {
        final IResourceDescription.Delta delta = deltas.get(i);
        // monitor handling
        if (subMonitor.isCanceled())
            throw new OperationCanceledException();
        subMonitor.subTask("Compiling " + delta.getUri().lastSegment() + " (" + i + " of " + numberOfDeltas + ")");
        access.setMonitor(subMonitor.newChild(1));
        final String uri = delta.getUri().toString();
        final Set<IFile> derivedResources = newLinkedHashSet();
        for (OutputConfiguration config : outputConfigurations.values()) {
            if (config.isCleanUpDerivedResources()) {
                Iterable<IMarker> markers = generatorMarkers.get(config);
                for (IMarker marker : markers) {
                    String source = derivedResourceMarkers.getSource(marker);
                    if (source != null && source.equals(uri))
                        derivedResources.add((IFile) marker.getResource());
                }
            }
        }
        access.setPostProcessor(new ApplauseEclipseResourceFileSystemAccess2.IFileCallback() {

            public boolean beforeFileDeletion(IFile file) {
                derivedResources.remove(file);
                context.needRebuild();
                return true;
            }

            public void afterFileUpdate(IFile file) {
                handleFileAccess(file);
            }

            public void afterFileCreation(IFile file) {
                handleFileAccess(file);
            }

            protected void handleFileAccess(IFile file) {
                try {
                    derivedResources.remove(file);
                    derivedResourceMarkers.installMarker(file, uri);
                    context.needRebuild();
                } catch (CoreException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        if (delta.getNew() != null) {
            try {
                handleChangedContents(delta, context, access);
            } catch (OperationCanceledException e) {
                throw e;
            } catch (Exception e) {
                logger.error("Error during compilation of '" + delta.getUri() + "'.", e);
            }
        }
        access.flushSourceTraces();
        SubMonitor deleteMonitor = SubMonitor.convert(subMonitor.newChild(1), derivedResources.size());
        for (IFile iFile : newLinkedHashSet(derivedResources)) {
            IMarker marker = derivedResourceMarkers.findDerivedResourceMarker(iFile, uri);
            if (marker != null)
                marker.delete();
            if (derivedResourceMarkers.findDerivedResourceMarkers(iFile).length == 0) {
                access.deleteFile(iFile, deleteMonitor);
                context.needRebuild();
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) WrappedException(org.eclipse.emf.common.util.WrappedException) CoreException(org.eclipse.core.runtime.CoreException) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) Delta(org.eclipse.xtext.resource.IResourceDescription.Delta) IMarker(org.eclipse.core.resources.IMarker)

Example 38 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project applause by applause.

the class ApplauseBuilderParticipant method refreshOutputFolders.

protected void refreshOutputFolders(IBuildContext ctx, Map<String, OutputConfiguration> outputConfigurations, IProgressMonitor monitor) throws CoreException {
    SubMonitor subMonitor = SubMonitor.convert(monitor, outputConfigurations.size());
    for (OutputConfiguration config : outputConfigurations.values()) {
        SubMonitor child = subMonitor.newChild(1);
        final IProject project = ctx.getBuiltProject();
        IContainer container = getContainer(project, config.getOutputDirectory());
        container.refreshLocal(IResource.DEPTH_INFINITE, child);
    }
}
Also used : OutputConfiguration(org.eclipse.xtext.generator.OutputConfiguration) SubMonitor(org.eclipse.core.runtime.SubMonitor) IContainer(org.eclipse.core.resources.IContainer) IProject(org.eclipse.core.resources.IProject)

Example 39 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project bndtools by bndtools.

the class ExportPatternsListPart method generatePackageInfos.

private static void generatePackageInfos(final Collection<? extends FileVersionTuple> pkgs) throws CoreException {
    final IWorkspaceRunnable wsOperation = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            SubMonitor progress = SubMonitor.convert(monitor, pkgs.size());
            MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "Errors occurred while creating packageinfo files.", null);
            for (FileVersionTuple pkg : pkgs) {
                IContainer[] locations = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocationURI(pkg.getFile().toURI());
                if (locations != null && locations.length > 0) {
                    IContainer container = locations[0];
                    PackageInfoStyle packageInfoStyle = PackageInfoStyle.calculatePackageInfoStyle(container.getProject());
                    IFile pkgInfoFile = container.getFile(new Path(packageInfoStyle.getFileName()));
                    try {
                        String formattedPackageInfo = packageInfoStyle.format(pkg.getVersion(), pkg.getName());
                        ByteArrayInputStream input = new ByteArrayInputStream(formattedPackageInfo.getBytes("UTF-8"));
                        if (pkgInfoFile.exists())
                            pkgInfoFile.setContents(input, false, true, progress.newChild(1, 0));
                        else
                            pkgInfoFile.create(input, false, progress.newChild(1, 0));
                    } catch (CoreException e) {
                        status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Error creating file " + pkgInfoFile.getFullPath(), e));
                    } catch (UnsupportedEncodingException e) {
                    /* just ignore, should never happen */
                    }
                }
            }
            if (!status.isOK())
                throw new CoreException(status);
        }
    };
    IRunnableWithProgress uiOperation = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                ResourcesPlugin.getWorkspace().run(wsOperation, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
        }
    };
    try {
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(true, true, uiOperation);
    } catch (InvocationTargetException e) {
        throw (CoreException) e.getTargetException();
    } catch (InterruptedException e) {
    // ignore
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IFile(org.eclipse.core.resources.IFile) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileVersionTuple(bndtools.editor.contents.PackageInfoDialog.FileVersionTuple) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IContainer(org.eclipse.core.resources.IContainer) PackageInfoStyle(bndtools.editor.contents.PackageInfoStyle)

Example 40 with SubMonitor

use of org.eclipse.core.runtime.SubMonitor in project bndtools by bndtools.

the class JAREntryPart method createProgressMonitor.

private static SubMonitor createProgressMonitor(ZipEntry entry, long limit, IProgressMonitor monitor) {
    SubMonitor progress;
    long size = entry.getSize();
    if (size == -1) {
        progress = SubMonitor.convert(monitor);
    } else {
        long ticks = (limit == -1) ? size : Math.min(size, limit);
        progress = SubMonitor.convert(monitor, (int) ticks);
    }
    return progress;
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor)

Aggregations

SubMonitor (org.eclipse.core.runtime.SubMonitor)61 CoreException (org.eclipse.core.runtime.CoreException)27 IStatus (org.eclipse.core.runtime.IStatus)25 Status (org.eclipse.core.runtime.Status)24 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 IOException (java.io.IOException)12 IFile (org.eclipse.core.resources.IFile)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)10 InputStream (java.io.InputStream)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IPath (org.eclipse.core.runtime.IPath)9 IProject (org.eclipse.core.resources.IProject)8 File (java.io.File)7 MultiStatus (org.eclipse.core.runtime.MultiStatus)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IContainer (org.eclipse.core.resources.IContainer)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 URI (java.net.URI)3