@Test
 public void testGetRelativePath() throws Exception {
   assertEquals(Path.EMPTY.toString(), GitUtils.getRelativePath(new Path("/file/a/"), Path.EMPTY));
   assertEquals(
       Path.EMPTY.toString(), GitUtils.getRelativePath(new Path("/file/a/b/"), Path.EMPTY));
   assertEquals("b/", GitUtils.getRelativePath(new Path("/file/a/b/"), new Path("../")));
   assertEquals("b/c/", GitUtils.getRelativePath(new Path("/file/a/b/c/"), new Path("../../")));
   assertEquals("c/", GitUtils.getRelativePath(new Path("/file/a/b/c/"), new Path("../")));
   assertEquals("b/c", GitUtils.getRelativePath(new Path("/file/a/b/c"), new Path("../")));
 }
Example #2
0
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
  */
 public String getText(Object element) {
   if (element instanceof LibraryStandin) {
     return ((LibraryStandin) element).getSystemLibraryPath().toOSString();
   } else if (element instanceof SubElement) {
     SubElement subElement = (SubElement) element;
     StringBuffer text = new StringBuffer();
     if (subElement.getType() == SubElement.SOURCE_PATH) {
       text.append(JREMessages.VMLibraryBlock_0);
       IPath systemLibrarySourcePath = subElement.getParent().getSystemLibrarySourcePath();
       if (systemLibrarySourcePath != null && !Path.EMPTY.equals(systemLibrarySourcePath)) {
         text.append(systemLibrarySourcePath.toOSString());
       } else {
         text.append(JREMessages.VMLibraryBlock_1);
       }
     } else if (subElement.getType() == SubElement.JAVADOC_URL) {
       text.append(JREMessages.LibraryLabelProvider_0);
       URL javadocLocation = subElement.getParent().getJavadocLocation();
       if (javadocLocation != null) {
         text.append(javadocLocation.toExternalForm());
       } else {
         text.append(JREMessages.VMLibraryBlock_1);
       }
     }
     return text.toString();
   }
   return null;
 }
Example #3
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
   */
  public Image getImage(Object element) {
    String key = null;
    IStatus status = Status.OK_STATUS;
    if (element instanceof LibraryStandin) {
      LibraryStandin library = (LibraryStandin) element;
      IPath sourcePath = library.getSystemLibrarySourcePath();
      if (sourcePath != null && !Path.EMPTY.equals(sourcePath)) {
        key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE;
      } else {
        key = ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE;
      }
      status = library.validate();

    } else if (element instanceof SubElement) {
      if (((SubElement) element).getType() == SubElement.SOURCE_PATH) {
        key = ISharedImages.IMG_OBJS_JAR_WITH_SOURCE;
      } else {
        key = ISharedImages.IMG_OBJS_JAVADOCTAG;
      }
    }
    if (key != null) {
      if (!status.isOK()) {
        ImageDescriptor base = JavaUI.getSharedImages().getImageDescriptor(key);
        JDIImageDescriptor descriptor =
            new JDIImageDescriptor(base, JDIImageDescriptor.IS_OUT_OF_SYNCH);
        return JDIDebugUIPlugin.getImageDescriptorRegistry().get(descriptor);
      }
      return JavaUI.getSharedImages().getImage(key);
    }
    return null;
  }
 public IPath getProjectLocation() {
   String projectName = getProjectName();
   if (projectName.isEmpty()) {
     return null;
   }
   if (!Path.EMPTY.isValidPath(getLocationString())) {
     return null;
   }
   return Path.fromOSString(getLocationString());
 }
Example #5
0
    public void update(Observable o, Object arg) {
      final IWorkspace workspace = DLTKUIPlugin.getWorkspace();
      final String name = fNameGroup.getName();
      // check whether the project name field is empty
      if (name.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterProjectName);
        setPageComplete(false);
        return;
      }
      // check whether the project name is valid
      final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT);
      if (!nameStatus.isOK()) {
        setErrorMessage(nameStatus.getMessage());
        setPageComplete(false);
        return;
      }
      // check whether project already exists
      final IProject handle = getProjectHandle();

      if (!isInLocalServer()) {
        if (handle.exists()) {
          setErrorMessage(
              NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists);
          setPageComplete(false);
          return;
        }
      }

      IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
      String newProjectNameLowerCase = name.toLowerCase();
      for (IProject currentProject : projects) {
        String existingProjectName = currentProject.getName();
        if (existingProjectName.toLowerCase().equals(newProjectNameLowerCase)) {
          setErrorMessage(
              NewWizardMessages.ScriptProjectWizardFirstPage_Message_projectAlreadyExists);
          setPageComplete(false);
          return;
        }
      }

      final String location = fPHPLocationGroup.getLocation().toOSString();
      // check whether location is empty
      if (location.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_enterLocation);
        setPageComplete(false);
        return;
      }
      // check whether the location is a syntactically correct path
      if (!Path.EMPTY.isValidPath(location)) {
        setErrorMessage(NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory);
        setPageComplete(false);
        return;
      }
      // check whether the location has the workspace as prefix
      IPath projectPath = Path.fromOSString(location);
      if (!fPHPLocationGroup.isInWorkspace() && Platform.getLocation().isPrefixOf(projectPath)) {
        setErrorMessage(
            NewWizardMessages.ScriptProjectWizardFirstPage_Message_cannotCreateInWorkspace);
        setPageComplete(false);
        return;
      }
      // If we do not place the contents in the workspace validate the
      // location.
      if (!fPHPLocationGroup.isInWorkspace()) {
        IEnvironment environment = getEnvironment();
        if (EnvironmentManager.isLocal(environment)) {
          final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath);
          File file = projectPath.toFile();
          if (!locationStatus.isOK()) {
            setErrorMessage(locationStatus.getMessage());
            setPageComplete(false);
            return;
          }

          if (!canCreate(projectPath.toFile())) {
            setErrorMessage(
                NewWizardMessages.ScriptProjectWizardFirstPage_Message_invalidDirectory);
            setPageComplete(false);
            return;
          }
        }
      }

      if (fragment != null) {
        fragment.getWizardModel().putObject("ProjectName", fNameGroup.getName());
        if (!fragment.isComplete()) {
          setErrorMessage((String) fragment.getWizardModel().getObject(ERROR_MESSAGE));
          setPageComplete(false);
          return;
        }
      }

      setPageComplete(true);
      setErrorMessage(null);
      setMessage(null);
    }
    public void update(Observable o, Object arg) {

      final IWorkspace workspace = JavaPlugin.getWorkspace();

      final String name = fNameGroup.getName();
      // check whether the project name field is empty
      if (name.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName);
        setPageComplete(false);
        return;
      }

      // check whether the project name is valid
      final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT);
      if (!nameStatus.isOK()) {
        setErrorMessage(nameStatus.getMessage());
        setPageComplete(false);
        return;
      }

      // check whether project already exists
      final IProject handle = workspace.getRoot().getProject(name);
      if (handle.exists()) {
        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists);
        setPageComplete(false);
        return;
      }

      // check whether package name is valid
      final String packageName = fNameGroup.getPackageName();
      if (packageName.length() == 0) {
        setErrorMessage(null);
        setMessage("Enter a top level package name.");
        setPageComplete(false);
        return;
      }
      if (JavaConventions.validatePackageName(
                  packageName, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3)
              .getSeverity()
          == IStatus.ERROR) {
        setErrorMessage(null);
        setMessage("The entered top level package name is not valid.");
        setPageComplete(false);
        return;
      }

      IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name);
      if (projectLocation.toFile().exists()) {
        try {
          // correct casing
          String canonicalPath = projectLocation.toFile().getCanonicalPath();
          projectLocation = new Path(canonicalPath);
        } catch (IOException e) {
          JavaPlugin.log(e);
        }

        String existingName = projectLocation.lastSegment();
        if (!existingName.equals(fNameGroup.getName())) {
          setErrorMessage(
              Messages.format(
                  NewWizardMessages
                      .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot,
                  BasicElementLabels.getResourceName(existingName)));
          setPageComplete(false);
          return;
        }

        setErrorMessage("A project at specified location already exists.");
        setPageComplete(false);
        return;
      }

      final String location = fLocationGroup.getLocation().toOSString();

      // check whether location is empty
      if (location.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation);
        setPageComplete(false);
        return;
      }

      // check whether the location is a syntactically correct path
      if (!Path.EMPTY.isValidPath(location)) {
        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory);
        setPageComplete(false);
        return;
      }

      IPath projectPath = Path.fromOSString(location);

      if (fLocationGroup.isWorkspaceRadioSelected())
        projectPath = projectPath.append(fNameGroup.getName());

      if (projectPath.toFile().exists()) { // create from existing source
        if (Platform.getLocation().isPrefixOf(projectPath)) { // create
          // from
          // existing
          // source
          // in
          // workspace
          if (!Platform.getLocation().equals(projectPath.removeLastSegments(1))) {
            setErrorMessage(
                NewRooWizardMessages.NewRooProjectWizardPageOne_Message_notOnWorkspaceRoot);
            setPageComplete(false);
            return;
          }

          if (!projectPath.toFile().exists()) {
            setErrorMessage(
                NewRooWizardMessages.NewRooProjectWizardPageOne_notExisingProjectOnWorkspaceRoot);
            setPageComplete(false);
            return;
          }
        }
      } else if (!fLocationGroup.isWorkspaceRadioSelected()) { // create at
        // non
        // existing
        // external
        // location
        if (!canCreate(projectPath.toFile())) {
          setErrorMessage(
              NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation);
          setPageComplete(false);
          return;
        }

        // If we do not place the contents in the workspace validate the
        // location.
        final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath);
        if (!locationStatus.isOK()) {
          setErrorMessage(locationStatus.getMessage());
          setPageComplete(false);
          return;
        }
      }

      if (firstValidation) {
        firstValidation = false;
        if (RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall() == null) {
          setErrorMessage("No Roo installation configured in workspace preferences.");
          setPageComplete(false);
          return;
        }
      } else {
        IRooInstall install = null;
        if (useDefaultRooInstall()) {
          install = RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall();
        } else {
          String installName = getRooInstallName();
          if (installName != null) {
            install = RooCoreActivator.getDefault().getInstallManager().getRooInstall(installName);
          }
        }
        if (install == null) {
          setErrorMessage("No Roo installation configured in workspace preferences.");
          setPageComplete(false);
          return;
        } else {
          installError = install.validate();
          if (installError != null && !installError.isOK()) {
            setErrorMessage(installError.getMessage());
            setPageComplete(false);
            return;
          }
        }
      }

      setPageComplete(true);
      setErrorMessage(null);
      setMessage(null);
    }
Example #7
0
 @Override
 IPath buildChildPath(IPath parent, String key) {
   IPath nextPath = Path.EMPTY.append(parent);
   nextPath.setDevice(key);
   return nextPath;
 }
Example #8
0
 public IFileHandle getFile(IPath path) {
   if (path == null || Path.EMPTY.equals(path)) {
     throw new IllegalArgumentException(Messages.RSEEnvironment_EmptyFileNameError);
   }
   return new RSEFileHandle(this, getURIFor(host, path.toString()));
 }
    public void update(Observable o, Object arg) {

      final IWorkspace workspace = JavaPlugin.getWorkspace();

      final String name = fNameGroup.getName();

      // check whether the project name field is empty
      if (name.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName);
        setPageComplete(false);
        return;
      }

      // check whether the project name is valid
      IStatus nameStatus = workspace.validateName(name, IResource.PROJECT);
      if (nameStatus.isOK()) {
        // there are further restrictions on Grails project names
        nameStatus = validateProjectName(name);
      }
      if (!nameStatus.isOK()) {
        setErrorMessage(nameStatus.getMessage());
        setPageComplete(false);
        return;
      }

      // check whether project already exists
      final IProject handle = workspace.getRoot().getProject(name);
      if (handle.exists()) {
        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_projectAlreadyExists);
        setPageComplete(false);
        return;
      }

      IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(name);
      if (projectLocation.toFile().exists()) {
        try {
          // correct casing
          String canonicalPath = projectLocation.toFile().getCanonicalPath();
          projectLocation = new Path(canonicalPath);
        } catch (IOException e) {
          JavaPlugin.log(e);
        }

        String existingName = projectLocation.lastSegment();
        if (!existingName.equals(fNameGroup.getName())) {
          setErrorMessage(
              Messages.format(
                  NewWizardMessages
                      .NewJavaProjectWizardPageOne_Message_invalidProjectNameForWorkspaceRoot,
                  BasicElementLabels.getResourceName(existingName)));
          setPageComplete(false);
          return;
        }
      }

      final String location = fLocationGroup.getLocation().toOSString();

      // check whether location is empty
      if (location.length() == 0) {
        setErrorMessage(null);
        setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterLocation);
        setPageComplete(false);
        return;
      }

      // check whether the location is a syntactically correct path
      if (!Path.EMPTY.isValidPath(location)) {
        setErrorMessage(NewWizardMessages.NewJavaProjectWizardPageOne_Message_invalidDirectory);
        setPageComplete(false);
        return;
      }

      IPath projectPath = Path.fromOSString(location);

      if (fLocationGroup.isWorkspaceRadioSelected())
        projectPath = projectPath.append(fNameGroup.getName());

      boolean importing = false;
      if (projectPath.toFile().exists()) { // create from existing source
        if (Platform.getLocation()
            .isPrefixOf(projectPath)) { // create from existing source in workspace
          if (!projectPath.toFile().exists()) {
            setErrorMessage(
                org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages
                    .NewGrailsProjectWizardPageOne_notExisingProjectOnWorkspaceRoot);
            setPageComplete(false);
            return;
          }
        }
        importing = true;
      } else if (!fLocationGroup
          .isWorkspaceRadioSelected()) { // create at non existing external location
        if (!canCreate(projectPath.toFile())) {
          setErrorMessage(
              NewWizardMessages.NewJavaProjectWizardPageOne_Message_cannotCreateAtExternalLocation);
          setPageComplete(false);
          return;
        }

        // If we do not place the contents in the workspace validate the
        // location.
        final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath);
        if (!locationStatus.isOK()) {
          setErrorMessage(locationStatus.getMessage());
          setPageComplete(false);
          return;
        }
      }

      // Let other checks perform before this one.
      // If a location was specified, the project name must match the last segment of the location
      if (!projectPath.isEmpty()) {
        String expectedProjectName = projectPath.lastSegment();
        if ((name == null) || !name.equals(expectedProjectName)) {
          setErrorMessage(
              NewGrailsWizardMessages
                  .NewGrailsProjectWizardPageOne_invalidProjectNameForExternalLocation);
          setPageComplete(false);
          return;
        }
      }

      if (GrailsCoreActivator.getDefault().getInstallManager().getDefaultGrailsInstall() == null) {
        setErrorMessage(
            org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages
                .NewGrailsProjectWizardPageOne_noGrailsInstallationInWorkspacePreferences);
        setPageComplete(false);
        return;
      }

      setPageComplete(true);
      setErrorMessage(null);
      if (importing) {
        // Project exists, but is not in workspace therefore import it.
        setMessage(
            Messages.format(
                org.grails.ide.eclipse.ui.internal.wizard.NewGrailsWizardMessages
                    .NewGrailsProjectWizardPageOne_importingExistingProject,
                BasicElementLabels.getResourceName(projectPath.lastSegment())));
      } else {
        setMessage(null);
      }
    }