Search in sources :

Example 11 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-plugins by JetBrains.

the class OsgiManifestPsiTest method testBundleReference.

public void testBundleReference() {
    ManifestFile file = createFile("Require-Bundle: org.apache.felix.framework\n");
    PsiReference ref = file.findReferenceAt(16);
    assertNotNull(ref);
    PsiElement target = ref.resolve();
    assertTrue(String.valueOf(target), target instanceof Header);
    assertEquals("Bundle-SymbolicName", ((Header) target).getName());
}
Also used : Header(org.jetbrains.lang.manifest.psi.Header) PsiReference(com.intellij.psi.PsiReference) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile) PsiElement(com.intellij.psi.PsiElement)

Example 12 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-plugins by JetBrains.

the class OsgiPsiUtilTest method doTest.

private void doTest(String original, String expected, final boolean replace) {
    myFixture.configureByText("MANIFEST.MF", original);
    WriteCommandAction.runWriteCommandAction(null, () -> {
        ManifestFile manifestFile = (ManifestFile) myFixture.getFile();
        if (replace) {
            OsgiPsiUtil.setHeader(manifestFile, "TestHeader", "TestValue");
        } else {
            OsgiPsiUtil.appendToHeader(manifestFile, "TestHeader", "TestValue");
        }
    });
    myFixture.checkResult(expected);
}
Also used : ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile)

Example 13 with ManifestFile

use of org.jetbrains.lang.manifest.psi.ManifestFile in project intellij-plugins by JetBrains.

the class BundleManifestCache method getManifest.

@Nullable
public BundleManifest getManifest(@NotNull Module module) {
    OsmorcFacet facet = OsmorcFacet.getInstance(module);
    if (facet == null)
        return null;
    CachedValue<BundleManifest> value = myCache.get(facet);
    if (value == null) {
        value = myManager.createCachedValue(() -> {
            OsmorcFacetConfiguration configuration = facet.getConfiguration();
            BundleManifest manifest = null;
            List<Object> dependencies = ContainerUtil.newSmartList(configuration);
            switch(configuration.getManifestGenerationMode()) {
                case Manually:
                    {
                        PsiFile manifestFile = findInModuleRoots(facet.getModule(), configuration.getManifestLocation());
                        if (manifestFile instanceof ManifestFile) {
                            manifest = readManifest((ManifestFile) manifestFile);
                            dependencies.add(manifestFile);
                        } else {
                            dependencies.add(PsiModificationTracker.MODIFICATION_COUNT);
                        }
                        break;
                    }
                case OsmorcControlled:
                    {
                        Map<String, String> map = ContainerUtil.newHashMap(configuration.getAdditionalPropertiesAsMap());
                        map.put(Constants.BUNDLE_SYMBOLICNAME, configuration.getBundleSymbolicName());
                        map.put(Constants.BUNDLE_VERSION, configuration.getBundleVersion());
                        map.put(Constants.BUNDLE_ACTIVATOR, configuration.getBundleActivator());
                        manifest = new BundleManifest(map);
                        break;
                    }
                case Bnd:
                    {
                        PsiFile bndFile = findInModuleRoots(facet.getModule(), configuration.getBndFileLocation());
                        if (bndFile != null) {
                            manifest = readProperties(bndFile);
                            dependencies.add(bndFile);
                        } else {
                            dependencies.add(PsiModificationTracker.MODIFICATION_COUNT);
                        }
                        break;
                    }
                case Bundlor:
                    // not supported
                    break;
            }
            return CachedValueProvider.Result.create(manifest, dependencies);
        }, false);
        myCache.put(facet, value);
    }
    return value.getValue();
}
Also used : OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)13 Header (org.jetbrains.lang.manifest.psi.Header)4 PsiFile (com.intellij.psi.PsiFile)3 Nullable (org.jetbrains.annotations.Nullable)2 HeaderValue (org.jetbrains.lang.manifest.psi.HeaderValue)2 OsmorcFacet (org.osmorc.facet.OsmorcFacet)2 OsmorcFacetConfiguration (org.osmorc.facet.OsmorcFacetConfiguration)2 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 List (java.util.List)1 HeaderValuePart (org.jetbrains.lang.manifest.psi.HeaderValuePart)1 Section (org.jetbrains.lang.manifest.psi.Section)1 Version (org.osgi.framework.Version)1 Clause (org.osmorc.manifest.lang.psi.Clause)1