Java Code Examples for org.eclipse.core.resources.IFolder

The following examples show how to use org.eclipse.core.resources.IFolder. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: bonita-studio   Source File: DeleteHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected boolean selectionCanBeDeleted(IStructuredSelection selection, Repository currentRepository) {
    for (Object sel : selection.toList()) {
        if (sel instanceof IAdaptable) {
            IResource adapter = ((IAdaptable) sel).getAdapter(IResource.class);
            if (adapter != null) {
                if (Objects.equals(currentRepository.getProject(), adapter)) {
                    return false;
                }
                IRepositoryFileStore fileStore = currentRepository.getFileStore(adapter);
                if (fileStore != null && !fileStore.canBeDeleted()) {
                    return false;
                } else if (fileStore == null && currentRepository.getRepositoryStore(adapter) != null
                        && adapter instanceof IFolder) {
                    return false;
                }
            }
        } else {
            return false;
        }
    }
    return selection.size() > 0;
}
 
Example 2
Source Project: xtext-xtend   Source File: JavaClasspathTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testJavaSourceLevelMismatch() throws Exception {
	IProject project = testHelper.getProject();

	// create a fake java.util.List without type param
	IFolder folder = project.getFolder(new Path("src/java/util"));
	IResourcesSetupUtil.createFolder(folder.getFullPath());
	IFile list = folder.getFile("List.xtend");
	list.create(new StringInputStream("package java.util; class List {}"), true, null);

	IFile file = project.getFile("src/Foo.xtend");
	if (!file.exists())
		file.create(new StringInputStream(TEST_CLAZZ),
				true, null);
	IResourcesSetupUtil.cleanBuild();
	IResourcesSetupUtil.waitForBuild();
	markerAssert.assertErrorMarker(file, IssueCodes.JDK_NOT_ON_CLASSPATH);

	list.delete(true, null);
	IResourcesSetupUtil.cleanBuild();
	IResourcesSetupUtil.waitForBuild();
	markerAssert.assertNoErrorMarker(file);
}
 
Example 3
@Override
public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
	ensureLocalFileStore(IFolder.class);
	if (resource != null && !resource.exists()) {
		monitor = Policy.monitorFor(monitor);
		monitor.beginTask(MessageFormat.format("Creating folder {0}", path.lastSegment()), 100); //$NON-NLS-1$
		try {
			if ((options & EFS.SHALLOW) == 0) {
				createParentsRecursive(resource, Policy.subMonitorFor(monitor, 80));
			} else {
				Policy.subMonitorFor(monitor, 80).done();
			}
			((IFolder) resource).create(IResource.FORCE, true, Policy.subMonitorFor(monitor, 20));
		} catch (CoreException e) {
			fileNotFoundError(e, path);
		}
	}
	return this;
}
 
Example 4
Source Project: uima-uimaj   Source File: ProjectCustomizer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a folder, if it does not exist, in a given container
 * 
 * @param container
 *          an IContainer
 * @param folderName
 *          The folder name
 * @return the handle (IFolder) to the folder
 * @throws PearException
 *           If a problem occurs
 */
public static IFolder createFolder(IContainer container, String folderName) throws PearException {
  try {
    IFolder folder = container.getFolder(new Path(folderName));
    // If the folder does not exist, create and return, failure returns null
    if (!folder.exists()) {
      folder.create(true, true, null);
      return folder;
    } else {
      // return what already exisited
      return folder;
    }
  } catch (Throwable e) {
    PearException subEx = new PearException("folderName could not be created properly.", e);
    throw subEx;
  }
}
 
Example 5
Source Project: Pydev   Source File: PythonPackageWizard.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the complete package path given by the user (all filled with __init__) 
 * and returns the last __init__ module created.
 */
public static IFile createPackage(IProgressMonitor monitor, IContainer validatedSourceFolder, String packageName)
        throws CoreException {
    IFile lastFile = null;
    if (validatedSourceFolder == null) {
        return null;
    }
    IContainer parent = validatedSourceFolder;
    for (String packagePart : StringUtils.dotSplit(packageName)) {
        IFolder folder = parent.getFolder(new Path(packagePart));
        if (!folder.exists()) {
            folder.create(true, true, monitor);
        }
        parent = folder;
        IFile file = parent.getFile(new Path("__init__"
                + FileTypesPreferences.getDefaultDottedPythonExtension()));
        if (!file.exists()) {
            file.create(new ByteArrayInputStream(new byte[0]), true, monitor);
        }
        lastFile = file;
    }

    return lastFile;
}
 
Example 6
Source Project: thym   Source File: PluginContentProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	if (!(parentElement instanceof IFolder)) {
		return new Object[0];
	}
	IFolder folder = (IFolder) parentElement;
	if (folder.getProjectRelativePath().segmentCount() > 1) {// only plugins folder at the root of the project
		return new Object[0];
	}
	List<HybridPluginFolder> plugins = new ArrayList<>();
	HybridProject project = HybridProject.getHybridProject(folder.getProject());
	try {
		for (IResource member : folder.members()) {
			if (member instanceof IFolder) {
				IFolder pluginFolder = (IFolder) member;
				plugins.add(new HybridPluginFolder(pluginFolder, getPlugin(pluginFolder.getName(), project)));
			}
		}
	} catch (CoreException e) {
		HybridUI.log(IStatus.ERROR, "Error retrieving the installed plugins", e);
	}

	return plugins.toArray();
}
 
Example 7
/**
 * WAR projects: Is this resource an html or jsp page under the war directory or one of its
 * subdirectories? Legacy GWT projects: Is this resource an html file?
 *
 * @param resource
 * @return whether the resource matches the specified conditions (a servable html/jsp page).
 */
private boolean resourceIsHostPage(IResource resource) {
  IProject project = resource.getProject();

  if (WebAppUtilities.isWebApp(project)) {
    IFolder war = WebAppUtilities.getWarSrc(project);

    if (war != null) {
      if (war.getFullPath().isPrefixOf(resource.getFullPath())) {
        return ResourceUtils.hasJspOrHtmlExtension(resource);
      }
    }
  } else {
    // Legacy GWT project
    return "html".equalsIgnoreCase(resource.getFileExtension());
  }

  return false;
}
 
Example 8
/**
 * Create a source entry (including the dir structure) and add it to the raw
 * classpath.
 * 
 * @param javaProject The Java project that receives the source entry
 * @param directoryName The source directory name
 * @param outputDirectoryName The optional output location of this source
 *          directory. Pass null for the default output location.
 */
private static void addAndCreateSourceEntry(IJavaProject javaProject,
    String directoryName, String outputDirectoryName) throws CoreException {
  IFolder srcFolder = javaProject.getProject().getFolder(directoryName);
  ResourceUtils.createFolderStructure(javaProject.getProject(),
      srcFolder.getProjectRelativePath());
  
  IPath workspaceRelOutPath = null;
  if (outputDirectoryName != null) {
    // Ensure output directory exists
    IFolder outFolder = javaProject.getProject().getFolder(outputDirectoryName);
    ResourceUtils.createFolderStructure(javaProject.getProject(),
        outFolder.getProjectRelativePath());
    workspaceRelOutPath = outFolder.getFullPath();
  }
  
  JavaProjectUtilities.addRawClassPathEntry(javaProject,
      JavaCore.newSourceEntry(srcFolder.getFullPath(),
          ClasspathEntry.EXCLUDE_NONE, workspaceRelOutPath));
}
 
Example 9
Source Project: Pydev   Source File: AbstractWorkbenchTestCase.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a package structure below a source folder.
 */
protected IFile createPackageStructure(IContainer sourceFolder, String packageName, IProgressMonitor monitor)
        throws CoreException {
    IFile lastFile = null;
    if (sourceFolder == null) {
        return null;
    }
    IContainer parent = sourceFolder;
    for (String packagePart : StringUtils.dotSplit(packageName)) {
        IFolder folder = parent.getFolder(new Path(packagePart));
        if (!folder.exists()) {
            folder.create(true, true, monitor);
        }
        parent = folder;
        IFile file = parent.getFile(new Path("__init__"
                + FileTypesPreferences.getDefaultDottedPythonExtension()));
        if (!file.exists()) {
            file.create(new ByteArrayInputStream(new byte[0]), true, monitor);
        }
        lastFile = file;
    }

    return lastFile;
}
 
Example 10
Source Project: bonita-studio   Source File: Repository.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public IRepositoryFileStore getFileStore(final IResource resource) {
    if (resource == null) {
        return null;
    }
    for (final IRepositoryStore<? extends IRepositoryFileStore> store : getAllStores()) {
        IFolder container = store.getResource();
        if (Objects.equals(resource.getParent(), container)
                || Objects.equals(resource.getParent(), resource.getWorkspace().getRoot())) {
            IRepositoryFileStore fStore = store.getChild(resource.getName(), false);
            if (fStore != null) {
                return fStore;
            }
        }
    }
    return null;
}
 
Example 11
Source Project: Pydev   Source File: ScopedPreferences.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the contents of the configuration file to be used or null.
 */
private static IFile getProjectConfigFile(IProject project, String filename, boolean createPath) {
    try {
        if (project != null && project.exists()) {
            IFolder folder = project.getFolder(".settings");
            if (createPath) {
                if (!folder.exists()) {
                    folder.create(true, true, new NullProgressMonitor());
                }
            }
            return folder.getFile(filename);
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
 
Example 12
/**
 * 得到子文件
 * @param folder
 *            文件夹
 * @param fileExtension
 *            子文件后缀名
 * @param list
 *            子文件集合
 * @throws CoreException
 *             ;
 */
public static void getChildFiles(IFolder folder, String fileExtension, List<IFile> list) throws CoreException {
	if (list == null) {
		list = new ArrayList<IFile>();
	}
	if (folder.isAccessible() && folder.exists()) {
		IResource[] members = folder.members();
		for (IResource resource : members) {
			if (resource instanceof IFile && (fileExtension).equalsIgnoreCase(resource.getFileExtension())) {
				list.add((IFile) resource);
			} else if (resource instanceof IFolder) {
				getChildFiles((IFolder) resource, fileExtension, list);
			}
		}
	}
}
 
Example 13
private static void importTraceAsSymlink() throws TmfTraceImportException, CoreException {
    TraceTypeHelper helper = TmfTraceTypeUIUtils.selectTraceType(fTestFile.getAbsolutePath(), null, null);
    final boolean IS_WINDOWS = System.getProperty("os.name").contains("Windows"); //$NON-NLS-1$ //$NON-NLS-2$
    IProject project = TmfProjectRegistry.createProject(TRACE_PROJECT_NAME, null, new NullProgressMonitor());
    assertNotNull(project);
    TmfProjectElement projectElement = TmfProjectRegistry.getProject(project);
    TmfTraceFolder folder = projectElement.getTracesFolder();
    assertNotNull(folder);

    IFolder subFolder = folder.getResource().getFolder(SYMBOLIC_FOLDER_NAME);
    TraceUtils.createFolder(subFolder, new NullProgressMonitor());

    IFile file = subFolder.getFile(fTestFile.getName());
    assertNotNull(file);
    ResourceUtil.createSymbolicLink(file, new Path(fTestFile.getAbsolutePath()), !IS_WINDOWS, null);
    folder.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
    TmfTraceTypeUIUtils.setTraceType(file, helper, false);
}
 
Example 14
Source Project: tracecompass   Source File: TmfExperimentElement.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private List<IResource> getTraceResources() {
    IFolder folder = getResource();
    final List<IResource> list = new ArrayList<>();
    try {
        folder.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy resource) throws CoreException {
                /*
                 * Trace represented by a file, or a link for backward compatibility
                 */
                if (resource.getType() == IResource.FILE || resource.isLinked()) {
                    list.add(resource.requestResource());
                    /* don't visit linked folders, as they might contain files */
                    return false;
                }
                return true;
            }
        }, IResource.NONE);
    } catch (CoreException e) {
    }
    list.sort(Comparator.comparing(resource -> resource.getFullPath().toString()));
    return list;
}
 
Example 15
@Override
public boolean isRejected(IFolder folder) {
	IMavenProjectFacade mavenProjectFacade = MavenPlugin.getMavenProjectRegistry().getProject(folder.getProject());
	if (mavenProjectFacade == null) {
		return false;
	}
	IPath outputLocation = mavenProjectFacade.getOutputLocation();
	if (outputLocation == null) {
		return false;
	} else if (folder.getFullPath().equals(outputLocation)) {
		return true;
	}
	IPath testOutputLocation = mavenProjectFacade.getTestOutputLocation();
	if (testOutputLocation == null) {
		return false;
	} else if (folder.getFullPath().equals(testOutputLocation)) {
		return true;
	}
	return false;
}
 
Example 16
Source Project: google-cloud-eclipse   Source File: WebProjectUtilTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWebInfFile_dynamicWebProject() throws CoreException, IOException {
  IProject project = testProjectCreator
      .withFacets(JavaFacet.VERSION_1_7, WebFacetUtils.WEB_25).getProject();
  IFile webXml = WebProjectUtil.findInWebInf(project, new Path("web.xml"));
  assertNotNull(webXml);
  assertTrue(webXml.exists());
  IFolder webInfDir = (IFolder) webXml.getParent();

  // should be found alongside the web.xml
  IFile fooTxt =
      WebProjectUtil.createFileInWebInf(
          project, new Path("foo.txt"), asInputStream("foo"), false /*overwrite*/, null);
  assertNotNull(fooTxt);
  assertTrue(fooTxt.exists());
  assertEquals(webInfDir.getProjectRelativePath().append("foo.txt").toString(),
      fooTxt.getProjectRelativePath().toString());
  assertEquals("foo", readAsString(fooTxt));
}
 
Example 17
Source Project: gama   Source File: FileUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static IFile findExistingLinkedFile(final IFolder folder, final String name) {
	final IFile[] result = new IFile[1];
	try {
		folder.accept((IResourceVisitor) resource -> {
			if (resource.isLinked()) {
				final String p = resource.getLocation().toString();
				if (p.equals(name)) {
					result[0] = (IFile) resource;
					return false;
				}
			}
			return true;

		}, IResource.DEPTH_INFINITE, IResource.FILE);
	} catch (final CoreException e1) {
		e1.printStackTrace();
	}
	final IFile file = result[0];
	return file;
}
 
Example 18
private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException {
	ArrayList<ResourceTraversal> res= new ArrayList<ResourceTraversal>();
	IContainer container= (IContainer)pack.getResource();
	
	if (container != null) {
		res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
		if (pack.exists()) { // folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167
			Object[] nonJavaResources= pack.getNonJavaResources();
			for (int i= 0; i < nonJavaResources.length; i++) {
				Object resource= nonJavaResources[i];
				if (resource instanceof IFolder) {
					res.add(new ResourceTraversal(new IResource[] { (IResource)resource }, IResource.DEPTH_INFINITE, 0));
				}
			}
		}
	}

	return res.toArray(new ResourceTraversal[res.size()]);
}
 
Example 19
private List<IAdaptable> getFoldersAndElements(IResource[] resources) {
	List<IAdaptable> list= new ArrayList<IAdaptable>();
	for (int i= 0; i < resources.length; i++) {
		IResource resource= resources[i];

		if (resource instanceof IFolder) {
			IFolder folder= (IFolder) resource;
			IJavaElement element= JavaCore.create(folder);

			if (element instanceof IPackageFragment) {
				list.add(element);
			} else {
				list.add(folder);
			}
		}
	}
	return list;
}
 
Example 20
Source Project: thym   Source File: PlatformContentProvider.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object[] getChildren(Object parentElement) {
	if (!(parentElement instanceof IFolder)) {
		return new Object[0];
	}
	IFolder folder = (IFolder) parentElement;
	if (folder.getProjectRelativePath().segmentCount() > 1) {// only platforms folder at the root of the project
		return new Object[0];
	}
	List<HybridPlatformFolder> platformFolders = new ArrayList<>();
	try {
		HybridProject project = HybridProject.getHybridProject(folder.getProject());
		for (IResource member : folder.members()) {
			if (member instanceof IFolder) {
				IFolder platformFolder = (IFolder) member;
				platformFolders.add(
						new HybridPlatformFolder((IFolder) member, getPlatform(project, platformFolder.getName())));
			}
		}
		
	} catch (CoreException e) {
		HybridUI.log(IStatus.ERROR, "Error reading cordova platforms", e);
	}
	return platformFolders.toArray();
}
 
Example 21
@Test
public void testDisabled() throws Exception {
	IJavaProject project = createJavaProject("foo");
	participant.getBuilderPreferenceAccess().setAutoBuildEnabled(project, false);
	addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
	IFolder folder = project.getProject().getFolder("src");
	IFile file = folder.getFile("Foo" + F_EXT);
	file.create(new StringInputStream("object Foo"), true, monitor());
	build();
	IFile generatedFile = project.getProject().getFile("./src-gen/Foo.txt");
	assertFalse(generatedFile.exists());
	participant.getBuilderPreferenceAccess().setAutoBuildEnabled(project, true);
	file.touch(monitor());
	build();
	assertTrue(generatedFile.exists());
}
 
Example 22
public void testWebAppLaunchShortcutStrategy() throws CoreException,
    UnsupportedEncodingException {
  IJavaProject javaProject = getTestProject();
  ILaunchShortcutStrategy strategy = new WebAppLaunchShortcutStrategy();

  WebAppUtilities.verifyIsWebApp(javaProject.getProject());
  IFolder warFolder = WebAppUtilities.getWarSrc(javaProject.getProject());

  IResource selection = warFolder.getFile("Hello.html");
  String url = strategy.generateUrl(selection, false);
  assertTrue(url.equals("Hello.html"));

  // Now we'll add a file in a subdirectory of war.
  IFolder warSubDir = warFolder.getFolder("subdir");
  warSubDir.create(true, true, null);
  IFile otherHello = warSubDir.getFile("OtherHello.html");
  ResourceUtils.createFile(otherHello.getFullPath(), "(other hello)");

  String otherUrl = strategy.generateUrl(otherHello, false);
  assertTrue(otherUrl.equals("subdir/OtherHello.html"));
}
 
Example 23
Source Project: gwt-eclipse-plugin   Source File: ModuleFile.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether a folder is on the public path of this module. The public paths include the
 * paths explicitly declared with <code>&lt;public&gt;</code> tags and all of their descendant
 * sub-folders.
 *
 * @param folder the folder to check
 * @return <code>true</code> if this folder is on a public path, and <code>false</code> otherwise
 */
public boolean isPublicPath(IFolder folder) {
  IFolder[] publicFolders = getFolders(getPublicPaths());

  IContainer moduleContainer = getFile().getParent();
  IContainer container = folder;

  // Walk up the ancestor chain looking for a public path matching this folder
  while (container.getType() == IResource.FOLDER) {
    // If we reach the module's container, we're done searching
    if (container.equals(moduleContainer)) {
      return false;
    }

    for (IFolder publicFolder : publicFolders) {
      if (container.equals(publicFolder)) {
        return true;
      }
    }

    container = container.getParent();
  }

  return false;
}
 
Example 24
/**
 * Returns the resource handle that corresponds to the element that was created or
 * will be created.
 * @return A resource or null if the page contains illegal values.
 * @since 3.0
 */
public IResource getModifiedResource() {
	IPackageFragmentRoot root= getPackageFragmentRoot();
	if (root != null) {
		IPackageFragment pack= root.getPackageFragment(getPackageText());
		IResource packRes= pack.getResource();
		if (isCreatePackageDocumentation()) {
			if (JavaModelUtil.is50OrHigher(getJavaProject())) {
				return pack.getCompilationUnit(PACKAGE_INFO_JAVA_FILENAME).getResource();
			} else if (packRes instanceof IFolder){
				return ((IFolder) packRes).getFile(PACKAGE_HTML_FILENAME);
			}
		}

		return packRes;
	}
	return null;
}
 
Example 25
private IFolder createExperiment(String experimentName) {
    IFolder expResource = fExperimentFolderRoot.getResource();
    IWorkspaceRoot workspaceRoot = expResource.getWorkspace().getRoot();
    IPath folderPath = expResource.getFullPath().append(experimentName);
    IFolder folder = workspaceRoot.getFolder(folderPath);
    return folder;
}
 
Example 26
Source Project: dsl-devkit   Source File: CheckResourceUtil.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the name of containing package.
 *
 * @param xtextDocument
 *          the xtext document
 * @return the name of containing package
 */
public String getNameOfContainingPackage(final IXtextDocument xtextDocument) {
  IFile file = xtextDocument.getAdapter(IFile.class);
  if (file != null && file.getParent() instanceof IFolder) {
    IJavaProject javaProject = JavaCore.create(file.getProject());
    try {
      IPackageFragment myFragment = javaProject.findPackageFragment(file.getParent().getFullPath());
      return myFragment.getElementName();
    } catch (JavaModelException e) {
      LOGGER.error("Could not determine package for file of given document");
    }
  }
  return null;
}
 
Example 27
private IResource downloadFileTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {

        IFolder folder = traceFolder;
        String traceName = trace.getName();

        traceName = TmfTraceCoreUtils.validateName(traceName);

        IResource resource = folder.findMember(traceName);
        if ((resource != null) && resource.exists()) {
            String newName = fConflictHandler.checkAndHandleNameClash(resource.getFullPath(), monitor);
            if (newName == null) {
                return null;
            }
            traceName = newName;
        }
        SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
        subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, 1);

        IPath destination = folder.getLocation().addTrailingSeparator().append(traceName);
        IFileInfo info = trace.fetchInfo();
        subMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + trace.getName());
        try (InputStream in = trace.openInputStream(EFS.NONE, new NullProgressMonitor())) {
            copy(in, folder, destination, subMonitor, info.getLength());
        }
        folder.refreshLocal(IResource.DEPTH_INFINITE, null);
        return folder.findMember(traceName);
    }
 
Example 28
Source Project: n4js   Source File: AbstractOutlineWorkbenchTest.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void createProjectStructure() throws CoreException {
	final IProject project = createJSProject(getProjectName());
	IFolder folder = configureProjectWithXtext(project);
	IFolder moduleFolder = createFolder(folder, getModuleFolder());
	modelAsText = getModelAsText();
	file = createTestFile(moduleFolder, getFileName(), modelAsText);
	assertMarkers("File should have no errors", file, 0);
}
 
Example 29
Source Project: tracecompass   Source File: TmfProjectElement.java    License: Eclipse Public License 2.0 5 votes vote down vote up
static void createFolderStructure(IContainer parent) throws CoreException {
    IFolder folder = parent.getFolder(new Path(TmfTracesFolder.TRACES_RESOURCE_NAME));
    createFolder(folder);

    folder = parent.getFolder(new Path(TmfExperimentFolder.EXPER_RESOURCE_NAME));
    createFolder(folder);

    // create folder for supplementary tracing files
    folder = parent.getFolder(new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME));
    createFolder(folder);
}
 
Example 30
@After
public void deleteFilesCreatedByTest() throws Exception {
	IProject project = testHelper.getProject();
	IFolder folder = project.getFolder("src");
	folder.accept((IResource resource) -> {
		if (resource instanceof IFile)
			resource.delete(true, new NullProgressMonitor());
		return true;
	});
	syncUtil.waitForBuild(null);
}
 
Example 31
Source Project: eclipse.jdt.ls   Source File: CopyResourceChange.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public CopyResourceChange(IResource res, IContainer dest, INewNameQuery newNameQuery) {
	Assert.isTrue(res instanceof IFile || res instanceof IFolder);
	Assert.isTrue(dest instanceof IProject || dest instanceof IFolder);

	fNewNameQuery= newNameQuery;
	fSource= res;
	fTarget= dest;

	// Copy resource change isn't undoable and isn't used
	// as a redo/undo change right now.
	setValidationMethod(SAVE_IF_DIRTY);
}
 
Example 32
Source Project: thym   Source File: HybridProjectCreator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
private void createFolder(IFolder folder, IProgressMonitor monitor) throws CoreException {
    IContainer parent = folder.getParent();
    IFolder parentFolder = (IFolder)parent.getAdapter(IFolder.class);
    if ( parentFolder != null ) {
        createFolder(parentFolder, monitor);
    }
    if ( !folder.exists() ) {
        folder.create(false, true, monitor);
    }
}
 
Example 33
private Object[] addLocalEnvironment(Object parentElement) {
    IFolder parent = (IFolder) parentElement;
    IFile localEnv = parent.getFile("Local.xml");
    List<Object> children = new ArrayList<>();
    children.add(localEnv);
    children.addAll(Arrays.asList(super.getChildren(parentElement)));
    return children.toArray();
}
 
Example 34
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
          try {
              if (element instanceof IFile) {
                  IFile file= (IFile) element;
                  if (file.getName().equals(".classpath") || file.getName().equals(".project")) //$NON-NLS-1$//$NON-NLS-2$
                      return false;
              } else if (element instanceof IPackageFragmentRoot) {
                  IClasspathEntry cpe= ((IPackageFragmentRoot)element).getRawClasspathEntry();
                  if (cpe == null || cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER || cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY || cpe.getEntryKind() == IClasspathEntry.CPE_VARIABLE)
                      return false;
              } else if (element instanceof PackageFragmentRootContainer) {
              	return false;
              } else if (element instanceof IPackageFragment) {
			IPackageFragment fragment= (IPackageFragment)element;
              	if (fragment.isDefaultPackage() && !fragment.hasChildren())
              		return false;
              } else if (element instanceof IFolder) {
              	IFolder folder= (IFolder)element;
              	if (folder.getName().startsWith(".")) //$NON-NLS-1$
              		return false;
              }
          } catch (JavaModelException e) {
              JavaPlugin.log(e);
          }
          /*if (element instanceof IPackageFragmentRoot) {
              IPackageFragmentRoot root= (IPackageFragmentRoot)element;
              if (root.getElementName().endsWith(".jar") || root.getElementName().endsWith(".zip")) //$NON-NLS-1$ //$NON-NLS-2$
                  return false;
          }*/
          return /*super.select(viewer, parentElement, element) &&*/ fOutputFolderFilter.select(viewer, parentElement, element);
      }
 
Example 35
/***/
@SuppressWarnings("resource")
protected IFile doCreateTestFile(IFolder folder, String fullName, CharSequence content) throws CoreException {
	IFile file = folder.getFile(fullName);
	createFolder(folder);
	file.create(new StringInputStream(content.toString()), true, monitor());
	waitForAutoBuild();
	return file;
}
 
Example 36
private static IPath[] listAllSourcePaths() throws JavaModelException {
	Set<IPath> classpaths = new HashSet<>();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (IProject project : projects) {
		if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
			continue;
		}
		IJavaProject javaProject = JavaCore.create(project);
		if (javaProject != null && javaProject.exists()) {
			IClasspathEntry[] classpath = javaProject.getRawClasspath();
			for (IClasspathEntry entry : classpath) {
				if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
					IPath path = entry.getPath();
					if (path == null) {
						continue;
					}

					IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
					if (folder.exists() && !folder.isDerived()) {
						IPath location = folder.getLocation();
						if (location != null && !ResourceUtils.isContainedIn(location, classpaths)) {
							classpaths.add(location);
						}
					}
				}
			}
		}
	}

	return classpaths.toArray(new IPath[classpaths.size()]);
}
 
Example 37
/***/
protected void replaceFileContentAndWaitForRefresh(IFolder folder, IFile file, String newContent, long newTimestamp)
		throws CoreException, IOException {
	File fileInFilesystem = file.getLocation().toFile();
	FileWriter fileWriter = new FileWriter(fileInFilesystem);
	fileWriter.write(newContent);
	fileWriter.close();
	// We need to update the time of the file since out-of-sync is detected by timestamp on (most) OS
	fileInFilesystem.setLastModified(newTimestamp * 1000);
	folder.refreshLocal(IResource.DEPTH_INFINITE, monitor());
	waitForAutoBuild();
}
 
Example 38
/**
 * Creates a folder resource handle for the folder with the given workspace path.
 *
 * @param folderPath the path of the folder to create a handle for
 * @return the new folder resource handle
 */
private IFolder createFolderHandle(IPath folderPath) {
	if (folderPath.isValidPath(folderPath.toString()) && folderPath.segmentCount() >= 2)
		return JavaPlugin.getWorkspace().getRoot().getFolder(folderPath);
	else
		return null;
}
 
Example 39
/**
 * @since 2.17
 */
public static IFolder addSourceFolder(IJavaProject javaProject, String folderName, String[] inclusionPatterns, String[] exclusionPatterns, boolean build) throws CoreException,
		JavaModelException {
	
	IProject project = javaProject.getProject();
	IPath projectPath = project.getFullPath();
	
	deleteClasspathEntry(javaProject, projectPath);
	
	IFolder srcFolder = createSubFolder(project, folderName); //$NON-NLS-1$
	IClasspathEntry srcFolderClasspathEntry = JavaCore.newSourceEntry(srcFolder.getFullPath(), getInclusionPatterns(inclusionPatterns), getExclusionPatterns(exclusionPatterns), null);
	addToClasspath(javaProject, srcFolderClasspathEntry, build);
	return srcFolder;
}
 
Example 40
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
	if (element instanceof IFolder) {
		try {
			if (containsPackage((IFolder)element))
				return true;
			else
				return false;
		} catch (CoreException e) {
			return true;
		}
	}

	return true;
}