Search in sources :

Example 11 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration 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)

Example 12 with OsmorcFacetConfiguration

use of org.osmorc.facet.OsmorcFacetConfiguration in project intellij-plugins by JetBrains.

the class BndProjectImporter method createModule.

private ModifiableRootModel createModule(ModifiableModuleModel moduleModel, Project project, LanguageLevel projectLevel) throws Exception {
    String name = project.getName();
    Module module = moduleModel.findModuleByName(name);
    if (module == null) {
        String path = project.getBase().getPath() + File.separator + name + ModuleFileType.DOT_DEFAULT_EXTENSION;
        module = moduleModel.newModule(path, StdModuleTypes.JAVA.getId());
    }
    ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    for (ContentEntry entry : rootModel.getContentEntries()) {
        rootModel.removeContentEntry(entry);
    }
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof ModuleJdkOrderEntry || entry instanceof ModuleSourceOrderEntry)) {
            rootModel.removeOrderEntry(entry);
        }
    }
    rootModel.inheritSdk();
    ContentEntry contentEntry = rootModel.addContentEntry(url(project.getBase()));
    for (File src : project.getSourcePath()) {
        contentEntry.addSourceFolder(url(src), false);
    }
    File testSrc = project.getTestSrc();
    if (testSrc != null) {
        contentEntry.addSourceFolder(url(testSrc), true);
    }
    contentEntry.addExcludeFolder(url(project.getTarget()));
    LanguageLevel sourceLevel = LanguageLevel.parse(project.getProperty(JAVAC_SOURCE));
    if (sourceLevel == projectLevel)
        sourceLevel = null;
    rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(sourceLevel);
    CompilerModuleExtension compilerExt = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerExt.inheritCompilerOutputPath(false);
    compilerExt.setExcludeOutput(true);
    compilerExt.setCompilerOutputPath(url(project.getSrcOutput()));
    compilerExt.setCompilerOutputPathForTests(url(project.getTestOutput()));
    String targetLevel = project.getProperty(JAVAC_TARGET);
    CompilerConfiguration.getInstance(myProject).setBytecodeTargetLevel(module, targetLevel);
    OsmorcFacet facet = OsmorcFacet.getInstance(module);
    if (project.isNoBundles() && facet != null) {
        FacetUtil.deleteFacet(facet);
        facet = null;
    } else if (!project.isNoBundles() && facet == null) {
        facet = FacetUtil.addFacet(module, OsmorcFacetType.getInstance());
    }
    if (facet != null) {
        OsmorcFacetConfiguration facetConfig = facet.getConfiguration();
        facetConfig.setManifestGenerationMode(ManifestGenerationMode.Bnd);
        facetConfig.setBndFileLocation(FileUtil.getRelativePath(path(project.getBase()), path(project.getPropertiesFile()), '/'));
        Map.Entry<String, Attrs> bsn = project.getBundleSymbolicName();
        File bundle = project.getOutputFile(bsn != null ? bsn.getKey() : name, project.getBundleVersion());
        facetConfig.setJarFileLocation(path(bundle), OutputPathType.SpecificOutputPath);
        facetConfig.setDoNotSynchronizeWithMaven(true);
    }
    return rootModel;
}
Also used : Attrs(aQute.bnd.header.Attrs) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

OsmorcFacetConfiguration (org.osmorc.facet.OsmorcFacetConfiguration)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 OsmorcFacet (org.osmorc.facet.OsmorcFacet)4 PsiFile (com.intellij.psi.PsiFile)3 File (java.io.File)3 Module (com.intellij.openapi.module.Module)2 Nullable (org.jetbrains.annotations.Nullable)2 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)2 OutputPathType (org.jetbrains.osgi.jps.model.OutputPathType)2 Attrs (aQute.bnd.header.Attrs)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Pair (com.intellij.openapi.util.Pair)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ZipFile (java.util.zip.ZipFile)1 Element (org.jdom.Element)1 NotNull (org.jetbrains.annotations.NotNull)1