List of usage examples for org.eclipse.jdt.core IJavaProject getRawClasspath
IClasspathEntry[] getRawClasspath() throws JavaModelException;
From source file:in.cypal.studio.gwt.core.facet.UpgradeDelegate.java
License:Apache License
private void removeGWTEntries(IProject project, IProgressMonitor monitor) throws JavaModelException { monitor = Util.getNonNullMonitor(monitor); monitor.beginTask("Removing old entries...", 2); try {/* ww w. j av a 2s. c o m*/ IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); IClasspathEntry[] oldClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : oldClasspath) { if (!classpathEntry.getPath().lastSegment().startsWith("gwt")) classpathEntries.add(classpathEntry); } javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), new SubProgressMonitor(monitor, 1)); IPath webContent = ComponentCore.createComponent(project).getRootFolder().getProjectRelativePath(); IFile theLink = project.getFile(webContent.append("WEB-INF").append("lib").append("gwt-servlet.jar")); theLink.delete(true, new SubProgressMonitor(monitor, 1)); } catch (CoreException e) { Activator.logException(e); } finally { monitor.done(); } }
From source file:in.cypal.studio.gwt.samples.wizards.SamplesWizard.java
License:Apache License
public IClasspathEntry ensureSourceFolder(IJavaProject javaProject) throws JavaModelException { IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); IClasspathEntry sampleSrc = null;// ww w . j a v a 2 s.c o m for (int i = 0; i < classpathEntries.length; i++) { if (classpathEntries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;// we are interested only in source folders String folderName = classpathEntries[i].getPath().lastSegment(); if (folderName.equals(SAMPLE_SRC)) { sampleSrc = classpathEntries[i]; break; } } if (sampleSrc == null) { addSourceFolder(javaProject, classpathEntries); } return sampleSrc; }
From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java
License:Open Source License
private List<ICompilationUnit> getCompilationUnits() throws JavaModelException { List<ICompilationUnit> compilationUnits = new ArrayList<ICompilationUnit>(); IJavaProject javaProject = JavaCore.create(project); IClasspathEntry[] entries = javaProject.getRawClasspath(); for (IClasspathEntry entry : entries) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry); for (IPackageFragmentRoot root : roots) { if (root.isArchive()) { continue; }//from w ww . j a v a2 s.co m IJavaElement[] children = root.getChildren(); for (IJavaElement child : children) { if (child instanceof IPackageFragment) { IPackageFragment packageFragment = (IPackageFragment) child; ICompilationUnit[] cus = packageFragment.getCompilationUnits(); for (ICompilationUnit cu : cus) { cleanupMarkers(cu.getUnderlyingResource()); compilationUnits.add(cu); } } } } } } return compilationUnits; }
From source file:info.evanchik.eclipse.felix.FelixLaunchConfiguration.java
License:Open Source License
/** * Gets the path to the specified bundle in the following manner:<br> * <br>//from w ww . jav a 2s. c om * <ol> * <li>If the bundle is found in the Plug-in Registry and is not a workspace * resource, return the path to the bundle</li> * <li>If the bundle is in the Plug-in Registry but is a workspace resource, * return the path to the path to the output location that contains the * package specified ({@code project/output folder})</li> * <li>If the bundle is not found in the Plug-in Registry then look for it * in the OSGi platform</li> * </ol> * * @param bundleName * the symbolic name of the bundle * @param packageName * the name of the package used to locate the output folder * @return a fully qualified path to the requested bundle or null if it does * not exist * @throws CoreException */ private static String getBundlePath(String bundleName, String packageName) throws CoreException { final IPluginModelBase model = PluginRegistry.findModel(bundleName); if (model != null) { final IResource resource = model.getUnderlyingResource(); if (!isWorkspaceModel(model)) { return model.getInstallLocation(); } final IProject project = resource.getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { final IJavaProject jProject = JavaCore.create(project); final IClasspathEntry[] entries = jProject.getRawClasspath(); for (int i = 0; i < entries.length; i++) { final int kind = entries[i].getEntryKind(); if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) { final IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]); for (int j = 0; j < roots.length; j++) { if (roots[j].getPackageFragment(packageName).exists()) { // if source folder, find the output folder if (kind == IClasspathEntry.CPE_SOURCE) { IPath path = entries[i].getOutputLocation(); if (path == null) { path = jProject.getOutputLocation(); } path = path.removeFirstSegments(1); return project.getLocation().append(path).toOSString(); } // else if is a library jar, then get the // location of the jar itself final IResource jar = roots[j].getResource(); if (jar != null) { return jar.getLocation().toOSString(); } } } } } } } final Bundle bundle = Platform.getBundle(bundleName); if (bundle != null) { try { URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$ url = FileLocator.toFileURL(url); String path = url.getFile(); if (path.startsWith("file:")) { //$NON-NLS-1$ path = path.substring(5); } path = new File(path).getAbsolutePath(); if (path.endsWith("!")) { //$NON-NLS-1$ path = path.substring(0, path.length() - 1); } return path; } catch (IOException e) { } } return null; }
From source file:io.mapzone.ide.build.BuildRunner.java
License:Open Source License
protected void refreshWorkspace(IProgressMonitor monitor) throws CoreException { monitor.beginTask("Refresh workspace", IProgressMonitor.UNKNOWN); File root = workspace.getRoot().getRawLocation().toFile(); for (File f : root.listFiles()) { if (f.isDirectory() && !f.getName().startsWith(".")) { //IProject project = workspace.getRoot().getProject( f.getName() ); IProjectDescription description = workspace.loadProjectDescription( new Path(f.getAbsolutePath()).append(IProjectDescription.DESCRIPTION_FILE_NAME)); IProject project = workspace.getRoot().getProject(description.getName()); if (!project.exists()) { project.create(description, submon(monitor, 1)); }// w w w .j a v a 2 s .co m project.open(submon(monitor, 1)); IJavaProject javaProject = JavaCore.create(project); if (javaProject.exists()) { javaProject.makeConsistent(submon(monitor, 1)); for (IClasspathEntry entry : javaProject.getRawClasspath()) { log.info(" Classpath entry: " + entry); } } // IOverwriteQuery overwriteQuery = new IOverwriteQuery() { // public String queryOverwrite(String file) { return ALL; } // }; // ImportOperation importOperation = new ImportOperation( // project.getFullPath(), new File( baseDir ), FileSystemStructureProvider.INSTANCE, overwriteQuery ); // importOperation.setCreateContainerStructure( false ); // importOperation.run( new NullProgressMonitor() ); } } monitor.done(); }
From source file:io.sarl.eclipse.wizards.newfile.NewSarlFileWizardPage.java
License:Apache License
private static IPath determinePackageName(IPath path) { if (path != null) { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); try {//from w w w.j a va2s. c om if (project != null && project.hasNature(JavaCore.NATURE_ID)) { final IJavaProject javaProject = JavaCore.create(project); for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getPath().isPrefixOf(path)) { return path.removeFirstSegments(entry.getPath().segmentCount()); } } } } catch (Exception e) { // Ignore the exceptions since they are not useful (hopefully) } } return null; }
From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java
License:Apache License
private static boolean hasSourcePath(IJavaProject javaProject, IPath path) { if (path != null) { final IPath pathInProject = javaProject.getProject().getFullPath().append(path); try {/*from w ww .ja v a 2 s . co m*/ for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE && pathInProject.equals(entry.getPath())) { return true; } } } catch (Throwable exception) { // } } return false; }
From source file:io.sarl.eclipse.wizards.newproject.NewSarlProjectWizard.java
License:Apache License
private static String buildInvalidOutputPathMessageFragment(IJavaProject javaProject) { final StringBuilder sourceFolders = new StringBuilder(); try {//from w w w . ja va 2s .c om for (final IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourceFolders.append("\t"); //$NON-NLS-1$ sourceFolders.append(entry.getPath().toOSString()); sourceFolders.append("\n"); //$NON-NLS-1$ } } } catch (Throwable exception) { // } return sourceFolders.toString(); }
From source file:io.takari.m2e.lifecycle.test.LifecycleBasicTest.java
License:Open Source License
private IClasspathEntry getJREContainer(IJavaProject jproject) throws JavaModelException { for (IClasspathEntry cpe : jproject.getRawClasspath()) { if (JavaRuntime.JRE_CONTAINER.equals(cpe.getPath().segment(0))) { return cpe; }/*from w ww. j a v a 2 s.c om*/ } return null; }
From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java
License:Apache License
private void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { if (project == null) { throw new IllegalStateException("Project must be created before giving it a Java nature"); }//w w w .j a v a 2 s . com final IFolder repoLink = createRepoLink(monitor, project, repoPath); IFile classpath = repoLink.getFile("development/ide/eclipse/.classpath"); IFile classpathDestination = project.getFile(".classpath"); if (classpathDestination.exists()) { classpathDestination.delete(true, monitor); } classpath.copy(classpathDestination.getFullPath(), true, monitor); final IProjectDescription description = project.getDescription(); final String[] natures = description.getNatureIds(); final String[] newNatures = Arrays.copyOf(natures, natures.length + 1); newNatures[natures.length] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); final IJavaProject javaProject = JavaCore.create(project); @SuppressWarnings("rawtypes") final Map options = javaProject.getOptions(true); // Compliance level need to be 1.6 JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options); javaProject.setOptions(options); IClasspathEntry[] classPath = mangleClasspath(javaProject.getRawClasspath(), project, repoLink); javaProject.setRawClasspath(classPath, monitor); javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor); }