/**
   * 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
   * @param outputLocation The location where class files are written to, <b>null</b> for project
   *     output folder
   * @return The handle to the new source container
   * @throws CoreException Creation failed
   */
  public static IPackageFragmentRoot addSourceContainer(
      IJavaProject jproject,
      String containerName,
      IPath[] inclusionFilters,
      IPath[] exclusionFilters,
      String outputLocation)
      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);

    IPath outputPath = null;
    if (outputLocation != null) {
      IFolder folder = project.getFolder(outputLocation);
      if (!folder.exists()) {
        CoreUtility.createFolder(folder, false, true, null);
      }
      outputPath = folder.getFullPath();
    }
    IClasspathEntry cpe =
        JavaCore.newSourceEntry(root.getPath(), inclusionFilters, exclusionFilters, outputPath);
    addToClasspath(jproject, cpe);
    return root;
  }
Пример #2
0
  /** OT: new method: OT specific project creation. Creates a IJavaProject. */
  public static IJavaProject createOTJavaProject(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) && !project.hasNature(JavaCore.OTJ_NATURE_ID)) {
      addNatureToProject(project, JavaCore.NATURE_ID, null);
      // add OT nature to project
      addNatureToProject(project, JavaCore.OTJ_NATURE_ID, null);
    }
    IProjectDescription description = project.getDescription();
    // add OT build spec to project
    description.setBuildSpec(OTDTPlugin.createProjectBuildCommands(description));
    project.setDescription(description, null);

    IJavaProject jproject = JavaCore.create(project);

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

    OTREContainer.initializeOTJProject(project);

    return jproject;
  }
 /**
  * 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);
 }
  /**
   * 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;
  }