private void updateEntries() throws Exception {
    final List<IClasspathEntry> newEntries = new ArrayList<>();
    for (final String referenceLibrary : SARL_REFERENCE_LIBRARIES) {
      // Retreive the bundle
      final Bundle bundle = Platform.getBundle(referenceLibrary);
      if (bundle == null) {
        throw new NameNotFoundException("No bundle found for: " + referenceLibrary); // $NON-NLS-1$
      }

      final IPath bundlePath = BundleUtil.getBundlePath(bundle);
      final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath);

      IClasspathAttribute[] extraAttributes = null;
      if (referenceLibrary.startsWith("io.sarl")) { // $NON-NLS-1$
        final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath);
        final IClasspathAttribute attr;
        if (javadocPath == null) {
          attr =
              JavaCore.newClasspathAttribute(
                  IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, JAVADOC_URL);
        } else {
          attr =
              JavaCore.newClasspathAttribute(
                  IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                  javadocPath.makeAbsolute().toOSString());
        }
        extraAttributes = new IClasspathAttribute[] {attr};
      }

      newEntries.add(
          JavaCore.newLibraryEntry(
              bundlePath, sourceBundlePath, null, new IAccessRule[] {}, extraAttributes, false));
    }
    this.entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
  }
  public void elementEncode(XMLWriter writer, IPath projectPath, boolean newLine) {
    // Keeping this as a HashMap (not a Map) for the XMLWriter
    HashMap parameters = new HashMap();

    parameters.put(TAG_ENTRY_KIND, IncludePathEntry.entryKindToString(this.entryKind));
    parameters.put(TAG_CONTENT_KIND, IncludePathEntry.contentKindToString(this.contentKind));
    parameters.put(
        TAG_CREATEDREFERENCE, createdReference ? "true" : "false"); // $NON-NLS-1$ //$NON-NLS-2$

    IPath xmlPath = this.path;
    if (this.entryKind != IIncludePathEntry.IPE_VARIABLE
        && this.entryKind != IIncludePathEntry.IPE_CONTAINER) {
      // translate to project relative from absolute (unless a device path)
      if (projectPath != null && projectPath.isPrefixOf(xmlPath)) {
        if (xmlPath.segment(0).equals(projectPath.segment(0))) {
          xmlPath = xmlPath.removeFirstSegments(1);
          xmlPath = xmlPath.makeRelative();
        } else {
          xmlPath = xmlPath.makeAbsolute();
        }
      }
    }
    parameters.put(TAG_PATH, String.valueOf(xmlPath));
    if (resource != null) {
      parameters.put(TAG_RESOURCE, resource.getName());
    }
    if (this.isExported) {
      parameters.put(TAG_EXPORTED, "true"); // $NON-NLS-1$
    }

    writer.printTag(TAG_INCLUDEPATHENTRY, parameters);
    writer.endTag(TAG_INCLUDEPATHENTRY);
  }
 /**
  * Respects images residing in any plug-in. If path is relative, then this bundle is looked up for
  * the image, otherwise, for absolute path, first segment is taken as id of plug-in with image
  *
  * @generated
  * @param path the path to image, either absolute (with plug-in id as first segment), or relative
  *     for bundled images
  * @return the image descriptor
  */
 public static ImageDescriptor findImageDescriptor(String path) {
   final IPath p = new Path(path);
   if (p.isAbsolute() && p.segmentCount() > 1) {
     return AbstractUIPlugin.imageDescriptorFromPlugin(
         p.segment(0), p.removeFirstSegments(1).makeAbsolute().toString());
   } else {
     return getBundledImageDescriptor(p.makeAbsolute().toString());
   }
 }
  /*
   * Appends a path to a URI and returns the new combined URI in an array of 2 elements,
   * where the first element is in decoded form and the second element is in encoded form.
   */
  private String[] appendPathToURI(URI uriObj, IPath path) {

    String schemeSpecificPart = uriObj.getSchemeSpecificPart();

    if (schemeSpecificPart.endsWith("/")) path = path.makeRelative();
    else path = path.makeAbsolute();

    return new String[] {
      uriObj.getScheme() + ':' + schemeSpecificPart + path,
      uriObj.getScheme() + ':' + uriObj.getRawSchemeSpecificPart() + path
    };
  }
示例#5
0
 /**
  * Get list of clones for the given workspace or path. When <code>path</code> is not <code>null
  * </code> the result is narrowed to clones under the <code>path</code>.
  *
  * @param workspaceId the workspace ID. Must be null if path is provided.
  * @param path path under the workspace starting with project ID. Must be null if workspaceId is
  *     provided.
  * @return the request
  */
 private WebRequest listGitClonesRequest(String workspaceId, IPath path) {
   assertTrue(workspaceId == null && path != null || workspaceId != null && path == null);
   String requestURI = SERVER_LOCATION + GIT_SERVLET_LOCATION + Clone.RESOURCE + '/';
   if (workspaceId != null) {
     requestURI += "workspace/" + workspaceId;
   } else {
     requestURI += "path" + (path.isAbsolute() ? path : path.makeAbsolute());
   }
   WebRequest request = new GetMethodWebRequest(requestURI);
   request.setHeaderField(ProtocolConstants.HEADER_ORION_VERSION, "1");
   setAuthentication(request);
   return request;
 }
示例#6
0
  /**
   * 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;
  }
  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();
  }
  private IProject openProject(final IPath projectPath) throws CoreException {
    final ResourceSet set = ScaResourceFactoryUtil.createResourceSet();
    final IProgressMonitor progressMonitor = new NullProgressMonitor();
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot root = workspace.getRoot();
    final IWorkspaceDescription description = workspace.getDescription();
    final File projectPathFile = projectPath.toFile();
    final IPath projectDescriptionPath = projectPath.append(".project");

    if (!projectPathFile.isDirectory()) {
      throw new IllegalStateException("Provided project path must be a directory");
    }

    if (!projectDescriptionPath.toFile().exists()) {
      throw new IllegalStateException("Provided project path must include .project file");
    }

    final IProjectDescription projDesc = workspace.loadProjectDescription(projectDescriptionPath);
    final IProject project = root.getProject(projDesc.getName());

    if (project.exists()) {
      // If the project exists, make sure that it is the same project the user requested
      // ...this should only happen if the user forced a workspace with -data
      // that already contained a project with the same name but different path
      // from the one provided on the command line
      if (!project.getLocation().equals(projectPath.makeAbsolute())) {
        throw new IllegalStateException(
            "Provided project path conflicts with existing project in workspace");
      }
    } else {
      // If the project doesn't exist in the workspace, create a linked project
      projDesc.setName(projDesc.getName());
      if (Platform.getLocation().isPrefixOf(projectPath)) {
        projDesc.setLocation(null);
      } else {
        projDesc.setLocation(projectPath);
      }

      final WorkspaceModifyOperation operation =
          new WorkspaceModifyOperation() {

            @Override
            protected void execute(final IProgressMonitor monitor)
                throws CoreException, InvocationTargetException, InterruptedException {

              final SubMonitor progressMonitor = SubMonitor.convert(monitor, 1);
              System.out.println(
                  "Loading project " + projDesc.getName() + " " + projDesc.getLocation());
              project.create(projDesc, progressMonitor.newChild(1));
            }
          };

      try {
        operation.run(new NullProgressMonitor());
      } catch (final InvocationTargetException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      } catch (final InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }

    // Finally open the project
    Assert.isTrue(project.exists());

    final WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {
          @Override
          protected void execute(final IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {
            project.open(monitor);
          }
        };

    try {
      operation.run(new NullProgressMonitor());
    } catch (final InvocationTargetException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (final InterruptedException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    return project;
  }