Search in sources :

Example 1 with SelectedBundle

use of org.osmorc.run.ui.SelectedBundle in project intellij-plugins by JetBrains.

the class OsgiRunConfiguration method getModules.

@NotNull
@Override
public Module[] getModules() {
    List<Module> modules = new ArrayList<>();
    ModuleManager moduleManager = ModuleManager.getInstance(getProject());
    for (SelectedBundle selectedBundle : getBundlesToDeploy()) {
        if (selectedBundle.isModule()) {
            Module module = moduleManager.findModuleByName(selectedBundle.getName());
            if (module != null) {
                modules.add(module);
            } else {
                LOG.error("no module [" + selectedBundle.getName() + "]");
            }
        }
    }
    return modules.toArray(new Module[modules.size()]);
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) Module(com.intellij.openapi.module.Module) ModuleManager(com.intellij.openapi.module.ModuleManager) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with SelectedBundle

use of org.osmorc.run.ui.SelectedBundle 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 SelectedBundle

use of org.osmorc.run.ui.SelectedBundle in project intellij-plugins by JetBrains.

the class SelectedBundleTest method testToString.

@Test
public void testToString() {
    SelectedBundle testObject = new SelectedBundle(SelectedBundle.BundleType.Module, "testName", "/test/path");
    assertThat(testObject.toString(), equalTo("testName (path)"));
    testObject = new SelectedBundle(SelectedBundle.BundleType.Module, "testName", null);
    assertThat(testObject.toString(), equalTo("testName"));
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) Test(org.junit.Test)

Example 4 with SelectedBundle

use of org.osmorc.run.ui.SelectedBundle in project intellij-plugins by JetBrains.

the class SelectedBundleTest method testEquals.

@Test
public void testEquals() {
    SelectedBundle testObject = new SelectedBundle(SelectedBundle.BundleType.Module, "testName", "/test/path");
    assertThat(testObject, equalTo(testObject));
    testObject = new SelectedBundle(SelectedBundle.BundleType.Module, "testName", null);
    assertThat(testObject, equalTo(testObject));
    testObject = new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "testName", "/test/path");
    assertThat(testObject, equalTo(testObject));
    testObject = new SelectedBundle(SelectedBundle.BundleType.PlainLibrary, "testName", null);
    assertThat(testObject, equalTo(testObject));
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) Test(org.junit.Test)

Example 5 with SelectedBundle

use of org.osmorc.run.ui.SelectedBundle in project intellij-plugins by JetBrains.

the class KnopflerfishRunner method setupParameters.

/**
   * See <a href="http://www.knopflerfish.org/releases/current/docs/running.html">Running Knopflerfish</a>.
   */
@Override
protected void setupParameters(@NotNull JavaParameters parameters) {
    ParametersList vmParameters = parameters.getVMParametersList();
    ParametersList programParameters = parameters.getProgramParametersList();
    // framework-specific options
    vmParameters.addProperty("org.knopflerfish.framework.debug.errors", "true");
    if (GenericRunProperties.isDebugMode(myAdditionalProperties)) {
        // todo: more detailed settings in the dialog (?)
        vmParameters.addProperty("org.knopflerfish.verbosity", "10");
        vmParameters.addProperty("org.knopflerfish.framework.debug.startlevel", "true");
        vmParameters.addProperty("org.knopflerfish.framework.debug.classloader", "true");
    }
    parameters.setMainClass(MAIN_CLASS);
    programParameters.add("-init");
    programParameters.add("-launch");
    // bundles and start levels
    MultiMap<Integer, String> startBundles = new MultiMap<>();
    List<String> installBundles = ContainerUtil.newSmartList();
    for (SelectedBundle bundle : myBundles) {
        String bundlePath = bundle.getBundlePath();
        if (bundlePath == null)
            continue;
        boolean isFragment = CachingBundleInfoProvider.isFragmentBundle(bundlePath);
        if (bundle.isStartAfterInstallation() && !isFragment) {
            int startLevel = getBundleStartLevel(bundle);
            startBundles.putValue(startLevel, bundlePath);
        } else {
            installBundles.add(bundlePath);
        }
    }
    if (!installBundles.isEmpty()) {
        int defaultStartLevel = myRunConfiguration.getDefaultStartLevel();
        programParameters.addAll("-initlevel", String.valueOf(defaultStartLevel));
        for (String bundle : installBundles) {
            programParameters.addAll("-install", bundle);
        }
    }
    for (Integer startLevel : startBundles.keySet()) {
        programParameters.addAll("-initlevel", String.valueOf(startLevel));
        for (String bundle : startBundles.get(startLevel)) {
            programParameters.addAll("-install", bundle);
        }
    }
    int frameworkStartLevel = getFrameworkStartLevel();
    programParameters.addAll("-startlevel", String.valueOf(frameworkStartLevel));
    for (Integer startLevel : startBundles.keySet()) {
        for (String bundle : startBundles.get(startLevel)) {
            programParameters.addAll("-start", bundle);
        }
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ParametersList(com.intellij.execution.configurations.ParametersList) SelectedBundle(org.osmorc.run.ui.SelectedBundle)

Aggregations

SelectedBundle (org.osmorc.run.ui.SelectedBundle)14 ParametersList (com.intellij.execution.configurations.ParametersList)4 MultiMap (com.intellij.util.containers.MultiMap)3 Test (org.junit.Test)3 CantRunException (com.intellij.execution.CantRunException)2 Module (com.intellij.openapi.module.Module)2 ModuleManager (com.intellij.openapi.module.ModuleManager)2 File (java.io.File)2 Element (org.jdom.Element)2 NotNull (org.jetbrains.annotations.NotNull)2 ExecutionException (com.intellij.execution.ExecutionException)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 JarFile (java.util.jar.JarFile)1 Attribute (org.jdom.Attribute)1 OsgiBuildException (org.jetbrains.osgi.jps.build.OsgiBuildException)1 OsmorcFacet (org.osmorc.facet.OsmorcFacet)1 BundleCompiler (org.osmorc.make.BundleCompiler)1