예제 #1
0
  @Override
  public boolean equals(Object obj) {
    if (obj instanceof ProjectState) {
      return mProject.equals(((ProjectState) obj).mProject);
    } else if (obj instanceof IProject) {
      return mProject.equals(obj);
    }

    return false;
  }
  /**
   * This method will ensure that the Acceleo project has a dependency with all the project
   * containing a dynamic metamodels used in the module.
   *
   * @param module The Acceleo module
   * @param inputFile The file in the Acceleo editor
   */
  private void checkDependenciesWithDynamicMetamodels(Module module, IFile inputFile) {
    List<TypedModel> input = module.getInput();
    for (TypedModel typedModel : input) {
      List<EPackage> takesTypesFrom = typedModel.getTakesTypesFrom();
      for (EPackage ePackage : takesTypesFrom) {
        Map<String, String> dynamicEcorePackagePaths =
            AcceleoPackageRegistry.INSTANCE.getDynamicEcorePackagePaths();
        String packagePath = dynamicEcorePackagePaths.get(ePackage.getNsURI());
        if (packagePath == null) {
          return;
        }
        IPath path = new Path(packagePath);
        IFile metamodelFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        if (metamodelFile != null && metamodelFile.isAccessible()) {
          // We have found the "ecore" file for the dynamic metamodel
          IProject metamodelProject = metamodelFile.getProject();
          IProject inputProject = inputFile.getProject();
          if (!inputProject.equals(metamodelProject)) {
            // The dynamic metamodel is not in the project of the generator, let's find if
            // this dynamic metamodel is in a dependency of the project of the generator.
            boolean foundProject = false;

            AcceleoProject acceleoProject = new AcceleoProject(inputProject);
            List<IProject> recursivelyAccessibleProjects =
                acceleoProject.getRecursivelyAccessibleProjects();
            for (IProject iProject : recursivelyAccessibleProjects) {
              if (iProject.equals(metamodelProject)) {
                foundProject = true;
              }
            }

            if (!foundProject) {
              // The dynamic metamodel is not in a dependency of the current project, log a
              // warning.
              try {
                AcceleoMarkerUtils.createMarkerOnFile(
                    AcceleoMarkerUtils.WARNING_MARKER_ID,
                    inputFile,
                    0,
                    typedModel.getStartPosition(),
                    typedModel.getEndPosition(),
                    AcceleoUIMessages.getString(
                        "AcceleoCompileOperation.NoDependencyWithDynamicMetamodelProject", //$NON-NLS-1$
                        metamodelProject.getName(),
                        inputProject.getName()));
              } catch (CoreException e) {
                AcceleoUIActivator.log(e, true);
              }
            }
          }
        }
      }
    }
  }
  /*
   * Refreshes the external folders referenced on the buildpath of the given
   * source project
   */
  public void refreshReferences(IProject source, IProgressMonitor monitor) {
    IProject externalProject = getExternalFoldersProject();
    if (source.equals(externalProject)) return;
    if (!ScriptProject.hasScriptNature(source)) return;
    try {
      HashSet externalFolders =
          getExternalFolders(((ScriptProject) DLTKCore.create(source)).getResolvedBuildpath());
      if (externalFolders == null) return;
      final Iterator iterator = externalFolders.iterator();
      Job refreshJob =
          new Job(Messages.refreshing_external_folders) {
            public boolean belongsTo(Object family) {
              return family == ResourcesPlugin.FAMILY_MANUAL_REFRESH;
            }

            protected IStatus run(IProgressMonitor pm) {
              try {
                while (iterator.hasNext()) {
                  IPath externalPath = (IPath) iterator.next();
                  IFolder folder = getFolder(externalPath);
                  if (folder != null) folder.refreshLocal(IResource.DEPTH_INFINITE, pm);
                }
              } catch (CoreException e) {
                return e.getStatus();
              }
              return Status.OK_STATUS;
            }
          };
      refreshJob.schedule();
    } catch (CoreException e) {
      Util.log(e, "Exception while refreshing external project"); // $NON-NLS-1$
    }
    return;
  }
 public static IPath toFullPath(IResource resource) {
   if (resource == null) {
     return null;
   }
   IProject project = resource.getProject();
   if (!project.equals(MANAGER.getExternalSourceArchivesProject())) {
     return null;
   }
   return new Path(resource.getLocationURI().getPath());
 }
 @Override
 protected void structureChanged(IFile file, boolean added) {
   // If a plugin.xml file has been added to the project the editor should update
   if (added && ICoreConstants.PLUGIN_FILENAME_DESCRIPTOR.equalsIgnoreCase(file.getName())) {
     IProject project = getCommonProject();
     if (project == null || project.equals(file.getProject())) {
       monitorFile(file);
     }
   }
   super.structureChanged(file, added);
 }
  public void refreshReferences(IProject source, IProgressMonitor monitor) {
    IProject externalProject = getExternalSourceArchivesProject();
    if (source.equals(externalProject)) return;
    if (!CeylonNature.isEnabled(source)) return;
    Set<IPath> externalSourceArchives =
        getExternalSourceArchives(CeylonBuilder.getProjectExternalModules(source));
    if (externalSourceArchives == null) return;

    runRefreshJob(externalSourceArchives);
    return;
  }
예제 #7
0
 /* (non-Javadoc)
  * Method declared on ViewerFilter.
  */
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   if (element instanceof IPackageFragmentRoot) {
     IPackageFragmentRoot root = (IPackageFragmentRoot) element;
     if (root.isArchive()) {
       // don't filter out JARs contained in the project itself
       IResource resource = root.getResource();
       if (resource != null) {
         IProject jarProject = resource.getProject();
         IProject container = root.getJavaProject().getProject();
         return container.equals(jarProject);
       }
       return false;
     }
   }
   return true;
 }
예제 #8
0
 /* (non-Javadoc)
  * Method declared on ViewerFilter.
  */
 public boolean select(Viewer viewer, Object parentElement, Object element) {
   if (element instanceof BuildPathContainer) return false;
   if (element instanceof IProjectFragment) {
     IProjectFragment root = (IProjectFragment) element;
     if (root.isArchive()) {
       // don't filter out archives contained in the project itself
       IResource resource = root.getResource();
       if (resource != null) {
         IProject archiveProject = resource.getProject();
         IProject container = root.getScriptProject().getProject();
         return container.equals(archiveProject);
       }
       return false;
     }
   }
   return true;
 }
예제 #9
0
 public void clearCacheForProject(IProject project) {
   if (project != null) {
     // System.out.println("TypeCache.clearCacheForProject: CLEARING " + project);
     List<IType> typesToClear = new LinkedList<IType>();
     synchronized (_typeCacheEntries) {
       for (Map.Entry<IType, TypeCacheEntry> entry : _typeCacheEntries.entrySet()) {
         IResource resource = entry.getValue().getResource();
         if (resource != null && project.equals(resource.getProject())) {
           typesToClear.add(entry.getKey());
         }
       }
       for (IType typeToClear : typesToClear) {
         clearCacheForType(typeToClear);
       }
     }
   }
 }
 public IResource[] getResourcesToDelete() {
   List<IResource> resources = new ArrayList<IResource>(dependencyMap.size());
   IPath projectPath = project.getLocation();
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   for (ProjectDependency pd : dependencyMap.keySet()) {
     if (pd.getDependencyKind() == DependencyKind.Archive) {
       IPath p = pd.getPath();
       if (projectPath.isPrefixOf(p)) {
         p = p.removeFirstSegments(projectPath.segmentCount() - 1);
       }
       IFile f = root.getFile(p);
       if (f.exists() && project.equals(f.getProject())) {
         resources.add(f);
       }
     }
   }
   return resources.toArray(new IResource[0]);
 }
  /*
   * Refreshes the external folders referenced on the classpath of the given source project
   */
  public void refreshReferences(final IProject[] sourceProjects, IProgressMonitor monitor) {
    IProject externalProject = getExternalSourceArchivesProject();
    Set<IPath> externalSourceArchives = null;
    for (IProject project : sourceProjects) {
      if (project.equals(externalProject)) continue;
      if (!CeylonNature.isEnabled(project)) continue;

      Set<IPath> sourceArchivesInProject =
          getExternalSourceArchives(CeylonBuilder.getProjectExternalModules(project));

      if (sourceArchivesInProject == null || sourceArchivesInProject.size() == 0) continue;
      if (externalSourceArchives == null) externalSourceArchives = new HashSet<>();

      externalSourceArchives.addAll(sourceArchivesInProject);
    }
    if (externalSourceArchives == null) return;

    runRefreshJob(externalSourceArchives);
  }
 public ToBeBuilt removeProject(IProject project, IProgressMonitor monitor) {
   SubMonitor progress =
       SubMonitor.convert(monitor, Iterables.size(builderState.getAllResourceDescriptions()));
   ToBeBuilt result = new ToBeBuilt();
   Iterable<IResourceDescription> allResourceDescriptions =
       builderState.getAllResourceDescriptions();
   for (IResourceDescription description : allResourceDescriptions) {
     Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(description.getURI());
     boolean onlyOnThisProject = true;
     Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
     while (iterator.hasNext() && onlyOnThisProject) {
       Pair<IStorage, IProject> storage2Project = iterator.next();
       onlyOnThisProject = project.equals(storage2Project.getSecond());
     }
     if (onlyOnThisProject) result.getToBeDeleted().add(description.getURI());
     progress.worked(1);
   }
   return result;
 }
예제 #13
0
 public boolean doNeedRebuild(
     final JavaBuilderState it,
     final Procedure1<? super UnconfirmedStructuralChangesDelta> processor) {
   boolean _xblockexpression = false;
   {
     final Iterator<UnconfirmedStructuralChangesDelta> i = this.unconfirmedDeltas.iterator();
     boolean _hasNext = i.hasNext();
     boolean _while = _hasNext;
     while (_while) {
       {
         final UnconfirmedStructuralChangesDelta unconfirmed = i.next();
         boolean _and = false;
         int _buildNumber = unconfirmed.getBuildNumber();
         Integer _buildNumber_1 = it.getBuildNumber();
         boolean _lessThan = (_buildNumber < (_buildNumber_1).intValue());
         if (!_lessThan) {
           _and = false;
         } else {
           IProject _project = unconfirmed.getProject();
           IProject _project_1 = it.getProject();
           boolean _equals = _project.equals(_project_1);
           _and = (_lessThan && _equals);
         }
         if (_and) {
           i.remove();
           boolean _notEquals = (!Objects.equal(processor, null));
           if (_notEquals) {
             processor.apply(unconfirmed);
           }
         }
       }
       boolean _hasNext_1 = i.hasNext();
       _while = _hasNext_1;
     }
     int _size = this.unconfirmedDeltas.size();
     boolean _notEquals = (_size != 0);
     _xblockexpression = (_notEquals);
   }
   return _xblockexpression;
 }
예제 #14
0
  /** @see org.teiid.designer.core.workspace.ModelWorkspace#findModelProject(IResource) */
  @Override
  public ModelProject findModelProject(final IResource resource) {
    CoreArgCheck.isNotNull(resource);

    // if(!ModelerCore.hasModelNature(resource.getProject())) {
    // return null;
    // }

    IProject rsrcProject = null;
    switch (resource.getType()) {
      case IResource.FOLDER:
        rsrcProject = ((IFolder) resource).getProject();
        break;
      case IResource.FILE:
        rsrcProject = ((IFile) resource).getProject();
        break;
      case IResource.PROJECT:
        rsrcProject = (IProject) resource;
        break;
      case IResource.ROOT:
      default:
        // throw new IllegalArgumentException("Invalid resource type, {0}, for IResource {1}");
    }

    try {
      final ModelProject[] projects = getModelProjects();
      for (int ndx = projects.length; --ndx >= 0; ) {
        final ModelProject mdlProject = projects[ndx];
        if (rsrcProject != null && rsrcProject.equals(mdlProject.getResource())) {
          return mdlProject;
        }
      }
    } catch (ModelWorkspaceException e) {
      // do nothing
    }
    return null;
  }
  /**
   * SIMPLY COPIED;
   *
   * @param currentProject
   * @param containerProject
   * @param className
   * @throws CoreException
   */
  private void doProjectReferenceChange(
      IProject currentProject, IJavaProject containerProject, String className)
      throws CoreException {
    if (currentProject == null || currentProject.equals(containerProject.getProject())) {
      return;
    }

    IProjectDescription desc = currentProject.getDescription();
    IProject[] refs = desc.getReferencedProjects();
    IProject[] newRefs = new IProject[refs.length + 1];
    System.arraycopy(refs, 0, newRefs, 0, refs.length);
    newRefs[refs.length] = containerProject.getProject();
    desc.setReferencedProjects(newRefs);
    currentProject.setDescription(desc, new NullProgressMonitor());

    IPath dependsOnPath = containerProject.getProject().getFullPath();

    IJavaProject javaProject = (IJavaProject) currentProject.getNature(JavaCore.NATURE_ID);
    IClasspathEntry prjEntry = JavaCore.newProjectEntry(dependsOnPath, true);

    boolean dependsOnPresent = false;
    for (IClasspathEntry cpEntry : javaProject.getRawClasspath()) {
      if (cpEntry.equals(prjEntry)) {
        dependsOnPresent = true;
      }
    }

    if (!dependsOnPresent) {
      IClasspathEntry[] entryList = new IClasspathEntry[1];
      entryList[0] = prjEntry;
      ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
      newEntries.addAll(Arrays.asList(javaProject.getRawClasspath()));
      newEntries.addAll(Arrays.asList(entryList));
      javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), null);
    }
  }
 public static boolean isTheSourceArchiveProject(IProject project) {
   return project != null
       && project.equals(getExternalSourceArchiveManager().getExternalSourceArchivesProject());
 }
예제 #17
0
 private void processEntryChanges(
     IResourceDelta projectDelta, Map<IProject, Boolean> projectsToSave) {
   // check each resource with user-set encoding to see if it has
   // been moved/deleted or if derived state has been changed
   IProject currentProject = (IProject) projectDelta.getResource();
   Preferences projectRegularPrefs = getPreferences(currentProject, false, false, true);
   Preferences projectDerivedPrefs = getPreferences(currentProject, false, true, true);
   Map<Boolean, String[]> affectedResourcesMap = new HashMap<>();
   try {
     // no regular preferences for this project
     if (projectRegularPrefs == null) affectedResourcesMap.put(Boolean.FALSE, new String[0]);
     else affectedResourcesMap.put(Boolean.FALSE, projectRegularPrefs.keys());
     // no derived preferences for this project
     if (projectDerivedPrefs == null) affectedResourcesMap.put(Boolean.TRUE, new String[0]);
     else affectedResourcesMap.put(Boolean.TRUE, projectDerivedPrefs.keys());
   } catch (BackingStoreException e) {
     // problems with the project scope... we will miss the changes (but will log)
     String message = Messages.resources_readingEncoding;
     Policy.log(
         new ResourceStatus(
             IResourceStatus.FAILED_GETTING_CHARSET, currentProject.getFullPath(), message, e));
     return;
   }
   for (Iterator<Boolean> it = affectedResourcesMap.keySet().iterator(); it.hasNext(); ) {
     Boolean isDerived = it.next();
     String[] affectedResources = affectedResourcesMap.get(isDerived);
     Preferences projectPrefs =
         isDerived.booleanValue() ? projectDerivedPrefs : projectRegularPrefs;
     for (int i = 0; i < affectedResources.length; i++) {
       IResourceDelta memberDelta = projectDelta.findMember(new Path(affectedResources[i]));
       // no changes for the given resource
       if (memberDelta == null) continue;
       if (memberDelta.getKind() == IResourceDelta.REMOVED) {
         boolean shouldDisableCharsetDeltaJobForCurrentProject = false;
         // remove the setting for the original location - save its value though
         String currentValue = projectPrefs.get(affectedResources[i], null);
         projectPrefs.remove(affectedResources[i]);
         if ((memberDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
           IPath movedToPath = memberDelta.getMovedToPath();
           IResource resource = workspace.getRoot().findMember(movedToPath);
           if (resource != null) {
             Preferences encodingSettings =
                 getPreferences(
                     resource.getProject(), true, resource.isDerived(IResource.CHECK_ANCESTORS));
             if (currentValue == null || currentValue.trim().length() == 0)
               encodingSettings.remove(getKeyFor(movedToPath));
             else encodingSettings.put(getKeyFor(movedToPath), currentValue);
             IProject targetProject = workspace.getRoot().getProject(movedToPath.segment(0));
             if (targetProject.equals(currentProject))
               // if the file was moved inside the same project disable charset listener
               shouldDisableCharsetDeltaJobForCurrentProject = true;
             else projectsToSave.put(targetProject, Boolean.FALSE);
           }
         }
         projectsToSave.put(
             currentProject, Boolean.valueOf(shouldDisableCharsetDeltaJobForCurrentProject));
       }
     }
     if (moveSettingsIfDerivedChanged(
         projectDelta, currentProject, projectPrefs, affectedResources)) {
       // if settings were moved between preferences files disable charset listener so we don't
       // react to changes made by ourselves
       projectsToSave.put(currentProject, Boolean.TRUE);
     }
   }
 }
예제 #18
0
 public boolean isCoveredBy(BuildJob other) {
   if (other.fProject == null) {
     return true;
   }
   return fProject != null && fProject.equals(other.fProject);
 }