Пример #1
0
 protected void generateFiles(IProgressMonitor monitor) throws CoreException {
   super.generateFiles(monitor);
   // Copy the default splash screen if the branding option is selected
   if (copyBrandingDirectory()) {
     super.generateFiles(
         monitor, Activator.getDefault().getBundle().getEntry("branding/")); // $NON-NLS-1$
   }
 }
Пример #2
0
 /**
  * creates a new container instance.
  *
  * @param description the container type description.
  * @param parameters the parameter passed to the container constructor.
  * @return the factored container instance.
  * @see
  *     org.eclipse.ecf.core.provider.IContainerInstantiator#createInstance(org.eclipse.ecf.core.ContainerTypeDescription,
  *     java.lang.Object[])
  */
 public IContainer createInstance(
     final ContainerTypeDescription description, final Object[] parameters)
     throws ContainerCreateException {
   try {
     final RemoteOSGiService remoteOSGiService = Activator.getDefault().getRemoteOSGiService();
     String descriptionName = description.getName();
     boolean wss = descriptionName.equals(ROSGI_WEBSOCKETSS_CONFIG);
     boolean ws = (descriptionName.equals(ROSGI_WEBSOCKETS_CONFIG) || wss);
     Namespace ns =
         (wss
             ? R_OSGiWSSNamespace.getDefault()
             : ((ws) ? R_OSGiWSNamespace.getDefault() : R_OSGiNamespace.getDefault()));
     ID containerID = null;
     if (parameters == null) {
       String localHost = "localhost"; // $NON-NLS-1$
       if (useHostname) {
         try {
           localHost = InetAddress.getLocalHost().getCanonicalHostName();
         } catch (UnknownHostException e) {
           // Ignore
         }
       }
       final String nsScheme = ns.getScheme();
       final String wsProtocol = (wss ? WSS_PROTOCOL : (ws ? WS_PROTOCOL : null));
       int listeningPort =
           remoteOSGiService.getListeningPort((wsProtocol != null) ? wsProtocol : nsScheme);
       int idPort = -1;
       if (WSS_PROTOCOL.equals(wsProtocol) && listeningPort != WSS_DEFAULT_PORT)
         idPort = listeningPort;
       else if (WS_PROTOCOL.equals(wsProtocol) && listeningPort != WS_DEFAULT_PORT)
         idPort = listeningPort;
       String portStr = (idPort > 0 ? (":" + idPort) : ""); // $NON-NLS-1$ //$NON-NLS-2$
       containerID =
           createR_OSGiID(ns, new String(nsScheme + "://" + localHost + portStr)); // $NON-NLS-1$
     } else if (parameters.length > 0) {
       if (parameters[0] instanceof ID) containerID = (ID) parameters[0];
       else if (parameters[0] instanceof String)
         containerID = createR_OSGiID(ns, (String) parameters[0]);
       else if (parameters[0] instanceof Map) {
         Map params = (Map) parameters[0];
         String idStr = (String) params.get(ID_PROP);
         if (idStr == null)
           throw new NullPointerException("No ID prop found in parameters map"); // $NON-NLS-1$
         containerID = createR_OSGiID(ns, idStr);
       }
     }
     if (containerID == null)
       throw new ContainerCreateException(
           "Unsupported arguments " //$NON-NLS-1$
               + Arrays.asList(parameters));
     if (wss) return new R_OSGiWSSRemoteServiceContainer(remoteOSGiService, containerID);
     else if (ws) return new R_OSGiWSRemoteServiceContainer(remoteOSGiService, containerID);
     else return new R_OSGiRemoteServiceContainer(remoteOSGiService, containerID);
   } catch (Exception e) {
     throw new ContainerCreateException("Could not create R_OSGI ID", e); // $NON-NLS-1$
   }
 }
Пример #3
0
 private void notifyListeners() {
   for (DatabaseModelListener listener : listeners) {
     try {
       listener.connectedStatusChangedTo(connected());
     } catch (Exception exc) {
       IStatus status =
           new Status(
               IStatus.ERROR, Activator.PLUGIN_ID, "error during listener notification", exc);
       Activator.getDefault().getLog().log(status);
     }
   }
 }
Пример #4
0
 public URL getTemplateLocation() {
   try {
     String[] candidates = getDirectoryCandidates();
     for (int i = 0; i < candidates.length; i++) {
       if (Activator.getDefault().getBundle().getEntry(candidates[i]) != null) {
         URL candidate = new URL(getInstallURL(), candidates[i]);
         return candidate;
       }
     }
   } catch (MalformedURLException e) { // do nothing
   }
   return null;
 }
Пример #5
0
  /**
   * Looks for the project in all workspaces of the user and removes it when found.
   *
   * @see WorkspaceResourceHandler#handleRemoveProject(HttpServletRequest, HttpServletResponse,
   *     WebWorkspace)
   * @param userName the user name
   * @param webProject the project to remove
   * @return ServerStatus <code>OK</code> if the project has been found and successfully removed,
   *     <code>ERROR</code> if an error occurred or the project couldn't be found
   */
  public static ServerStatus removeProject(String userName, WebProject webProject) {
    try {
      WebUser webUser = WebUser.fromUserId(userName);
      JSONArray workspacesJSON = webUser.getWorkspacesJSON();
      for (int i = 0; i < workspacesJSON.length(); i++) {
        JSONObject workspace = workspacesJSON.getJSONObject(i);
        String workspaceId = workspace.getString(ProtocolConstants.KEY_ID);
        WebWorkspace webWorkspace = WebWorkspace.fromId(workspaceId);
        JSONArray projectsJSON = webWorkspace.getProjectsJSON();
        for (int j = 0; j < projectsJSON.length(); j++) {
          JSONObject project = projectsJSON.getJSONObject(j);
          String projectId = project.getString(ProtocolConstants.KEY_ID);
          if (projectId.equals(webProject.getId())) {
            // If found, remove project from workspace
            try {
              WorkspaceResourceHandler.removeProject(userName, webWorkspace, webProject);
            } catch (CoreException e) {
              // we are unable to write in the platform location!
              String msg =
                  NLS.bind(
                      "Server content location could not be written: {0}",
                      Activator.getDefault().getRootLocationURI());
              return new ServerStatus(
                  IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
            }

            return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
          }
        }
      }
    } catch (JSONException e) {
      // ignore, no project will be harmed
    }
    // FIXME: not sure about this one
    return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
  }
Пример #6
0
  private boolean handlePost(
      HttpServletRequest request, HttpServletResponse response, String pathString)
      throws IOException, JSONException, ServletException, URISyntaxException, CoreException,
          NoHeadException, NoMessageException, ConcurrentRefUpdateException,
          WrongRepositoryStateException {
    // make sure required fields are set
    JSONObject toAdd = OrionServlet.readJSONRequest(request);
    if (toAdd.optBoolean(GitConstants.KEY_PULL, false)) {
      GitUtils.createGitCredentialsProvider(toAdd);
      GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
      boolean force = toAdd.optBoolean(GitConstants.KEY_FORCE, false);
      return pull(request, response, cp, pathString, force);
    }

    Clone clone = new Clone();
    String url = toAdd.optString(GitConstants.KEY_URL, null);
    // method handles repository clone or just repository init
    // decision is based on existence of GitUrl argument
    boolean initOnly;
    if (url == null || url.isEmpty()) initOnly = true;
    else {
      initOnly = false;
      if (!validateCloneUrl(url, request, response)) return true;
      clone.setUrl(new URIish(url));
    }
    String cloneName = toAdd.optString(ProtocolConstants.KEY_NAME, null);
    if (cloneName == null) cloneName = request.getHeader(ProtocolConstants.HEADER_SLUG);
    // expected path /workspace/{workspaceId}
    String workspacePath = toAdd.optString(ProtocolConstants.KEY_LOCATION, null);
    // expected path /file/{workspaceId}/{projectName}[/{path}]
    String filePathString = toAdd.optString(ProtocolConstants.KEY_PATH, null);
    IPath filePath = filePathString == null ? null : new Path(filePathString);
    if (filePath != null && filePath.segmentCount() < 3) filePath = null;
    if (filePath == null && workspacePath == null) {
      String msg =
          NLS.bind(
              "Either {0} or {1} should be provided: {2}",
              new Object[] {ProtocolConstants.KEY_PATH, ProtocolConstants.KEY_LOCATION, toAdd});
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    // only during init operation filePath or cloneName must be provided
    // during clone operation, name can be obtained from URL
    if (initOnly && filePath == null && cloneName == null) {
      String msg =
          NLS.bind(
              "Either {0} or {1} should be provided: {2}",
              new Object[] {ProtocolConstants.KEY_PATH, GitConstants.KEY_NAME, toAdd});
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
    }
    if (!validateCloneName(cloneName, request, response)) return true;

    // prepare the WebClone object, create a new project if necessary
    WebProject webProject = null;
    boolean webProjectExists = false;
    if (filePath != null) {
      // path format is /file/{workspaceId}/{projectName}/[filePath]
      clone.setId(filePath.toString());
      webProject = GitUtils.projectFromPath(filePath);
      // workspace path format needs to be used if project does not exist
      if (webProject == null) {
        String msg = NLS.bind("Specified project does not exist: {0}", filePath.segment(2));
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
      }
      webProjectExists = true;
      clone.setContentLocation(
          webProject.getProjectStore().getFileStore(filePath.removeFirstSegments(3)).toURI());
      if (cloneName == null)
        cloneName = filePath.segmentCount() > 2 ? filePath.lastSegment() : webProject.getName();
    } else if (workspacePath != null) {
      IPath path = new Path(workspacePath);
      // TODO: move this to CloneJob
      // if so, modify init part to create a new project if necessary
      WebWorkspace workspace = WebWorkspace.fromId(path.segment(1));
      String id = WebProject.nextProjectId();
      if (cloneName == null) cloneName = new URIish(url).getHumanishName();
      cloneName = getUniqueProjectName(workspace, cloneName);
      webProjectExists = false;
      webProject = WebProject.fromId(id);
      webProject.setName(cloneName);

      try {
        WorkspaceResourceHandler.computeProjectLocation(request, webProject, null, false);
      } catch (CoreException e) {
        // we are unable to write in the platform location!
        String msg =
            NLS.bind(
                "Server content location could not be written: {0}",
                Activator.getDefault().getRootLocationURI());
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
      } catch (URISyntaxException e) {
        // should not happen, we do not allow linking at this point
      }

      try {
        // If all went well, add project to workspace
        WorkspaceResourceHandler.addProject(request.getRemoteUser(), workspace, webProject);
      } catch (CoreException e) {
        return statusHandler.handleRequest(
            request,
            response,
            new ServerStatus(
                IStatus.ERROR,
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Error persisting project state",
                e));
      }

      URI baseLocation = getURI(request);
      baseLocation =
          new URI(
              baseLocation.getScheme(),
              baseLocation.getUserInfo(),
              baseLocation.getHost(),
              baseLocation.getPort(),
              workspacePath,
              baseLocation.getQuery(),
              baseLocation.getFragment());
      clone.setId(GitUtils.pathFromProject(workspace, webProject).toString());
      clone.setContentLocation(webProject.getProjectStore().toURI());
    }
    clone.setName(cloneName);
    clone.setBaseLocation(getURI(request));
    JSONObject cloneObject = clone.toJSON();
    String cloneLocation = cloneObject.getString(ProtocolConstants.KEY_LOCATION);

    if (initOnly) {
      // git init
      InitJob job =
          new InitJob(
              clone, TaskJobHandler.getUserId(request), request.getRemoteUser(), cloneLocation);
      return TaskJobHandler.handleTaskJob(request, response, job, statusHandler);
    }
    // git clone
    // prepare creds
    GitCredentialsProvider cp = GitUtils.createGitCredentialsProvider(toAdd);
    cp.setUri(new URIish(clone.getUrl()));

    // if all went well, clone
    CloneJob job =
        new CloneJob(
            clone,
            TaskJobHandler.getUserId(request),
            cp,
            request.getRemoteUser(),
            cloneLocation,
            webProjectExists
                ? null
                : webProject /* used for cleaning up, so null when not needed */);
    return TaskJobHandler.handleTaskJob(request, response, job, statusHandler);
  }
Пример #7
0
 protected URL getInstallURL() {
   return Activator.getDefault().getInstallURL();
 }