Example usage for org.eclipse.jdt.core IJavaProject getElementName

List of usage examples for org.eclipse.jdt.core IJavaProject getElementName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getElementName.

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathContainer.java

License:Apache License

public static void runInitialize(final IPath containerPath, final IJavaProject javaProject) {
    Job job = new Job("Initializing Ceylon dependencies for project " + javaProject.getElementName()) {
        @Override//from  ww w . j a v a 2 s.c  o m
        protected IStatus run(IProgressMonitor monitor) {
            try {

                IClasspathContainer c = getClasspathContainer(containerPath, javaProject);
                CeylonClasspathContainer container;
                if (c instanceof CeylonClasspathContainer) {
                    container = (CeylonClasspathContainer) c;
                } else {
                    IClasspathEntry entry = getCeylonClasspathEntry(containerPath, javaProject);
                    IClasspathAttribute[] attributes = entry == null ? new IClasspathAttribute[0]
                            : entry.getExtraAttributes();
                    if (c == null) {
                        container = new CeylonClasspathContainer(javaProject, containerPath,
                                new IClasspathEntry[0], attributes);
                    } else {
                        // this might be the persisted one: reuse the persisted entries
                        container = new CeylonClasspathContainer(javaProject, containerPath,
                                c.getClasspathEntries(), attributes);
                    }
                }

                final IProject p = javaProject.getProject();
                Job job = new BuildProjectAndDependenciesJob("Initial build of project " + p.getName(), p) {
                    protected boolean reallyRun() {
                        return !CeylonBuilder.isModelAvailable(p);
                    }
                };
                job.setRule(p.getWorkspace().getRoot());
                job.setPriority(Job.BUILD);
                job.schedule(3000);

                boolean changed = container.resolveClasspath(monitor, true);
                if (changed) {
                    container.refreshClasspathContainer(monitor, javaProject);
                }

                return Status.OK_STATUS;

            } catch (JavaModelException ex) {
                // unless there are issues with the JDT, this should never happen
                return new Status(IStatus.ERROR, PLUGIN_ID, "could not get container", ex);
            }
        }
    };
    job.setUser(false);
    job.setPriority(Job.BUILD);
    job.setRule(getWorkspace().getRoot());
    job.schedule();
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonProjectModulesInitializer.java

License:Apache License

/**
 * Initialize the container with the "persisted" classpath 
 * entries, and then schedule the refresh.
 *//*from  w w w. ja v a  2 s.  c o m*/
public void initialize(IPath containerPath, final IJavaProject project) throws CoreException {
    int size = containerPath.segmentCount();
    if (size > 0) {
        if (containerPath.segment(0).equals(CeylonProjectModulesContainer.CONTAINER_ID)) {
            IClasspathContainer c = getClasspathContainer(containerPath, project);
            CeylonProjectModulesContainer container;
            if (c instanceof CeylonProjectModulesContainer) {
                container = (CeylonProjectModulesContainer) c;
            } else {
                IClasspathEntry entry = getCeylonClasspathEntry(containerPath, project);
                IClasspathAttribute[] attributes = entry == null ? new IClasspathAttribute[0]
                        : entry.getExtraAttributes();
                if (c == null) {
                    container = new CeylonProjectModulesContainer(project, containerPath,
                            new IClasspathEntry[0], attributes);
                } else {
                    // this might be the persisted one: reuse the persisted entries
                    container = new CeylonProjectModulesContainer(project, containerPath,
                            c.getClasspathEntries(), attributes);
                }
            }

            setClasspathContainer(containerPath, new IJavaProject[] { project },
                    new IClasspathContainer[] { container }, null);

            final Job initDependenciesJob = new InitDependenciesJob(
                    "Initializing dependencies for project " + project.getElementName(), container);
            initDependenciesJob.setUser(false);
            initDependenciesJob.setPriority(Job.BUILD);
            initDependenciesJob.setRule(getWorkspace().getRoot());

            // Before scheduling the InitDependenciesJob, we will wait for the end of the Java Tooling initialization Job 
            final long waitUntil = System.currentTimeMillis() + 120000;

            Job initDependenciesWhenJavaToolingIsInitialized = new Job(
                    "Waiting for the end of the Java Tooling Initialization before initializing Ceylon dependencies for project "
                            + project.getElementName() + " ...") {
                private Job initJavaToolingJob = null;

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    if (initJavaToolingJob == null) {
                        Job[] jobs = getJobManager().find(JavaUI.ID_PLUGIN);
                        for (Job job : jobs) {
                            if (job.getClass().getEnclosingClass().equals(InitializeAfterLoadJob.class)) {
                                initJavaToolingJob = job;
                            }
                        }
                    }

                    if (initJavaToolingJob != null) {
                        if (initJavaToolingJob.getState() == Job.WAITING
                                || initJavaToolingJob.getState() == Job.RUNNING) {
                            if (System.currentTimeMillis() < waitUntil) {
                                //                                    System.out.println("Waiting 1 seconde more for the end of the Java Tooling Initialization before initializing Ceylon dependencies for project " + project.getElementName() + " ...");
                                schedule(1000);
                                return Status.OK_STATUS;
                            } else {
                                //                                    System.out.println("The Java Tooling is not initialized after 2 minutes, so start initializing Ceylon dependencies for project " + project.getElementName() + " anyway !");
                            }
                        }
                    }

                    boolean shouldSchedule = true;
                    for (Job job : getJobManager().find(initDependenciesJob)) {
                        if (job.getState() == Job.WAITING) {
                            //                                System.out.println("An InitDependenciesJob for project " + project.getElementName() + " is already scheduled. Finally don't schedule a new one after the Java Tooling has initialized");
                            shouldSchedule = false;
                            break;
                        }
                    }

                    if (shouldSchedule) {
                        //                            System.out.println("Scheduling the initialization of the Ceylon dependencies for project " + project.getElementName() + " after the Java Tooling has been initialized");
                        initDependenciesJob.schedule();
                    }
                    return Status.OK_STATUS;
                }
            };

            initDependenciesWhenJavaToolingIsInitialized.setPriority(Job.BUILD);
            initDependenciesWhenJavaToolingIsInitialized.setSystem(true);
            initDependenciesWhenJavaToolingIsInitialized.schedule();
        }
    }
}

From source file:com.sabre.buildergenerator.TestHelper.java

License:Open Source License

public static int runJavaFile(IJavaProject javaProject, String mainClassQName, String[] args, final Writer out,
        final Writer err) throws CoreException, InterruptedException {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager
            .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
    ILaunchConfigurationWorkingCopy wc = type.newInstance(null, "TestConfig-" + javaProject.getElementName());
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, javaProject.getElementName());
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainClassQName);
    StringBuffer argsLine = new StringBuffer();
    if (args != null) {
        for (String arg : args) {
            if (argsLine.length() > 0) {
                argsLine.append(" ");
            }//from ww w  .jav a  2 s . co m
            argsLine.append(arg);
        }
    }
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, argsLine.toString());
    wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-ea");

    ILaunchConfiguration config = wc.doSave();
    WaitingProgressMonitor progressMonitor = new WaitingProgressMonitor();
    ILaunch launch = config.launch(ILaunchManager.RUN_MODE, progressMonitor, true, false);
    progressMonitor.waitTillDone(5000);
    int exitValue = -1;
    if (launch.getProcesses().length == 1) {
        IProcess iProcess = launch.getProcesses()[0];
        if (out != null) {
            iProcess.getStreamsProxy().getOutputStreamMonitor().addListener(new IStreamListener() {
                public void streamAppended(String text, IStreamMonitor monitor) {
                    try {
                        out.write(text);
                        out.flush();
                    } catch (IOException e) {
                    }
                }
            });
        }
        if (err != null) {
            iProcess.getStreamsProxy().getErrorStreamMonitor().addListener(new IStreamListener() {
                public void streamAppended(String text, IStreamMonitor monitor) {
                    try {
                        err.write(text);
                        err.flush();
                    } catch (IOException e) {
                    }
                }
            });
        }

        while (!iProcess.isTerminated()) {
            Thread.sleep(100);
        }
        exitValue = iProcess.getExitValue();
    }

    return exitValue;
}

From source file:com.servoy.eclipse.docgenerator.ui.handler.AutopilotDocumentationGenerationHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection != null) {
        IPackageFragment pkg = null;//from w ww  .  j ava 2  s .c o  m
        Iterator<?> entries = selection.iterator();
        while (entries.hasNext()) {
            Object entry = entries.next();
            if (entry instanceof IPackageFragment) {
                if (pkg == null) {
                    pkg = (IPackageFragment) entry;
                }
            } else if (entry instanceof IJavaProject) {
                if (pkg == null) {
                    IJavaProject javaPrj = (IJavaProject) entry;
                    try {
                        // pick the package with the shortest name
                        for (IPackageFragment frag : javaPrj.getPackageFragments()) {
                            if (pkg == null) {
                                pkg = frag;
                            } else if (pkg.getElementName().length() > pkg.getElementName().length()) {
                                pkg = frag;
                            }
                        }
                    } catch (JavaModelException e) {
                        LogUtil.logger().log(Level.SEVERE,
                                "Exception while searching for root package in project '"
                                        + javaPrj.getElementName() + "'.",
                                e);
                        e.printStackTrace();
                    }
                }
            }
        }

        if (pkg != null && pkg.getResource() != null && pkg.getResource().getLocation() != null) {
            final IPackageFragment pkgFinal = pkg;
            IJavaProject prj = pkg.getJavaProject();

            // Build a map with the selected package and its project.
            final Map<String, List<String>> prjPkg = new HashMap<String, List<String>>();
            List<String> pkgNames = new ArrayList<String>();
            pkgNames.add(pkg.getElementName());
            prjPkg.put(prj.getElementName(), pkgNames);

            final WorkspaceJob docgenJob = new WorkspaceJob("Generating documentation") {
                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                    // Post a documentation generation request.
                    // Post a documentation generation request.
                    DocumentationGenerationRequest req = new DocumentationGenerationRequestFromUI(pkgFinal,
                            true, monitor) {
                        @Override
                        protected boolean isRunningModal() {
                            Boolean b = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
                            return b != null ? b.booleanValue() : false;
                        }

                        @Override
                        protected void postponeAction(Action act) {
                            setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
                            setProperty(IProgressConstants.ACTION_PROPERTY, act);
                        }
                    };
                    Dictionary<String, String> props = new Hashtable<String, String>();
                    monitor.beginTask("Generating documentation", 100);

                    final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
                    context.registerService(DocumentationGenerationRequest.class.getName(), req, props);

                    return Status.OK_STATUS;
                }
            };
            docgenJob.setUser(true);
            docgenJob.schedule();

        }
    }
    return null;
}

From source file:com.servoy.eclipse.docgenerator.ui.handler.DocumentationGenerationRequestFromUI.java

License:Open Source License

public DocumentationGenerationRequestFromUI(IPackageFragment pkg, boolean autopilot, IProgressMonitor monitor) {
    IJavaProject prj = pkg.getJavaProject();
    this.autopilot = autopilot;
    if (!autopilot) {
        // If autopilot is disabled, we generate a single XML file for the entire tree rooted at the given package.
        outputFile = pkg.getResource().getFullPath().append(DocumentationBuilder.EXTENSION_XML_FILE);
    } else {//from  w w w . j  a v a  2 s.c  om
        outputFile = null;
    }

    // Build a map with the selected package and its project.
    prjPkg = new HashMap<String, List<String>>();
    List<String> pkgNames = new ArrayList<String>();
    pkgNames.add(pkg.getElementName());
    prjPkg.put(prj.getElementName(), pkgNames);

    this.monitor = monitor;
}

From source file:com.servoy.eclipse.docgenerator.ui.handler.ExplicitDocumentationGenerationHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
    if (selection != null) {
        IPackageFragment pkg = null;/*from ww  w. j  a v  a  2 s .com*/
        Iterator<?> entries = selection.iterator();
        while (entries.hasNext()) {
            Object entry = entries.next();
            if (entry instanceof IPackageFragment) {
                if (pkg == null) {
                    pkg = (IPackageFragment) entry;
                }
            }
        }

        if (pkg != null && pkg.getResource() != null && pkg.getResource().getLocation() != null) {
            final IPackageFragment pkgFinal = pkg;
            IJavaProject prj = pkg.getJavaProject();

            // Build a map with the selected package and its project.
            final Map<String, List<String>> prjPkg = new HashMap<String, List<String>>();
            List<String> pkgNames = new ArrayList<String>();
            pkgNames.add(pkg.getElementName());
            prjPkg.put(prj.getElementName(), pkgNames);

            final WorkspaceJob docgenJob = new WorkspaceJob("Generating documentation") {
                @Override
                public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
                    monitor.beginTask("Generating documentation", 100);

                    // Post a documentation generation request.
                    DocumentationGenerationRequest req = new DocumentationGenerationRequestFromUI(pkgFinal,
                            false, monitor) {
                        @Override
                        protected boolean isRunningModal() {
                            Boolean b = (Boolean) getProperty(IProgressConstants.PROPERTY_IN_DIALOG);
                            return b != null ? b.booleanValue() : false;
                        }

                        @Override
                        protected void postponeAction(Action act) {
                            setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
                            setProperty(IProgressConstants.ACTION_PROPERTY, act);
                        }
                    };
                    Dictionary<String, String> props = new Hashtable<String, String>();
                    final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
                    context.registerService(DocumentationGenerationRequest.class.getName(), req, props);

                    return Status.OK_STATUS;
                }
            };
            docgenJob.setUser(true);
            docgenJob.schedule();
        }
    }
    return null;
}

From source file:com.sureassert.uc.builder.SAUCBuildWorker.java

License:Open Source License

public synchronized void processJavaProject(ProjectProcessEntity projectProcessEntity, //
        Set<ProjectProcessEntity> alreadyProcessed, boolean hasProjectChanged,
        IProgressMonitor progressMonitor) {

    // if (!isStandaloneBuild) {
    // try {//www  .  ja  v  a  2s.  co  m
    // BasicUtils.debug("Starting build...");
    // int numErrors = BuildClient.getInstance().sendMessage(//
    // new StartBuildPPEMessage(new SerializableProjectProcessEntity(projectProcessEntity)));
    // } catch (Exception e) {
    // throw new RuntimeException(e);
    // } finally {
    // BasicUtils.debug("Build complete");
    // }
    // return;
    // }

    // JaCoCoClient jacocoClient = new JaCoCoClient(new SAUCEditorCoverageListenner());
    CoveragePrinter coveragePrinter = new CoveragePrinter(new SAUCEditorCoverageListenner());

    alreadyProcessed.add(projectProcessEntity);
    AspectJSigCache.clear();
    Map<IJavaProject, Set<ProcessEntity>> pEsByProject = null;
    IJavaProject javaProject = projectProcessEntity.getJavaProject();
    Map<IPath, Set<Signature>> affectedFileSigs = projectProcessEntity.getAffectedFileSigs();
    Set<IPath> affectedFiles = null;
    if (affectedFileSigs != null) {
        affectedFiles = affectedFileSigs.keySet();
        if (affectedFiles != null && affectedFiles.isEmpty())
            affectedFiles = null;
    }
    IWorkspace workspace = javaProject.getProject().getWorkspace();
    ProjectClassLoaders projectCLs = null;
    IFile file = null;
    IResource resource = javaProject.getResource();
    long startTime = System.nanoTime();
    sfFactory = new SourceFileFactory();
    javaPathData = new JavaPathData();
    InstrumentationSession jaCoCoSession = new InstrumentationSession(SaUCPreferences.getIsCoverageEnabled());
    boolean fullBuild = (affectedFiles == null);
    Set<ProcessEntity> allProcessEntities = null;
    IProject project = (IProject) resource;
    progressMonitor.beginTask("Processing " + project.getName(), 2000);
    try {
        BasicUtils.debug("-------------------------------------------------");
        BasicUtils.debug("Sureassert UC building project " + project.getName());
        BasicUtils.debug("ProcessEntities: " + projectProcessEntity.toString());

        // Get classloader using classpath of this project
        jaCoCoSession.start();
        projectCLs = ProjectClassLoaders.getClassLoaders(javaProject, affectedFiles == null, jaCoCoSession);
        PersistentDataFactory.getInstance().setCurrentUseCase(null, null, null, null, null, false, null, false);
        PersistentDataFactory.getInstance().setCurrentProject(project.getName(), //
                EclipseUtils.getRawPath(project).toString());
        PropertyFile propertyFile = new PropertyFile(new File(project.getLocation().toFile(), //
                PropertyFile.DEFAULT_PROPERTY_FILENAME));
        propertyFile.loadExtensions(projectCLs.projectCL);
        SourceModelFactory smFactory = new SourceModelFactory(projectCLs);
        UseCaseExecutionDelegate.INSTANCE.init(javaPathData, sfFactory, projectCLs.transformedCL);

        long getPEsStartTime = System.nanoTime();
        // Delete markers for all changed files
        if (hasProjectChanged)
            MarkerUtils.deleteAllMarkers(affectedFiles, project, sfFactory, javaPathData);
        ProcessEntityFactory peFactory = new ProcessEntityFactory(javaPathData, this);
        // Get ProcessEntities
        // Stage 1
        if (fullBuild) {
            ProjectClassLoaders.cleanTransformedDirs(javaProject);
            pEsByProject = peFactory.getProcessEntitiesFullBuild(resource, project, //
                    javaProject, projectCLs, hasProjectChanged, smFactory, sfFactory, //
                    new SubProgressMonitor(progressMonitor, 1000));
        } else {
            pEsByProject = peFactory.getProcessEntitiesIncBuild(affectedFileSigs, resource, project, //
                    javaProject, projectCLs, hasProjectChanged, smFactory, sfFactory, //
                    new SubProgressMonitor(progressMonitor, 1000));
        }
        BasicUtils.debug("Got ProcessEntities in " + ((System.nanoTime() - getPEsStartTime) / 1000000) + //
                "ms");
        Set<ProcessEntity> unprocessedEntities = pEsByProject.get(javaProject);
        if (unprocessedEntities == null)
            unprocessedEntities = new HashSet<ProcessEntity>();
        allProcessEntities = new HashSet<ProcessEntity>(unprocessedEntities);

        // Pre-process 1
        for (ProcessEntity processEntity : unprocessedEntities) {
            file = processEntity.getFile();
            SourceFile sourceFile = sfFactory.getSourceFile(file);
            // Delete internal/class level error markers
            MarkerUtils.deleteUCMarkers(sourceFile, -1, 1, null, null);
            MarkerUtils.deleteJUnitMarkers(sourceFile, -1, 1, null, null);

            executeNamedInstances(processEntity, projectCLs.transformedCL, smFactory, sfFactory);
            registerSINTypes(processEntity, projectCLs.transformedCL, smFactory, sfFactory);
        }

        // Set default values in UseCases and sort the PEs according to dependencies
        List<ProcessEntity> currentProcessEntities = new ArrayList<ProcessEntity>(unprocessedEntities);
        // System.out.println(">Unsorted: " + currentProcessEntities.toString());
        currentProcessEntities = ProcessEntity.setDefaultsAndSort(currentProcessEntities, //
                projectCLs.transformedCL, smFactory, sfFactory);
        // System.out.println(">Sorted: " + currentProcessEntities.toString());

        // Process
        // Stage 2
        // Iterate over unprocessed java files

        // jacocoClient.startSession();

        boolean lastPass = false;
        IProgressMonitor processStageMonitor = new SubProgressMonitor(progressMonitor, 1000);
        try {
            while (!currentProcessEntities.isEmpty()) {

                int peIndex = 0;
                processStageMonitor.beginTask("Executing", currentProcessEntities.size());
                for (ProcessEntity processEntity : currentProcessEntities) {
                    processStageMonitor.worked(1);
                    int percentComplete = (int) (((double) peIndex / (double) currentProcessEntities.size())
                            * 100);
                    file = processEntity.getFile();
                    SourceFile sourceFile = sfFactory.getSourceFile(file);
                    try {
                        if (javaProject != null && javaProject.exists()) {
                            processJavaType(processEntity, projectCLs, javaProject, smFactory, //
                                    sourceFile, processStageMonitor, percentComplete);
                        }
                        // File processed successfully, remove from list.
                        unprocessedEntities.remove(processEntity);

                    } catch (NamedInstanceNotFoundException ninfe) {
                        if (lastPass) {
                            // The last pass is activated when all files remain in the list; on
                            // this last pass we must report the error.
                            int lineNum = sourceFile.getLineNum(ninfe.getSourceLocation());
                            MarkerUtils.addMarker(sfFactory, javaPathData, sourceFile, ninfe.getMessage(),
                                    lineNum, //
                                    IMarker.SEVERITY_ERROR, false);
                            unprocessedEntities.remove(processEntity);
                        } else {
                            // The named instance may be loaded in a subsequent file,
                            // leave this file in the list.
                        }

                    } catch (SAUCBuildInterruptedError e) {
                        throw e;
                    } catch (LicenseBreachException e) {
                        throw e;
                    } catch (Throwable e) {
                        String msg = e instanceof CircularDependencyException ? "" : "Sureassert UC error: ";
                        MarkerUtils.addMarker(sfFactory, javaPathData, sourceFile,
                                msg + BasicUtils.toDisplayStr(e), -1, IMarker.SEVERITY_ERROR, false);

                        // iretrievable error, remove from list.
                        unprocessedEntities.remove(processEntity);
                    }
                    peIndex++;
                } // end execute process entity loop

                if (lastPass)
                    break;

                if (unprocessedEntities.size() == currentProcessEntities.size()) {
                    // Every file resulted in a retry request for the next pass;
                    // therefore on the next and last pass they must report their errors.
                    lastPass = true;
                }

                // Replace working list with cut-down list
                currentProcessEntities = new ArrayList<ProcessEntity>(unprocessedEntities);
            }
        } finally {
            processStageMonitor.done();
        }

        addSourceModelErrors(smFactory);

    } catch (SAUCBuildInterruptedError e) {
        throw e;
    } catch (Throwable e) {
        if (e instanceof LicenseBreachException) {
            PersistentDataFactory.getInstance().registerLicenseBreached();
        } else if (e instanceof CompileErrorsException) {
            try {
                handleCompileErrors((CompileErrorsException) e, sfFactory);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } else {
            if (e instanceof SAException)
                file = ((SAException) e).getFile();
            EclipseUtils.reportError(e);
            if (file != null) {
                String msg = e instanceof CircularDependencyException ? "" : "Sureassert UC error: ";
                try {
                    MarkerUtils.addMarker(sfFactory, javaPathData, sfFactory.getSourceFile(file),
                            msg + BasicUtils.toDisplayStr(e), -1, IMarker.SEVERITY_ERROR, false);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
        // PersistentDataFactory.getInstance().setNewPersistentStore(javaProject.getProject().getName());

    } finally {

        // Add coverage markers

        jaCoCoSession.end(sfFactory, javaPathData, new SubProgressMonitor(progressMonitor, 1000), this);

        // jacocoClient.dumpExecData();
        // jacocoClient.printInfo(sfFactory, javaPathData, new
        // SubProgressMonitor(progressMonitor, 1000), this);
        // coveragePrinter.printInfo(sfFactory, javaPathData, new
        // SubProgressMonitor(progressMonitor, 1000), this, null);

        // Update coverage report
        Set<IPath> checkPaths = javaPathData.getAllCachedFilePaths();
        checkPaths.addAll(EclipseUtils.toPaths(PersistentDataFactory.getInstance().getMarkedFilePaths()));
        if (allProcessEntities != null)
            checkPaths.addAll(ProcessEntity.getPaths(allProcessEntities));
        // new CoverageReporter().reportCoverage(checkPaths, javaPathData, workspace,
        // sfFactory);

        // Clear caches
        NamedInstanceFactory.getInstance().clear();
        PersistentDataFactory.getInstance().clearMarkedFilePaths();
        UseCaseExecutionDelegate.INSTANCE.dispose();
        if (projectCLs != null)
            projectCLs.clear();
        sfFactory = null;
        BasicUtils.debug("-------------------------------------------------");
        BasicUtils.debug("Sureassert UC builder finished \"" + javaProject.getElementName() + //
                "\" in " + ((System.nanoTime() - startTime) / 1000000) + "ms");

        // Get foreign client project process entities that now require building
        if (pEsByProject != null) {
            for (Entry<IJavaProject, Set<ProcessEntity>> projectPEs : pEsByProject.entrySet()) {
                if (!projectPEs.getKey().equals(javaProject)) {
                    ProjectProcessEntity ppe = ProjectProcessEntity.newFromProcessEntities(//
                            projectPEs.getKey(), projectPEs.getValue());
                    if (!alreadyProcessed.contains(ppe))
                        processJavaProject(ppe, alreadyProcessed, false,
                                new SubProgressMonitor(progressMonitor, 0));
                }
            }
        }
        progressMonitor.setTaskName("Building workspace"); // occasional Eclipse bug workaround
        progressMonitor.done();
    }
}

From source file:com.surelogic.sierra.client.eclipse.actions.ScanChangedProjectsAction.java

@Override
public void run(final List<IJavaProject> projects) {
    if (projects.size() <= 0) {
        return;/*  w w w.  j  a v  a  2  s  .  co  m*/
    }

    /*
     * License check: A hack because Sierra is not using SLJobs yet.
     */
    final SLStatus failed = SLLicenseUtility.validateSLJob(SLLicenseProduct.SIERRA,
            new NullSLProgressMonitor());
    if (failed != null) {
        IStatus status = SLEclipseStatusUtility.convert(failed, Activator.getDefault());
        ErrorDialogUtility.open(null, null, status, true);
        return;
    }

    new AbstractSierraDatabaseJob("Checking last scan times") {
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(getName(), projects.size() + 1);
            try {
                Data.getInstance().withReadOnly(new DBQuery<Void>() {
                    @Override
                    public Void perform(final Query q) {
                        final Map<IJavaProject, Date> times = new HashMap<IJavaProject, Date>(projects.size());
                        List<IJavaProject> noScanYet = null;
                        final Scans scans = new Scans(q);
                        for (final IJavaProject p : projects) {
                            final ScanInfo info = scans.getLatestScanInfo(p.getElementName());
                            if (info != null) {
                                times.put(p, info.getScanTime());
                            } else {
                                // No scan on the project yet
                                if (noScanYet == null) {
                                    noScanYet = new ArrayList<IJavaProject>();
                                }
                                noScanYet.add(p);
                            }
                        }

                        monitor.worked(1);

                        final Collection<ICompilationUnit> selectedCompilationUnits = JDTUtility
                                .modifiedCompUnits(times, monitor);

                        boolean startedScan = false;
                        if (!selectedCompilationUnits.isEmpty()) {
                            new NewPartialScan().scan(selectedCompilationUnits);
                            startedScan = true;
                        }
                        if (noScanYet != null) {
                            new NewScan().scan(noScanYet);
                            startedScan = true;
                        }

                        if (!startedScan) {
                            BalloonUtility.showMessage("Nothing changed",
                                    "Sierra did not detect any files that changed since your last scan(s)");
                        }
                        return null;
                    }
                });
            } catch (final TransactionException e) {
                final int errNo = 46;
                final String msg = I18N.err(errNo, getName());
                return SLEclipseStatusUtility.createErrorStatus(errNo, msg, e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
}

From source file:com.sympedia.genfw.util.ClasspathHelper.java

License:Open Source License

public static IJavaProject getJavaProject(String projectName) {
    try {/*from   w  w w  .ja v a2  s. co  m*/
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IJavaModel javaModel = JavaCore.create(root);
        IJavaProject javaProjects[] = javaModel.getJavaProjects();
        for (int n = 0; n < javaProjects.length; n++) {
            IJavaProject javaProject = javaProjects[n];
            if (javaProject.getElementName().equals(projectName)) {
                return javaProject;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return null;
}

From source file:com.technophobia.substeps.junit.launcher.tab.component.ProjectComponent.java

License:Open Source License

private String handleProjectButtonSelected() {
    final IJavaProject project = chooseJavaProject();
    if (project == null) {
        return "";
    }//from   www.j a  v a 2 s. c om

    return project.getElementName();
}