public IFile getFile() {
   String fileName = unitName;
   if (!fileName.endsWith(".ceylon")) fileName += ".ceylon";
   IPath path = packageFragment.getPath().append(fileName);
   IProject project = sourceDir.getJavaProject().getProject();
   return project.getFile(path.makeRelativeTo(project.getFullPath()));
 }
 /* (non-Javadoc)
  * @see org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer#getCompilationPath(java.lang.String)
  */
 public IPath getCompilationPath(String sourceName) {
   IPath path = new Path(sourceName);
   IPath base = new Path(fDirectory.getPath());
   if (base.isPrefixOf(path)) {
     if (fSubfolders) {
       base = path.removeLastSegments(1);
     }
     return path.makeRelativeTo(base);
   }
   return null;
 }
Ejemplo n.º 3
0
 @Override
 protected void service(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   traceRequest(req);
   String pathInfoString = req.getPathInfo();
   String queryString = getQueryString(req);
   IPath pathInfo =
       new Path(
           null /*don't parse host:port as device*/,
           pathInfoString == null ? "" : pathInfoString); // $NON-NLS-1$
   if (pathInfo.segmentCount() > 0) {
     String hostedHost = pathInfo.segment(0);
     IHostedSite site = HostingActivator.getDefault().getHostingService().get(hostedHost);
     if (site != null) {
       IPath path = pathInfo.removeFirstSegments(1);
       IPath contextPath = new Path(req.getContextPath());
       IPath contextlessPath = path.makeRelativeTo(contextPath).makeAbsolute();
       URI[] mappedPaths;
       try {
         mappedPaths = getMapped(site, contextlessPath, queryString);
       } catch (URISyntaxException e) {
         handleException(
             resp,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_BAD_REQUEST,
                 "Could not create target URI	",
                 e));
         return;
       }
       if (mappedPaths != null) {
         serve(req, resp, site, mappedPaths);
       } else {
         handleException(
             resp,
             new ServerStatus(
                 IStatus.ERROR,
                 HttpServletResponse.SC_NOT_FOUND,
                 NLS.bind("No mappings matched {0}", path),
                 null));
       }
     } else {
       String msg = NLS.bind("Hosted site {0} is stopped", hostedHost);
       handleException(
           resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, msg, null));
     }
   } else {
     super.doGet(req, resp);
   }
 }
Ejemplo n.º 4
0
  @SuppressWarnings("unused")
  private void copyProjectProperties(IProject project, IPath destinationPath) {
    final IFile source = project.getFile(PROJECT_PROPERTIES_FILE_NAME);
    if (!source.exists()) {
      assert false : PROJECT_PROPERTIES_COULD_NOT_BE_COPIED_COMMA__BECAUSE_IT_DOES_NOT_EXIST_;
      return;
    }

    final IFile destination =
        newProject.getFile(
            destinationPath
                .makeRelativeTo(newProject.getFullPath())
                .append(PROJECT_PROPERTIES_FILE_NAME));
    if (!destination.exists())
      try {
        System.out.println("source: " + source + " ; target: " + destination);
        source.copy(destination.getFullPath(), true, null);
      } catch (CoreException e) {
        e.printStackTrace();
      }
  }
  @Override
  public void processResourceDeltas(
      final IModuleResourceDelta[] deltas,
      ZipOutputStream zip,
      Map<ZipEntry, String> deleteEntries,
      final String deletePrefix,
      final String deltaPrefix,
      final boolean adjustGMTOffset)
      throws IOException, CoreException {
    for (final IModuleResourceDelta delta : deltas) {
      final int deltaKind = delta.getKind();
      final IResource deltaResource =
          (IResource) delta.getModuleResource().getAdapter(IResource.class);
      final IProject deltaProject = deltaResource.getProject();
      final ILiferayProject lrproject = LiferayCore.create(deltaProject);
      final IFolder webappRoot = lrproject.getDefaultDocrootFolder();
      final IPath deltaFullPath = deltaResource.getFullPath();

      boolean deltaZip = false;
      IPath deltaPath = null;

      if (webappRoot != null && webappRoot.exists()) {
        final IPath containerFullPath = webappRoot.getFullPath();

        if (containerFullPath.isPrefixOf(deltaFullPath)) {
          deltaZip = true;
          deltaPath = new Path(deltaPrefix + deltaFullPath.makeRelativeTo(containerFullPath));
        }
      }

      if (deltaZip == false && new Path("WEB-INF").isPrefixOf(delta.getModuleRelativePath())) {
        final List<IFolder> folders = CoreUtil.getSourceFolders(JavaCore.create(deltaProject));

        for (IFolder folder : folders) {
          final IPath folderPath = folder.getFullPath();

          if (folderPath.isPrefixOf(deltaFullPath)) {
            deltaZip = true;
            break;
          }
        }
      }

      if (deltaZip == false
          && (deltaKind == IModuleResourceDelta.ADDED
              || deltaKind == IModuleResourceDelta.CHANGED
              || deltaKind == IModuleResourceDelta.REMOVED)) {
        final IPath targetPath = JavaCore.create(deltaProject).getOutputLocation();

        deltaZip = true;
        deltaPath = new Path("WEB-INF/classes").append(deltaFullPath.makeRelativeTo(targetPath));
      }

      if (deltaZip) {
        if (deltaKind == IModuleResourceDelta.ADDED || deltaKind == IModuleResourceDelta.CHANGED) {
          addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
        } else if (deltaKind == IModuleResourceDelta.REMOVED) {
          addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
        } else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
          final IModuleResourceDelta[] children = delta.getAffectedChildren();
          processResourceDeltas(
              children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
        }
      }
    }
  }
  /**
   * Scan traceFolder for files that match the patterns specified in the template file. When there
   * is a match, the trace package element is used to determine the trace name and trace type.
   *
   * @param traceGroup The parent trace group element
   * @param parentElement The immediate parent trace group or folder element
   * @param traceFolder The folder to scan
   * @param recursionLevel The recursion level (needed to find directory traces under the
   *     traceFolder
   * @param monitor The progress monitor
   * @throws CoreException Thrown by the file system implementation
   * @throws InterruptedException Thrown if operation was cancelled
   */
  private void generateElementsFromArchive(
      final RemoteImportTraceGroupElement traceGroup,
      final TracePackageElement parentElement,
      final IFileStore traceFolder,
      final int recursionLevel,
      IProgressMonitor monitor)
      throws CoreException, InterruptedException {

    int localRecursionLevel = recursionLevel + 1;
    IFileStore[] sources = traceFolder.childStores(EFS.NONE, monitor);

    for (int i = 0; i < sources.length; i++) {
      ModalContext.checkCanceled(monitor);
      SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);

      IFileStore fileStore = sources[i];
      IPath fullArchivePath = TmfTraceCoreUtils.newSafePath(fileStore.toURI().getPath());

      IFileInfo sourceInfo = fileStore.fetchInfo();
      if (!sourceInfo.isDirectory()) {

        String rootPathString = traceGroup.getRootImportPath();
        IPath rootPath = TmfTraceCoreUtils.newSafePath(rootPathString);
        IPath relativeTracePath = Path.EMPTY;
        if (rootPath.isPrefixOf(fullArchivePath)) {
          relativeTracePath = fullArchivePath.makeRelativeTo(rootPath);
        }
        Entry<Pattern, TracePackageTraceElement> matchingTemplateEntry =
            getMatchingTemplateElement(relativeTracePath);
        if (matchingTemplateEntry != null) {
          TracePackageTraceElement matchingTemplateElement = matchingTemplateEntry.getValue();
          String traceType = matchingTemplateElement.getTraceType();

          // If a single file is part of a directory trace, use the parent directory instead
          TracePackageElement parent = parentElement;
          if (matchesDirectoryTrace(relativeTracePath, matchingTemplateEntry)) {
            fullArchivePath = fullArchivePath.removeLastSegments(1);
            fDirectoryTraces.add(fullArchivePath);
            fileStore = fileStore.getParent();
            parent = parentElement.getParent();
            // Let the auto-detection choose the best trace type
            traceType = null;
          } else if ((localRecursionLevel > 1) && (!traceGroup.isRecursive())) {
            // Don't consider file traces on level 2 if it's not recursive
            continue;
          }
          String traceName = fullArchivePath.lastSegment();
          String fileName = fileStore.getName();
          // create new elements to decouple from input elements
          TracePackageTraceElement traceElement =
              new TracePackageTraceElement(parent, traceName, traceType);
          RemoteImportTraceFilesElement tracePackageFilesElement =
              new RemoteImportTraceFilesElement(traceElement, fileName, fileStore);
          tracePackageFilesElement.setVisible(false);
        }
      } else {
        if (traceGroup.isRecursive() || localRecursionLevel < 2) {
          RemoteImportFolderElement folder =
              new RemoteImportFolderElement(parentElement, fileStore.getName());
          generateElementsFromArchive(
              traceGroup, folder, fileStore, localRecursionLevel, subMonitor);
        }
      }
    }
  }