Search in sources :

Example 6 with OsmorcFacet

use of org.osmorc.facet.OsmorcFacet 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 7 with OsmorcFacet

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

OsmorcFacet (org.osmorc.facet.OsmorcFacet)7 Module (com.intellij.openapi.module.Module)4 OsmorcFacetConfiguration (org.osmorc.facet.OsmorcFacetConfiguration)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiFile (com.intellij.psi.PsiFile)2 ManifestFile (org.jetbrains.lang.manifest.psi.ManifestFile)2 Attrs (aQute.bnd.header.Attrs)1 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 Pair (com.intellij.openapi.util.Pair)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 DependenciesBuilder (com.intellij.packageDependencies.DependenciesBuilder)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1