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

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

Introduction

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

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.siteview.mde.launching.JUnitLaunchConfigurationDelegate.java

License:Open Source License

private String getTestPluginId(ILaunchConfiguration configuration) throws CoreException {
    IJavaProject javaProject = getJavaProject(configuration);
    IMonitorModelBase model = MonitorRegistry.findModel(javaProject.getProject());
    if (model == null)
        abort(NLS.bind(MDEMessages.JUnitLaunchConfiguration_error_notaplugin,
                javaProject.getProject().getName()), null, IStatus.OK);
    if (model instanceof IFragmentModel)
        return ((IFragmentModel) model).getFragment().getPluginId();

    return model.getMonitorBase().getId();
}

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

License:Open Source License

public void run() {

    if (System.getProperty(SaUCApplicationLaunchShortcut.IS_KILL_BUILD_ENV_VAR_NAME) != null)
        return;//from w w  w  . j  ava 2s.c  om

    /*
     * if (!SaUCPreferences.isLicenseKeyValid()) {
     * // Display license nag message if its time and restart the nag counter.
     * if (licenseNagRunner != null && !licenseNagRunner.isAlive()) {
     * EclipseUtils.displayDialog(LicenseNagRunner.LICENSE_NAG_MESSAGE_TITLE, //
     * LicenseNagRunner.LICENSE_NAG_MESSAGE, false, IStatus.INFO);
     * licenseNagRunner = new LicenseNagRunner();
     * licenseNagRunner.start();
     * }
     * }
     */

    IJavaProject javaProject = EclipseUtils.getJavaProject(resource);
    if (javaProject != null) {
        // try {
        Set<IPath> affectedFiles = (delta == null) ? null : EclipseUtils.getAffectedFiles(delta, "java");

        try {

            // In case runner killed before backup restore...
            WorkspaceProperties.restorePreInitPropFileBackups(//
                    EclipseUtils.getWorkspaceLocation(javaProject.getProject().getWorkspace())
                            .getAbsolutePath());
            // Execute SA Builder on affected files
            processJavaProject(new ProjectProcessEntity(javaProject, affectedFiles), //
                    new HashSet<ProjectProcessEntity>(), true, progressMonitor);

        } catch (SAUCBuildInterruptedError ie) {
            throw new OperationCanceledException();
        } finally {
            Timer timer = new Timer("Cleanup");

            // Seems to help avoid file locks
            // System.gc();

            if (PersistentDataFactory.getInstance().getNumSystemErrors() > 0) {
                EclipseUtils.displayDialog("Sureassert UC Error", //
                        "Warning: Sureassert UC encountered unexpected errors, please check the Eclipse Error Log (Window->Show View->Error Log)", //
                        true, IStatus.WARNING);
            }

            if (PersistentDataFactory.getInstance().isLicensedBreached()) {
                EclipseUtils.displayDialog("Sureassert UC License Restriction", //
                        "Cannot execute UseCases - the maximum number of UseCase methods permitted by free license has been reached ("
                                + maxUseCases + ").  " + //
                                "To continue use, please purchase a commercial license from www.sureassert.com and enter the key "
                                + //
                                "in the Sureassert UC Preferences Page (Window->Preferences).", //
                        true, IStatus.WARNING);
            }

            if (!isBuildCancelled(progressMonitor)) {
                // Serialize PersistentDataFactory
                PersistentDataFactory.getInstance().serialize(project.getName(), //
                        EclipseUtils.getRawPath(project).toFile());
            } else {
                // Re-load old PersistentDataFactory
                try {
                    PersistentDataFactory.getInstance().load(project.getName(), //
                            EclipseUtils.getRawPath(project).toFile(), //
                            javaProject.getProject().getWorkspace().getRoot().getLocation().toFile());
                } catch (PersistentDataLoadException e) {
                    EclipseUtils.reportError(e, false);
                }
            }

            timer.printExpiredTime();
        }
    }
}

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 {/*  w w w .ja  va2  s  . c o  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.sureassert.uc.builder.SAUCBuildWorker.java

License:Open Source License

private void processJavaType(ProcessEntity processEntity, ProjectClassLoaders projectCLs, //
        IJavaProject project, SourceModelFactory smFactory, SourceFile sourceFile, //
        IProgressMonitor monitor, int percentComplete) throws Exception {

    IType javaType = processEntity.getJavaType();

    boolean clearRuntimePersistentData = true;
    if (EclipseUtils.hasMethodAnnotations(javaType, Exemplar.class.getSimpleName(), projectCLs.projectCL, true)
            || //
            EclipseUtils.hasMethodAnnotations(javaType, Exemplars.class.getSimpleName(), projectCLs.projectCL,
                    true)/* www.  j  ava2s  .  c  o  m*/
            || //
            EclipseUtils.hasMethodAnnotations(javaType, UseCase.class.getSimpleName(), projectCLs.projectCL,
                    true)
            || //
            EclipseUtils.hasMethodAnnotations(javaType, MultiUseCase.class.getSimpleName(),
                    projectCLs.projectCL, true)) {

        TestDouble testDouble = PersistentDataFactory.getInstance().getClassDoubleForDoubledClassName(//
                javaType.getFullyQualifiedName());

        if (testDouble != null) {
            for (Signature methodSig : processEntity.getProcessSigs()) {
                List<UseCaseModel> ucModels = processEntity.getUseCaseModels(methodSig);
                for (UseCaseModel ucModel : ucModels) {
                    ucModel.setError("Cannot define UseCase - class " + javaType.getFullyQualifiedName() + //
                            " has TestDouble " + testDouble.getTestDoubleClassName());
                }
            }
        } else {
            handleUseCases(projectCLs.transformedCL, processEntity, project, smFactory, sourceFile, //
                    monitor, percentComplete);
            clearRuntimePersistentData = false;
        }
    }

    if (EclipseUtils.hasClassAnnotation(javaType, HasJUnit.class.getSimpleName())) {
        handleJUnits(projectCLs, javaType, sourceFile, smFactory, clearRuntimePersistentData, //
                monitor, project.getProject(), percentComplete);
    }

    if (BasicUtils.isJUnitTestClass(sourceFile.getSource())) {
        handleJUnits2(projectCLs, javaType, sourceFile, monitor, project, percentComplete);
    }
}

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

License:Open Source License

private void handleJUnits2(ProjectClassLoaders projectCLs, IType jUnitType, SourceFile sourceFile, //
        IProgressMonitor monitor, IJavaProject javaProject, int percentComplete) //
        throws ClassNotFoundException, IOException, CoreException, TypeConverterException,
        NamedInstanceNotFoundException {

    if (isBuildCancelled(monitor))
        throw new SAUCBuildInterruptedError();

    if (EclipseUtils.hasClassAnnotation(jUnitType, NoAutoRun.class.getSimpleName()) || //
            !SaUCPreferences.getIsJUnitAutomationEnabled())
        return;//from   www  .j  a v a  2s .  c  o  m

    ClassLoader classLoader = projectCLs.transformedCL;

    // Delete all markers as all UseCases will be executed
    int startOffset = jUnitType.getSourceRange().getOffset();
    int startLine = sourceFile.getLineNum(startOffset);
    int endOffset = startOffset + jUnitType.getSourceRange().getLength();
    int endLine = sourceFile.getLineNum(endOffset);

    // Exclude sub-types
    List<Range> excludeRanges = EclipseUtils.getSubtypeRanges(jUnitType, sourceFile);
    MarkerUtils.deleteJUnitMarkers(sourceFile, startLine, endLine, excludeRanges, null);

    JUnitExecutor juExecutor = new JUnitExecutor(jUnitType, sfFactory, javaPathData);
    List<ExecutorResult> results;
    try {
        results = juExecutor.execute(classLoader, javaProject, true, monitor, percentComplete, //
                SaUCPreferences.getJUnitExcludeFilter());
    } catch (Exception e) {
        results = new ArrayList<ExecutorResult>();
        results.add(new ExecutorResult(BasicUtils.toDisplayStr(e), Type.ERROR, null));
    }

    for (ExecutorResult result : results) {
        if (!UseCaseExecutionDelegate.ignoreResult(result)) {
            String resultClassName = result.getClassName();
            if (resultClassName == null)
                resultClassName = jUnitType.getFullyQualifiedName();
            int lineNum = result.getErrorLineNum();
            String javaPathStr = PersistentDataFactory.getInstance().getJavaPathStr(resultClassName);
            if (javaPathStr == null) {
                EclipseUtils.reportError("Could not determine source file for class " + resultClassName);
            } else {
                IFile file = javaPathData.getFile(new Path(javaPathStr),
                        javaProject.getProject().getWorkspace());
                SourceFile resultSourceFile = sfFactory.getSourceFile(file);
                MarkerUtils.addMarker(sfFactory, javaPathData, resultSourceFile, result.getDescription(),
                        lineNum, EclipseUtils.getSeverity(result), true);
            }
        }
    }
}

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

License:Open Source License

/**
 * Executes all JUnits in the given project
 * /*from  w w  w  . j  av a  2s.  c  o  m*/
 * @param project
 * @throws CoreException
 */
@SuppressWarnings("unused")
private void executeAllJUnits(IJavaProject javaProject, ProjectClassLoaders projectCLs, //
        IProgressMonitor monitor, int percentComplete) throws CoreException {

    IProject project = javaProject.getProject();
    IWorkspace workspace = project.getWorkspace();
    Set<IPath> allPaths = EclipseUtils.getAllFiles(project, "java");
    for (IPath path : allPaths) {
        try {
            IFile file = javaPathData.getFile(path, workspace);
            SourceFile sourceFile = sfFactory.getSourceFile(file);
            ICompilationUnit javaUnit = javaPathData.getJavaUnit(path, workspace);
            if (javaUnit.exists() && BasicUtils.isJUnitTestClass(sourceFile.getSource())) {
                for (IType type : javaUnit.getAllTypes()) {
                    handleJUnits2(projectCLs, type, sourceFile, monitor, javaProject, percentComplete);
                }
            }

        } catch (Exception e) {
            EclipseUtils.reportError(e);
        }
    }
}

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

License:Open Source License

private void handleUseCases(ClassLoader classLoader, ProcessEntity processEntity, IJavaProject project, //
        SourceModelFactory smFactory, SourceFile sourceFile, IProgressMonitor monitor, int percentComplete)
        throws ClassNotFoundException, IOException, CoreException, SecurityException, IllegalArgumentException,
        NoSuchFieldException, IllegalAccessException, InstantiationException, UseCaseException,
        NamedInstanceNotFoundException, InvocationTargetException, EvaluatorException, NoSuchMethodException,
        LicenseBreachException {//  w w w. ja  v  a  2s  . c  om

    //
    // if ((processEntity.getProcessSigs().isEmpty() || (processEntity.getProcessSigs().size()
    // == 1 && processEntity.getProcessSigs().contains(null))) && //
    // BasicUtils.isJUnitTestClass(sourceFile.getSource())) {
    // addMarker(sourceFile, "Cannot define UseCases on a JUnit test class unless \"" + //
    // WorkspacePreferences.instance.getVisitTestClassesOptionName() + "\"" + //
    // " option is enabled in preferences.", -1, IMarker.SEVERITY_ERROR, false);
    // return;
    // }

    IType javaType = processEntity.getJavaType();
    String className = javaType.getFullyQualifiedName();
    Class<?> clazz = classLoader.loadClass(className);

    if (processEntity.isChanged()) {
        // Delete all markers as all UseCases will be executed
        int startOffset = javaType.getSourceRange().getOffset();
        int startLine = sourceFile.getLineNum(startOffset);
        int endOffset = startOffset + javaType.getSourceRange().getLength();
        int endLine = sourceFile.getLineNum(endOffset);

        // Exclude sub-types
        List<Range> excludeRanges = EclipseUtils.getSubtypeRanges(javaType, sourceFile);
        MarkerUtils.deleteUCMarkers(sourceFile, startLine, endLine, excludeRanges, null);
    }

    if (clazz.isInterface())
        return;

    // Instantiate class
    SourceModel sourceModel = smFactory.getSourceModel(sourceFile, javaType.getCompilationUnit());
    int currentLineNum = -1;

    try {

        for (Signature methodSig : processEntity.getProcessSigs()) {

            if (isBuildCancelled(monitor))
                throw new SAUCBuildInterruptedError();

            // NOTE: Runtime persistent data must only be deleted once before all
            // UseCases that pertain to any given signature, as data is keyed
            // by signature, not by specific UseCase.
            boolean clearRuntimePersistentData = true;

            List<UseCaseModel> ucModels = processEntity.getUseCaseModels(methodSig);
            UseCaseMetadata ucMetadata = processEntity.getUseCaseMetadata(methodSig);
            IMethod method = sourceModel.getMethod(methodSig);
            currentLineNum = getStartLineNumIncUseCase(method, sourceFile);

            // Delete current markers on this method
            // currentLineNum = ucMetadata.startLine;
            if (ucMetadata.startOffset > -1) {
                // int startLine = sourceFile.getLineNum(ucMetadata.startOffset);
                int endOffset = method.getSourceRange().getOffset() + method.getSourceRange().getLength();
                int endLine = sourceFile.getLineNum(endOffset);
                MarkerUtils.deleteUCMarkers(sourceFile, currentLineNum, endLine, null, null);
            }

            for (UseCaseModel ucModel : ucModels) {
                Signature superSig = ucModel.getInheritedFromSignature();
                if (superSig != null) {
                    // Delete markers from affected superclass/interface UseCase methods
                    try {
                        String superPathStr = PersistentDataFactory.getInstance()
                                .getJavaPathStr(superSig.getClassName());
                        Path superPath = new Path(superPathStr);
                        IFile superFile = javaPathData.getFile(superPath, project.getProject().getWorkspace());
                        ICompilationUnit superUnit = javaPathData.getJavaUnit(superPath,
                                project.getProject().getWorkspace());
                        SourceFile superSourceFile = sfFactory.getSourceFile(superFile);
                        SourceModel superSourceModel = smFactory.getSourceModel(superSourceFile, superUnit);
                        IMethod superMethod = superSourceModel.getMethod(superSig);
                        int superLineNum = ucModel.getDeclaredLineNum();
                        int endOffset = superMethod.getSourceRange().getOffset()
                                + superMethod.getSourceRange().getLength();
                        int endLine = superSourceFile.getLineNum(endOffset);
                        MarkerUtils.deleteUCMarkers(superSourceFile, superLineNum, endLine, null,
                                UseCaseExecutor.getSubUCMarkerPostfix(ucModel));
                    } catch (Throwable e) {
                        EclipseUtils.reportError(e);
                    }
                }
            }

            for (UseCaseModel ucModel : ucModels) {

                if (isBuildCancelled(monitor))
                    throw new SAUCBuildInterruptedError();

                // Check license
                if (!SaUCPreferences.isLicenseKeyValid()
                        && PersistentDataFactory.getInstance().getNumUseCaseSigs() >= maxUseCases) {
                    throw new LicenseBreachException();
                }

                currentLineNum = ucModel.getDeclaredLineNum();
                UseCaseExecutionCommand ucExecCommand = new UseCaseExecutionCommand(ucModel, sourceModel, //
                        sourceFile, javaType, project.getProject(), methodSig);
                UseCaseExecutionDelegate.INSTANCE.executeUseCase(ucExecCommand, monitor, percentComplete, //
                        clearRuntimePersistentData, true);

                clearRuntimePersistentData = false;
            } // end UseCaseModel loop
        } // end method loop

    } catch (UseCaseException uce) {
        UseCaseExecutionDelegate.handleUCException(project.getProject(), uce, currentLineNum, sourceFile,
                sfFactory, javaPathData);
    }
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

private void addMavenClasspathEntries(Set<IRuntimeClasspathEntry> resolved,
        IRuntimeClasspathEntry runtimeClasspathEntry, ILaunchConfiguration configuration, int scope,
        IProgressMonitor monitor) throws CoreException {
    IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
    MavenJdtPlugin plugin = MavenJdtPlugin.getDefault();
    IClasspathManager buildpathManager = plugin.getBuildpathManager();
    IClasspathEntry[] cp = buildpathManager.getClasspath(javaProject.getProject(), scope, false, monitor);
    for (IClasspathEntry entry : cp) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_PROJECT:
            addProjectEntries(resolved, entry.getPath(), scope, getArtifactClassifier(entry), configuration,
                    monitor);/*from w w  w.ja  va2s  . c  o  m*/
            break;
        case IClasspathEntry.CPE_LIBRARY:
            resolved.add(JavaRuntime.newArchiveRuntimeClasspathEntry(entry.getPath()));
            break;
        default:
            break;
        }
    }
}

From source file:com.tasktop.dropwizard.launcher.DropwizardRuntimeClasspathProvider.java

License:Open Source License

protected int getArtifactScope(ILaunchConfiguration configuration) throws CoreException {
    String typeid = configuration.getType().getAttribute("id"); //$NON-NLS-1$
    if (DropwizardLaunchConstants.ID_DROPWIZARD_APPLICATION.equals(typeid)) {
        IResource[] resources = configuration.getMappedResources();

        // MNGECLIPSE-530: NPE starting openarchitecture workflow 
        if (resources == null || resources.length == 0) {
            return IClasspathManager.CLASSPATH_RUNTIME;
        }// w w w  .  j  a v  a  2 s .  c  o m

        // ECLIPSE-33: applications from test sources should use test scope 
        final Set<IPath> testSources = new HashSet<IPath>();
        IJavaProject javaProject = JavaRuntime.getJavaProject(configuration);
        IMavenProjectFacade facade = projectManager.create(javaProject.getProject(), new NullProgressMonitor());
        if (facade == null) {
            return IClasspathManager.CLASSPATH_RUNTIME;
        }

        testSources.addAll(Arrays.asList(facade.getTestCompileSourceLocations()));

        for (int i = 0; i < resources.length; i++) {
            for (IPath testPath : testSources) {
                if (testPath.isPrefixOf(resources[i].getProjectRelativePath())) {
                    return IClasspathManager.CLASSPATH_TEST;
                }
            }
        }
        return IClasspathManager.CLASSPATH_RUNTIME;
    }
    throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, 0,
            "Unsupported launch configuration type", null));
}

From source file:com.technophobia.eclipse.project.cache.listener.ClassFileChangedListener.java

License:Open Source License

@Override
public void elementChanged(final ElementChangedEvent event) {
    if (event.getType() == ElementChangedEvent.POST_CHANGE) {
        final IJavaElementDelta delta = event.getDelta();
        final Collection<IJavaElementDelta> changeNodes = new ArrayList<IJavaElementDelta>();
        findChangeNodes(delta, changeNodes);

        for (final IJavaElementDelta changeNode : changeNodes) {
            final IJavaProject javaProject = changeNode.getElement().getJavaProject();
            if (javaProject != null && isClassFileChange(changeNode, javaProject)) {
                final IProject project = javaProject.getProject();
                FeatureEditorPlugin.instance().info("Class files have changed for project " + project);
                projectChangedNotifier.doCallback(project);
            }/*from w w w  . jav a  2s.  com*/
        }
    }
}