Package org.eclipse.core.runtime

Examples of org.eclipse.core.runtime.SubMonitor


        }
        return progress;
    }

    protected static void readAsText(ZipFile zipFile, ZipEntry entry, String encoding, Writer out, long limit, IProgressMonitor monitor) throws IOException {
        SubMonitor progress = createProgressMonitor(entry, limit, monitor);

        boolean limitReached = false;
        InputStream stream = zipFile.getInputStream(entry);
        try {
            long total = 0;

            byte[] buffer = new byte[1024];
            while (true) {
                if (progress.isCanceled())
                    return;
                int bytesRead = stream.read(buffer, 0, 1024);
                if (bytesRead < 0)
                    break;
                String string = new String(buffer, 0, bytesRead, encoding);
                out.write(string);

                total += bytesRead;
                progress.worked(bytesRead);
                if (limit >= 0 && total >= limit) {
                    limitReached = true;
                    return;
                }
            }
View Full Code Here


        return (char) b;
    }

    protected static void readAsHex(ZipFile zipFile, ZipEntry entry, Writer out, long limit, int groupsOf8BytesPerLine, IProgressMonitor monitor) throws IOException {
        SubMonitor progress = createProgressMonitor(entry, limit, monitor);

        boolean limitReached = false;
        long offsetInFile = 0;
        int bytesPerLine = groupsOf8BytesPerLine * 8;
        int asciiPosition = 0;
        char[] asciiBuffer = new char[bytesPerLine + (2 * (groupsOf8BytesPerLine - 1))];
        int bytePosition = 0;
        byte[] buffer = new byte[1024];

        InputStream stream = zipFile.getInputStream(entry);
        try {
            long total = 0;

            while (true) {
                if (progress.isCanceled())
                    return;
                int bytesRead = stream.read(buffer, 0, 1024);
                if (bytesRead < 0)
                    break;

                for (int i = 0; i < bytesRead; i++) {
                    if (bytePosition == 0) {
                        String s = String.format("0x%04x ", offsetInFile);
                        out.write(s);
                        offsetInFile += bytesPerLine;
                    }

                    asciiBuffer[asciiPosition] = byteToChar(buffer[i]);
                    asciiPosition++;

                    out.write(pseudo[(buffer[i] & 0xf0) >>> 4]); // Convert to a string character
                    out.write(pseudo[(buffer[i] & 0x0f)]); // convert the nibble to a String Character
                    out.write(' ');
                    bytePosition++;

                    /* do a linebreak after the required number of bytes */
                    if (bytePosition >= bytesPerLine) {
                        out.write(' ');
                        out.write(asciiBuffer);
                        out.write('\n');
                        asciiPosition = 0;
                        bytePosition = 0;
                    }

                    /* put 2 extra spaces between bytes */
                    if ((bytePosition > 0) && (bytePosition % 8 == 0)) {
                        asciiBuffer[asciiPosition++] = ' ';
                        asciiBuffer[asciiPosition++] = ' ';
                        out.write(' ');
                    }
                }

                total += bytesRead;
                progress.worked(bytesRead);
                if (limit >= 0 && total >= limit) {
                    limitReached = true;
                    return;
                }
            }
View Full Code Here

     * make workspace resource modifications.
     *
     * @throws CoreException
     */
    protected void processGeneratedProject(ProjectPaths projectPaths, BndEditModel bndModel, IJavaProject project, IProgressMonitor monitor) throws CoreException {
        SubMonitor progress = SubMonitor.convert(monitor, 3);

        Document document = new Document("");
        bndModel.saveChangesTo(document);
        progress.worked(1);

        ByteArrayInputStream bndInput;
        try {
            bndInput = new ByteArrayInputStream(document.get().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            return;
        }
        IFile bndBndFile = project.getProject().getFile(Project.BNDFILE);
        if (bndBndFile.exists()) {
            bndBndFile.setContents(bndInput, false, false, progress.newChild(1));
        }

        BndProject proj = generateBndProject(project.getProject(), progress.newChild(1));

        progress.setWorkRemaining(proj.getResources().size());
        for (Map.Entry<String,BndProjectResource> resource : proj.getResources().entrySet()) {
            importResource(project.getProject(), resource.getKey(), resource.getValue(), progress.newChild(1));
        }

        if (!bndBndFile.exists()) {
            bndBndFile.create(bndInput, false, progress.newChild(1));
        }

        /* Version control ignores */
        VersionControlIgnoresPluginTracker versionControlIgnoresPluginTracker = Plugin.getDefault().getVersionControlIgnoresPluginTracker();
        Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresPluginTracker, project, null);
View Full Code Here

            try {
                // Run using the progress bar from the wizard dialog
                getContainer().run(false, false, new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            SubMonitor progress = SubMonitor.convert(monitor, 3);

                            // Generate the Bnd model
                            final BndEditModel bndModel = generateBndModel(progress.newChild(1));

                            // Make changes to the project
                            final IWorkspaceRunnable op = new IWorkspaceRunnable() {
                                public void run(IProgressMonitor monitor) throws CoreException {
                                    processGeneratedProject(ProjectPaths.get(pageOne.getProjectLayout()), bndModel, javaProj, monitor);
                                }
                            };
                            javaProj.getProject().getWorkspace().run(op, progress.newChild(2));
                        } catch (CoreException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                });
View Full Code Here

    public static interface Processor<T> {
        void process(T obj, IProgressMonitor monitor) throws CoreException;
    }

    public static <T> void processDependencyMap(Collection<T> input, Map<T,Set<T>> dependencies, Processor<T> processor, IProgressMonitor monitor) throws CoreException, CircularDependencyException {
        SubMonitor progress = SubMonitor.convert(monitor, input.size());
        Set<T> processed = new TreeSet<T>();
        Stack<T> callStack = new Stack<T>();
        for (T selected : input) {
            processDependencyMap(selected, callStack, dependencies, processed, processor, progress);
        }
View Full Code Here

        return null;
    }

    @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(model, 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 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));
    }
View Full Code Here

        weights.add(weight);
        totalWeight += weight;
    }

    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
        SubMonitor progress = SubMonitor.convert(monitor, "Composite Task...", totalWeight);

        for (int i = 0; i < tasks.size(); i++) {
            tasks.get(i).run(progress.newChild(weights.get(i), SubMonitor.SUPPRESS_NONE));
            if (progress.isCanceled())
                return;
        }
    }
View Full Code Here

    }

    private static void generatePackageInfos(final Collection< ? extends FileVersionTuple> pkgs) throws CoreException {
        final IWorkspaceRunnable wsOperation = new IWorkspaceRunnable() {
            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) {
                        IFile pkgInfoFile = locations[0].getFile(new Path(PACKAGEINFO));

                        try {
                            ByteArrayInputStream input = new ByteArrayInputStream(pkg.formatVersionSpec().getBytes("UTF-8"));
                            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 */
                        }
View Full Code Here

            indirectResources = Collections.<ResourceDescriptor> emptySet();
        }
        final MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, "Errors occurred while processing JPM4J dependencies.", null);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                SubMonitor progress = SubMonitor.convert(monitor, result.size() + indirectResources.size());
                progress.setTaskName("Processing dependencies...");

                // Process all resources (including non-selected ones) into the repository
                for (ResourceDescriptor resource : result)
                    processResource(resource, status, progress.newChild(1));
                for (ResourceDescriptor resource : indirectResources)
                    processResource(resource, status, progress.newChild(1));
            }
        };

        try {
            getContainer().run(true, true, runnable);
View Full Code Here

        this.origin = origin;
        this.repository = repository;
    }

    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
        SubMonitor progress = SubMonitor.convert(monitor, 5);
        progress.setTaskName("Querying dependencies...");

        try {
            Set<ResourceDescriptor> resources = repository.getResources(origin, true);
            directResources = new HashSet<ResourceDescriptor>();
            indirectResources = new HashSet<ResourceDescriptor>();

            for (ResourceDescriptor resource : resources) {
                if (resource.dependency)
                    indirectResources.add(resource);
                else
                    directResources.add(resource);
            }
            progress.worked(5);
        } catch (Exception e) {
            error = "Error searching repository: " + e.getMessage();
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.core.runtime.SubMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.