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.wizards.exportgradle.ProjectSetupBuilder.java
License:Open Source License
@NonNull public String setProject(@NonNull List<IJavaProject> selectedProjects) throws CoreException { mModules.clear();/*from ww w . ja v a 2 s . com*/ // build a list of all projects that must be included. This is in case // some dependencies have not been included in the selected projects. We also include // parent projects so that the full multi-project setup is correct. // Note that if two projects are selected that are not related, both will be added // in the same multi-project anyway. try { for (IJavaProject javaProject : selectedProjects) { GradleModule module; if (javaProject.getProject().hasNature(AdtConstants.NATURE_DEFAULT)) { module = processAndroidProject(javaProject); } else { module = processJavaProject(javaProject); } mOriginalModules.add(module); } Collection<GradleModule> modules = mModules.values(); computeRootAndPaths(modules); return null; } catch (InternalException e) { return e.getMessage(); } }
From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ProjectSetupBuilder.java
License:Open Source License
@NonNull private GradleModule processAndroidProject(@NonNull IJavaProject javaProject) throws InternalException, CoreException { // get/create the module GradleModule module = createModuleOnDemand(javaProject); if (module.isConfigured()) { return module; }/* w ww. j a v a2s .co m*/ module.setType(GradleModule.Type.ANDROID); ProjectState projectState = Sdk.getProjectState(javaProject.getProject()); assert projectState != null; // add library project dependencies List<LibraryState> libraryProjects = projectState.getLibraries(); for (LibraryState libraryState : libraryProjects) { ProjectState libProjectState = libraryState.getProjectState(); if (libProjectState != null) { IJavaProject javaLib = getJavaProject(libProjectState); if (javaLib != null) { GradleModule libModule = processAndroidProject(javaLib); module.addDependency(libModule); } else { throw new InternalException(String.format( "Project %1$s is missing. Needed by %2$s.\n" + "Make sure all dependencies are opened.", libraryState.getRelativePath(), javaProject.getProject().getName())); } } else { throw new InternalException(String.format( "Project %1$s is missing. Needed by %2$s.\n" + "Make sure all dependencies are opened.", libraryState.getRelativePath(), javaProject.getProject().getName())); } } // add java project dependencies List<IJavaProject> javaDepProjects = getReferencedProjects(javaProject); for (IJavaProject javaDep : javaDepProjects) { GradleModule libModule = processJavaProject(javaDep); module.addDependency(libModule); } return module; }
From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ProjectSetupBuilder.java
License:Open Source License
@NonNull private GradleModule processJavaProject(@NonNull IJavaProject javaProject) throws InternalException, CoreException { // get/create the module GradleModule module = createModuleOnDemand(javaProject); if (module.isConfigured()) { return module; }// w w w. j a v a 2 s.c om module.setType(GradleModule.Type.JAVA); // add java project dependencies List<IJavaProject> javaDepProjects = getReferencedProjects(javaProject); for (IJavaProject javaDep : javaDepProjects) { // Java project should not reference Android project! if (javaDep.getProject().hasNature(AdtConstants.NATURE_DEFAULT)) { throw new InternalException(String.format( "Java project %1$s depends on Android project %2$s!\n" + "This is not a valid dependency", javaProject.getProject().getName(), javaDep.getProject().getName())); } GradleModule libModule = processJavaProject(javaDep); module.addDependency(libModule); } return module; }
From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ProjectSetupBuilder.java
License:Open Source License
@NonNull private static List<IJavaProject> getReferencedProjects(IJavaProject javaProject) throws JavaModelException, InternalException { List<IJavaProject> projects = Lists.newArrayList(); IClasspathEntry entries[] = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : entries) { if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE && classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { // found required project on build path String subProjectRoot = classpathEntry.getPath().toString(); IJavaProject subProject = getJavaProject(subProjectRoot); // is project available in workspace? if (subProject != null) { projects.add(subProject); } else { throw new InternalException(String.format( "Project '%s' is missing project dependency '%s' in Eclipse workspace.\n" + "Make sure all dependencies are opened.", javaProject.getProject().getName(), classpathEntry.getPath().toString())); }/*from w ww .j a v a 2 s .c om*/ } } return projects; }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator.java
License:Open Source License
/** * Adds the given folder to the project's class path. * * @param javaProject The Java Project to update. * @param sourceFolders Template Parameters. * @param monitor An existing monitor./*from w w w. j a v a2 s . c o m*/ * @throws JavaModelException if the classpath could not be set. */ private void setupSourceFolders(IJavaProject javaProject, String[] sourceFolders, IProgressMonitor monitor) throws JavaModelException { IProject project = javaProject.getProject(); // get the list of entries. IClasspathEntry[] entries = javaProject.getRawClasspath(); // remove the project as a source folder (This is the default) entries = removeSourceClasspath(entries, project); // add the source folders. for (String sourceFolder : sourceFolders) { IFolder srcFolder = project.getFolder(sourceFolder); // remove it first in case. entries = removeSourceClasspath(entries, srcFolder); entries = ProjectHelper.addEntryToClasspath(entries, JavaCore.newSourceEntry(srcFolder.getFullPath())); } javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewTestProjectCreationPage.java
License:Open Source License
/** * Callback invoked when the user edits the project text field. *///from w w w .j a va2 s. c o m private void onProjectFieldUpdated() { String project = mTestedProjectNameField.getText(); // Is this a valid project? IJavaProject[] projects = mProjectChooserHelper.getAndroidProjects(null /*javaModel*/); for (IJavaProject p : projects) { if (p.getProject().getName().equals(project)) { setExistingProject(p.getProject()); return; } } }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewTestProjectCreationPage.java
License:Open Source License
/** * Callback called when the user uses the "Browse Projects" button. *//*from ww w.j a v a2 s. c om*/ private void onProjectBrowse() { IJavaProject p = mProjectChooserHelper.chooseJavaProject(mTestedProjectNameField.getText(), null /*message*/); if (p != null) { setExistingProject(p.getProject()); mTestedProjectNameField.setText(mExistingTestedProject.getName()); } }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.TestTargetPage.java
License:Open Source License
private void initializeList() { ProjectChooserHelper helper = new ProjectChooserHelper(getShell(), null /*filter*/); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IJavaModel javaModel = JavaCore.create(workspaceRoot); IJavaProject[] androidProjects = helper.getAndroidProjects(javaModel); mProjectList.setElements(androidProjects); if (mValues.testedProject != null) { for (IJavaProject project : androidProjects) { if (project.getProject() == mValues.testedProject) { mProjectList.setSelection(new Object[] { project }); break; }/* w w w.j a v a 2 s . c o m*/ } } else { // No initial selection: force the user to choose mProjectList.setSelection(new int[0]); } }
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. * //ww w .ja v a 2 s . co 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 w w . ja v a 2s.com*/ 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); } }