Java Code Examples for org.eclipse.core.resources.IFolder#getProjectRelativePath()
The following examples show how to use
org.eclipse.core.resources.IFolder#getProjectRelativePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebAppProjectProperties.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static IPath getWarSrcDir(IProject project) { String warSrcDir = getProjectProperties(project).get(WAR_SRC_DIR, null); if (warSrcDir == null) { /* * If the property value is null, that means it was never set for this project (setWarSrcDir automatically * converts null to empty string). To handle legacy projects (pre-GPE 1.3), we'll check to see if it contains a * root folder named "war" and if does, use that as the default setting. */ IFolder defaultWar = project.getFolder(WebAppUtilities.DEFAULT_WAR_DIR_NAME); if (defaultWar.exists()) { return defaultWar.getProjectRelativePath(); } else { return null; } } else if (warSrcDir.length() == 0) { return null; } else { return new Path(warSrcDir); } }
Example 2
Source File: RenamePackageProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public IResource getRefactoredResource(IResource element) { IFolder packageFolder= (IFolder) fPackage.getResource(); if (packageFolder == null) return element; IContainer newPackageFolder= (IContainer) getNewPackage().getResource(); if (packageFolder.equals(element)) return newPackageFolder; IPath packagePath= packageFolder.getProjectRelativePath(); IPath elementPath= element.getProjectRelativePath(); if (packagePath.isPrefixOf(elementPath)) { if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) { IPath pathInPackage= elementPath.removeFirstSegments(packagePath.segmentCount()); if (element instanceof IFile) return newPackageFolder.getFile(pathInPackage); else return newPackageFolder.getFolder(pathInPackage); } } return element; }
Example 3
Source File: AppEngineStandardProjectConvertJobTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Test public void testAppEngineFacetAdded() throws CoreException, InterruptedException { IProject project = projectCreator.getProject(); IFacetedProject facetedProject = ProjectFacetsManager.create(project); Job convertJob = new AppEngineStandardProjectConvertJob(facetedProject); convertJob.schedule(); convertJob.join(); assertTrue(AppEngineStandardFacet.hasFacet(facetedProject)); // verify App Engine standard files are present IFile webXml = WebProjectUtil.findInWebInf(project, new Path("web.xml")); assertTrue(webXml.exists()); IFile appEngineWebXml = AppEngineConfigurationUtil.findConfigurationFile(project, new Path("appengine-web.xml")); assertTrue(appEngineWebXml.exists()); // verify no overlap in WEB-INF and source paths // Java 1.7 facet sets the source path to src/ which will overlap with the // default src/main/webapp used in the AppEngineStandardFacet installer IFolder webInfFolder = (IFolder) webXml.getParent(); assertEquals("WEB-INF", webInfFolder.getName()); IPath webInfPath = webInfFolder.getProjectRelativePath(); List<IPath> sourcePaths = WebProjectUtil.getJavaSourcePaths(project); for (IPath sourcePath : sourcePaths) { assertFalse(sourcePath.isPrefixOf(webInfPath)); } }
Example 4
Source File: RenamePackageProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public IResource getRefactoredResource(IResource element) { IFolder packageFolder= (IFolder) fPackage.getResource(); if (packageFolder == null) { return element; } IContainer newPackageFolder= (IContainer) getNewPackage().getResource(); if (packageFolder.equals(element)) { return newPackageFolder; } IPath packagePath= packageFolder.getProjectRelativePath(); IPath elementPath= element.getProjectRelativePath(); if (packagePath.isPrefixOf(elementPath)) { if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) { IPath pathInPackage= elementPath.removeFirstSegments(packagePath.segmentCount()); if (element instanceof IFile) { return newPackageFolder.getFile(pathInPackage); } else { return newPackageFolder.getFolder(pathInPackage); } } } return element; }
Example 5
Source File: TmfProjectRegistryTest.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
/** * Test * {@link TmfProjectRegistry#createProject(String, java.net.URI, IProgressMonitor)} * Also, test {@link TmfNavigatorContentProvider} in normal project nature case. * * @throws Exception if exception happens */ @Test public void testCreateTracingProject() throws Exception { IProgressMonitor progressMonitor = new NullProgressMonitor(); IProject project = TmfProjectRegistry.createProject(TRACING_PROJECT_NAME, null, progressMonitor); IProjectDescription desc = project.getDescription(); assertTrue(desc.hasNature(TmfProjectNature.ID)); TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true); // Supplementary folder IFolder supplFolder = projectElement.getSupplementaryFolder(); IPath path = supplFolder.getProjectRelativePath(); assertEquals(TRACING_NATURE_SUPPL_PATH, path.toOSString()); // Verify content provider for project and project model element TmfNavigatorContentProvider contentProvider = new TmfNavigatorContentProvider(); assertEquals(project.getParent(), contentProvider.getParent(project)); Object[] children = contentProvider.getChildren(project); assertEquals(2, children.length); List<Object> childrenList = new ArrayList<>(); childrenList.addAll(Arrays.asList(children[0], children[1])); // Traces folder TmfTraceFolder traceFolder = projectElement.getTracesFolder(); assertNotNull(traceFolder); String name = traceFolder.getLabelText(); assertEquals(TRACES_LABEL_TEXT, name); path = traceFolder.getResource().getProjectRelativePath(); assertEquals(TRACING_NATURE_TRACES_PATH, path.toOSString()); IFile file = traceFolder.getResource().getFile("trace"); File tmpFile = file.getLocation().toFile(); tmpFile.createNewFile(); traceFolder.getResource().refreshLocal(IResource.DEPTH_ZERO, progressMonitor); traceFolder.refresh(); assertEquals(project, contentProvider.getParent(traceFolder)); // Experiments folder TmfExperimentFolder expFolder = projectElement.getExperimentsFolder(); assertNotNull(expFolder); name = expFolder.getLabelText(); assertEquals(EXPERIMENTS_LABEL_TEXT, name); path = expFolder.getResource().getProjectRelativePath(); assertEquals(TRACING_NATURE_EXPERIMENTS_PATH, path.toOSString()); IFolder folder = expFolder.getResource().getFolder("exp"); folder.create(true, true, progressMonitor); expFolder.getResource().refreshLocal(IResource.DEPTH_ZERO, progressMonitor); expFolder.refresh(); assertEquals(project, contentProvider.getParent(expFolder)); assertTrue(childrenList.contains(expFolder)); assertTrue(childrenList.contains(traceFolder)); // Delete Traces and Experiment directory traceFolder.getResource().delete(true, progressMonitor); expFolder.getResource().delete(true, progressMonitor); projectElement.refresh(); traceFolder = projectElement.getTracesFolder(); assertNotNull(traceFolder); assertFalse(traceFolder.getResource().exists()); expFolder = projectElement.getExperimentsFolder(); assertNotNull(expFolder); assertFalse(expFolder.getResource().exists()); }
Example 6
Source File: SARLProjectConfigurator.java From sarl with Apache License 2.0 | 4 votes |
/** Configure the SARL project. * * <p>This function does the following:<ul> * <li>Add the SARL nature to the project;</li> * <li>Create the standard SARL folders if {@code createFolders} is evaluated to true;</li> * <li>Set the output configuration of the project from the * {@link SARLPreferences#setSpecificSARLConfigurationFor(IProject, IPath) general SARL configuration};</li> * <li>Reset the Java configuration in order to follow the SARL configuration, if {@code configureJabvaNature} * is evaluated to true.</li> * </ul> * * @param project the project. * @param addNatures indicates if the natures must be added to the project by calling {@link #addSarlNatures(IProject, IProgressMonitor)}. * @param configureJavaNature indicates if the Java configuration elements must be configured. * @param createFolders indicates if the folders must be created or not. * @param monitor the monitor. * @see #addSarlNatures(IProject, IProgressMonitor) * @see #configureSARLSourceFolders(IProject, boolean, IProgressMonitor) */ public static void configureSARLProject(IProject project, boolean addNatures, boolean configureJavaNature, boolean createFolders, IProgressMonitor monitor) { try { final SubMonitor subMonitor = SubMonitor.convert(monitor, 11); // Add Natures final IStatus status = Status.OK_STATUS; if (addNatures) { addSarlNatures(project, subMonitor.newChild(1)); if (status != null && !status.isOK()) { SARLEclipsePlugin.getDefault().getLog().log(status); } } // Ensure SARL specific folders. final OutParameter<IFolder[]> sourceFolders = new OutParameter<>(); final OutParameter<IFolder[]> testSourceFolders = new OutParameter<>(); final OutParameter<IFolder[]> generationFolders = new OutParameter<>(); final OutParameter<IFolder[]> testGenerationFolders = new OutParameter<>(); final OutParameter<IFolder> generationFolder = new OutParameter<>(); final OutParameter<IFolder> testGenerationFolder = new OutParameter<>(); final OutParameter<IFolder> outputFolder = new OutParameter<>(); final OutParameter<IFolder> testOutputFolder = new OutParameter<>(); ensureSourceFolders(project, createFolders, subMonitor, sourceFolders, testSourceFolders, generationFolders, testGenerationFolders, generationFolder, testGenerationFolder, outputFolder, testOutputFolder); // SARL specific configuration final IFolder testGenerationFolderFolder = testGenerationFolder.get(); final IPath testGenerationFolderPath = testGenerationFolderFolder == null ? null : testGenerationFolderFolder.getProjectRelativePath(); SARLPreferences.setSpecificSARLConfigurationFor(project, generationFolder.get().getProjectRelativePath(), testGenerationFolderPath); subMonitor.worked(1); // Create the Java project if (configureJavaNature) { if (!addNatures) { addNatures(project, subMonitor.newChild(1), JavaCore.NATURE_ID); } final IJavaProject javaProject = JavaCore.create(project); subMonitor.worked(1); // Build path BuildPathsBlock.flush( buildClassPathEntries(javaProject, sourceFolders.get(), testSourceFolders.get(), generationFolders.get(), testGenerationFolders.get(), testOutputFolder.get().getFullPath(), false, true), outputFolder.get().getFullPath(), javaProject, null, subMonitor.newChild(1)); } subMonitor.done(); } catch (CoreException exception) { SARLEclipsePlugin.getDefault().log(exception); } }