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.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;//from   www . j av a 2  s .co  m
    if (javaProject != null && javaProject.exists()) {
        name = javaProject.getElementName();
    }
    config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, name);
}

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

License:Open Source License

/**
 * Show a dialog that lets the user select a project. This in turn provides
 * context for the main type, allowing the user to key a main type name, or
 * constraining the search for main types to the specified project.
 *///w w w . j  a  v a  2 s .c  om
protected void handleProjectButtonSelected() {
    IJavaProject javaProject = mProjectChooserHelper.chooseJavaProject(mProjText.getText().trim(),
            "Please select a project to launch");
    if (javaProject == null) {
        return;
    } // end if
    String projectName = javaProject.getElementName();
    mProjText.setText(projectName);

    // get the list of activities and fill the combo
    IProject project = javaProject.getProject();
    loadActivities(project);
}

From source file:com.android.ide.eclipse.adt.internal.project.ProjectChooserHelper.java

License:Open Source License

/**
 * Helper method to get the Android project with the given name
 *
 * @param projectName the name of the project to find
 * @return the {@link IProject} for the Android project. <code>null</code> if not found.
 *///w ww. j  av a  2s .  co m
public IProject getAndroidProject(String projectName) {
    IProject iproject = null;
    IJavaProject[] javaProjects = getAndroidProjects(null);
    if (javaProjects != null) {
        for (IJavaProject javaProject : javaProjects) {
            if (javaProject.getElementName().equals(projectName)) {
                iproject = javaProject.getProject();
                break;
            }
        }
    }
    return iproject;
}

From source file:com.android.ide.eclipse.adt.launch.AndroidLaunchController.java

License:Open Source License

/**
 * For the current launchInfo, create additional DelayedLaunchInfo that should be used to
 * sync APKs that we are dependent on to the device.
 * /*from w w w .  j av a  2  s.c  o m*/
 * @param launchInfo the original launch info that we want to find the 
 * @return a list of DelayedLaunchInfo (may be empty if no dependencies were found or error)
 */
public List<DelayedLaunchInfo> getDependenciesLaunchInfo(DelayedLaunchInfo launchInfo) {
    List<DelayedLaunchInfo> dependencies = new ArrayList<DelayedLaunchInfo>();

    // Convert to equivalent JavaProject
    IJavaProject javaProject;
    try {
        //assuming this is an Android (and Java) project since it is attached to the launchInfo.
        javaProject = BaseProjectHelper.getJavaProject(launchInfo.getProject());
    } catch (CoreException e) {
        // return empty dependencies
        AdtPlugin.printErrorToConsole(launchInfo.getProject(), e);
        return dependencies;
    }

    // Get all projects that this depends on
    List<IJavaProject> androidProjectList;
    try {
        androidProjectList = ProjectHelper.getAndroidProjectDependencies(javaProject);
    } catch (JavaModelException e) {
        // return empty dependencies
        AdtPlugin.printErrorToConsole(launchInfo.getProject(), e);
        return dependencies;
    }

    // for each project, parse manifest and create launch information
    for (IJavaProject androidProject : androidProjectList) {
        // Parse the Manifest to get various required information
        // copied from LaunchConfigDelegate
        AndroidManifestParser manifestParser;
        try {
            manifestParser = AndroidManifestParser.parse(androidProject, null /* errorListener */,
                    true /* gatherData */, false /* markErrors */);
        } catch (CoreException e) {
            AdtPlugin.printErrorToConsole(launchInfo.getProject(),
                    String.format("Error parsing manifest of %s", androidProject.getElementName()));
            continue;
        }

        // Get the APK location (can return null)
        IFile apk = ProjectHelper.getApplicationPackage(androidProject.getProject());
        if (apk == null) {
            // getApplicationPackage will have logged an error message
            continue;
        }

        // Create new launchInfo as an hybrid between parent and dependency information
        DelayedLaunchInfo delayedLaunchInfo = new DelayedLaunchInfo(androidProject.getProject(),
                manifestParser.getPackage(), manifestParser.getPackage(), launchInfo.getLaunchAction(), apk,
                manifestParser.getDebuggable(), manifestParser.getApiLevelRequirement(), launchInfo.getLaunch(),
                launchInfo.getMonitor());

        // Add to the list
        dependencies.add(delayedLaunchInfo);
    }

    return dependencies;
}

From source file:com.android.ide.eclipse.adt.launch.EmulatorConfigTab.java

License:Open Source License

public void initializeFrom(ILaunchConfiguration configuration) {
    AvdManager avdManager = Sdk.getCurrent().getAvdManager();

    TargetMode mode = LaunchConfigDelegate.DEFAULT_TARGET_MODE; // true == automatic
    try {/*from   w ww.  ja  va 2 s  . co  m*/
        mode = TargetMode
                .getMode(configuration.getAttribute(LaunchConfigDelegate.ATTR_TARGET_MODE, mode.getValue()));
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    mAutoTargetButton.setSelection(mode.getValue());
    mManualTargetButton.setSelection(!mode.getValue());

    // look for the project name to get its target.
    String stringValue = "";
    try {
        stringValue = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                stringValue);
    } catch (CoreException ce) {
        // let's not do anything here, we'll use the default value
    }

    IProject project = null;

    // get the list of existing Android projects from the workspace.
    IJavaProject[] projects = BaseProjectHelper.getAndroidProjects();
    if (projects != null) {
        // look for the project whose name we read from the configuration.
        for (IJavaProject p : projects) {
            if (p.getElementName().equals(stringValue)) {
                project = p.getProject();
                break;
            }
        }
    }

    // update the AVD list
    AvdInfo[] avds = null;
    if (avdManager != null) {
        avds = avdManager.getValidAvds();
    }

    IAndroidTarget projectTarget = null;
    if (project != null) {
        projectTarget = Sdk.getCurrent().getTarget(project);
    } else {
        avds = null; // no project? we don't want to display any "compatible" AVDs.
    }

    mPreferredAvdSelector.setAvds(avds, projectTarget);

    stringValue = "";
    try {
        stringValue = configuration.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, stringValue);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }

    if (stringValue != null && stringValue.length() > 0 && avdManager != null) {
        AvdInfo targetAvd = avdManager.getAvd(stringValue, true /*validAvdOnly*/);
        mPreferredAvdSelector.setSelection(targetAvd);
    } else {
        mPreferredAvdSelector.setSelection(null);
    }

    boolean value = LaunchConfigDelegate.DEFAULT_WIPE_DATA;
    try {
        value = configuration.getAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA, value);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    mWipeDataButton.setSelection(value);

    value = LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM;
    try {
        value = configuration.getAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM, value);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    mNoBootAnimButton.setSelection(value);

    int index = -1;

    index = LaunchConfigDelegate.DEFAULT_SPEED;
    try {
        index = configuration.getAttribute(LaunchConfigDelegate.ATTR_SPEED, index);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    if (index == -1) {
        mSpeedCombo.clearSelection();
    } else {
        mSpeedCombo.select(index);
    }

    index = LaunchConfigDelegate.DEFAULT_DELAY;
    try {
        index = configuration.getAttribute(LaunchConfigDelegate.ATTR_DELAY, index);
    } catch (CoreException e) {
        // let's not do anything here, we'll put a proper value in
        // performApply anyway
    }
    if (index == -1) {
        mDelayCombo.clearSelection();
    } else {
        mDelayCombo.select(index);
    }

    String commandLine = null;
    try {
        commandLine = configuration.getAttribute(LaunchConfigDelegate.ATTR_COMMANDLINE, ""); //$NON-NLS-1$
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    if (commandLine != null) {
        mEmulatorCLOptions.setText(commandLine);
    }
}

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

License:Open Source License

/**
 * Show a dialog that lets the user select a Android project.  This in turn provides
 * context for the main type, allowing the user to key a main type name, or
 * constraining the search for main types to the specified project.
 *//*w w w.  j  av a  2  s  .  c om*/
private void handleProjectButtonSelected() {
    IJavaProject project = mProjectChooserHelper.chooseJavaProject(getProjectName());
    if (project == null) {
        return;
    }

    String projectName = project.getElementName();
    mProjText.setText(projectName);
    loadInstrumentations(project.getProject());
}

From source file:com.android.ide.eclipse.adt.launch.MainLaunchConfigTab.java

License:Open Source License

/**
 * Show a dialog that lets the user select a project. This in turn provides
 * context for the main type, allowing the user to key a main type name, or
 * constraining the search for main types to the specified project.
 *///w w  w  .j a  v  a 2  s  .  co  m
protected void handleProjectButtonSelected() {
    IJavaProject javaProject = mProjectChooserHelper.chooseJavaProject(mProjText.getText().trim());
    if (javaProject == null) {
        return;
    } // end if
    String projectName = javaProject.getElementName();
    mProjText.setText(projectName);

    // get the list of activities and fill the combo
    IProject project = javaProject.getProject();
    loadActivities(project);
}

From source file:com.android.ide.eclipse.auidt.internal.launch.EmulatorConfigTab.java

License:Open Source License

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
    AvdManager avdManager = Sdk.getCurrent().getAvdManager();

    TargetMode mode = AndroidLaunchConfiguration.parseTargetMode(configuration,
            LaunchConfigDelegate.DEFAULT_TARGET_MODE);

    boolean multipleDevices = mode.isMultiDevice();
    if (multipleDevices && !mSupportMultiDeviceLaunch) {
        // The launch config says to run on multiple devices, but this launch type does not
        // suppport multiple devices. In such a case, switch back to default mode.
        // This could happen if a launch config used for Run is then used for Debug.
        multipleDevices = false;//from   w ww  .  j  a v  a2s  . com
        mode = LaunchConfigDelegate.DEFAULT_TARGET_MODE;
    }

    mAutoTargetButton.setSelection(mode == TargetMode.AUTO);
    mManualTargetButton.setSelection(mode == TargetMode.MANUAL);
    mAllDevicesTargetButton.setSelection(multipleDevices);

    mDeviceTypeCombo.setEnabled(multipleDevices);
    if (multipleDevices) {
        int index = 0;
        if (mode == TargetMode.ALL_EMULATORS) {
            index = 1;
        } else if (mode == TargetMode.ALL_DEVICES) {
            index = 2;
        }
        mDeviceTypeCombo.select(index);
    }

    // look for the project name to get its target.
    String stringValue = "";
    try {
        stringValue = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                stringValue);
    } catch (CoreException ce) {
        // let's not do anything here, we'll use the default value
    }

    IProject project = null;

    // get the list of existing Android projects from the workspace.
    IJavaProject[] projects = BaseProjectHelper.getAndroidProjects(null /*filter*/);
    if (projects != null) {
        // look for the project whose name we read from the configuration.
        for (IJavaProject p : projects) {
            if (p.getElementName().equals(stringValue)) {
                project = p.getProject();
                break;
            }
        }
    }

    // update the AVD list
    if (project != null) {
        mProjectTarget = Sdk.getCurrent().getTarget(project);
    }

    updateAvdList(avdManager);

    stringValue = "";
    try {
        stringValue = configuration.getAttribute(LaunchConfigDelegate.ATTR_AVD_NAME, stringValue);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }

    if (stringValue != null && stringValue.length() > 0 && avdManager != null) {
        AvdInfo targetAvd = avdManager.getAvd(stringValue, true /*validAvdOnly*/);
        mPreferredAvdSelector.setSelection(targetAvd);
    } else {
        mPreferredAvdSelector.setSelection(null);
    }

    boolean value = LaunchConfigDelegate.DEFAULT_WIPE_DATA;
    try {
        value = configuration.getAttribute(LaunchConfigDelegate.ATTR_WIPE_DATA, value);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    mWipeDataButton.setSelection(value);

    value = LaunchConfigDelegate.DEFAULT_NO_BOOT_ANIM;
    try {
        value = configuration.getAttribute(LaunchConfigDelegate.ATTR_NO_BOOT_ANIM, value);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    mNoBootAnimButton.setSelection(value);

    int index = -1;

    index = LaunchConfigDelegate.DEFAULT_SPEED;
    try {
        index = configuration.getAttribute(LaunchConfigDelegate.ATTR_SPEED, index);
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    if (index == -1) {
        mSpeedCombo.clearSelection();
    } else {
        mSpeedCombo.select(index);
    }

    index = LaunchConfigDelegate.DEFAULT_DELAY;
    try {
        index = configuration.getAttribute(LaunchConfigDelegate.ATTR_DELAY, index);
    } catch (CoreException e) {
        // let's not do anything here, we'll put a proper value in
        // performApply anyway
    }
    if (index == -1) {
        mDelayCombo.clearSelection();
    } else {
        mDelayCombo.select(index);
    }

    String commandLine = null;
    try {
        commandLine = configuration.getAttribute(LaunchConfigDelegate.ATTR_COMMANDLINE, ""); //$NON-NLS-1$
    } catch (CoreException e) {
        // let's not do anything here, we'll use the default value
    }
    if (commandLine != null) {
        mEmulatorCLOptions.setText(commandLine);
    }
}

From source file:com.centurylink.mdw.plugin.launch.AutoTestLaunchShortcut.java

License:Apache License

@Override
protected void launchGroovy(ICompilationUnit unit, IJavaProject javaProject, String mode) {
    IType runType = null;//from   www.j a va2 s .  c o m

    // if unit is null, then we are not looking for a run type
    if (unit != null) {
        IType[] types = null;
        try {
            types = unit.getAllTypes();
        } catch (JavaModelException e) {
            GroovyCore.errorRunningGroovy(e);
            return;
        }
        runType = findClassToRun(types);
        if (runType == null) {
            GroovyCore.errorRunningGroovy(new Exception("Unable to find run type: " + unit));
            return;
        }
    }

    Map<String, String> launchConfigProperties = createLaunchProperties(runType, javaProject);

    try {
        ILaunchConfigurationWorkingCopy workingConfig = findOrCreateLaunchConfig(launchConfigProperties,
                runType != null ? runType.getElementName() : javaProject.getElementName());
        workingConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
                Arrays.asList(JavaRuntime.computeDefaultRuntimeClassPath(javaProject)));
        workingConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs);
        ILaunchConfiguration launchConfig = workingConfig.doSave();
        DebugPlugin.getDefault().addDebugEventListener(
                new AutoTestDebugListener(launchConfig, testCaseRun.getTestCase(), testCaseRun.getLog()));
        DebugUITools.launch(launchConfig, mode);

        // don't return until execution complete
        try {
            while (testCaseRun.getTestCase().getStatus().equals(TestCase.STATUS_RUNNING)
                    || testCaseRun.getTestCase().getStatus().equals(TestCase.STATUS_WAITING))
                Thread.sleep(500);
        } catch (InterruptedException ex) {
        }
    } catch (CoreException ex) {
        GroovyCore.errorRunningGroovyFile((IFile) unit.getResource(), ex);
    }
}

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

License:Open Source License

private static IJavaModelStatus validateLibraryContents(IPath path, IJavaProject project, String entryPathMsg) {
    JavaModelManager manager = JavaModelManager.getJavaModelManager();
    try {/*from  w w w .j  av a2  s .c o m*/
        manager.verifyArchiveContent(path);
    } catch (CoreException e) {
        if (e.getStatus().getMessage() == Messages.status_IOException) {
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH,
                    Messages.bind(Messages.classpath_archiveReadError,
                            new String[] { entryPathMsg, project.getElementName() }));
        }
    }
    return JavaModelStatus.VERIFIED_OK;
}