@Override
  void assertNewConversationFilesAreCreatedSuccessfully(AdaptableRegistry data) {
    IEclipsePreferences seamFacetPrefs = SeamCorePlugin.getSeamPreferences(earProject);
    SeamProjectsSet seamPrjSet = new SeamProjectsSet(earProject);

    String sessionBeanPackagePath = getPackagePath(getSessionBeanPackageName(seamFacetPrefs));

    IContainer seamProjectSrcActionFolder = seamPrjSet.getActionFolder();
    IContainer seamProjectWebContentFolder = seamPrjSet.getViewsFolder();

    String seamPageName = data.getValue(ISeamParameter.SEAM_PAGE_NAME);
    String seamLocalInterfaceName = data.getValue(ISeamParameter.SEAM_LOCAL_INTERFACE_NAME);
    String seamBeanName = data.getValue(ISeamParameter.SEAM_BEAN_NAME);

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_SRC_ACTION + "}/
    //		${" + ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/
    //		${" + ISeamParameter.SEAM_BEAN_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    // //$NON-NLS-4$

    IResource beanJava =
        seamProjectSrcActionFolder.findMember(
            sessionBeanPackagePath + "/" + seamBeanName + ".java");
    assertResourceIsCreatedAndHasNoProblems(
        beanJava,
        seamProjectSrcActionFolder.toString()
            + "/"
            + sessionBeanPackagePath
            + "/"
            + seamBeanName
            + ".java");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_SRC_ACTION + "}/
    //		${" + ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/
    //		${" + ISeamParameter.SEAM_LOCAL_INTERFACE_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$
    // //$NON-NLS-3$ //$NON-NLS-4$

    IResource localInterfaceJava =
        seamProjectSrcActionFolder.findMember(
            sessionBeanPackagePath + "/" + seamLocalInterfaceName + ".java");
    assertResourceIsCreatedAndHasNoProblems(
        localInterfaceJava,
        seamProjectSrcActionFolder.toString()
            + "/"
            + sessionBeanPackagePath
            + "/"
            + seamLocalInterfaceName
            + ".java");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_WEBCONTENT_PATH + "}/
    //		${" + ISeamParameter.SEAM_PAGE_NAME +"}.xhtml",	 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IResource seamPageNameXhtml = seamProjectWebContentFolder.findMember(seamPageName + ".xhtml");
    assertResourceIsCreatedAndHasNoProblems(
        seamPageNameXhtml, seamProjectWebContentFolder.toString() + "/" + seamPageName + ".xhtml");
  }
 /**
  * Possible failures:
  *
  * <ul>
  *   <li>NO_ELEMENTS_TO_PROCESS - the root supplied to the operation is <code>null</code>.
  *   <li>INVALID_NAME - the name provided to the operation is <code>null</code> or is not a valid
  *       script folder name.
  *   <li>READ_ONLY - the root provided to this operation is read only.
  *   <li>NAME_COLLISION - there is a pre-existing resource (file) with the same name as a folder
  *       in the script folder's hierarchy.
  *   <li>ELEMENT_NOT_PRESENT - the underlying resource for the root is missing
  * </ul>
  *
  * @see IScriptModelStatus
  * @see ScriptConventions
  */
 @Override
 public IModelStatus verify() {
   if (getParentElement() == null) {
     return new ModelStatus(IModelStatusConstants.NO_ELEMENTS_TO_PROCESS);
   }
   IPath packageName = this.pkgName == null ? null : this.pkgName.append("."); // $NON-NLS-1$
   String packageNameValue = null;
   if (packageName != null) {
     packageNameValue = packageName.toOSString();
   }
   if (this.pkgName == null
       || (this.pkgName.segmentCount() > 0
           && !Util.isValidFolderNameForPackage(
               (IContainer) getParentElement().getResource(), packageName.toString()))) {
     return new ModelStatus(IModelStatusConstants.INVALID_NAME, packageNameValue);
   }
   IProjectFragment root = (IProjectFragment) getParentElement();
   if (root.isReadOnly()) {
     return new ModelStatus(IModelStatusConstants.READ_ONLY, root);
   }
   IContainer parentFolder = (IContainer) root.getResource();
   int i;
   for (i = 0; i < this.pkgName.segmentCount(); i++) {
     IResource subFolder = parentFolder.findMember(this.pkgName.segment(i));
     if (subFolder != null) {
       if (subFolder.getType() != IResource.FOLDER) {
         return new ModelStatus(
             IModelStatusConstants.NAME_COLLISION,
             Messages.bind(Messages.status_nameCollision, subFolder.getFullPath().toString()));
       }
       parentFolder = (IContainer) subFolder;
     }
   }
   return ModelStatus.VERIFIED_OK;
 }
  public Object getSourceElement(IStackFrame stackFrame) {
    if (stackFrame instanceof ScriptStackFrame) {
      ScriptStackFrame sf = (ScriptStackFrame) stackFrame;
      URI uri = sf.getFileName();

      String pathname = uri.getPath();
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
        pathname = pathname.substring(1);
      }

      File file = new File(pathname);

      IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
      IContainer container = root.getContainerForLocation(new Path(file.getParent()));

      if (container != null) {
        IResource resource = container.findMember(file.getName());

        if (resource instanceof IFile) {
          return (IFile) resource;
        }
      } else {
        return file;
      }
    }

    return null;
  }
  public static IPath[] chooseExclusionPattern(
      Shell shell,
      IContainer currentSourceFolder,
      String title,
      String message,
      IPath initialPath,
      boolean multiSelection) {
    Class[] acceptedClasses = new Class[] {IFolder.class, IFile.class};
    ISelectionStatusValidator validator =
        new TypedElementSelectionValidator(acceptedClasses, multiSelection);
    ViewerFilter filter = new TypedViewerFilter(acceptedClasses);

    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();

    IResource initialElement = null;
    if (initialPath != null) {
      IContainer curr = currentSourceFolder;
      int nSegments = initialPath.segmentCount();
      for (int i = 0; i < nSegments; i++) {
        IResource elem = curr.findMember(initialPath.segment(i));
        if (elem != null) {
          initialElement = elem;
        }
        if (elem instanceof IContainer) {
          curr = (IContainer) elem;
        } else {
          break;
        }
      }
    }

    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, lp, cp);
    dialog.setTitle(title);
    dialog.setValidator(validator);
    dialog.setMessage(message);
    dialog.addFilter(filter);
    dialog.setInput(currentSourceFolder);
    dialog.setInitialSelection(initialElement);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    dialog.setHelpAvailable(false);

    if (dialog.open() == Window.OK) {
      Object[] objects = dialog.getResult();
      int existingSegments = currentSourceFolder.getFullPath().segmentCount();

      IPath[] resArr = new IPath[objects.length];
      for (int i = 0; i < objects.length; i++) {
        IResource currRes = (IResource) objects[i];
        IPath path = currRes.getFullPath().removeFirstSegments(existingSegments).makeRelative();
        if (currRes instanceof IContainer) {
          path = path.addTrailingSeparator();
        }
        resArr[i] = path;
      }
      return resArr;
    }
    return null;
  }
Пример #5
0
 protected void runPubJob(IContainer container) {
   if (container.findMember(DartCore.PUBSPEC_FILE_NAME) != null) {
     RunPubJob runPubJob = new RunPubJob(container, command, false);
     runPubJob.schedule();
   } else {
     MessageDialog.openError(
         getShell(), ActionMessages.RunPubAction_fail, ActionMessages.RunPubAction_fileNotFound);
   }
 }
Пример #6
0
	private IFile getFileForPathImpl(IPath path, IProject project) {
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		if (path.isAbsolute()) {
			IFile c = root.getFileForLocation(path);
			return c;
		}
		if (project != null && project.exists()) {
			ICProject cproject = CoreModel.getDefault().create(project);
			if (cproject != null) {
				try {
					ISourceRoot[] roots = cproject.getAllSourceRoots();
					for (ISourceRoot sourceRoot : roots) {
						IResource r = sourceRoot.getResource();
						if (r instanceof IContainer) {
							IContainer parent = (IContainer) r;
							IResource res = parent.findMember(path);
							if (res != null && res.exists() && res instanceof IFile) {
								IFile file = (IFile) res;
								return file;
							}
						}
					}

					IOutputEntry entries[] = cproject.getOutputEntries();
					for (IOutputEntry pathEntry : entries) {
						IPath p = pathEntry.getPath();
						IResource r = root.findMember(p);
						if (r instanceof IContainer) {
							IContainer parent = (IContainer) r;
							IResource res = parent.findMember(path);
							if (res != null && res.exists() && res instanceof IFile) {
								IFile file = (IFile) res;
								return file;
							}
						}
					}
					
				} catch (CModelException _) {
					Activator.getDefault().getLog().log(_.getStatus());
				}
			}
		}
		return null;
	}
Пример #7
0
  private void map(final RepositoryMapping m) {
    final IResource r;
    final File git;
    final IResource dotGit;
    IContainer c = null;

    m.clear();
    r = getProject().findMember(m.getContainerPath());
    if (r instanceof IContainer) {
      c = (IContainer) r;
    } else if (r != null) {
      c = Utils.getAdapter(r, IContainer.class);
    }

    if (c == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    m.setContainer(c);

    IPath absolutePath = m.getGitDirAbsolutePath();
    if (absolutePath == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    git = absolutePath.toFile();
    if (!git.isDirectory() || !new File(git, "config").isFile()) { // $NON-NLS-1$
      logAndUnmapGoneMappedResource(m);
      return;
    }

    try {
      m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git));
    } catch (IOException ioe) {
      logAndUnmapGoneMappedResource(m);
      return;
    }

    m.fireRepositoryChanged();

    trace(
        "map " //$NON-NLS-1$
            + c
            + " -> " //$NON-NLS-1$
            + m.getRepository());
    try {
      c.setSessionProperty(MAPPING_KEY, m);
    } catch (CoreException err) {
      Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err);
    }

    dotGit = c.findMember(Constants.DOT_GIT);
    if (dotGit != null && dotGit.getLocation().toFile().equals(git)) {
      protect(dotGit);
    }
  }
 /*
  * Get the resources for the given resource names
  */
 public IResource[] getResources(IContainer container, String[] hierarchy) throws CoreException {
   IResource[] resources = new IResource[hierarchy.length];
   for (int i = 0; i < resources.length; i++) {
     resources[i] = container.findMember(hierarchy[i]);
     if (resources[i] == null) {
       resources[i] = buildResources(container, new String[] {hierarchy[i]})[0];
     }
   }
   return resources;
 }
 // MyDefect : Refactored
 private void reOpenEditor(boolean wasOpen, String newName, IWorkbenchPage iwbp)
     throws PartInitException {
   // reopen if needed (if the rename failed, this will fail silently):
   if (wasOpen) {
     IContainer folder = resSelectedResource.getParent();
     IResource newResource = folder.findMember(newName);
     if (newResource != null) {
       IDE.openEditor(iwbp, (IFile) newResource);
     }
   }
 }
Пример #10
0
  private void savePubspecFile(IContainer container) {
    IResource resource = container.findMember(DartCore.PUBSPEC_FILE_NAME);
    if (resource != null) {
      IEditorPart editor = EditorUtility.isOpenInEditor(resource);
      if (editor != null && editor.isDirty()) {
        if (MessageDialog.openQuestion(
            getShell(),
            NLS.bind(ActionMessages.RunPubAction_commandText, command),
            ActionMessages.RunPubAction_savePubspecMessage)) {

          editor.doSave(new NullProgressMonitor());
        }
      }
    }
  }
  // Assert that the two containers have equal contents
  protected void assertEquals(IContainer container1, IContainer container2) throws CoreException {
    assertEquals(container1.getName(), container2.getName());
    List members1 = new ArrayList();
    members1.addAll(Arrays.asList(container1.members()));

    List members2 = new ArrayList();
    members2.addAll(Arrays.asList(container2.members()));

    assertTrue(members1.size() == members2.size());
    for (int i = 0; i < members1.size(); i++) {
      IResource member1 = (IResource) members1.get(i);
      IResource member2 = container2.findMember(member1.getName());
      assertNotNull(member2);
      assertEquals(member1, member2);
    }
  }
Пример #12
0
  private static IResource findMember(IContainer container, String path) {
    // even though the filesystem is case-insensitive on Windows, Eclipse's Resource
    // APIs only find files in a case-sensitive manner.  since Robot does not do
    // this at runtime, we'll need to lessen the restriction by doing a more
    // expensive segment-by-segment comparison here
    if (Platform.OS_WIN32.equals(Platform.getOS())) {
      List<String> segments = getPathSegments(path);
      while (!segments.isEmpty()) {
        String nextSegment = segments.remove(0);

        if ("..".equals(nextSegment)) {
          container = container.getParent();
        } else if (".".equals(nextSegment)) {
          continue;
        } else {
          try {
            IResource[] members = container.members();
            for (IResource member : members) {
              if (nextSegment.equalsIgnoreCase(member.getName())) {
                if (member instanceof IContainer) {
                  // found the next folder in the path, continue
                  container = (IContainer) member;
                  break;
                } else if (segments.isEmpty()) {
                  // leaf node, this is the file we're looking for
                  return member;
                }
              }
            }
          } catch (CoreException e) {
            // do nothing, we'll just return a null for this path below
          }
        }
      }

      // error condition - for a malformed or non-existent path we return nothing
      return null;
    } else {
      // non-windows OS - simple Eclipse API works well
      return container.findMember(path);
    }
  }
Пример #13
0
  /**
   * Helper method - returns the targeted item (IResource if internal or java.io.File if external),
   * or null if unbound Internal items must be referred to using container relative paths.
   */
  public static Object getTarget(IContainer container, IPath path, boolean checkResourceExistence) {

    if (path == null) return null;

    // lookup - inside the container
    if (path.getDevice() == null) { // container relative paths should not contain a device
      // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=18684)
      // (case of a workspace rooted at d:\ )
      IResource resource = container.findMember(path);
      if (resource != null) {
        if (!checkResourceExistence || resource.exists()) return resource;
        return null;
      }
    }

    // if path is relative, it cannot be an external path
    // (see http://dev.eclipse.org/bugs/show_bug.cgi?id=22517)
    if (!path.isAbsolute()) return null;

    // lookup - outside the container
    File externalFile = new File(path.toOSString());
    if (!checkResourceExistence) {
      return externalFile;
    } else if (existingExternalFiles.contains(externalFile)) {
      return externalFile;
    } else {
      if (ModelWorkspaceManager.ZIP_ACCESS_VERBOSE) {
        System.out.println(
            "("
                + Thread.currentThread()
                + ") [ModelWorkspaceImpl.getTarget(...)] Checking existence of "
                + path.toString()); // $NON-NLS-1$ //$NON-NLS-2$
      }
      if (externalFile.exists()) {
        // cache external file
        existingExternalFiles.add(externalFile);
        return externalFile;
      }
    }
    return null;
  }
Пример #14
0
  /**
   * Check if the file exists within the current project. It will first check the root of the
   * project and then the sources. If the file cannot be found in either, return false. An empty
   * file name would immediately return false.
   *
   * @return True if the file exists.
   */
  public static boolean fileExistsInSources(IFile original, String fileName) {
    if (fileName.trim().isEmpty()) {
      return false;
    }
    IContainer container = original.getParent();
    IResource resourceToOpen = container.findMember(fileName);
    IFile file = null;

    if (resourceToOpen == null) {
      IResource sourcesFolder = container.getProject().findMember("SOURCES"); // $NON-NLS-1$
      file = container.getFile(new Path(fileName));
      if (sourcesFolder != null) {
        file = ((IFolder) sourcesFolder).getFile(new Path(fileName));
      }
      if (!file.exists()) {
        return false;
      }
    }

    return true;
  }
Пример #15
0
  /**
   * Hide our private parts from the navigators other browsers.
   *
   * @throws CoreException
   */
  public void markTeamPrivateResources() throws CoreException {
    for (final Object rmObj : mappings) {
      final RepositoryMapping rm = (RepositoryMapping) rmObj;
      final IContainer c = rm.getContainer();
      if (c == null) continue; // Not fully mapped yet?

      final IResource dotGit = c.findMember(Constants.DOT_GIT);
      if (dotGit != null) {
        try {
          final Repository r = rm.getRepository();
          final File dotGitDir = dotGit.getLocation().toFile().getCanonicalFile();
          if (dotGitDir.equals(r.getDirectory())) {
            trace("teamPrivate " + dotGit); // $NON-NLS-1$
            dotGit.setTeamPrivateMember(true);
          }
        } catch (IOException err) {
          throw new CoreException(Activator.error(CoreText.Error_CanonicalFile, err));
        }
      }
    }
  }
 /**
  * DOC smallet Comment method "afterImportAs".
  *
  * @param newName
  * @param technicalName
  * @throws InvocationTargetException
  */
 private static Project afterImportAs(String newName, String technicalName)
     throws InvocationTargetException {
   // Rename in ".project" and "talendProject" or "talend.project"
   // TODO SML Optimize
   final IWorkspace workspace = org.eclipse.core.resources.ResourcesPlugin.getWorkspace();
   IContainer containers = (IProject) workspace.getRoot().findMember(new Path(technicalName));
   IResource file2 = containers.findMember(IProjectDescription.DESCRIPTION_FILE_NAME);
   try {
     FilesUtils.replaceInFile(
         "<name>.*</name>",
         file2.getLocation().toOSString(),
         "<name>" + technicalName + "</name>"); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
     // TDI-19269
     final IProject project = workspace.getRoot().getProject(technicalName);
     XmiResourceManager xmiManager = new XmiResourceManager();
     try {
       final Project loadProject = xmiManager.loadProject(project);
       loadProject.setTechnicalLabel(technicalName);
       loadProject.setLabel(newName);
       loadProject.setLocal(true);
       loadProject.setId(0);
       loadProject.setUrl(null);
       loadProject.setCreationDate(null);
       loadProject.setDescription("");
       loadProject.setType(null);
       // ADD xqliu 2012-03-12 TDQ-4771 clear the list of Folders
       if (loadProject.getFolders() != null) {
         loadProject.getFolders().clear();
       }
       // ~ TDQ-4771
       xmiManager.saveResource(loadProject.eResource());
       return loadProject;
     } catch (PersistenceException e) {
       //
     }
   } catch (IOException e) {
     throw new InvocationTargetException(e);
   }
   return null;
 }
 /**
  * Creates any destination package fragment(s) which do not exists yet. Return true if a read-only
  * package fragment has been found among package fragments, false otherwise
  */
 private boolean createNeededPackageFragments(
     IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder)
     throws JavaModelException {
   boolean containsReadOnlyPackageFragment = false;
   IContainer parentFolder = (IContainer) root.resource();
   JavaElementDelta projectDelta = null;
   String[] sideEffectPackageName = null;
   char[][] inclusionPatterns = root.fullInclusionPatternChars();
   char[][] exclusionPatterns = root.fullExclusionPatternChars();
   for (int i = 0; i < newFragName.length; i++) {
     String subFolderName = newFragName[i];
     sideEffectPackageName = Util.arrayConcat(sideEffectPackageName, subFolderName);
     IResource subFolder = parentFolder.findMember(subFolderName);
     if (subFolder == null) {
       // create deepest folder only if not a move (folder will be moved in
       // processPackageFragmentResource)
       if (!(moveFolder && i == newFragName.length - 1)) {
         createFolder(parentFolder, subFolderName, this.force);
       }
       parentFolder = parentFolder.getFolder(new Path(subFolderName));
       sourceFolder = sourceFolder.getFolder(new Path(subFolderName));
       if (Util.isReadOnly(sourceFolder)) {
         containsReadOnlyPackageFragment = true;
       }
       IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName);
       if (i < newFragName.length - 1 // all but the last one are side effect packages
           && !Util.isExcluded(parentFolder, inclusionPatterns, exclusionPatterns)) {
         if (projectDelta == null) {
           projectDelta = getDeltaFor(root.getJavaProject());
         }
         projectDelta.added(sideEffectPackage);
       }
       this.createdElements.add(sideEffectPackage);
     } else {
       parentFolder = (IContainer) subFolder;
     }
   }
   return containsReadOnlyPackageFragment;
 }
 /**
  * Execute the operation - creates the new script folder and any side effect folders.
  *
  * @exception ModelException if the operation is unable to complete
  */
 @Override
 protected void executeOperation() throws ModelException {
   ModelElementDelta delta = null;
   IProjectFragment root = (IProjectFragment) getParentElement();
   beginTask(Messages.operation_createScriptFolderProgress, this.pkgName.segmentCount());
   IContainer parentFolder = (IContainer) root.getResource();
   IPath sideEffectPackageName = Path.EMPTY;
   ArrayList<IScriptFolder> results = new ArrayList<IScriptFolder>(this.pkgName.segmentCount());
   int i;
   for (i = 0; i < this.pkgName.segmentCount(); i++) {
     String subFolderName = this.pkgName.segment(i);
     sideEffectPackageName = sideEffectPackageName.append(subFolderName);
     IResource subFolder = parentFolder.findMember(subFolderName);
     if (subFolder == null) {
       createFolder(parentFolder, subFolderName, force);
       parentFolder = parentFolder.getFolder(new Path(subFolderName));
       IScriptFolder addedFrag = root.getScriptFolder(sideEffectPackageName);
       if (!Util.isExcluded(parentFolder, root)) {
         if (delta == null) {
           delta = newModelElementDelta();
         }
         delta.added(addedFrag);
       }
       results.add(addedFrag);
     } else {
       parentFolder = (IContainer) subFolder;
     }
     worked(1);
   }
   if (results.size() > 0) {
     this.resultElements = new IModelElement[results.size()];
     results.toArray(this.resultElements);
     if (delta != null) {
       addDelta(delta);
     }
   }
   done();
 }
Пример #19
0
 /** @see IModelElement#getUnderlyingResource() */
 public IResource getUnderlyingResource() throws ModelException {
   IResource rootResource = this.parent.getUnderlyingResource();
   if (rootResource == null) {
     // jar package fragment root that has no associated resource
     return null;
   }
   // the underlying resource may be a folder or a project (in the case
   // that the project folder
   // is atually the package fragment root)
   if (rootResource.getType() == IResource.FOLDER || rootResource.getType() == IResource.PROJECT) {
     IContainer folder = (IContainer) rootResource;
     String[] segs = this.path.segments();
     for (int i = 0; i < segs.length; ++i) {
       IResource child = folder.findMember(segs[i]);
       if (child == null || child.getType() != IResource.FOLDER) {
         throw newNotPresentException();
       }
       folder = (IFolder) child;
     }
     return folder;
   } else {
     return rootResource;
   }
 }
Пример #20
0
  private boolean validateClass(String className) {
    String errorMessage = null;
    boolean valid = true;
    if (className.length() == 0) {
      errorMessage = MESSAGE_CLASS_SPECIFIED;
      valid = false;
    }
    if (className.replace('\\', '/').indexOf('/', 1) > 0) {
      errorMessage = MESSAGE_CLASS_VALID;
      valid = false;
    }
    int dotLoc = className.indexOf('.');
    if (dotLoc != -1) {
      errorMessage = MESSAGE_CLASS_DOT;
      valid = false;
    }
    if (container.findMember(className + "." + getExtension()) != null) {
      errorMessage = MESSAGE_CLASS_EXISTS;
      valid = false;
    }
    if (classDirty) setErrorMessage(errorMessage);

    return valid;
  }
  @Override
  void assertNewEntityFilesAreCreatedSuccessfully(AdaptableRegistry data) {
    IEclipsePreferences seamFacetPrefs = SeamCorePlugin.getSeamPreferences(earProject);
    SeamProjectsSet seamPrjSet = new SeamProjectsSet(earProject);

    String sessionBeanPackagePath = getPackagePath(getSessionBeanPackageName(seamFacetPrefs));
    String entityBeanPackagePath = getPackagePath(getEntityBeanPackageName(seamFacetPrefs));

    IContainer seamProjectSrcActionFolder = seamPrjSet.getActionFolder();
    IContainer seamProjectSrcModelFolder = seamPrjSet.getModelFolder();
    IContainer seamProjectWebContentFolder = seamPrjSet.getViewsFolder();

    String seamPageName = data.getValue(ISeamParameter.SEAM_PAGE_NAME);
    String seamMasterPageName = data.getValue(ISeamParameter.SEAM_MASTER_PAGE_NAME);
    String seamEntityClassName = data.getValue(ISeamParameter.SEAM_ENTITY_CLASS_NAME);

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_WEBCONTENT_PATH + "}/
    //		${" + ISeamParameter.SEAM_PAGE_NAME +"}.xhtml", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IResource seamPageNameXhtml = seamProjectWebContentFolder.findMember(seamPageName + ".xhtml");
    assertResourceIsCreatedAndHasNoProblems(
        seamPageNameXhtml, seamProjectWebContentFolder.toString() + "/" + seamPageName + ".xhtml");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_WEBCONTENT_PATH + "}/
    //		${" + ISeamParameter.SEAM_MASTER_PAGE_NAME +"}.xhtml",	 //$NON-NLS-1$ //$NON-NLS-2$
    // //$NON-NLS-3$

    IResource seamMasterPageNameXhtml =
        seamProjectWebContentFolder.findMember(seamMasterPageName + ".xhtml");
    assertResourceIsCreatedAndHasNoProblems(
        seamMasterPageNameXhtml,
        seamProjectWebContentFolder.toString() + "/" + seamMasterPageName + ".xhtml");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_SRC_MODEL + "}/
    //		${" + ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_PATH + "}/
    //		${" + ISeamParameter.SEAM_ENTITY_CLASS_NAME +"}.java", //$NON-NLS-1$ //$NON-NLS-2$
    // //$NON-NLS-3$ //$NON-NLS-4$

    IResource entityClassJava =
        seamProjectSrcModelFolder.findMember(
            entityBeanPackagePath + "/" + seamEntityClassName + ".java");
    assertResourceIsCreatedAndHasNoProblems(
        entityClassJava,
        seamProjectSrcModelFolder.toString()
            + "/"
            + entityBeanPackagePath
            + "/"
            + seamEntityClassName
            + ".java");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_SRC_ACTION + "}/
    //		${" + ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/
    //		${" + ISeamParameter.SEAM_ENTITY_CLASS_NAME +"}Home.java", //$NON-NLS-1$ //$NON-NLS-2$
    // //$NON-NLS-3$ //$NON-NLS-4$

    IResource entityHomeJava =
        seamProjectSrcActionFolder.findMember(
            sessionBeanPackagePath + "/" + seamEntityClassName + "Home.java");
    assertResourceIsCreatedAndHasNoProblems(
        entityHomeJava,
        seamProjectSrcActionFolder.toString()
            + "/"
            + sessionBeanPackagePath
            + "/"
            + seamEntityClassName
            + "Home.java");

    //
    //		"${" + ISeamParameter.SEAM_PROJECT_SRC_ACTION + "}/
    //		${" + ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_PATH + "}/
    //		${" + ISeamParameter.SEAM_ENTITY_CLASS_NAME +"}List.java", //$NON-NLS-1$ //$NON-NLS-2$
    // //$NON-NLS-3$ //$NON-NLS-4$

    IResource entityListJava =
        seamProjectSrcActionFolder.findMember(
            sessionBeanPackagePath + "/" + seamEntityClassName + "List.java");
    assertResourceIsCreatedAndHasNoProblems(
        entityListJava,
        seamProjectSrcActionFolder.toString()
            + "/"
            + sessionBeanPackagePath
            + "/"
            + seamEntityClassName
            + "List.java");
  }
Пример #22
0
 public ModelWorkspaceItem getWorkspaceItem(final IPath path) {
   CoreArgCheck.isNotNull(path);
   try {
     // first get all the projects
     ModelProject[] projects = getModelProjects();
     for (int i = 0; i < projects.length; i++) {
       ModelProject project = projects[i];
       if (!project.exists()) {
         continue;
       }
       if (!project.isOpen()) {
         // See if the underlying project is open ...
         final IProject iproj = (IProject) project.getResource();
         if (!iproj.isOpen()) {
           continue;
         }
         // Try to open the ModelProject, since the IProject is open ...
         project.open(null);
         if (!project.isOpen()) {
           continue; // couldn't open it!
         }
       }
       if (project.getPath().equals(path)) {
         return project;
       }
       // Iterate over all the path segments navigating to the child by name
       ModelWorkspaceItem item = project;
       final String[] segments = path.segments();
       for (int j = 1; j < segments.length; j++) {
         final String segment = segments[j];
         if (!item.exists()) {
           // Must be in the process of closing (see defect 10957) ...
           return null;
         }
         final IResource itemResource = item.getResource();
         item = item.getChild(segment);
         if (item == null) {
           // May be a newly created IResource for which there is yet no ModelWorkspaceItem
           if (itemResource instanceof IContainer) {
             final IContainer itemContainer = (IContainer) itemResource;
             final IResource child = itemContainer.findMember(segment);
             if (child != null) {
               // Find the ModelWorkspaceItem ...
               item =
                   ModelWorkspaceManager.getModelWorkspaceManager()
                       .findModelWorkspaceItem(child, true);
             }
           }
         }
         if (item == null) {
           break;
         } else if (item.getPath().equals(path)) {
           return item;
         }
       }
     }
   } catch (ModelWorkspaceException e) {
     // do nothing
   }
   return null;
 }
Пример #23
0
  /**
   * Updates completions for the BibTeX -data
   *
   * @param bibNames Names of the BibTeX -files that the document uses
   * @param resource The resource of the document
   */
  private void updateBibs(String[] bibNames, boolean biblatexMode, IResource resource) {
    IProject project = getCurrentProject();
    if (project == null) return;

    if (!biblatexMode) {
      for (int i = 0; i < bibNames.length; i++) {
        if (!bibNames[i].endsWith(".bib")) {
          bibNames[i] += ".bib";
        }
      }
    }

    if (bibContainer.checkFreshness(bibNames)) {
      return;
    }

    TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILE_PROPERTY, bibNames);

    List<String> newBibs = bibContainer.updateBibHash(bibNames);

    IPath path = resource.getFullPath().removeFirstSegments(1).removeLastSegments(1);
    if (!path.isEmpty()) path = path.addTrailingSeparator();

    KpsewhichRunner filesearch = new KpsewhichRunner();

    for (Iterator<String> iter = newBibs.iterator(); iter.hasNext(); ) {
      String name = iter.next();
      try {
        String filepath = "";
        // First try local search
        IResource res = project.findMember(path + name);
        // Try searching relative to main file
        if (res == null) {
          IContainer sourceDir = TexlipseProperties.getProjectSourceDir(project);
          res = sourceDir.findMember(name);
        }

        if (res != null) {
          filepath = res.getLocation().toOSString();
        }
        if (res == null) {
          // Try Kpsewhich
          filepath = filesearch.getFile(resource, name, "bibtex");
          if (filepath.length() > 0 && !(new File(filepath).isAbsolute())) {
            // filepath is a local path
            res = project.findMember(path + filepath);
            if (res != null) {
              filepath = res.getLocation().toOSString();
            } else {
              filepath = "";
            }
          } else if (filepath.length() > 0) {
            // Create a link to resource
            IPath p = new Path(filepath);
            if (name.indexOf('/') >= 0) {
              // Remove path from name
              name = name.substring(name.lastIndexOf('/') + 1);
            }
            IFile f = project.getFile(path + name);
            if (f != null && !f.exists()) {
              f.createLink(p, IResource.NONE, null);
            }
          }
        }

        if (filepath.length() > 0) {
          BibParser parser = new BibParser(filepath);
          try {
            List<ReferenceEntry> bibEntriesList = parser.getEntries();
            if (bibEntriesList != null && bibEntriesList.size() > 0) {
              bibContainer.addRefSource(path + name, bibEntriesList);
            } else if (bibEntriesList == null) {
              MarkerHandler marker = MarkerHandler.getInstance();
              marker.addFatalError(
                  editor,
                  "The BibTeX file " + filepath + " contains fatal errors, parsing aborted.");
              continue;
            }
          } catch (IOException ioe) {
            TexlipsePlugin.log("Can't read BibTeX file " + filepath, ioe);
          }
        } else {
          MarkerHandler marker = MarkerHandler.getInstance();
          marker.addFatalError(editor, "The BibTeX file " + name + " not found.");
        }

      } catch (CoreException ce) {
        TexlipsePlugin.log("Can't run Kpathsea", ce);
      }
    }
    bibContainer.organize();
  }