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

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

Introduction

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

Prototype

boolean exists();

Source Link

Document

Returns whether this Java element exists in the model.

Usage

From source file:org.compiere.mfg_scm.eclipse.db.DbfBootstrap.java

License:Apache License

private String[] addProjectToClasspath(String[] previouscp, IJavaProject project) throws CoreException {
    // IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
    // IJavaProject project =
    // JavaCore.getJavaCore().create(root.getProject(projectName));
    if ((project != null) && (project.exists() && project.isOpen())) {
        String[] projectcp = JavaRuntime.computeDefaultRuntimeClassPath(project);
        return StringUtil.concatUniq(projectcp, previouscp);
    } else {/*from   w  ww  . j  ava2s.com*/
        return previouscp;
    }
}

From source file:org.cubictest.exporters.selenium.launch.LaunchConfigurationDelegate.java

License:Open Source License

/**
 * Performs a check on the launch configuration's attributes. If an
 * attribute contains an invalid value, a {@link CoreException} with the
 * error is thrown./*from w ww.j  a v  a2 s . c  o  m*/
 * 
 * @param configuration
 *            the launch configuration to verify
 * @param launch
 *            the launch to verify
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             an exception is thrown when the verification fails
 */
private void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor)
        throws CoreException {
    try {
        final IJavaProject javaProject = getJavaProject(configuration);
        if ((javaProject == null) || !javaProject.exists()) {
            ErrorHandler.logAndShowErrorDialog(ERROR_INVALID_PROJECT_GOT_TO_BE_A_JAVA_PROJEDT);
            throw new CoreException(new Status(IStatus.ERROR, SeleniumExporterPlugin.PLUGIN_ID,
                    ERROR_INVALID_PROJECT_GOT_TO_BE_A_JAVA_PROJEDT));
        }

        if (javaProject.findType(CUBICTEST_SELENIUM_RUNNER_CLASS) != null) {
            return;
        }

        PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
            public void run() {
                CustomStepWizard.addLibToClasspath(javaProject, new Shell());
            }
        });
        if (javaProject.findType(CUBICTEST_SELENIUM_RUNNER_CLASS) != null) {
            return;
        } else {

            PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
                public void run() {
                    ErrorHandler.logAndShowErrorDialog(REMOTE_CUBIC_RUNNER_IS_NOT_ON_THE_CLASSPATH);
                }
            });
        }
        throw new CoreException(new Status(IStatus.ERROR, SeleniumExporterPlugin.PLUGIN_ID,
                REMOTE_CUBIC_RUNNER_IS_NOT_ON_THE_CLASSPATH));

    } finally {
        monitor.done();
    }
}

From source file:org.cubictest.exporters.selenium.launch.SeleniumRunnerTab.java

License:Open Source License

protected void mapResources(ILaunchConfigurationWorkingCopy config) {
    try {//from  w  w w  .  jav a  2s. c om
        //CONTEXTLAUNCHING
        IJavaProject javaProject = getJavaProject();
        if (javaProject != null && javaProject.exists() && javaProject.isOpen()) {
            JavaMigrationDelegate.updateResourceMapping(config);
        }
    } catch (CoreException ce) {
        setErrorMessage(ce.getStatus().getMessage());
    }
}

From source file:org.dev.toos.constcode.model.ConstModelSet.java

License:Apache License

/**?*/
public static void refresh(IProgressMonitor monitor) {
    activateModel = null;/*from ww  w  . j  a  va2s  .c om*/
    /* 1.??projectsxml
     *   1.1.
     *   1.2.?
     * 2.
     */
    //
    HashMap<String, ConstModel> oldModeMap = new HashMap<String, ConstModel>(modeBeanMap);
    Message.updateTask(monitor, "scanning projects...", 3, 1);
    //
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    if (projects != null) {
        for (int i = 0; i < projects.length; i++) {
            IProject pro = projects[i];
            Message.updateTask(monitor, "scanning projects(" + pro.getName() + "?)", projects.length, i);
            if (pro.isOpen() == false)
                continue;
            if (pro.exists() == false)
                continue;
            IJavaProject javaProject = JavaCore.create(pro);
            if (javaProject == null || javaProject.exists() == false)
                continue;
            //?Javacore-codes.xml?
            try {
                IJavaElement[] javaElements = javaProject.getChildren();
                if (javaElements == null)
                    continue;
                oldModeMap.remove(javaProject.getElementName());
                if (existConstModel(javaProject) == true)
                    getConstModel(javaProject).refresh(monitor);//
                else
                    newConstModel(javaProject, monitor).refresh(monitor);//
            } catch (Exception e) {
                Message.errorInfo("Refresh Job", e);
            }
        }
    }
    //
    for (ConstModel constModel : getModeBeanList())
        if (constModel.getGroups().size() == 0)
            oldModeMap.put(constModel.getProjectName(), constModel);
    for (Entry<String, ConstModel> ent : oldModeMap.entrySet())
        ConstModelSet.removeModel(ent.getValue().getProject());
    //
    Message.updateTask(monitor, "activate current Project...", 3, 2);
    if (getModeBeanList().size() != 0) {
        String projectName = null;
        IProject currentProject = ResourcesPlugin.getWorkspace().getRoot().getProject();
        if (currentProject != null) {
            ConstModel currentModel = modeBeanMap.get(currentProject.getName());
            if (currentModel != null)
                projectName = currentModel.getProjectName();
        }
        if (projectName == null)
            projectName = getModeBeanList().get(0).getProjectName();
        activateModel(projectName);
    }
    //
    Message.updateTask(monitor, "process callBack function...", 3, 3);
}

From source file:org.deved.antlride.integration.jdt.AntlrJavaTargetService.java

License:Open Source License

public Map<String, Object> getClasspathInformation(IProgressMonitor monitor, AntlrBuildUnit unit)
        throws CoreException {

    final IJavaProject javaProject = JavaCore.create(unit.getFile().getProject());

    if (javaProject == null || !javaProject.exists()) {
        return Collections.emptyMap();
    }//from  w ww.  j av  a2  s  .  c o  m

    IRuntimeClasspathEntry[] runtimeClassPath = computeDefaultRuntimeClassPath(javaProject);
    Version v = new Version();
    runtimeClassPath = mergeClasspath(v, monitor, unit, runtimeClassPath);

    String[] classpath = getLocationClassPath(runtimeClassPath);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("classpath", classpath);
    map.put("description", v.version);
    return map;
}

From source file:org.deved.antlride.integration.jdt.AntlrJavaTargetService.java

License:Open Source License

public boolean accept(IResource resource) {
    boolean accept = false;
    try {/*ww w. j a v  a  2 s. com*/
        IProject project = resource.getProject();
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject.exists()) {
            IPath resourcePath = new Path(project.getName()).append(resource.getProjectRelativePath());
            IPath outputLocation = javaProject.getOutputLocation();
            if (resourcePath.segmentCount() >= outputLocation.segmentCount()) {
                for (int segmentIndex = 0; segmentIndex < outputLocation.segmentCount(); segmentIndex++) {
                    if (!outputLocation.segment(segmentIndex).equals(resourcePath.segment(segmentIndex))) {
                        accept = true;
                        break;
                    }
                }
            }
        } else {
            accept = true;
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    // if (!accept) {
    // System.out.println("Excluding " + resource);
    // }
    return accept;
}

From source file:org.deved.antlride.jdt.env.JDTEnvironmentRepository.java

License:Open Source License

public JavaEnvironment getEnvironment(IProject project) {
    try {/*from   w  w  w  . ja  v  a  2s .  co m*/
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject != null && javaProject.exists()) {
            IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject);
            if (vmInstall == null) {
                vmInstall = JavaRuntime.getDefaultVMInstall();
            }
            if (vmInstall != null) {
                return new JDTEnvironment(vmInstall);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:org.deved.antlride.jdt.launch.AntlrAbstractJavaLauncher.java

License:Open Source License

public final void launch(final boolean rebuild, final AntlrBuildUnit unit, final AntlrTestCase testCase)
        throws CoreException {
    try {/*from   www .  j  a v  a2 s . c o  m*/
        final IJavaProject javaProject = JavaCore.create(unit.getFile().getProject());
        if (javaProject != null /* && javaProject.exists() */) {
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
            dialog.run(true, true, new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor)
                        throws InvocationTargetException, InterruptedException {
                    try {
                        AntlrDeployer deployer = AntlrDeployerRepository.createDeployer();
                        deployer.deployRuntime();

                        IPath compilerPath = deployCompiler();
                        IGrammar grammar = unit.getGrammar();
                        IPath src = getFolder(grammar, "src", false);
                        IPath classes = getFolder(grammar, "classes", rebuild);

                        final IJavaProject javaProject = JavaCore.create(unit.getFile().getProject());

                        IRuntimeClasspathEntry[] runtimeClassPath;
                        if (javaProject.exists()) {
                            runtimeClassPath = AntlrJavaTargetService
                                    .computeDefaultRuntimeClassPath(javaProject);
                        } else {
                            runtimeClassPath = new IRuntimeClasspathEntry[0];
                        }

                        runtimeClassPath = AntlrJavaTargetService.mergeClasspath(monitor, unit,
                                runtimeClassPath);

                        String[] classpath = AntlrJavaTargetService.getMementoClassPath(runtimeClassPath);
                        // ++++++++++++++++++++++++++++++++++++++++++++++++++++
                        // ++++++++++++++++++++ generate code
                        // ++++++++++++++++++++++++++++++++++++++++++++++++++++
                        if (rebuild) {
                            generateCode(monitor, unit, javaProject, classpath, src);
                            // ++++++++++++++++++++++++++++++++++++++++++++++++++++
                            // ++++++++++++++++++++ compile
                            // ++++++++++++++++++++++++++++++++++++++++++++++++++++
                            compile(monitor, unit, javaProject, runtimeClassPath, compilerPath, src, classes);
                        }

                        doLaunch(monitor, javaProject, runtimeClassPath, rebuild, unit, testCase, compilerPath,
                                src, classes);
                    } catch (CoreException e) {
                        showError(e.getStatus());
                    } catch (UnknownHostException e) {
                        showError(createFailStatus(e));
                    } catch (IOException e) {
                        showError(createFailStatus(e));
                    }

                }
            });
        }
    } catch (Exception ex) {
        showError(createFailStatus(ex));
    }
}

From source file:org.drools.eclipse.action.ConvertToDroolsProjectAction.java

License:Apache License

public void selectionChanged(IAction action, ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structured = (IStructuredSelection) selection;
        if (structured.size() == 1) {
            Object element = structured.getFirstElement();
            if (element instanceof IJavaProject) {
                project = (IJavaProject) element;
            } else if (element instanceof IProject) {
                IJavaProject javaProject = JavaCore.create((IProject) element);
                if (javaProject != null && javaProject.exists()) {
                    project = javaProject;
                }//  w  ww.j  a  va 2 s . c o  m
            }
        }
    }
}

From source file:org.drools.eclipse.debug.DebugUtil.java

License:Apache License

public static IValue getValueByExpression(String expression, IValue value) {
    if (!(value instanceof IJavaObject)) {
        return null;
    }/*from   ww  w  .j av a  2 s .  co m*/
    IJavaObject javaValue = (IJavaObject) value;
    try {
        IJavaType type = javaValue.getJavaType();
        if (!(type instanceof IJavaClassType)) {
            return null;
        }
        IJavaStackFrame stackFrame = getStackFrame(javaValue);
        if (stackFrame == null) {
            return null;
        }

        // find the project the snippets will be compiled in.
        ISourceLocator locator = javaValue.getLaunch().getSourceLocator();
        Object sourceElement = null;
        if (locator instanceof ISourceLookupDirector) {
            String[] sourcePaths = ((IJavaClassType) type).getSourcePaths(null);
            if (sourcePaths != null && sourcePaths.length > 0) {
                sourceElement = ((ISourceLookupDirector) locator).getSourceElement(sourcePaths[0]);
            }
            if (!(sourceElement instanceof IJavaElement) && sourceElement instanceof IAdaptable) {
                sourceElement = ((IAdaptable) sourceElement).getAdapter(IJavaElement.class);
            }
        }
        if (sourceElement == null) {
            sourceElement = locator.getSourceElement(stackFrame);
            if (!(sourceElement instanceof IJavaElement) && sourceElement instanceof IAdaptable) {
                Object newSourceElement = ((IAdaptable) sourceElement).getAdapter(IJavaElement.class);
                // if the source is a drl during the execution of the rule
                if (newSourceElement != null) {
                    sourceElement = newSourceElement;
                }
            }
        }
        IJavaProject project = null;
        if (sourceElement instanceof IJavaElement) {
            project = ((IJavaElement) sourceElement).getJavaProject();
        } else if (sourceElement instanceof IResource) {
            IJavaProject resourceProject = JavaCore.create(((IResource) sourceElement).getProject());
            if (resourceProject.exists()) {
                project = resourceProject;
            }
        }
        if (project == null) {
            return null;
        }

        IAstEvaluationEngine evaluationEngine = JDIDebugPlugin.getDefault().getEvaluationEngine(project,
                (IJavaDebugTarget) stackFrame.getDebugTarget());

        EvaluationBlock evaluationBlock = new EvaluationBlock(javaValue, (IJavaReferenceType) type,
                (IJavaThread) stackFrame.getThread(), evaluationEngine);
        return evaluationBlock.evaluate(expression);

    } catch (CoreException e) {
        DroolsEclipsePlugin.log(e);
    }
    return null;
}