Package org.eclipse.core.resources

Examples of org.eclipse.core.resources.IProject


        workspace.run(create, null);
        return project1;
    }

    protected void addJavaNature(String projectName) throws CoreException {
        IProject project1 = root.getProject(projectName);
        IProjectDescription description = project1.getDescription();
        description.setNatureIds(new String[]{JavaCore.NATURE_ID});
        project1.setDescription(description, null);
    }
View Full Code Here


   
    private IProject createNewProject() {
        if (newProject != null) {
            return newProject;
        }
        final IProject newProjectHandle = mainPage.getProjectHandle();

        // get a project descriptor
        IPath newPath = null;
        if (!mainPage.useDefaults())
            newPath = mainPage.getLocationPath();

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IProjectDescription description = workspace
                .newProjectDescription(newProjectHandle.getName());
        description.setLocation(newPath);
        addNatures(description);

        // create the new project operation
        WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
            protected void execute(IProgressMonitor monitor)
                    throws CoreException {
                createProject(description, newProjectHandle, monitor);
            }
        };

        // run the new project creation operation
        try {
            getContainer().run(true, true, op);
        } catch (InterruptedException e) {
            return null;
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (t instanceof CoreException) {
                if (((CoreException) t).getStatus().getCode() == IResourceStatus.CASE_VARIANT_EXISTS) {
                    MessageDialog.openError(getShell(),
                        "NewProject.errorMessage",
                        "NewProject.caseVariantExistsError"
                                + newProjectHandle.getName());
                } else {
                    ErrorDialog.openError(getShell(),
                        "NewProject.errorMessage", null, // no special message
                        ((CoreException) t).getStatus());
                }
View Full Code Here

           
            // also add classpath of required projects
            String[] names = project.getRequiredProjectNames();
            for ( int i = 0; i < names.length; i++ ) {
                String projectName = names[i];
                IProject reqProject = project.getProject().getWorkspace()
                    .getRoot().getProject(projectName);
                if (reqProject != null) {
                    IJavaProject reqJavaProject = JavaCore.create(reqProject);
                    pathElements.addAll(getProjectClassPathURLs(reqJavaProject));
                }
View Full Code Here

    public static final String BUILDER_ID = "org.drools.ide.droolsbuilder";

    protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
            throws CoreException {
        IProject currentProject = getProject();
        if (currentProject == null || !currentProject.isAccessible()) {
            return new IProject[0];
        }
        try {
            if (monitor != null && monitor.isCanceled())
                throw new OperationCanceledException();

            if (kind == IncrementalProjectBuilder.FULL_BUILD) {
                fullBuild(monitor);
            } else {
                IResourceDelta delta = getDelta(getProject());
                if (delta == null) {
                    fullBuild(monitor);
                } else {
                    incrementalBuild(delta, monitor);
                }
            }
        } catch (CoreException e) {
            IMarker marker = currentProject.createMarker(IDroolsModelMarker.DROOLS_MODEL_PROBLEM_MARKER);
            marker.setAttribute(IMarker.MESSAGE, "Error when trying to build Drools project: " + e.getLocalizedMessage());
            marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
        }
        return null;
    }
View Full Code Here

   
    String[] oldRequired = this.oldResolvedClasspath == null ? CharOperation.NO_STRINGS : this.project.projectPrerequisites(this.oldResolvedClasspath);
    IClasspathEntry[] newResolvedClasspath = this.project.getResolvedClasspath();
    String[] newRequired = this.project.projectPrerequisites(newResolvedClasspath);
    try {
      IProject projectResource = this.project.getProject();
      IProjectDescription description = projectResource.getDescription();
      
      IProject[] projectReferences = description.getDynamicReferences();
     
      HashSet oldReferences = new HashSet(projectReferences.length);
      for (int i = 0; i < projectReferences.length; i++){
        String projectName = projectReferences[i].getName();
        oldReferences.add(projectName);
      }
      HashSet newReferences = (HashSet)oldReferences.clone();
 
      for (int i = 0; i < oldRequired.length; i++){
        String projectName = oldRequired[i];
        newReferences.remove(projectName);
      }
      for (int i = 0; i < newRequired.length; i++){
        String projectName = newRequired[i];
        newReferences.add(projectName);
      }
 
      Iterator iter;
      int newSize = newReferences.size();
     
      checkIdentity: {
        if (oldReferences.size() == newSize){
          iter = newReferences.iterator();
          while (iter.hasNext()){
            if (!oldReferences.contains(iter.next())){
              break checkIdentity;
            }
          }
          return;
        }
      }
      String[] requiredProjectNames = new String[newSize];
      int index = 0;
      iter = newReferences.iterator();
      while (iter.hasNext()){
        requiredProjectNames[index++] = (String)iter.next();
      }
      Util.sort(requiredProjectNames); // ensure that if changed, the order is consistent
     
      IProject[] requiredProjectArray = new IProject[newSize];
      IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot();
      for (int i = 0; i < newSize; i++){
        requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]);
      }
      description.setDynamicReferences(requiredProjectArray);
      projectResource.setDescription(description, null);
 
    } catch(CoreException e){
      if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(this.project.getElementName()))
        throw new JavaModelException(e);
    }
View Full Code Here

    ArrayList collector = new ArrayList();
    for (int i = 0, max = elements.length; i < max; i++) {
      // collect all the java project
      IJavaElement element = elements[i];
      IJavaProject javaProject = element.getJavaProject();
      IProject project = javaProject.getProject();
      State state = null;
      State currentState = (State) projectsStates.get(project);
      if (currentState != null) {
        state = currentState;
      } else {
        state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(project, null);
        if (state != null) {
          projectsStates.put(project, state);
        }
      }
      if (state == null) continue;
      if (element.getElementType() == IJavaElement.JAVA_PROJECT) {
        IPackageFragmentRoot[] roots = null;
        try {
          roots = javaProject.getPackageFragmentRoots();
        } catch (JavaModelException e) {
          // ignore
        }
        if (roots == null) continue;
        IRegion region2 = JavaCore.newRegion();
        for (int j = 0; j < roots.length; j++) {
          region2.add(roots[j]);
        }
        IResource[] res = getGeneratedResources(region2, includesNonJavaResources);
        for (int j = 0, max2 = res.length; j < max2; j++) {
          collector.add(res[j]);
        }
        continue;
      }
      IPath outputLocation = null;
      try {
        outputLocation = javaProject.getOutputLocation();
      } catch (JavaModelException e) {
        // ignore
      }
      IJavaElement root = element;
      while (root != null && root.getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT) {
        root = root.getParent();
      }
      if (root == null) continue;
      IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) root;
      int rootPathSegmentCounts = packageFragmentRoot.getPath().segmentCount();
      try {
        IClasspathEntry entry = packageFragmentRoot.getRawClasspathEntry();
        IPath entryOutputLocation = entry.getOutputLocation();
        if (entryOutputLocation != null) {
          outputLocation = entryOutputLocation;
        }
      } catch (JavaModelException e) {
        e.printStackTrace();
      }
      if (outputLocation == null) continue;
      IContainer container = (IContainer) project.getWorkspace().getRoot().findMember(outputLocation);
      switch(element.getElementType()) {
        case IJavaElement.COMPILATION_UNIT :
          // get the .class files generated when this element was built
          ICompilationUnit unit = (ICompilationUnit) element;
          getGeneratedResource(unit, container, state, rootPathSegmentCounts, collector);
View Full Code Here

       
        // recurse in project to get all its indirect exports (only consider exported entries from there on)       
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
          IResource member = workspaceRoot.findMember(entry.getPath());
          if (member != null && member.getType() == IResource.PROJECT){ // double check if bound to project (23977)
            IProject projRsc = (IProject) member;
            if (JavaProject.hasJavaNature(projRsc)) {
              JavaProject javaProject = (JavaProject) JavaCore.create(projRsc);
              javaProject.computeExpandedClasspath(
                combinedEntry,
                rootIDs,
View Full Code Here

        if (!retrieveExportedRoots) return;
        if (referringEntry != null && !resolvedEntry.isExported()) return;

        IResource member = workspaceRoot.findMember(entryPath);
        if (member != null && member.getType() == IResource.PROJECT){// double check if bound to project (23977)
          IProject requiredProjectRsc = (IProject) member;
          if (JavaProject.hasJavaNature(requiredProjectRsc)){ // special builder binary output
            rootIDs.add(rootID);
            JavaProject requiredProject = (JavaProject)JavaCore.create(requiredProjectRsc);
            requiredProject.computePackageFragmentRoots(
              requiredProject.getResolvedClasspath(),
View Full Code Here

   *    the given classpath and output location are compatible, otherwise a status
   *    object indicating what is wrong with the classpath or output location
   */
  public static IJavaModelStatus validateClasspath(IJavaProject javaProject, IClasspathEntry[] rawClasspath, IPath projectOutputLocation) {

    IProject project = javaProject.getProject();
    IPath projectPath= project.getFullPath();
    String projectName = javaProject.getElementName();

    /* validate output location */
    if (projectOutputLocation == null) {
      return new JavaModelStatus(IJavaModelStatusConstants.NULL_PATH);
View Full Code Here

        break;

      // project entry check
      case IClasspathEntry.CPE_PROJECT :
        if (path.isAbsolute() && path.segmentCount() == 1) {
          IProject prereqProjectRsc = workspaceRoot.getProject(path.segment(0));
          IJavaProject prereqProject = JavaCore.create(prereqProjectRsc);
          try {
            if (!prereqProjectRsc.exists() || !prereqProjectRsc.hasNature(JavaCore.NATURE_ID)){
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundProject, new String[] {path.segment(0), projectName}));
            }
            if (!prereqProjectRsc.isOpen()){
              return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_closedProject, new String[] {path.segment(0)}));
            }
            if (!JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
              long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
              long prereqProjectTargetJDK = CompilerOptions.versionToJdkLevel(prereqProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
View Full Code Here

TOP

Related Classes of org.eclipse.core.resources.IProject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.