Пример #1
0
  public static String getProjectName(URI uri) {
    if ("platform".equals(uri.scheme())) {
      if (uri.segmentCount() < 3) {
        return null;
      }

      String[] segments = uri.segments();
      if (!"resource".equals(segments[0])) {
        return null;
      }

      return segments[1];
    }

    if ("file".equals(uri.scheme())) {
      // TODO getLocation() not working for linked projects!!!
      String[] wsSegments = ResourcesHelper.ROOT.getLocation().segments();
      String[] uriSegments = uri.segments();
      if (uriSegments.length - 1 < wsSegments.length) {
        return null;
      }

      for (int i = 0; i < wsSegments.length; i++) {
        String wsSegment = wsSegments[i];
        String uriSegment = uriSegments[i];
        if (!uriSegment.equals(wsSegment)) {
          return null;
        }
      }

      return uriSegments[wsSegments.length];
    }

    return null;
  }
 /**
  * Returns the normalized form of the URI, using the given multiple candidates (this means that
  * more than 2 modules had a matching name).
  *
  * @param uri The URI that is to be normalized.
  * @param candidateURIs URIs of the modules that can potentially be a match for <code>uri</code>.
  * @return the normalized form
  */
 private URI findBestMatchFor(URI uri, Set<URI> candidateURIs) {
   URI normalized = null;
   final Iterator<URI> candidatesIterator = candidateURIs.iterator();
   final List<String> referenceSegments = Arrays.asList(uri.segments());
   Collections.reverse(referenceSegments);
   int highestEqualFragments = 0;
   while (candidatesIterator.hasNext()) {
     final URI next = candidatesIterator.next();
     int equalFragments = 0;
     final List<String> candidateSegments = Arrays.asList(next.segments());
     Collections.reverse(candidateSegments);
     for (int i = 0; i < Math.min(candidateSegments.size(), referenceSegments.size()); i++) {
       if (candidateSegments.get(i) == referenceSegments.get(i)) {
         equalFragments++;
       } else {
         break;
       }
     }
     if (equalFragments > highestEqualFragments) {
       highestEqualFragments = equalFragments;
       normalized = next;
     }
   }
   return normalized;
 }
Пример #3
0
  public static boolean endsWith(URI sourceUri, URI testUri) {
    // TODO Waiting on new emf URI API
    String[] sourceSegments = sourceUri.segments();
    String[] testSegments = testUri.segments();
    int i = testSegments.length;
    int j = sourceSegments.length;
    if (j >= i) {
      boolean test = true;

      while (test && i > 0) {
        i--;
        j--;
        test = testSegments[i].equals(sourceSegments[j]);
      }
      return test;
    }
    return false;
  }
 @Override
 public URI normalize(URI uri) {
   if (uri.isFile()) {
     return uri;
   }
   String[] segments = uri.segments();
   String fileName =
       segments[0] + "_" + segments[1] + "." + getFileExtension(); // $NON-NLS-1$ //$NON-NLS-2$
   String dir = getTemporaryDirectoryPath();
   return URI.createFileURI(dir + File.separator + fileName);
 }
 /* @NonNull */
 @Override
 public Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri) {
   List<Pair<IStorage, IProject>> result = newArrayListWithCapacity(1);
   List<PackageFragmentRootData> packageFragmentRootDatas;
   synchronized (cachedPackageFragmentRootData) {
     packageFragmentRootDatas = newArrayList(cachedPackageFragmentRootData.values());
   }
   Iterator<PackageFragmentRootData> iterator = packageFragmentRootDatas.iterator();
   while (iterator.hasNext()) {
     PackageFragmentRootData data = iterator.next();
     if (data.exists()) {
       if (data.uriPrefix == null || uri.toString().startsWith(data.uriPrefix.toString())) {
         IStorage storage = data.uri2Storage.get(uri);
         if (storage != null) {
           for (IPackageFragmentRoot root : data.associatedRoots.values()) {
             result.add(Tuples.create(storage, root.getJavaProject().getProject()));
           }
         }
       }
     } else {
       iterator.remove();
     }
   }
   if (result.isEmpty() && uri.isArchive()) {
     String authority = uri.authority();
     authority = authority.substring(0, authority.length() - 1);
     URI archiveURI = URI.createURI(authority);
     if (archiveURI.isFile() || archiveURI.isPlatformResource()) {
       IPath archivePath =
           new Path(
               archiveURI.isPlatformResource()
                   ? archiveURI.toPlatformString(true)
                   : archiveURI.toFileString());
       for (PackageFragmentRootData data : packageFragmentRootDatas) {
         if (data.uriPrefix != null && archivePath.equals(data.getPath())) {
           // prefixes have an empty last segment.
           URI prefix =
               data.uriPrefix.lastSegment().length() == 0
                   ? data.uriPrefix.trimSegments(1)
                   : data.uriPrefix;
           URI expectedURI = prefix.appendSegments(uri.segments());
           IStorage storage = data.uri2Storage.get(expectedURI);
           if (storage != null) {
             for (IPackageFragmentRoot root : data.associatedRoots.values()) {
               result.add(Tuples.create(storage, root.getJavaProject().getProject()));
             }
           }
         }
       }
     }
   }
   return result;
 }
Пример #6
0
 public static URI getPivotURI(URI uri) {
   String oldScheme = uri.scheme();
   if (oldScheme == null) {
     oldScheme = "null";
   }
   String[] oldSegments = uri.segments();
   String[] newSegments = new String[oldSegments.length + 1];
   newSegments[0] = oldScheme;
   System.arraycopy(oldSegments, 0, newSegments, 1, oldSegments.length);
   URI pivotURI =
       URI.createHierarchicalURI(
           SCHEME_PIVOT, uri.authority(), uri.device(), newSegments, uri.query(), uri.fragment());
   return pivotURI;
 }
Пример #7
0
 public static URI getNonPivotURI(URI uri) {
   assert isPivotURI(uri);
   String[] oldSegments = uri.segments();
   String[] newSegments = new String[oldSegments.length - 1];
   newSegments[0] = uri.scheme();
   System.arraycopy(oldSegments, 1, newSegments, 0, oldSegments.length - 1);
   URI pivotURI =
       URI.createHierarchicalURI(
           oldSegments[0],
           uri.authority(),
           uri.device(),
           newSegments,
           uri.query(),
           uri.fragment());
   return pivotURI;
 }
Пример #8
0
  public static String getBundleId(URI uri) {
    if ("platform".equals(uri.scheme())) {
      if (uri.segmentCount() < 3) {
        return null;
      }

      String[] segments = uri.segments();
      if (!"plugin".equals(segments[0])) {
        return null;
      }

      return segments[1];
    }

    return null;
  }
Пример #9
0
  public static IFile getFile(Resource resource) {
    URI uri = resource.getURI();
    if (!"platform".equals(uri.scheme())) {
      return null;
    }
    if (uri.segmentCount() < 3) {
      return null;
    }

    String[] segments = uri.segments();
    if (!"resource".equals(segments[0])) {
      return null;
    }

    IPath path = new Path("/");
    for (int i = 1; i < segments.length; i++) {
      path = path.append(segments[i]);
    }

    return ResourcesHelper.ROOT.getFile(path);
  }
Пример #10
0
  public static String getFullPath(URI uri) {
    if ("platform".equals(uri.scheme())) {
      if (uri.segmentCount() < 3) {
        return null;
      }

      String[] segments = uri.segments();
      if (!"resource".equals(segments[0])) {
        return null;
      }

      IPath path = new Path("/");
      for (int i = 1; i < segments.length; i++) {
        String segment = segments[i];
        path = path.append(segment);
      }

      return path.toString();
    }

    return null;
  }
  @Override
  public void linkModel(EObject model, IDiagnosticConsumer diagnosticsConsumer) {
    Resource res = model.eResource();
    URI srcURI = res.getURI();
    URI cURI = null;
    String[] segments = srcURI.segments();
    if (segments[2].equals("source")) {
      segments[2] = "compiled";
      cURI = createURI(segments);
    } else if (segments[2].equals("mars") && segments[4].equals("source")) {
      segments[4] = "compiled";
      cURI = createURI(segments);
    }
    if (cURI != null) {
      IResource file = ResourcesPlugin.getWorkspace().getRoot().findMember(cURI.path());
      if (file == null) return;
      File f = new File(file.getLocation().toOSString());
      if (!f.exists()) return;
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db;
      try {
        db = dbf.newDocumentBuilder();
        Document doc = db.parse(f);
        doc.getDocumentElement().normalize();

        enrich(model, doc.getDocumentElement());

      } catch (ParserConfigurationException e) {
        e.printStackTrace();
      } catch (SAXException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Пример #12
0
 public static void dumpURI(URI uri, Logger logger) {
   logger.debug("URI: " + uri);
   logger.debug("authority: " + uri.authority());
   logger.debug("device: " + uri.device());
   logger.debug("devicePath: " + uri.devicePath());
   logger.debug("fileExtension: " + uri.fileExtension());
   logger.debug("fragment: " + uri.fragment());
   logger.debug("host: " + uri.host());
   logger.debug("lastSegment: " + uri.lastSegment());
   logger.debug("opaquePart: " + uri.opaquePart());
   logger.debug("path: " + uri.path());
   logger.debug("port: " + uri.port());
   logger.debug("query: " + uri.query());
   logger.debug("scheme: " + uri.scheme());
   logger.debug("segmentCount: " + uri.segmentCount());
   logger.debug("toFileString: " + uri.toFileString());
   logger.debug("userInfo: " + uri.userInfo());
   logger.debug("hasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("schemehasAbsolutePath: " + uri.hasAbsolutePath());
   logger.debug("hasAuthority: " + uri.hasAuthority());
   logger.debug("hasDevice: " + uri.hasDevice());
   logger.debug("hasEmptyPath: " + uri.hasEmptyPath());
   logger.debug("hasFragment: " + uri.hasFragment());
   logger.debug("hasOpaquePart: " + uri.hasOpaquePart());
   logger.debug("hasPath: " + uri.hasPath());
   logger.debug("hasQuery: " + uri.hasQuery());
   logger.debug("hasRelativePath: " + uri.hasRelativePath());
   logger.debug("hasTrailingPathSeparator: " + uri.hasTrailingPathSeparator());
   logger.debug("isCurrentDocumentReference: " + uri.isCurrentDocumentReference());
   logger.debug("isEmpty: " + uri.isEmpty());
   logger.debug("isFile: " + uri.isFile());
   logger.debug("isHierarchical: " + uri.isHierarchical());
   logger.debug("isPrefix: " + uri.isPrefix());
   logger.debug("isRelative: " + uri.isRelative());
   logger.debug("segments: " + uri.segments());
 }
Пример #13
0
 public static boolean isPivotURI(URI uri) {
   return SCHEME_PIVOT.equals(uri.scheme()) && (uri.segments().length > 0);
 }