コード例 #1
0
  /**
   * Set the boolean symbol on and off image path. If the path is relative, then build absolute
   * path.
   *
   * <p><b>Rules:</b> <br>
   * If the image selected is on, then search off image. <br>
   * If the image selected is off, then search on image. <br>
   * If one or both is not found, the image path selected is the same for both.
   *
   * @param model
   * @param imagePath The path to the selected image (on or off or other)
   */
  public synchronized void setSymbolImagePath(ControlBoolSymbolModel model, IPath imagePath) {
    if (imagePath == null || imagePath.isEmpty()) {
      return;
    }
    if (!imagePath.isAbsolute()) {
      imagePath = org.csstudio.opibuilder.util.ResourceUtil.buildAbsolutePath(model, imagePath);
    }
    // Default
    this.onImagePath = imagePath;
    this.offImagePath = imagePath;

    // Search on or off equivalent
    if (ImageUtils.isOnImage(imagePath)) {
      IPath offImagePath = ImageUtils.searchOffImage(imagePath);
      if (offImagePath != null) {
        this.offImagePath = offImagePath;
      }
    } else if (ImageUtils.isOffImage(imagePath)) {
      IPath onImagePath = ImageUtils.searchOnImage(imagePath);
      if (onImagePath != null) {
        this.onImagePath = onImagePath;
      }
    }
    if (imagePath.getFileExtension() != null
        && "svg".compareToIgnoreCase(imagePath.getFileExtension()) == 0) {
      workingWithSVG = true;
    } else {
      workingWithSVG = false;
    }
    loadOffImage();
    loadOnImage();
  }
コード例 #2
0
  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();
  }
コード例 #3
0
ファイル: ResourceConfiguration.java プロジェクト: zhaog/cdt
  @Override
  public boolean hasCustomSettings() {
    IResourceInfo parentRc = getParentResourceInfo();
    if (parentRc instanceof FolderInfo) {
      IPath path = getPath();
      String ext = path.getFileExtension();
      if (ext == null) ext = ""; // $NON-NLS-1$
      ITool otherTool = ((FolderInfo) parentRc).getToolFromInputExtension(ext);
      if (otherTool == null) return true;

      ITool[] tti = getToolsToInvoke();
      if (tti.length != 1) return true;

      return ((Tool) tti[0]).hasCustomSettings((Tool) otherTool);
    }
    ITool[] tools = getTools();
    ITool[] otherTools = ((IFileInfo) parentRc).getTools();
    if (tools.length != otherTools.length) return true;

    for (int i = 0; i < tools.length; i++) {
      Tool tool = (Tool) tools[i];
      Tool otherTool = (Tool) otherTools[i];
      if (tool.hasCustomSettings(otherTool)) return true;
    }

    return false;
  }
コード例 #4
0
ファイル: StorageLabelProvider.java プロジェクト: aptana/rdt
  /*
   * Gets and caches an image for a JarEntryFile.
   * The image for a JarEntryFile is retrieved from the EditorRegistry.
   */
  private Image getImageForJarEntry(IStorage element) {
    if (fJarImageMap == null) return getDefaultImage();

    if (element == null || element.getName() == null) return getDefaultImage();

    // Try to find icon for full name
    String name = element.getName();
    Image image = (Image) fJarImageMap.get(name);
    if (image != null) return image;
    IFileEditorMapping[] mappings = getEditorRegistry().getFileEditorMappings();
    int i = 0;
    while (i < mappings.length) {
      if (mappings[i].getLabel().equals(name)) break;
      i++;
    }
    String key = name;
    if (i == mappings.length) {
      // Try to find icon for extension
      IPath path = element.getFullPath();
      if (path == null) return getDefaultImage();
      key = path.getFileExtension();
      if (key == null) return getDefaultImage();
      image = (Image) fJarImageMap.get(key);
      if (image != null) return image;
    }

    // Get the image from the editor registry
    ImageDescriptor desc = getEditorRegistry().getImageDescriptor(name);
    image = desc.createImage();

    fJarImageMap.put(key, image);

    return image;
  }
コード例 #5
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
 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;
 }
コード例 #6
0
  public static boolean isArchivePath(IPath path, boolean allowAllAchives) {
    if (allowAllAchives) return true;

    String ext = path.getFileExtension();
    if (ext != null && ext.length() != 0) {
      return isArchiveFileExtension(ext);
    }
    return false;
  }
コード例 #7
0
ファイル: AlexBuilder.java プロジェクト: baldo/eclipsefp
 static boolean hasCorrectExtension(final IPath path) {
   if (path == null) {
     return false;
   }
   String extension = path.getFileExtension();
   if (extension == null) {
     return false;
   }
   return extension.equals(FileUtil.EXTENSION_ALEX);
 }
コード例 #8
0
 protected IFile getReferencesFile(NamedModel element) {
   IFile file = ((IFileEditorInput) getEditorInput()).getFile();
   IProject project = file.getProject();
   IPath projectRelativePath = file.getProjectRelativePath();
   String fileExtension = projectRelativePath.getFileExtension();
   IPath prefix = projectRelativePath.removeLastSegments(1);
   String nameSegment = projectRelativePath.removeFileExtension().lastSegment();
   IPath referencesPath =
       prefix.append(nameSegment + "_" + element.getNameText()).addFileExtension(fileExtension);
   IFile refFile = project.getFile(referencesPath.toString());
   return refFile;
 }
コード例 #9
0
  public static boolean isExternalFolderPath(IPath externalPath) {
    if (externalPath == null) return false;
    if (ResourcesPlugin.getWorkspace().getRoot().getProject(externalPath.segment(0)).exists())
      return false;
    File externalFolder = externalPath.toFile();
    if (externalFolder.isFile()) return false;
    if (externalPath.getFileExtension() != null /*
													 * likely a .jar, .zip, .rar
													 * or other file
													 */ && !externalFolder.exists()) return false;
    return true;
  }
コード例 #10
0
 private void addSWTJars(List rtes) {
   if (fgSWTEntries == null) {
     fgSWTEntries = new ArrayList();
     Bundle bundle = Platform.getBundle("org.eclipse.swt"); // $NON-NLS-1$
     BundleDescription description =
         Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId());
     BundleDescription[] fragments = description.getFragments();
     for (int i = 0; i < fragments.length; i++) {
       Bundle fragmentBundle = Platform.getBundle(fragments[i].getName());
       URL bundleURL;
       try {
         bundleURL = FileLocator.resolve(fragmentBundle.getEntry("/")); // $NON-NLS-1$
       } catch (IOException e) {
         AntLaunching.log(e);
         continue;
       }
       String urlFileName = bundleURL.getFile();
       if (urlFileName.startsWith("file:")) { // $NON-NLS-1$
         try {
           urlFileName = new URL(urlFileName).getFile();
           if (urlFileName.endsWith("!/")) { // $NON-NLS-1$
             urlFileName = urlFileName.substring(0, urlFileName.length() - 2);
           }
         } catch (MalformedURLException e) {
           AntLaunching.log(e);
           continue;
         }
       }
       IPath fragmentPath = new Path(urlFileName);
       if (fragmentPath.getFileExtension() != null) { // JAR file
         fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath));
       } else { // folder
         File bundleFolder = fragmentPath.toFile();
         if (!bundleFolder.isDirectory()) {
           continue;
         }
         String[] names =
             bundleFolder.list(
                 new FilenameFilter() {
                   public boolean accept(File dir, String name) {
                     return name.endsWith(".jar"); // $NON-NLS-1$
                   }
                 });
         for (int j = 0; j < names.length; j++) {
           String jarName = names[j];
           fgSWTEntries.add(
               JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath.append(jarName)));
         }
       }
     }
   }
   rtes.addAll(fgSWTEntries);
 }
コード例 #11
0
ファイル: BuilderHelper.java プロジェクト: sergeyzsg/erlide
 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;
 }
コード例 #12
0
ファイル: Util.java プロジェクト: mickaelistria/rt.equinox.p2
  /** Returns the name of the Eclipse application launcher. */
  private static String getLauncherName(String name, String os, File installFolder) {
    if (os == null) {
      EnvironmentInfo info =
          (EnvironmentInfo)
              ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName());
      if (info == null) return null;
      os = info.getOS();
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_WIN32)) {
      IPath path = new Path(name);
      if ("exe".equals(path.getFileExtension())) // $NON-NLS-1$
      return name;
      return name + ".exe"; // $NON-NLS-1$
    }
    if (os.equals(Constants.MACOSX_BUNDLED)) {
      return "/Contents/MacOS/" + name; // $NON-NLS-1$
    }

    if (os.equals(org.eclipse.osgi.service.environment.Constants.OS_MACOSX)) {
      IPath path = new Path(name);
      if (path.segment(0).endsWith(".app")) // $NON-NLS-1$
      return name;

      String appName = null;
      if (installFolder != null) {
        File appFolder = new File(installFolder, name + ".app"); // $NON-NLS-1$
        if (appFolder.exists()) {
          try {
            appName = appFolder.getCanonicalFile().getName();
          } catch (IOException e) {
            appName = appFolder.getName();
          }
        }
      }

      StringBuffer buffer = new StringBuffer();
      if (appName != null) {
        buffer.append(appName);
      } else {
        buffer.append(name.substring(0, 1).toUpperCase());
        buffer.append(name.substring(1));
        buffer.append(".app"); // $NON-NLS-1$
      }
      buffer.append("/Contents/MacOS/"); // $NON-NLS-1$
      buffer.append(name);
      return buffer.toString();
    }
    return name;
  }
コード例 #13
0
  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;
  }
コード例 #14
0
 /** @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();
 }
コード例 #15
0
 /**
  * Determines if the filter matches the provided path.
  *
  * @param path the path.
  * @return true if the filter matches the provided path and the event should be given to the file
  *     change observer.
  */
 public boolean matches(IPath path) {
   if (getFilterType() == FileObserverFilterType.ALL) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.FILE
       && getFileFilter().getFullPath().equals(path)) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.FOLDER
       && path.isPrefixOf(getFolderFilter().getFullPath())) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.CONTENT_TYPE
       && matchesContentType(path.segment(path.segmentCount() - 1))) {
     return true;
   }
   if (getFilterType() == FileObserverFilterType.EXTENSION
       && matchesExtension(path.getFileExtension())) {
     return true;
   }
   return false;
 }
コード例 #16
0
  String getSourceLocation(IBinding methodBinding, ITypeBinding declaringClass) {
    if (methodBinding == null) {
      throw new IllegalStateException("Cannot find methodbinding, running without workspace?");
    }

    IJavaElement javaElement = methodBinding.getJavaElement();
    if (javaElement == null) {
      return null;
    }
    IPath path = javaElement.getPath();
    if ("jar".equals(path.getFileExtension())) {
      return path.lastSegment();
    } else if (declaringClass != null) {
      return declaringClass
          .getJavaElement()
          .getResource()
          .getProjectRelativePath()
          .toPortableString();
    } else {
      return javaElement.getPath().toPortableString();
    }
  }
コード例 #17
0
ファイル: ToscaFileService.java プロジェクト: CELAR/c-Eclipse
  /**
   * Recreates the data file from the given input path. In case the given path reflects a temporary
   * diagram file, it's path is used to recreate the data file, otherwise the given path is simply
   * made absolute and returned.
   *
   * @param inputPath the path to recreate the data file from
   * @return a file object representing the data file
   */
  public static IFile recreateDataFile(final IPath inputPath) {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IProject project = root.getFile(inputPath).getProject();

    final int matchingSegments = project.getFullPath().matchingFirstSegments(inputPath);
    final int totalSegments = inputPath.segmentCount();
    final String extension = inputPath.getFileExtension();

    IFile result = null;

    if (totalSegments > matchingSegments) {
      // it shall be more than just the project

      IPath resultPath = null;

      if (ToscaUI.TOSCA_DIAGRAM_FILE_EXTENSION.equals(extension)) {
        // we got a temporary file here, so rebuild the file of the model from its path
        String originalExtension = inputPath.segment(matchingSegments);
        if (originalExtension.startsWith(".")) { // $NON-NLS-1$
          originalExtension = originalExtension.substring(1);
        }

        final String[] segments = inputPath.segments();
        IPath originalPath = project.getFullPath();
        for (int index = matchingSegments + 1; index < segments.length; ++index) {
          originalPath = originalPath.append(segments[index]);
        }

        resultPath = originalPath.removeFileExtension().addFileExtension(originalExtension);
      } else {
        resultPath = inputPath.makeAbsolute();
      }

      result = root.getFile(resultPath);
    }

    return result;
  }
コード例 #18
0
  /*
   * Gets and caches an image for a JarEntryFile.
   * The image for a JarEntryFile is retrieved from the EditorRegistry.
   */
  private Image getImageForJarEntry(IStorage element) {
    if (element instanceof IJarEntryResource && !((IJarEntryResource) element).isFile()) {
      return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
    }

    if (fJarImageMap == null) return getDefaultImage();

    if (element == null || element.getName() == null) return getDefaultImage();

    // Try to find icon for full name
    String name = element.getName();
    Image image = fJarImageMap.get(name);
    if (image != null) return image;
    IFileEditorMapping[] mappings = getEditorRegistry().getFileEditorMappings();
    int i = 0;
    while (i < mappings.length) {
      if (mappings[i].getLabel().equals(name)) break;
      i++;
    }
    String key = name;
    if (i == mappings.length) {
      // Try to find icon for extension
      IPath path = element.getFullPath();
      if (path == null) return getDefaultImage();
      key = path.getFileExtension();
      if (key == null) return getDefaultImage();
      image = fJarImageMap.get(key);
      if (image != null) return image;
    }

    // Get the image from the editor registry
    ImageDescriptor desc = getEditorRegistry().getImageDescriptor(name);
    image = desc.createImage();

    fJarImageMap.put(key, image);

    return image;
  }
コード例 #19
0
  private static void handleClasspathLibrary(
      IClasspathEntry e, IWorkspaceRoot wsRoot, Set<File> jarFiles) {
    // get the IPath
    IPath path = e.getPath();

    IResource resource = wsRoot.findMember(path);

    if (SdkConstants.EXT_JAR.equalsIgnoreCase(path.getFileExtension())) {
      // case of a jar file (which could be relative to the workspace or a full path)
      if (resource != null && resource.exists() && resource.getType() == IResource.FILE) {
        jarFiles.add(new CPEFile(resource.getLocation().toFile(), e));
      } else {
        // if the jar path doesn't match a workspace resource,
        // then we get an OSString and check if this links to a valid file.
        String osFullPath = path.toOSString();

        File f = new CPEFile(osFullPath, e);
        if (f.isFile()) {
          jarFiles.add(f);
        }
      }
    }
  }
コード例 #20
0
ファイル: ToscaFileService.java プロジェクト: CELAR/c-Eclipse
  /**
   * Returns or constructs a temporary folder for diagram files used as Graphiti editor input files.
   * The given path reflects the path where the original data file is located. The folder is
   * constructed in the project root named after the data file extension {@link
   * #DATA_FILE_EXTENSION_RAW}.
   *
   * @param dataFilePath path of the actual BPMN2 model file
   * @return an IFolder for the temporary folder.
   * @throws CoreException in case the folder could not be created.
   */
  public static IFolder getOrCreateTempFolder(final IPath dataFilePath) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    String name = dataFilePath.getFileExtension();
    if (name == null || name.length() == 0) {
      name = "tosca"; // $NON-NLS-1$
    }

    String dir = dataFilePath.segment(0);
    IFolder folder = root.getProject(dir).getFolder("." + name); // $NON-NLS-1$
    if (!folder.exists()) {
      folder.create(true, true, null);
    }
    String[] segments = dataFilePath.segments();
    for (int i = 1; i < segments.length - 1; i++) {
      String segment = segments[i];
      folder = folder.getFolder(segment);
      if (!folder.exists()) {
        folder.create(true, true, null);
      }
    }
    return folder;
  }
コード例 #21
0
ファイル: ResourceConfiguration.java プロジェクト: zhaog/cdt
  public ResourceConfiguration(
      FolderInfo folderInfo, ITool baseTool, String id, String resourceName, IPath path) {
    super(folderInfo, path, id, resourceName);
    //		setParentFolder(folderInfo);
    //		setParentFolderId(folderInfo.getId());

    isExtensionResourceConfig = folderInfo.isExtensionElement();
    if (!isExtensionResourceConfig) setResourceData(new BuildFileData(this));

    if (folderInfo.getParent() != null)
      setManagedBuildRevision(folderInfo.getParent().getManagedBuildRevision());

    setDirty(false);
    toolsToInvoke = EMPTY_STRING;
    rcbsApplicability = new Integer(KIND_DISABLE_RCBS_TOOL);

    //	Get file extension.
    String extString = path.getFileExtension();
    if (baseTool != null) {
      if (baseTool.getParentResourceInfo() != folderInfo) baseTool = null;
    }
    // Add the resource specific tools to this resource.
    ITool tools[] = folderInfo.getFilteredTools();
    String subId = new String();
    for (int i = 0; i < tools.length; i++) {
      if (tools[i].buildsFileType(extString)) {
        baseTool = tools[i];
        break;
      }
    }

    if (baseTool != null) {
      subId = ManagedBuildManager.calculateChildId(baseTool.getId(), null);
      createTool(baseTool, subId, baseTool.getName(), false);
      setRebuildState(true);
    }
  }
コード例 #22
0
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }
    PHPexeItem phpExeItem = PHPLaunchUtilities.getPHPExe(configuration);
    if (phpExeItem == null) {
      Logger.log(Logger.ERROR, "Launch configuration could not find PHP exe item"); // $NON-NLS-1$
      monitor.setCanceled(true);
      monitor.done();
      return;
    }
    // get the launch info: php exe, php ini
    final String phpExeString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_EXECUTABLE_LOCATION, (String) null);
    final String phpIniString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_INI_LOCATION, (String) null);
    final String phpScriptString =
        configuration.getAttribute(IPHPDebugConstants.ATTR_FILE, (String) null);
    if (phpScriptString == null || phpScriptString.trim().length() == 0) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      displayErrorMessage(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_0);
      return;
    }
    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // locate the project from the php script
    final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    final IPath filePath = new Path(phpScriptString);
    final IResource scriptRes = workspaceRoot.findMember(filePath);
    if (scriptRes == null) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      displayErrorMessage(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_1);
      return;
    }

    // resolve php exe location
    final IPath phpExe = new Path(phpExeString);

    // resolve project directory
    IProject project = scriptRes.getProject();

    // Set Project Name as this is required by the source lookup computer
    // delegate
    final String projectString = project.getFullPath().toString();
    ILaunchConfigurationWorkingCopy wc = null;
    if (configuration.isWorkingCopy()) {
      wc = (ILaunchConfigurationWorkingCopy) configuration;
    } else {
      wc = configuration.getWorkingCopy();
    }
    wc.setAttribute(IPHPDebugConstants.PHP_Project, projectString);
    wc.setAttribute(
        IDebugParametersKeys.TRANSFER_ENCODING, PHPProjectPreferences.getTransferEncoding(project));
    wc.setAttribute(
        IDebugParametersKeys.OUTPUT_ENCODING, PHPProjectPreferences.getOutputEncoding(project));
    wc.doSave();

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    IPath projectLocation = project.getRawLocation();
    if (projectLocation == null) {
      projectLocation = project.getLocation();
    }

    // resolve the script location, but not relative to anything
    IPath phpFile = scriptRes.getLocation();

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // Resolve the PHP ini location
    // Locate the php ini by using the attribute. If the attribute was null,
    // try to locate an ini that exists next to the executable.
    File phpIni =
        (phpIniString != null && new File(phpIniString).exists())
            ? new File(phpIniString)
            : PHPINIUtil.findPHPIni(phpExeString);
    File tempIni = PHPINIUtil.prepareBeforeLaunch(phpIni, phpExeString, project);
    launch.setAttribute(IDebugParametersKeys.PHP_INI_LOCATION, tempIni.getAbsolutePath());

    // add process type to process attributes, basically the name of the exe
    // that was launched
    final Map<String, String> processAttributes = new HashMap<String, String>();
    String programName = phpExe.lastSegment();
    final String extension = phpExe.getFileExtension();
    if (extension != null) {
      programName = programName.substring(0, programName.length() - (extension.length() + 1));
    }
    programName = programName.toLowerCase();

    // used by the console colorer extension to determine what class to use
    // should allow the console color providers and line trackers to work
    // process.setAttribute(IProcess.ATTR_PROCESS_TYPE,
    // IPHPConstants.PHPProcessType);

    processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
    // used by the Console to give that console a name
    processAttributes.put(IProcess.ATTR_CMDLINE, phpScriptString);

    if (monitor.isCanceled()) {
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
      return;
    }

    // determine the environment variables
    String[] envVarString = null;
    DBGpTarget target = null;
    if (mode.equals(ILaunchManager.DEBUG_MODE)) {
      // check the launch for stop at first line, if not there go to
      // project specifics
      boolean stopAtFirstLine = PHPProjectPreferences.getStopAtFirstLine(project);
      stopAtFirstLine =
          configuration.getAttribute(IDebugParametersKeys.FIRST_LINE_BREAKPOINT, stopAtFirstLine);
      String sessionID = DBGpSessionHandler.getInstance().generateSessionId();
      String ideKey = null;
      if (phpExeItem != null) {
        DBGpProxyHandler proxyHandler =
            DBGpProxyHandlersManager.INSTANCE.getHandler(phpExeItem.getUniqueId());
        if (proxyHandler != null && proxyHandler.useProxy()) {
          ideKey = proxyHandler.getCurrentIdeKey();
          if (proxyHandler.registerWithProxy() == false) {
            displayErrorMessage(
                PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_2
                    + proxyHandler.getErrorMsg());
            DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
            return;
          }
        } else {
          ideKey = DBGpSessionHandler.getInstance().getIDEKey();
        }
      }
      target = new DBGpTarget(launch, phpFile.lastSegment(), ideKey, sessionID, stopAtFirstLine);
      target.setPathMapper(PathMapperRegistry.getByLaunchConfiguration(configuration));
      DBGpSessionHandler.getInstance().addSessionListener(target);
      envVarString = createDebugLaunchEnvironment(configuration, sessionID, ideKey, phpExe);

      int requestPort = getDebugPort(phpExeItem);
      // Check that the debug daemon is functional
      // DEBUGGER - Make sure that the active debugger id is indeed Zend's
      // debugger
      if (!PHPLaunchUtilities.isDebugDaemonActive(
          requestPort, XDebugCommunicationDaemon.XDEBUG_DEBUGGER_ID)) {
        PHPLaunchUtilities.showLaunchErrorMessage(
            NLS.bind(
                PHPDebugCoreMessages.ExeLaunchConfigurationDelegate_PortInUse,
                requestPort,
                phpExeItem.getName()));
        monitor.setCanceled(true);
        monitor.done();
        return;
      }

    } else {
      envVarString =
          PHPLaunchUtilities.getEnvironment(configuration, new String[] {getLibraryPath(phpExe)});
    }

    IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 30);
    subMonitor.beginTask(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_3, 10);

    // determine the working directory. default is the location of the
    // script
    IPath workingPath = phpFile.removeLastSegments(1);
    File workingDir = workingPath.makeAbsolute().toFile();

    boolean found = false;
    for (int i = 0; i < envVarString.length && !found; i++) {
      String envEntity = envVarString[i];
      String[] elements = envEntity.split("="); // $NON-NLS-1$
      if (elements.length > 0 && elements[0].equals("XDEBUG_WORKING_DIR")) { // $NON-NLS-1$
        found = true;
        workingPath = new Path(elements[1]);
        File temp = workingPath.makeAbsolute().toFile();
        if (temp.exists()) {
          workingDir = temp;
        }
      }
    }

    // Detect PHP SAPI type and thus where we need arguments
    File phpExeFile = new File(phpExeString);
    String sapiType = null;
    String phpV = null;
    PHPexeItem[] items = PHPexes.getInstance().getAllItems();
    for (PHPexeItem item : items) {
      if (item.getExecutable().equals(phpExeFile)) {
        sapiType = item.getSapiType();
        phpV = item.getVersion();
        break;
      }
    }
    String[] args = null;
    if (PHPexeItem.SAPI_CLI.equals(sapiType)) {
      args = PHPLaunchUtilities.getProgramArguments(launch.getLaunchConfiguration());
    }

    // define the command line for launching
    String[] cmdLine = null;
    cmdLine =
        PHPLaunchUtilities.getCommandLine(
            configuration,
            phpExe.toOSString(),
            tempIni.toString(),
            phpFile.toOSString(),
            args,
            phpV);

    // Launch the process
    final Process phpExeProcess = DebugPlugin.exec(cmdLine, workingDir, envVarString);
    // Attach a crash detector
    new Thread(new ProcessCrashDetector(launch, phpExeProcess)).start();

    IProcess eclipseProcessWrapper = null;
    if (phpExeProcess != null) {
      subMonitor.worked(10);
      eclipseProcessWrapper =
          DebugPlugin.newProcess(launch, phpExeProcess, phpExe.toOSString(), processAttributes);
      if (eclipseProcessWrapper == null) {

        // another error so we stop everything somehow
        phpExeProcess.destroy();
        subMonitor.done();
        DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
        throw new CoreException(new Status(IStatus.ERROR, PHPDebugPlugin.ID, 0, null, null));
      }

      // if launching in debug mode, create the debug infrastructure and
      // link it with the launched process
      if (mode.equals(ILaunchManager.DEBUG_MODE) && target != null) {
        target.setProcess(eclipseProcessWrapper);
        launch.addDebugTarget(target);
        subMonitor.subTask(PHPDebugCoreMessages.XDebug_ExeLaunchConfigurationDelegate_4);
        target.waitForInitialSession(
            (DBGpBreakpointFacade) IDELayerFactory.getIDELayer(),
            XDebugPreferenceMgr.createSessionPreferences(),
            monitor);
      }

    } else {
      // we did not launch
      if (mode.equals(ILaunchManager.DEBUG_MODE)) {
        DBGpSessionHandler.getInstance().removeSessionListener(target);
      }
      DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
    }
    subMonitor.done();
  }
コード例 #23
0
ファイル: FolderInfoModification.java プロジェクト: zhaog/cdt
  private void applyToolChain(ToolChain newNonRealTc) {
    ToolChain newRealTc = (ToolChain) ManagedBuildManager.getRealToolChain(newNonRealTc);

    ToolChainApplicabilityPaths tcApplicability = getToolChainApplicabilityPaths();
    PerTypeMapStorage<? extends IRealBuildObjectAssociation, Set<IPath>> storage =
        getCompleteObjectStore();

    @SuppressWarnings("unchecked")
    Map<ToolChain, Set<IPath>> tcMap =
        (Map<ToolChain, Set<IPath>>)
            storage.getMap(IRealBuildObjectAssociation.OBJECT_TOOLCHAIN, false);
    @SuppressWarnings("unchecked")
    Map<Tool, Set<IPath>> toolMap =
        (Map<Tool, Set<IPath>>) storage.getMap(IRealBuildObjectAssociation.OBJECT_TOOL, false);

    TcModificationUtil.removePaths(tcMap, fRealToolChain, tcApplicability.fFolderInfoPaths);
    TcModificationUtil.addPaths(tcMap, newRealTc, tcApplicability.fFolderInfoPaths);
    Tool[] newTools = (Tool[]) newNonRealTc.getTools();

    for (int i = 0; i < newTools.length; i++) {
      newTools[i] = (Tool) ManagedBuildManager.getRealTool(newTools[i]);
    }

    Set<Entry<Tool, Set<IPath>>> entrySet = tcApplicability.fToolPathMap.entrySet();
    for (Iterator<Entry<Tool, Set<IPath>>> iter = entrySet.iterator(); iter.hasNext(); ) {
      Map.Entry<Tool, Set<IPath>> entry = iter.next();
      Tool tool = entry.getKey();
      Set<IPath> pathSet = entry.getValue();

      TcModificationUtil.removePaths(toolMap, tool, pathSet);
    }

    for (int i = 0; i < newTools.length; i++) {
      TcModificationUtil.addPaths(toolMap, newTools[i], tcApplicability.fFolderInfoPaths);
    }

    if (tcApplicability.fFileInfoPaths.size() != 0) {
      FolderInfo foInfo = (FolderInfo) getResourceInfo();
      IManagedProject mProj = foInfo.getParent().getManagedProject();
      IProject project = mProj.getOwner().getProject();
      Tool[] filtered = (Tool[]) foInfo.filterTools(newTools, mProj);
      if (filtered.length != 0) {
        for (IPath p : tcApplicability.fFileInfoPaths) {
          boolean found = false;
          String ext = p.getFileExtension();
          if (ext == null) ext = ""; // $NON-NLS-1$
          for (int i = 0; i < filtered.length; i++) {
            if (filtered[i].buildsFileType(ext, project)) {
              TcModificationUtil.addPath(toolMap, filtered[i], p);
              found = true;
              break;
            }
          }

          if (!found) {
            if (DbgTcmUtil.DEBUG) {
              DbgTcmUtil.println("no tools found for path " + p); // $NON-NLS-1$
            }
          }
        }

      } else if (DbgTcmUtil.DEBUG) {
        DbgTcmUtil.println("no filtered tools"); // $NON-NLS-1$
      }
    }
  }
コード例 #24
0
  /**
   * Ask for a file name and save the viewer containing the currently selected GraphicalEditPart to
   * a image file.
   */
  @Override
  public void run() {
    final IEditorInput editorInput =
        (IEditorInput) getWorkbenchPart().getAdapter(IEditorInput.class);
    final SaveAsDialog dialog = new SaveAsDialog(new Shell(Display.getDefault()));
    dialog.setBlockOnOpen(true);
    if (editorInput == null) {
      dialog.setOriginalName("viewerImage" + counter + ".png");
    } else {
      final String fileName = editorInput.getName();
      final int extensionPos = fileName.lastIndexOf(".");
      dialog.setOriginalName(fileName.substring(0, extensionPos) + ".png");
    }
    dialog.create();
    dialog.setMessage(
        "If you don't choose an extension png will be used a default. "
            + "\n"
            + "Export is limited to file size of 15MByte -> you may use file ..(read more) "
            + "\n"
            + "type svg for very large graphs."
            + "\n"
            + "After export the workspace needs a manual refresh to show new image file.");
    dialog.setTitle("Specify file to export viewer image (png, jpeg, bmp, svg)");
    dialog.open();
    if (Window.CANCEL == dialog.getReturnCode()) {
      return;
    }

    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IPath path = root.getLocation().append(dialog.getResult());

    int format;
    final String ext = path.getFileExtension();
    if (ext.equals("png")) {
      format = SWT.IMAGE_PNG;
      // GIFs work only with 8Bit and not with 32 Bits color depth
      //		} else if (ext.equals("gif")) {
      //			format = SWT.IMAGE_GIF;
    } else if (ext.equals("jpeg")) {
      format = SWT.IMAGE_JPEG;
    } else if (ext.equals("bmp")) {
      format = SWT.IMAGE_BMP;
      // } else if (ext.equals("ico")) {
      // format = SWT.IMAGE_ICO;
    } else if (ext.equalsIgnoreCase("svg")) {
      format = SWT.IMAGE_UNDEFINED; // TODO: find a more appropriate constant for representing SVGs
    } else {
      MessageDialog.openError(
          null,
          "Invalid file extension!",
          "The specified extension ("
              + ext
              + ") is not a valid image format extension.\nPlease use png, jpeg, bmp or svg!");
      return;
    }

    IFigure figure = ((SimpleRootEditPart) viewer.getRootEditPart()).getFigure();
    if (figure instanceof Viewport) {
      // This seems to trim the figure to the smallest rectangle containing all child figures
      ((Viewport) figure).setSize(1, 1);
      ((Viewport) figure).validate();
      figure = ((Viewport) figure).getContents();
    }
    if (format == SWT.IMAGE_UNDEFINED) {
      try {
        final File file = path.toFile();
        this.exportToSVG(file, figure);
      } catch (final IOException e) {
        e.printStackTrace();
      }
    } else {
      final byte[] imageCode = createImage(figure, format);
      try {
        final File file = path.toFile();
        final FileOutputStream fos = new FileOutputStream(file);
        fos.write(imageCode);
        fos.flush();
        fos.close();
        counter++;
      } catch (final IOException e) {
        e.printStackTrace();
      }
    }
  }