List of usage examples for org.eclipse.jdt.core IJavaProject getProject
IProject getProject();
IProject
on which this IJavaProject
was created. From source file:com.android.ide.eclipse.adt.internal.build.PostCompilerHelper.java
License:Open Source License
/** * Writes the standard resources of a project and its referenced projects * into a {@link SignedJarBuilder}.//from w ww .j a va 2 s . c o m * Standard resources are non java/aidl files placed in the java package folders. * @param apkBuilder the {@link ApkBuilder}. * @param javaProject the javaProject object. * @param referencedJavaProjects the java projects that this project references. * @throws ApkCreationException if an error occurred * @throws SealedApkException if the APK is already sealed. * @throws DuplicateFileException if a file conflicts with another already added to the APK * at the same location inside the APK archive. * @throws CoreException */ private void writeStandardResources(ApkBuilder apkBuilder, IJavaProject javaProject, IJavaProject[] referencedJavaProjects) throws DuplicateFileException, ApkCreationException, SealedApkException, CoreException { IWorkspace ws = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wsRoot = ws.getRoot(); // create a list of path already put into the archive, in order to detect conflict ArrayList<String> list = new ArrayList<String>(); writeStandardProjectResources(apkBuilder, javaProject, wsRoot, list); for (IJavaProject referencedJavaProject : referencedJavaProjects) { // only include output from non android referenced project // (This is to handle the case of reference Android projects in the context of // instrumentation projects that need to reference the projects to be tested). if (referencedJavaProject.getProject().hasNature(AndroidConstants.NATURE_DEFAULT) == false) { writeStandardProjectResources(apkBuilder, referencedJavaProject, wsRoot, list); } } }
From source file:com.android.ide.eclipse.adt.internal.build.PostCompilerHelper.java
License:Open Source License
/** * Returns the list of the output folders for the specified {@link IJavaProject} objects, if * they are Android projects./* w w w . j a v a 2s.c om*/ * * @param referencedJavaProjects the java projects. * @return an array, always. Can be empty. * @throws CoreException */ private String[] getProjectOutputs(IJavaProject[] referencedJavaProjects) throws CoreException { ArrayList<String> list = new ArrayList<String>(); IWorkspace ws = ResourcesPlugin.getWorkspace(); IWorkspaceRoot wsRoot = ws.getRoot(); for (IJavaProject javaProject : referencedJavaProjects) { // only include output from non android referenced project // (This is to handle the case of reference Android projects in the context of // instrumentation projects that need to reference the projects to be tested). if (javaProject.getProject().hasNature(AndroidConstants.NATURE_DEFAULT) == false) { // get the output folder IPath path = null; try { path = javaProject.getOutputLocation(); } catch (JavaModelException e) { continue; } IResource outputResource = wsRoot.findMember(path); if (outputResource != null && outputResource.getType() == IResource.FOLDER) { String outputOsPath = outputResource.getLocation().toOSString(); list.add(outputOsPath); } } } return list.toArray(new String[list.size()]); }
From source file:com.android.ide.eclipse.adt.internal.build.SourceProcessor.java
License:Open Source License
protected SourceProcessor(@NonNull IJavaProject javaProject, @NonNull BuildToolInfo buildToolInfo, @NonNull IFolder genFolder, @NonNull DefaultSourceChangeHandler deltaVisitor) { mJavaProject = javaProject;//www. j ava2s .com mBuildToolInfo = buildToolInfo; mGenFolder = genFolder; mDeltaVisitor = deltaVisitor; mDeltaVisitor.init(this); IProject project = javaProject.getProject(); // get all the source files buildSourceFileList(); // load the known dependencies loadOutputAndDependencies(); boolean mustCompile = loadState(project); // if we stored that we have to compile some files, we build the list that will compile them // all. For now we have to reuse the full list since we don't know which files needed // compilation. if (mustCompile) { mToCompile.addAll(mFiles.keySet()); } }
From source file:com.android.ide.eclipse.adt.internal.editors.manifest.model.UiManifestPkgAttrNode.java
License:Open Source License
/** * When the label is clicked and there's already a package name, this method * attempts to find the project matching the android package name and it attempts * to open the manifest editor./*from w w w. ja va 2 s . co m*/ * * @param package_name The android package name to find. Must not be null. */ private void displayExistingManifest(String package_name) { // Look for the first project that uses this package name for (IJavaProject project : BaseProjectHelper.getAndroidProjects(null /*filter*/)) { // check that there is indeed a manifest file. IFile manifestFile = ProjectHelper.getManifest(project.getProject()); if (manifestFile == null) { // no file? skip this project. continue; } ManifestData manifestData = AndroidManifestHelper.parseForData(manifestFile); if (manifestData == null) { // skip this project. continue; } if (package_name.equals(manifestData.getPackage())) { // Found the project. IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (win != null) { IWorkbenchPage page = win.getActivePage(); if (page != null) { try { page.openEditor(new FileEditorInput(manifestFile), ManifestEditor.ID, true, /* activate */ IWorkbenchPage.MATCH_INPUT); } catch (PartInitException e) { AdtPlugin.log(e, "Opening editor failed for %s", //$NON-NLS-1$ manifestFile.getFullPath()); } } } // We found the project; even if we failed there's no need to keep looking. return; } } }
From source file:com.android.ide.eclipse.adt.internal.editors.manifest.model.UiManifestPkgAttrNode.java
License:Open Source License
/** * Returns all the possible android package names that could be used. * The prefix is not used./*w w w. ja v a 2 s . com*/ * * {@inheritDoc} */ @Override public String[] getPossibleValues(String prefix) { TreeSet<String> packages = new TreeSet<String>(); for (IJavaProject project : BaseProjectHelper.getAndroidProjects(null /*filter*/)) { // check that there is indeed a manifest file. ManifestData manifestData = AndroidManifestHelper.parseForData(project.getProject()); if (manifestData == null) { // skip this project. continue; } packages.add(manifestData.getPackage()); } return packages.toArray(new String[packages.size()]); }
From source file:com.android.ide.eclipse.adt.internal.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. * * @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) *//*from ww w . j a v a2s.co m*/ 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 ManifestData manifestData = AndroidManifestHelper.parseForData(androidProject.getProject()); if (manifestData == null) { 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(), manifestData.getPackage(), manifestData.getPackage(), launchInfo.getLaunchAction(), apk, manifestData.getDebuggable(), manifestData.getMinSdkVersionString(), launchInfo.getLaunch(), launchInfo.getMonitor()); // Add to the list dependencies.add(delayedLaunchInfo); } return dependencies; }
From source file:com.android.ide.eclipse.adt.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 av a 2 s.co m mode = LaunchConfigDelegate.DEFAULT_TARGET_MODE; } mAutoTargetButton.setSelection(mode == TargetMode.AUTO); mManualTargetButton.setSelection(mode == TargetMode.MANUAL); mAllDevicesTargetButton.setSelection(multipleDevices); targetModeChanged(); boolean reuseLastUsedDevice; try { reuseLastUsedDevice = configuration.getAttribute(LaunchConfigDelegate.ATTR_REUSE_LAST_USED_DEVICE, false); } catch (CoreException ex) { reuseLastUsedDevice = false; } mFutureLaunchesOnSameDevice.setSelection(reuseLastUsedDevice); 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); ManifestInfo mi = ManifestInfo.get(project); final int minApiLevel = mi.getMinSdkVersion(); final String minApiCodeName = mi.getMinSdkCodeName(); mProjectMinApiVersion = new AndroidVersion(minApiLevel, minApiCodeName); } 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.android.ide.eclipse.adt.internal.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 ww .j a va 2 s. co m private void handleProjectButtonSelected() { IJavaProject project = mProjectChooserHelper.chooseJavaProject(getProjectName(), "Please select a project to launch"); if (project == null) { return; } String projectName = project.getElementName(); mProjText.setText(projectName); loadInstrumentations(project.getProject()); }
From source file:com.android.ide.eclipse.adt.internal.launch.junit.InstrumentationRunnerValidator.java
License:Open Source License
/** * Initializes the InstrumentationRunnerValidator. * * @param javaProject the {@link IJavaProject} for the Android project to validate *///from w w w . j ava 2 s . c om InstrumentationRunnerValidator(IJavaProject javaProject) { mJavaProject = javaProject; ManifestData manifestData = AndroidManifestHelper.parseForData(javaProject.getProject()); init(manifestData); }
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. *//*from w w w . j a v a 2s. co m*/ 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); }