Package org.jetbrains.lang.manifest.psi

Examples of org.jetbrains.lang.manifest.psi.Header


import java.util.List;

public class OsgiManifestPsiTest extends LightIdeaTestCase {
  public void testClauses() {
    ManifestFile file = createFile("Import-Package: a.b,c.d;a=value;d:=value");
    Header header = file.getHeader("Import-Package");
    assertNotNull(header);
    List<HeaderValue> clauses = header.getHeaderValues();
    assertEquals(2, clauses.size());
    Clause clause1 = (Clause)clauses.get(0), clause2 = (Clause)clauses.get(1);
    assertEquals(0, clause1.getAttributes().size());
    assertEquals(0, clause1.getDirectives().size());
    assertEquals(1, clause2.getAttributes().size());
View Full Code Here


    assertAssignment(file, true, "d1", null);
  }

  public void testBundleVersion() {
    ManifestFile file = createFile("Bundle-Version: 1.2.3.b300\n");
    Header header = file.getHeader("Bundle-Version");
    assertNotNull(header);
    Object value = HeaderParserRepository.getInstance().getConvertedValue(header);
    assertEquals(new Version(1, 2, 3, "b300"), value);
  }
View Full Code Here

    return (String)getHeaderValue(BUNDLE_ACTIVATOR);
  }

  @Override
  public boolean isPackageExported(@NotNull String packageSpec) {
    Header header = myManifestFile.getHeader(EXPORT_PACKAGE);
    if (header == null) {
      return false;
    }

    List<BundleCapability> capabilities = ContainerUtil.newArrayList();
    String bsn = getBundleSymbolicName();
    String bv = getBundleVersion().toString();
    for (HeaderValue headerValue : header.getHeaderValues()) {
      List<BundleCapability> caps = FelixManifestParser.parseExportHeader(headerValue.getUnwrappedText(), bsn, bv);
      if (caps == null) return false// parse error
      capabilities.addAll(caps);
    }
View Full Code Here

  }

  @NotNull
  @Override
  public List<String> getReExportedBundles() {
    Header header = myManifestFile.getHeader(REQUIRE_BUNDLE);
    return header == null ? ContainerUtil.<String>emptyList() : ContainerUtil.mapNotNull(header.getHeaderValues(), new NullableFunction<HeaderValue, String>() {
             @Override
             public String fun(HeaderValue value) {
               Directive directive = ((Clause)value).getDirective(VISIBILITY_DIRECTIVE);
               return directive != null && VISIBILITY_REEXPORT.equals(directive.getValue()) ? value.getUnwrappedText() : null;
             }
View Full Code Here

    return satisfies(Collections.singletonList(capability), requirements);
  }

  @Override
  public boolean reExportsBundle(@NotNull BundleManifest otherBundle) {
    Header header = myManifestFile.getHeader(REQUIRE_BUNDLE);
    if (header == null) return false;

    for (HeaderValue value : header.getHeaderValues()) {
      String requireSpec = value.getUnwrappedText();
      // first check if the clause is set to re-export, if not, we can skip the more expensive checks
      Directive directive = ((Clause)value).getDirective(VISIBILITY_DIRECTIVE);
      if (directive == null) {
        continue; // skip to the next require
View Full Code Here

    return getHeaderValues(BUNDLE_CLASSPATH);
  }

  @Override
  public boolean isFragmentHostFor(@NotNull BundleManifest fragmentBundle) {
    Header header = fragmentBundle.getManifestFile().getHeader(FRAGMENT_HOST);
    if (header == null) return false;

    List<HeaderValue> clauses = header.getHeaderValues();
    // bundle should have exactly one clause
    // they follow the same semantics so i think it is safe to reuse this method here. We do not handle extension bundles at all.
    return clauses.size() == 1 && isRequiredBundle(clauses.get(0).getUnwrappedText());
  }
View Full Code Here

    return false;
  }

  private Object getHeaderValue(String headerName) {
    Header header = myManifestFile.getHeader(headerName);
    return header != null ? myRepository.getConvertedValue(header) : null;
  }
View Full Code Here

    Header header = myManifestFile.getHeader(headerName);
    return header != null ? myRepository.getConvertedValue(header) : null;
  }

  private List<String> getHeaderValues(String headerName) {
    Header header = myManifestFile.getHeader(headerName);
    return header == null ? ContainerUtil.<String>emptyList() : ContainerUtil.map(header.getHeaderValues(), new Function<HeaderValue, String>() {
      @Override
      public String fun(HeaderValue value) {
        return value.getUnwrappedText();
      }
    });
View Full Code Here

  public static boolean isHeader(@Nullable PsiElement element, @NotNull String headerName) {
    return element instanceof Header && headerName.equals(((Header)element).getName());
  }

  public static void setHeader(@NotNull ManifestFile manifestFile, @NotNull String headerName, @NotNull String headerValue) {
    Header header = manifestFile.getHeader(headerName);
    Header newHeader = createHeader(manifestFile.getProject(), headerName, headerValue);
    if (header != null) {
      header.replace(newHeader);
    }
    else {
      addHeader(manifestFile, newHeader);
View Full Code Here

      addHeader(manifestFile, newHeader);
    }
  }

  public static void appendToHeader(@NotNull ManifestFile manifestFile, @NotNull String headerName, @NotNull String headerValue) {
    Header header = manifestFile.getHeader(headerName);
    if (header != null) {
      HeaderValue oldValue = header.getHeaderValue();
      if (oldValue != null) {
        String oldText = trimTrailing(header.getText().substring(oldValue.getStartOffsetInParent(), header.getTextLength()));
        if (!oldText.isEmpty()) oldText += ",\n ";
        headerValue = oldText + headerValue;
      }
      header.replace(createHeader(manifestFile.getProject(), headerName, headerValue));
    }
    else {
      addHeader(manifestFile, createHeader(manifestFile.getProject(), headerName, headerValue));
    }
  }
View Full Code Here

TOP

Related Classes of org.jetbrains.lang.manifest.psi.Header

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.