Search in sources :

Example 1 with OsmorcFacet

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

the class AbstractOsgiQuickFix method getVerifiedManifestFile.

@Nullable
protected ManifestFile getVerifiedManifestFile(@NotNull PsiElement element) {
    Module module = ModuleUtilCore.findModuleForPsiElement(element);
    assert module != null : element;
    OsmorcFacet facet = OsmorcFacet.getInstance(module);
    if (facet != null) {
        OsmorcFacetConfiguration configuration = facet.getConfiguration();
        for (VirtualFile root : ModuleRootManager.getInstance(module).getContentRoots()) {
            VirtualFile file = root.findFileByRelativePath(configuration.getManifestLocation());
            if (file != null) {
                PsiFile psiFile = element.getManager().findFile(file);
                if (psiFile instanceof ManifestFile && CommonRefactoringUtil.checkReadOnlyStatus(psiFile)) {
                    return (ManifestFile) psiFile;
                }
            }
        }
    }
    OsmorcBundle.notification(getFamilyName(), OsmorcBundle.message("inspection.fix.no.manifest"), NotificationType.WARNING).notify(element.getProject());
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) ManifestFile(org.jetbrains.lang.manifest.psi.ManifestFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with OsmorcFacet

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

the class OsgiRunState method getSelectedBundles.

/**
   * Here we got the magic. All libs are turned into bundles sorted and returned.
   */
private List<SelectedBundle> getSelectedBundles() throws ExecutionException {
    final Ref<List<SelectedBundle>> result = Ref.create();
    final Ref<ExecutionException> error = Ref.create();
    ProgressManager.getInstance().run(new Task.Modal(myRunConfiguration.getProject(), "Preparing bundles...", false) {

        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            progressIndicator.setIndeterminate(false);
            AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
            try {
                Set<SelectedBundle> selectedBundles = new HashSet<>();
                // the bundles are module names, by now we try to find jar files in the output directory which we can then install
                ModuleManager moduleManager = ModuleManager.getInstance(myRunConfiguration.getProject());
                BundleCompiler bundleCompiler = new BundleCompiler(progressIndicator);
                int bundleCount = myRunConfiguration.getBundlesToDeploy().size();
                for (int i = 0; i < bundleCount; i++) {
                    progressIndicator.setFraction((double) i / bundleCount);
                    SelectedBundle selectedBundle = myRunConfiguration.getBundlesToDeploy().get(i);
                    if (selectedBundle.isModule()) {
                        // use the output jar name if it is a module
                        String name = selectedBundle.getName();
                        Module module = moduleManager.findModuleByName(name);
                        if (module == null) {
                            throw new CantRunException("Module '" + name + "' no longer exists. Please check your run configuration.");
                        }
                        OsmorcFacet facet = OsmorcFacet.getInstance(module);
                        if (facet == null) {
                            throw new CantRunException("Module '" + name + "' has no OSGi facet. Please check your run configuration.");
                        }
                        selectedBundle.setBundlePath(facet.getConfiguration().getJarFileLocation());
                        selectedBundles.add(selectedBundle);
                        // add all the library dependencies of the bundle
                        List<String> paths = bundleCompiler.bundlifyLibraries(module);
                        for (String path : paths) {
                            selectedBundles.add(new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "Dependency", path));
                        }
                    } else {
                        if (selectedBundles.contains(selectedBundle)) {
                            // if the user selected a dependency as runnable library, we need to replace the dependency with
                            // the runnable library part
                            selectedBundles.remove(selectedBundle);
                        }
                        selectedBundles.add(selectedBundle);
                    }
                }
                // filter out bundles which have the same symbolic name
                Map<String, SelectedBundle> filteredBundles = new HashMap<>();
                for (SelectedBundle selectedBundle : selectedBundles) {
                    String path = selectedBundle.getBundlePath();
                    if (path != null) {
                        String name = CachingBundleInfoProvider.getBundleSymbolicName(path);
                        String version = CachingBundleInfoProvider.getBundleVersion(path);
                        String key = name + version;
                        if (!filteredBundles.containsKey(key)) {
                            filteredBundles.put(key, selectedBundle);
                        }
                    }
                }
                List<SelectedBundle> sortedBundles = ContainerUtil.newArrayList(filteredBundles.values());
                Collections.sort(sortedBundles, START_LEVEL_COMPARATOR);
                result.set(sortedBundles);
            } catch (CantRunException e) {
                error.set(e);
            } catch (OsgiBuildException e) {
                LOG.warn(e);
                error.set(new CantRunException(e.getMessage()));
            } catch (Throwable t) {
                LOG.error(t);
                error.set(new CantRunException("Internal error: " + t.getMessage()));
            } finally {
                token.finish();
            }
        }
    });
    if (!result.isNull()) {
        return result.get();
    } else {
        throw error.get();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) SelectedBundle(org.osmorc.run.ui.SelectedBundle) ModuleManager(com.intellij.openapi.module.ModuleManager) CantRunException(com.intellij.execution.CantRunException) OsmorcFacet(org.osmorc.facet.OsmorcFacet) BundleCompiler(org.osmorc.make.BundleCompiler) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) AccessToken(com.intellij.openapi.application.AccessToken) OsgiBuildException(org.jetbrains.osgi.jps.build.OsgiBuildException) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module)

Example 3 with OsmorcFacet

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

the class AdditionalJARContentsWatcherManager method updateWatcherSetup.

public void updateWatcherSetup() {
    OsmorcFacet osmorcFacet = OsmorcFacet.getInstance(myModule);
    if (osmorcFacet != null) {
        List<VirtualFile> newAdditionalJARContents = new ArrayList<>();
        OsmorcFacetConfiguration osmorcFacetConfiguration = osmorcFacet.getConfiguration();
        List<Pair<String, String>> jarContents = osmorcFacetConfiguration.getAdditionalJARContents();
        for (Pair<String, String> jarContent : jarContents) {
            VirtualFile file = myFileSystem.findFileByPath(jarContent.getFirst());
            if (file != null) {
                newAdditionalJARContents.add(file);
            }
        }
        List<LocalFileSystem.WatchRequest> toRemove = new ArrayList<>();
        for (Iterator<VirtualFile> jarContentsIterator = myAdditionalBundleJARContents.iterator(); jarContentsIterator.hasNext(); ) {
            VirtualFile file = jarContentsIterator.next();
            if (!newAdditionalJARContents.contains(file)) {
                jarContentsIterator.remove();
                for (Iterator<LocalFileSystem.WatchRequest> watchIterator = myWatchRequests.iterator(); watchIterator.hasNext(); ) {
                    LocalFileSystem.WatchRequest watchRequest = watchIterator.next();
                    if (Comparing.strEqual(file.getPath(), watchRequest.getRootPath())) {
                        toRemove.add(watchRequest);
                        watchIterator.remove();
                    }
                }
            }
        }
        List<String> toAdd = new ArrayList<>();
        for (VirtualFile newAdditionalJARContent : newAdditionalJARContents) {
            if (!myAdditionalBundleJARContents.contains(newAdditionalJARContent)) {
                toAdd.add(newAdditionalJARContent.getPath());
                myAdditionalBundleJARContents.add(newAdditionalJARContent);
            }
        }
        Set<LocalFileSystem.WatchRequest> requests = myFileSystem.replaceWatchedRoots(toRemove, toAdd, null);
        myWatchRequests.addAll(requests);
    } else {
        cleanup();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Pair(com.intellij.openapi.util.Pair)

Example 4 with OsmorcFacet

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

the class PackageAccessibilityInspection method checkFile.

@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
    if (!(file instanceof PsiClassOwner) || !checkTests && ProjectRootsUtil.isInTestSource(file)) {
        return null;
    }
    final OsmorcFacet facet = OsmorcFacet.getInstance(file);
    if (facet == null) {
        return null;
    }
    final List<ProblemDescriptor> problems = ContainerUtil.newSmartList();
    DependenciesBuilder.analyzeFileDependencies(file, new DependenciesBuilder.DependencyProcessor() {

        @Override
        public void process(PsiElement place, PsiElement dependency) {
            if (dependency instanceof PsiClass) {
                Problem problem = checkAccessibility((PsiClass) dependency, facet);
                if (problem != null) {
                    problems.add(manager.createProblemDescriptor(place, problem.message, isOnTheFly, problem.fixes, problem.type));
                }
            }
        }
    }, DependencyVisitorFactory.VisitorOptions.SKIP_IMPORTS);
    return problems.isEmpty() ? null : problems.toArray(new ProblemDescriptor[problems.size()]);
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) DependenciesBuilder(com.intellij.packageDependencies.DependenciesBuilder) OsmorcFacet(org.osmorc.facet.OsmorcFacet) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with OsmorcFacet

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

the class ViewGeneratedManifestGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
    if (e != null) {
        Project project = e.getProject();
        if (project != null) {
            List<AnAction> actions = null;
            for (Module module : ModuleManager.getInstance(project).getModules()) {
                OsmorcFacet facet = OsmorcFacet.getInstance(module);
                if (facet != null) {
                    String jarFilePath = facet.getConfiguration().getJarFileLocation();
                    if (!jarFilePath.isEmpty()) {
                        String title = "[" + module.getName() + "] " + PathUtil.getFileName(jarFilePath);
                        ViewManifestAction action = new ViewManifestAction(title, jarFilePath);
                        if (actions == null)
                            actions = ContainerUtil.newSmartList();
                        actions.add(action);
                    }
                }
            }
            if (actions != null) {
                return actions.toArray(new AnAction[actions.size()]);
            }
        }
    }
    return AnAction.EMPTY_ARRAY;
}
Also used : Project(com.intellij.openapi.project.Project) OsmorcFacet(org.osmorc.facet.OsmorcFacet) Module(com.intellij.openapi.module.Module) AnAction(com.intellij.openapi.actionSystem.AnAction) NotNull(org.jetbrains.annotations.NotNull)

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