List of usage examples for org.eclipse.jdt.core IJavaProject getProject
IProject getProject();
IProject
on which this IJavaProject
was created. From source file:ca.mcgill.cs.swevo.ppa.ui.PPAUtil.java
License:Open Source License
public static ASTNode getSnippet(String codeSnippet, PPAOptions options, boolean isTypeBody, String requestName) {//from w w w . j a v a2 s . c om CompilationUnit cu = null; try { String ppaProjectName = getPPAProjectName(requestName); PPAJavaProjectHelper helper = new PPAJavaProjectHelper(); IJavaProject javaProject = helper.setupJavaProject(ppaProjectName); IFile newFile = PPAResourceUtil.copyJavaSourceFileSnippet(javaProject.getProject(), codeSnippet, SnippetUtil.SNIPPET_PACKAGE, SnippetUtil.SNIPPET_FILE, isTypeBody); cu = getCU(newFile, options); } catch (Exception e) { logger.error("Error while getting CU from PPA", e); } return cu; }
From source file:ca.mcgill.sable.soot.examples.NewSootExampleWizard.java
License:Open Source License
@Override public boolean performFinish() { boolean performFinish = super.performFinish(); if (performFinish) { IJavaProject newProject = (IJavaProject) getCreatedElement(); try {//from ww w .j a v a 2s . co m IClasspathEntry[] originalCP = newProject.getRawClasspath(); IClasspathEntry ajrtLIB = JavaCore.newVariableEntry( new Path(SootClasspathVariableInitializer.VARIABLE_NAME_CLASSES), new Path(SootClasspathVariableInitializer.VARIABLE_NAME_SOURCE), null); // Update the raw classpath with the new entry int originalCPLength = originalCP.length; IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1]; System.arraycopy(originalCP, 0, newCP, 0, originalCPLength); newCP[originalCPLength] = ajrtLIB; newProject.setRawClasspath(newCP, new NullProgressMonitor()); } catch (JavaModelException e) { } String templateFilePath = fromFile; InputStream is = null; FileOutputStream fos = null; try { is = SootPlugin.getDefault().getBundle().getResource(templateFilePath).openStream(); if (is == null) { new RuntimeException("Resource " + templateFilePath + " not found!").printStackTrace(); } else { IClasspathEntry[] resolvedClasspath = newProject.getResolvedClasspath(true); IClasspathEntry firstSourceEntry = null; for (IClasspathEntry classpathEntry : resolvedClasspath) { if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { firstSourceEntry = classpathEntry; break; } } if (firstSourceEntry != null) { IPath path = SootPlugin.getWorkspace().getRoot().getFile(firstSourceEntry.getPath()) .getLocation(); String srcPath = path.toString(); String newfileName = toFile; final IPath newFilePath = firstSourceEntry.getPath().append(newfileName); fos = new FileOutputStream(srcPath + File.separator + newfileName); int temp = is.read(); while (temp > -1) { fos.write(temp); temp = is.read(); } fos.close(); //refresh project newProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); final IWorkbenchPage activePage = JavaPlugin.getActivePage(); if (activePage != null) { final Display display = getShell().getDisplay(); if (display != null) { display.asyncExec(new Runnable() { public void run() { try { IResource newResource = SootPlugin.getWorkspace().getRoot() .findMember(newFilePath); IDE.openEditor(activePage, (IFile) newResource, true); } catch (PartInitException e) { JavaPlugin.log(e); } } }); } } } } } catch (Exception e) { e.printStackTrace(); } finally { try { if (is != null) is.close(); if (fos != null) fos.close(); } catch (IOException e) { } } } return performFinish; }
From source file:ca.uwaterloo.gsd.wpi.code.WpiMappingInterpreter.java
License:Open Source License
public WorkspacePluginModel getWorkspacePluginModel(IJavaProject project, IType type) { IFile pluginXml = null;/* w ww . j a va 2 s . com*/ InputStream pluginXmlInputStream = null; if (!type.isBinary() && type.getJavaProject().equals(project)) pluginXml = project.getProject().getFile("plugin.xml"); else { IJavaElement parent = type.getPackageFragment().getParent(); if (parent instanceof IPackageFragmentRoot) { IPackageFragmentRoot root = (IPackageFragmentRoot) parent; Object[] resources; try { resources = root.getNonJavaResources(); for (int i = 0; i < resources.length; i++) { if (resources[i] instanceof IFile) { IFile file = (IFile) resources[i]; if (file.getName().equals("plugin.xml")) { pluginXml = file; break; } } else if (resources[i] instanceof JarEntryFile) { JarEntryFile file = (JarEntryFile) resources[i]; if (file.getName().equals("plugin.xml")) { pluginXmlInputStream = file.getContents(); break; } } } } catch (Exception e) { e.printStackTrace(); } } } if (pluginXml != null && pluginXml.exists() || pluginXmlInputStream != null) { WorkspacePluginModel pluginModel = new WorkspacePluginModel(pluginXml, false); if (pluginModel != null) { if (pluginXmlInputStream != null) { try { pluginModel.reload(pluginXmlInputStream, false); } catch (CoreException e) { e.printStackTrace(); } } else pluginModel.load(); } return pluginModel; } return null; }
From source file:ccw.ClojureProject.java
License:Open Source License
public static List<IFolder> sourceFolders(IJavaProject jp) { List<IFolder> ret = new ArrayList<IFolder>(); try {//ww w .ja v a 2s.co m for (IPackageFragmentRoot root : jp.getAllPackageFragmentRoots()) if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { // System.err.println("SOURCE: " + root + " " + // root.getClass()); if (root.getResource() instanceof IFolder && root.getParent().getAdapter(IProject.class) == jp.getProject()) { ret.add((IFolder) root.getResource()); } } } catch (JavaModelException e) { CCWPlugin.logError(e); } return ret; }
From source file:ccw.wizards.NewClojureProjectWizard.java
License:Open Source License
private void setupJavaProjectClassPath(IJavaProject javaProject) throws CoreException { IClasspathEntry[] entriesOld = javaProject.getRawClasspath(); IClasspathEntry[] entriesNew = new IClasspathEntry[entriesOld.length + 1]; System.arraycopy(entriesOld, 0, entriesNew, 0, entriesOld.length); // Ensure a proper "src" directory is used for sources (and not the project) for (int i = 0; i < entriesOld.length; i++) { if (entriesOld[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { IFolder src = javaProject.getProject().getFolder("src"); if (!src.exists()) src.create(true, true, null); entriesNew[i] = JavaCore.newSourceEntry(src.getFullPath()); }// w ww . j a v a 2 s .co m } entriesNew[entriesOld.length] = JavaCore .newContainerEntry(Path.fromPortableString(JavaRuntime.JRE_CONTAINER)); javaProject.setRawClasspath(entriesNew, null); javaProject.save(null, true); }
From source file:ch.mlutz.plugins.t4e.container.T4eClasspathContainerInitializer.java
License:Open Source License
public void initialize(IPath containerPath, final IJavaProject project) { if (isT4eClasspathContainer(containerPath)) { IClasspathContainer container;// w w w . ja va2 s . c om final Activator plugin = Activator.getDefault(); try { container = JavaCore.getClasspathContainer(containerPath, project); } catch (JavaModelException e) { log.error("Unable to get container for " + containerPath.toString(), e); return; } // plugin.getMavenModelManager().initModels(new NullProgressMonitor()); T4eClasspathContainer t4eContainer; if (container == null) { // parse the pom.xml IProject resourceProject = project.getProject(); PomParser pomParser = new PomParser(); IFile pomFile = resourceProject.getFile("pom.xml"); List<Dependency> dependencies; if (pomFile.exists()) { try { pomParser.parse(pomFile.getContents()); } catch (UnsupportedEncodingException e) { log.warn("Unsupported encoding in pom.xml: " + e); } catch (CoreException e) { log.warn("CoreException when getting contents of pom.xml: " + e); } dependencies = pomParser.getDependencyManagement(); log.info("DependencyManagement dependencies count: " + String.valueOf(dependencies.size())); dependencies = pomParser.getDependencies(); log.info("Dependencies count: " + String.valueOf(dependencies.size())); } else { log.warn("pom.xml doesn't seem to exist."); } // add dependency management entries to T4eClasspathContainer7 List<IClasspathEntry> entryList = new ArrayList<IClasspathEntry>(); String mavenRepositoryBasePath = MavenTools.getMavenLocalRepoPath().replaceAll("\\\\", "/"); dependencies = pomParser.getDependencyManagement(); for (Dependency dependency : dependencies) { Path path = new Path( mavenRepositoryBasePath + "/" + dependency.getGroupId().replaceAll("\\.", "/") + "/" + dependency.getArtifactId() + "/" + dependency.getVersion() + "/" + dependency.getArtifactId() + "-" + dependency.getVersion() + ".jar"); entryList.add(JavaCore.newLibraryEntry(path, null, null, true)); } t4eContainer = new T4eClasspathContainer(new Path(Constants.CONTAINER_ID), (IClasspathEntry[]) entryList.toArray(new IClasspathEntry[0])); } else { t4eContainer = new T4eClasspathContainer(containerPath, container.getClasspathEntries()); } try { JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { t4eContainer }, new NullProgressMonitor()); } catch (JavaModelException e) { log.warn("Unable to set container for " + containerPath.toString(), e); return; } if (container != null) { return; } /* plugin.getBuildpathManager().scheduleUpdateClasspathContainer(project.getProject()); */ } }
From source file:ch.netcetera.eclipse.projectconfig.ui.handler.RunProjectConfigurationScriptHandler.java
License:Open Source License
/** * Gets the selected projects.//from ww w . ja va 2 s . co m * * @param selection the current selection * @return the selected projects */ private List<IProject> getProjectsFromSelection(ISelection selection) { List<IProject> projectList = new ArrayList<IProject>(); if (selection instanceof IStructuredSelection) { IStructuredSelection currentSelection = (IStructuredSelection) selection; if (!currentSelection.isEmpty()) { Iterator<IProject> iterator = currentSelection.iterator(); while (iterator.hasNext()) { IAdaptable selectedObject = iterator.next(); if (selectedObject instanceof IJavaProject) { IJavaProject javaProject = (IJavaProject) selectedObject; projectList.add(javaProject.getProject()); } else if (selectedObject instanceof IProject) { projectList.add(((IProject) selectedObject).getProject()); } } } } return projectList; }
From source file:cn.dockerfoundry.ide.eclipse.server.core.internal.debug.DebugProvider.java
License:Open Source License
/** * Returns either test sources, or non-test sources, based on a flag * setting. If nothing is found, returns empty list. *//*w w w. j ava 2 s . c o m*/ protected boolean containsDebugFiles(IJavaProject project) { try { IClasspathEntry[] entries = project.getResolvedClasspath(true); if (entries != null) { for (IClasspathEntry entry : entries) { if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath projectPath = project.getPath(); IPath relativePath = entry.getPath().makeRelativeTo(projectPath); IFolder folder = project.getProject().getFolder(relativePath); if (containsResource(folder, ".profile.d")) {//$NON-NLS-1$ return true; } } } } } catch (JavaModelException e) { DockerFoundryPlugin.logError(e); } catch (CoreException ce) { DockerFoundryPlugin.logError(ce); } return false; }
From source file:cn.ieclipse.adt.ext.helpers.ProjectHelper.java
License:Apache License
public static AndroidManifest getAndroidManifest(IJavaElement jEle) { AndroidManifest manifest = null;// w w w . j a v a2 s .c om IProject prj = null; IJavaProject jprj = jEle.getJavaProject(); // if (jEle instanceof IJavaProject) { // prj = jEle.getJavaProject().getProject(); // } else { // prj = (IProject) jEle; // } prj = jprj.getProject(); IFile file = getManifestLocation(prj); if (file != null) { try { manifest = new AndroidManifest(file.getLocation().toOSString(), jprj); } catch (Exception e) { } } return manifest; }
From source file:cn.ieclipse.adt.ext.wizards.EditComponentWizardPage.java
License:Apache License
public void setProject(IJavaProject project) { this.project = project.getProject(); intentHelper = new IntentReflectionHelper(project); }