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:com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.java

License:Open Source License

private void testModeChanged() {
    boolean isSingleTestMode = mTestRadioButton.getSelection();
    setEnableSingleTestGroup(isSingleTestMode);
    setEnableContainerTestGroup(!isSingleTestMode);
    if (!isSingleTestMode && mContainerText.getText().length() == 0) {
        String projText = mProjText.getText();
        if (Path.EMPTY.isValidSegment(projText)) {
            IJavaProject javaProject = getJavaModel().getJavaProject(projText);
            if (javaProject != null && javaProject.exists()) {
                setContainerElement(javaProject);
            }/*from w w  w  . ja v  a2  s.  c  o  m*/
        }
    }
    validatePage();
    updateLaunchConfigurationDialog();
}

From source file:com.android.ide.eclipse.adt.internal.launch.junit.AndroidJUnitLaunchConfigurationTab.java

License:Open Source License

private void initializeJavaProject(IJavaElement javaElement, ILaunchConfigurationWorkingCopy config) {
    IJavaProject javaProject = javaElement.getJavaProject();
    String name = null;/* ww  w  .jav  a2  s  .co m*/
    if (javaProject != null && javaProject.exists()) {
        name = javaProject.getElementName();
    }
    config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
}

From source file:com.basistech.m2e.code.quality.findbugs.EclipseFindbugsProjectConfigurator.java

License:Open Source License

@Override
protected void handleProjectConfigurationChange(final IMavenProjectFacade mavenProjectFacade,
        final IProject project, final IProgressMonitor monitor, final MavenPluginWrapper mavenPluginWrapper,
        MavenSession session) throws CoreException {
    log.debug("entering handleProjectConfigurationChange");
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null || !javaProject.exists() || !javaProject.getProject().isOpen()) {
        return;/*from   w w w.ja va 2s . c  o  m*/
    }
    final MavenPluginConfigurationTranslator mavenFindbugsConfig = MavenPluginConfigurationTranslator
            .newInstance(this, mavenPluginWrapper, project, mavenProjectFacade.getMavenProject(monitor),
                    monitor, session);
    UserPreferences prefs;
    try {
        final List<MojoExecution> mojoExecutions = mavenPluginWrapper.getMojoExecutions();
        if (mojoExecutions.size() != 1) {
            log.error("Wrong number of executions. Expected 1. Found " + mojoExecutions.size());
            return;
        }
        prefs = this.buildFindbugsPreferences(mavenFindbugsConfig);
        final EclipseFindbugsConfigManager fbPluginNature = EclipseFindbugsConfigManager.newInstance(project);
        // Add the builder and nature
        fbPluginNature.configure(monitor);
        FindbugsPlugin.saveUserPreferences(project, prefs);
        FindbugsPlugin.setProjectSettingsEnabled(project, null, true);
    } catch (final CoreException ex) {
        log.error(ex.getLocalizedMessage());
    }
}

From source file:com.centurylink.mdw.plugin.designer.DesignerProxy.java

License:Apache License

public TestCaseRun prepareTestCase(AutomatedTestCase testCase, int runNum, File resultDir,
        boolean createReplace, boolean verbose, PrintStream log, LogMessageMonitor monitor,
        boolean singleServer, boolean stubbing, boolean debug) throws RemoteException {
    if ((testCase.isGroovy() || testCase.isGherkin()) && !MdwPlugin.workspaceHasGroovySupport()) {
        String msg = "Please install Groovy support to execute test case: " + testCase.getName();
        throw new IllegalStateException(msg);
    }/*from   w  ww . j av  a2s  .c o m*/

    SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd-HHmmssSSS");
    try {
        if (!testCase.isLegacy() && !testCase.getProject().isFilePersist()) {
            // non-VCS asset-based -- load ruleSet content
            testCase.load();
            testCase.getRuleSetVO().setPackageName(testCase.getPackage().getName());
        }
        testCase.getTestCase().prepare();

        Map<String, ProcessVO> procCache = new HashMap<String, ProcessVO>();

        String masterRequestId = testCase.getMasterRequestId();

        if (masterRequestId == null)
            masterRequestId = project.getUser().getUsername() + "-" + sdf.format(new Date());
        else if (!testCase.isGroovy() && !testCase.isGherkin()
                && masterRequestId.equals(TestDataFilter.AnyNumberToken))
            masterRequestId = Long.toString(System.currentTimeMillis());
        if (testCase.isGherkin()) {
            if (masterRequestId.indexOf("${masterRequestId}") != -1)
                masterRequestId = masterRequestId.replace("${masterRequestId}",
                        project.getUser().getUsername() + "-" + sdf.format(new Date()));
        }
        testCase.setMasterRequestId(masterRequestId);
        TestCaseRun run;

        if (testCase.isGherkin()) {
            run = new GherkinTestCaseLaunch(testCase.getTestCase(), runNum, masterRequestId,
                    new DesignerDataAccess(dataAccess.getDesignerDataAccess()), monitor, procCache,
                    testCase.isLoadTest(), true, testCase.getProject().isOldNamespaces(), project);
        } else if (testCase.isGroovy()) {
            if (debug) {
                run = new AutoTestCaseRun(testCase, runNum, masterRequestId,
                        new DesignerDataAccess(dataAccess.getDesignerDataAccess()), monitor, procCache, debug);
            } else {
                List<String> classpathList = null;
                IJavaProject javaProject = project.getJavaProject();
                if (javaProject != null && javaProject.exists()) {
                    classpathList = Arrays.asList(JavaRuntime.computeDefaultRuntimeClassPath(javaProject));
                }
                run = new GroovyTestCaseRun(testCase.getTestCase(), runNum, masterRequestId,
                        new DesignerDataAccess(dataAccess.getDesignerDataAccess()), monitor, procCache,
                        testCase.isLoadTest(), true, testCase.getProject().isOldNamespaces(), classpathList);
            }
        } else {
            run = new TestCaseRun(testCase.getTestCase(), runNum, masterRequestId,
                    new DesignerDataAccess(dataAccess.getDesignerDataAccess()), monitor, procCache,
                    testCase.isLoadTest(), true, testCase.getProject().isOldNamespaces());
        }
        run.prepareTest(createReplace, resultDir, verbose, singleServer, stubbing, log);
        return run;
    } catch (Exception ex) {
        throw new RemoteException(ex.getMessage(), ex);
    }
}

From source file:com.centurylink.mdw.plugin.project.WorkflowProjectPage.java

License:Apache License

/**
 * @see WizardPage#getStatuses()/*from ww  w  . ja  va2 s .c  o  m*/
 */
public IStatus[] getStatuses() {
    if (!getProject().isRemote() && containsWhitespace(getSourceProjectName())) {
        IStatus s = new Status(IStatus.ERROR, getPluginId(), 0,
                "Source project name cannot contain whitespace.", null);
        return new IStatus[] { s };
    } else if (WorkflowProjectManager.getInstance().projectNameExists(getSourceProjectName())) {
        IStatus s = new Status(IStatus.ERROR, getPluginId(), 0, "Source project name already exists.", null);
        return new IStatus[] { s };
    } else if (getProject().isEarProject()) {
        // adding workflow facet to existing EAR project
        IJavaProject sourceProject = WorkflowProjectManager.getJavaProject(getSourceProjectName());
        if (!sourceProject.exists()) {
            return new IStatus[] { new Status(IStatus.ERROR, getPluginId(), 0,
                    "Source project name should refer to a Java project that exists in your workspace.",
                    null) };
        } else {
            return new IStatus[] { new Status(IStatus.INFO, getPluginId(), 0,
                    "Please ensure that Source project has either the 'EJB Module' facet or the 'Utility Module' facet\nand that it's included in the EAR project's deployment assembly.",
                    null) };
        }
    } else {
        return null;
    }
}

From source file:com.centurylink.mdw.plugin.WizardPage.java

License:Apache License

/**
 * Override to prefer non-temp package root.
 *//*  w  ww . ja  v a  2s .  co  m*/
@SuppressWarnings("restriction")
@Override
protected void initContainerPage(IJavaElement elem) {
    IPackageFragmentRoot tempRoot = null; // only as fallback
    IPackageFragmentRoot initRoot = null;
    if (elem != null) {
        initRoot = org.eclipse.jdt.internal.corext.util.JavaModelUtil.getPackageFragmentRoot(elem);
        try {
            if (initRoot == null || initRoot.getKind() != IPackageFragmentRoot.K_SOURCE) {
                IJavaProject jproject = elem.getJavaProject();
                if (jproject != null) {
                    initRoot = null;
                    if (jproject.exists()) {
                        IPackageFragmentRoot[] roots = jproject.getPackageFragmentRoots();
                        for (int i = 0; i < roots.length; i++) {
                            if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) {
                                if (roots[i].getElementName()
                                        .equals(MdwPlugin.getSettings().getTempResourceLocation())) {
                                    tempRoot = roots[i];
                                } else {
                                    initRoot = roots[i];
                                    break;
                                }
                            }
                        }
                    }
                    if (initRoot == null && tempRoot == null) {
                        initRoot = jproject.getPackageFragmentRoot(jproject.getResource());
                    }
                }
            }
        } catch (JavaModelException e) {
            org.eclipse.jdt.internal.ui.JavaPlugin.log(e);
        }
    }
    setPackageFragmentRoot(initRoot == null ? tempRoot : initRoot, true);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java

License:Open Source License

/**
 * Returns the java project that corresponds to the given path.
 * Returns null if the path doesn't correspond to a project.
 */// w  w w  . j av a  2 s .com
private static IJavaProject getJavaProject(IPath path, IJavaModel model) {
    IJavaProject project = model.getJavaProject(path.lastSegment());
    if (project.exists()) {
        return project;
    }
    return null;
}

From source file:com.google.gdt.eclipse.appengine.rpc.validators.JavaCompilationParticipant.java

License:Open Source License

@Override
public boolean isActive(IJavaProject project) {
    try {/*from ww w. j  a va2 s .  c  om*/
        boolean active = project.exists() && (project.getProject().hasNature(GaeNature.NATURE_ID)
                || project.getProject().hasNature(GWTNature.NATURE_ID));
        return active;
    } catch (CoreException e) {
        AppEngineRPCPlugin.log(e);
        return false;
    }
}

From source file:com.google.gdt.eclipse.core.JavaProjectUtilities.java

License:Open Source License

/**
 * Returns <code>true</code> if the given IJavaProject is not null, and
 * <code>javaProject.exists()</code> is true.
 *//*  w ww. j  a  v  a2  s . c  om*/
public static boolean isJavaProjectNonNullAndExists(IJavaProject javaProject) {
    return (javaProject != null && javaProject.exists());
}

From source file:com.google.gdt.eclipse.core.launch.LaunchConfigurationProcessorUtilities.java

License:Open Source License

/**
 * Uses the processor to update the given configuration.
 *///from www  .  j a v a  2 s  .  co  m
public static void updateViaProcessor(ILaunchConfigurationProcessor processor,
        ILaunchConfigurationWorkingCopy configuration) {
    IJavaProject javaProject = LaunchConfigurationUtilities.getJavaProject(configuration);
    if (javaProject != null && javaProject.exists()) {
        try {
            List<String> programArgs = parseProgramArgs(configuration);
            List<String> vmArgs = parseVmArgs(configuration);
            processor.update(configuration, javaProject, programArgs, vmArgs);
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
                    LaunchConfigurationProcessorUtilities.createArgsString(programArgs));
            configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
                    LaunchConfigurationProcessorUtilities.createArgsString(vmArgs));
        } catch (Throwable e) {
            CorePluginLog.logError(e, "Could not update the launch configuration");
        }
    }
}