Java Code Examples for org.eclipse.jdt.internal.ui.util.CoreUtility#createFolder()

The following examples show how to use org.eclipse.jdt.internal.ui.util.CoreUtility#createFolder() . 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: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Adds a source container to a IJavaProject.
 *
 * @param jproject
 *            The parent project
 * @param containerName
 *            The name of the new source container
 * @param inclusionFilters
 *            Inclusion filters to set
 * @param exclusionFilters
 *            Exclusion filters to set
 * @return The handle to the new source container
 * @throws CoreException
 *             Creation failed
 */
public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName, IPath[] inclusionFilters,
        IPath[] exclusionFilters) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IPackageFragmentRoot root = jproject.getPackageFragmentRoot(container);

    IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, null);
    addToClasspath(jproject, cpe);
    return root;
}
 
Example 2
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Creates and adds a class folder to the class path.
 *
 * @param jproject
 *            The parent project
 * @param containerName
 * @param sourceAttachPath
 *            The source attachment path
 * @param sourceAttachRoot
 *            The source attachment root path
 * @return The handle of the created root
 * @throws CoreException
 */
public static IPackageFragmentRoot addClassFolder(IJavaProject jproject, String containerName, IPath sourceAttachPath,
        IPath sourceAttachRoot) throws CoreException {
    IProject project = jproject.getProject();
    IContainer container = null;
    if (containerName == null || containerName.length() == 0) {
        container = project;
    } else {
        IFolder folder = project.getFolder(containerName);
        if (!folder.exists()) {
            CoreUtility.createFolder(folder, false, true, null);
        }
        container = folder;
    }
    IClasspathEntry cpe = JavaCore.newLibraryEntry(container.getFullPath(), sourceAttachPath, sourceAttachRoot);
    addToClasspath(jproject, cpe);
    return jproject.getPackageFragmentRoot(container);
}
 
Example 3
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a IJavaProject.
 *
 * @param projectName
 *            The name of the project
 * @param binFolderName
 *            Name of the output folder
 * @return Returns the Java project handle
 * @throws CoreException
 *             Project creation failed
 */
public static IJavaProject createJavaProject(String projectName, String binFolderName) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }

    if (!project.isOpen()) {
        project.open(null);
    }

    IPath outputLocation;
    if (binFolderName != null && binFolderName.length() > 0) {
        IFolder binFolder = project.getFolder(binFolderName);
        if (!binFolder.exists()) {
            CoreUtility.createFolder(binFolder, false, true, null);
        }
        outputLocation = binFolder.getFullPath();
    } else {
        outputLocation = project.getFullPath();
    }

    if (!project.hasNature(JavaCore.NATURE_ID)) {
        addNatureToProject(project, JavaCore.NATURE_ID, null);
    }

    IJavaProject jproject = JavaCore.create(project);

    jproject.setOutputLocation(outputLocation, null);
    jproject.setRawClasspath(new IClasspathEntry[0], null);

    return jproject;
}
 
Example 4
Source File: LoggedCreateTargetQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void createPackageFragmentRoot(IPackageFragmentRoot root) throws CoreException {
	final IJavaProject project= root.getJavaProject();
	if (!project.exists())
		createJavaProject(project.getProject());
	final IFolder folder= project.getProject().getFolder(root.getElementName());
	if (!folder.exists())
		CoreUtility.createFolder(folder, true, true, new NullProgressMonitor());
	final List<IClasspathEntry> list= Arrays.asList(project.getRawClasspath());
	list.add(JavaCore.newSourceEntry(folder.getFullPath()));
	project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), new NullProgressMonitor());
}
 
Example 5
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static IFolder ensureGeneratedSourceFolder(IProject project, String folderPath, boolean isIFolderRequired,
		boolean createFolder, IProgressMonitor monitor) throws CoreException {
	final IFolder folder = project.getFolder(Path.fromPortableString(folderPath));
	if (!folder.exists()) {
		if (createFolder) {
			CoreUtility.createFolder(folder, true, true, monitor);
		} else if (!isIFolderRequired) {
			monitor.done();
			return null;
		}
	}
	setDerived(folder);
	monitor.done();
	return folder;
}
 
Example 6
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static IFolder ensureSourceFolder(IProject project, String folderPath, boolean isIFolderRequired,
		boolean createFolder, IProgressMonitor monitor) throws CoreException {
	final IFolder folder = project.getFolder(Path.fromPortableString(folderPath));
	if (!folder.exists()) {
		if (createFolder) {
			CoreUtility.createFolder(folder, true, true, monitor);
		} else if (!isIFolderRequired) {
			monitor.done();
			return null;
		}
	}
	monitor.done();
	return folder;
}
 
Example 7
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static IFolder ensureOutputFolder(IProject project, String folderPath, boolean isIFolderRequired,
		boolean createFolder, IProgressMonitor monitor) throws CoreException {
	final IFolder folder = project.getFolder(Path.fromPortableString(folderPath));
	if (!folder.exists()) {
		if (createFolder) {
			CoreUtility.createFolder(folder, true, true, monitor);
		} else if (!isIFolderRequired) {
			monitor.done();
			return null;
		}
	}
	setDerived(folder);
	monitor.done();
	return folder;
}