/** Validate file name. */
  private void validateFileName() {
    String filename = txtFileName.getText();

    if (StringUtils.isEmpty(filename)) {
      setErrorMessage("Filename empty");
      setPageComplete(false);
      return;
    } else {
      setErrorMessage(null);
    }

    IPath npath = pathToProject.append(filename);
    npath = npath.addFileExtension(ICGCProject.ENTITIES_EXTENSION);

    boolean exists = CGCProject.getInstance().exists(npath, false);
    if (exists) {
      setErrorMessage("Resource already exists. Please try a new name");
      setPageComplete(false);
      return;
    } else {
      setErrorMessage(null);
    }

    setPageComplete(true);
  }
示例#2
0
 public IPath getErlForYrl(final IResource resource) {
   final IPath path = resource.getProjectRelativePath();
   if (!"yrl".equals(path.getFileExtension())) {
     return null;
   }
   IPath erl = path.removeFileExtension();
   erl = erl.addFileExtension("erl").setDevice(null);
   return erl;
 }
  String getNewName(String filename) {
    IPath path = new Path(filename);

    IPath result = new Path(newName);
    if (path.getFileExtension() != null) {
      result = result.addFileExtension(path.getFileExtension());
    }

    return result.toString();
  }
示例#4
0
 private IPath getBeamForErl(final IResource source) {
   final IErlProject erlProject =
       ErlModelManager.getErlangModel().getErlangProject(source.getProject());
   IPath p = erlProject.getOutputLocation();
   p = p.append(source.getName());
   if (!"erl".equals(p.getFileExtension())) {
     return null;
   }
   final IPath module = p.removeFileExtension();
   final IPath beamPath = module.addFileExtension("beam").setDevice(null);
   return beamPath;
 }
 /** @generated */
 public static String getUniqueFileName(
     IPath containerFullPath, String fileName, String extension) {
   if (containerFullPath == null) {
     containerFullPath = new Path(""); // $NON-NLS-1$
   }
   if (fileName == null || fileName.trim().length() == 0) {
     fileName = "default"; // $NON-NLS-1$
   }
   IPath filePath = containerFullPath.append(fileName);
   if (extension != null && !extension.equals(filePath.getFileExtension())) {
     filePath = filePath.addFileExtension(extension);
   }
   extension = filePath.getFileExtension();
   fileName = filePath.removeFileExtension().lastSegment();
   int i = 1;
   while (ResourcesPlugin.getWorkspace().getRoot().exists(filePath)) {
     i++;
     filePath = containerFullPath.append(fileName + i);
     if (extension != null) {
       filePath = filePath.addFileExtension(extension);
     }
   }
   return filePath.lastSegment();
 }
 protected void removeClassFile(IPath typePath, IContainer outputFolder) throws CoreException {
   if (typePath.lastSegment().indexOf('$') == -1) { // is not a nested type
     this.newState.removeQualifiedTypeName(typePath.toString());
     // add dependents even when the type thinks it does not exist to be on the safe side
     if (JavaBuilder.DEBUG) System.out.println("Found removed type " + typePath); // $NON-NLS-1$
     addDependentsOf(
         typePath,
         true); // when member types are removed, their enclosing type is structurally changed
   }
   IFile classFile =
       outputFolder.getFile(typePath.addFileExtension(SuffixConstants.EXTENSION_class));
   if (classFile.exists()) {
     if (JavaBuilder.DEBUG)
       System.out.println("Deleting class file of removed type " + typePath); // $NON-NLS-1$
     classFile.delete(IResource.FORCE, null);
   }
 }
  private static IPath findExecutable(IPath basename, boolean appendExtension) {
    if (Platform.OS_WIN32.equals(Platform.getOS()) && appendExtension) {
      String[] extensions = System.getenv(PATHEXT).split(File.pathSeparator);
      for (String ext : extensions) {
        if (ext.length() > 0 && ext.charAt(0) == '.') {
          ext = ext.substring(1);
        }
        IPath pathWithExt = basename.addFileExtension(ext);
        if (isExecutable(pathWithExt)) {
          return pathWithExt;
        }
      }

    } else if (isExecutable(basename)) {
      return basename;
    }
    return null;
  }
示例#8
0
 private void openValidationConjectures(IFile editorInputFile) {
   IPath p = new Path(editorInputFile.getName());
   p = p.addFileExtension("vtc");
   IFile vtcFile = editorInputFile.getParent().getFile(p);
   if (vtcFile.exists()) {
     try {
       ValidationConjecturesView v = getValidationConjecturesView();
       if (v != null) {
         conjectureData.clear();
         v.initializeLink(new InputStreamReader(vtcFile.getContents()), this);
         updateOverviewPage();
       }
     } catch (PartInitException e) {
       TracefileViewerPlugin.log(e);
     } catch (CoreException e) {
       TracefileViewerPlugin.log(e);
     }
   }
 }
  public IFile saveDDLFileAsResource(StringWriter out, String filename) {
    // maintenance of ddl file resource is only supported on OSGi platform
    if (!ConnectivityPlugin.isRunningOSGiPlatform()) return null;

    IPath thePath = new Path(filename);
    if ((thePath.getFileExtension() == null)
        || (!(thePath.getFileExtension().equalsIgnoreCase(DDL_FILE_EXTENSION)
            || thePath.getFileExtension().equalsIgnoreCase(ALTERNATE_DDL_FILE_EXTENSION)))) {
      thePath = thePath.addFileExtension(DDL_FILE_EXTENSION);
    }
    IFile theFile = ResourcesPlugin.getWorkspace().getRoot().getFile(thePath);
    OutputStream file = null;
    try {
      file = new ByteArrayOutputStream();

      // Save the file using encoding specified by user in
      // Window->Preferences...
      String encoding = ResourcesPlugin.getEncoding();
      if (encoding != null && !encoding.equals("")) {
        file.write(out.toString().getBytes(encoding));
      } else {
        file.write(out.toString().getBytes());
      }

      saveDocumentAsResource(theFile, file);
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    } finally {
      if (file != null) {
        try {
          file.close();
        } catch (IOException e1) {
        }
      }
    }
    return theFile;
  }
示例#10
0
 /**
  * Get version for the specified Firefox extension ID
  *
  * @param extensionID
  * @param profileDir
  * @return
  */
 public static String getExtensionVersion(String extensionID, IPath profileDir) {
   try {
     IPath dir = profileDir.append("extensions").append(extensionID); // $NON-NLS-1$
     InputStream rdfInputStream = null;
     if (dir.toFile().isFile()) {
       dir = Path.fromOSString(IOUtil.read(new FileInputStream(dir.toFile())));
     }
     if (dir.toFile().isDirectory()) {
       File installRdf = dir.append("install.rdf").toFile(); // $NON-NLS-1$
       if (installRdf.exists()) {
         rdfInputStream = new FileInputStream(installRdf);
       }
     } else if (dir.addFileExtension("xpi").toFile().isFile()) // $NON-NLS-1$
     {
       rdfInputStream =
           ZipUtil.openEntry(
               dir.addFileExtension("xpi").toFile(), // $NON-NLS-1$
               Path.fromPortableString("install.rdf")); // $NON-NLS-1$
     }
     if (rdfInputStream != null) {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder parser = factory.newDocumentBuilder();
       Document document = parser.parse(rdfInputStream);
       Node node = document.getDocumentElement().getFirstChild();
       while (node != null) {
         if ("description".equals(node.getNodeName().toLowerCase()) // $NON-NLS-1$
             || "rdf:description".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           NamedNodeMap attrs = node.getAttributes();
           Node about = attrs.getNamedItem("about"); // $NON-NLS-1$
           if (about == null) {
             about = attrs.getNamedItem("RDF:about"); // $NON-NLS-1$
           }
           if (about != null) {
             if ("urn:mozilla:install-manifest".equals(about.getNodeValue())) { // $NON-NLS-1$
               break;
             }
           }
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         NamedNodeMap attrs = node.getAttributes();
         Node version = attrs.getNamedItem("em:version"); // $NON-NLS-1$
         if (version != null) {
           return version.getNodeValue();
         }
         node = node.getFirstChild();
       }
       while (node != null) {
         if ("em:version".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           break;
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         return node.getTextContent();
       }
     }
   } catch (Exception e) {
     IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
   }
   return null;
 }