Search in sources :

Example 11 with SelectedBundle

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

the class EquinoxRunner method setupParameters.

/**
   * See <a href="http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html">Eclipse runtime options</a>.
   */
@Override
protected void setupParameters(@NotNull JavaParameters parameters) {
    ParametersList vmParameters = parameters.getVMParametersList();
    // bundles and start levels
    List<String> bundles = ContainerUtil.newArrayList();
    for (SelectedBundle bundle : myBundles) {
        String bundlePath = bundle.getBundlePath();
        if (bundlePath == null)
            continue;
        boolean isFragment = CachingBundleInfoProvider.isFragmentBundle(bundlePath);
        String bundleUrl = toFileUri(bundlePath);
        if (!isFragment) {
            int startLevel = getBundleStartLevel(bundle);
            bundleUrl += "@" + startLevel;
            if (bundle.isStartAfterInstallation()) {
                bundleUrl += ":start";
            }
        }
        bundles.add(bundleUrl);
    }
    if (!bundles.isEmpty()) {
        vmParameters.addProperty("osgi.bundles", StringUtil.join(bundles, ","));
    }
    int startLevel = getFrameworkStartLevel();
    vmParameters.addProperty("osgi.startLevel", String.valueOf(startLevel));
    int defaultStartLevel = myRunConfiguration.getDefaultStartLevel();
    vmParameters.addProperty("osgi.bundles.defaultStartLevel", String.valueOf(defaultStartLevel));
    if (GenericRunProperties.isStartConsole(myAdditionalProperties)) {
        vmParameters.addProperty("osgi.console");
        if (VersionComparatorUtil.compare(myInstance.getVersion(), "3.8") < 0) {
            vmParameters.addProperty("osgi.console.enable.builtin", "true");
        }
    }
    vmParameters.addProperty("osgi.clean", "true");
    if (GenericRunProperties.isDebugMode(myAdditionalProperties)) {
        vmParameters.addProperty("osgi.debug");
        vmParameters.addProperty("eclipse.consoleLog", "true");
    }
    String product = EquinoxRunProperties.getEquinoxProduct(myAdditionalProperties);
    String application = EquinoxRunProperties.getEquinoxApplication(myAdditionalProperties);
    if (!StringUtil.isEmptyOrSpaces(product)) {
        vmParameters.defineProperty("eclipse.product", product);
        vmParameters.defineProperty("eclipse.ignoreApp", "false");
    } else if (!StringUtil.isEmptyOrSpaces(application)) {
        vmParameters.defineProperty("eclipse.application", application);
        vmParameters.defineProperty("eclipse.ignoreApp", "false");
    } else {
        vmParameters.defineProperty("eclipse.ignoreApp", "true");
    }
    parameters.setMainClass(MAIN_CLASS);
}
Also used : ParametersList(com.intellij.execution.configurations.ParametersList) SelectedBundle(org.osmorc.run.ui.SelectedBundle)

Example 12 with SelectedBundle

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

the class AbstractFrameworkInstanceManager method collectBundles.

@NotNull
protected Collection<SelectedBundle> collectBundles(@NotNull FrameworkInstanceDefinition instance, @NotNull FrameworkBundleType type, @NotNull String[] bundleDirs, @NotNull Pattern sysNamePattern, @Nullable String sysControlClass, int sysExpected, @Nullable Pattern shellNamePattern, @Nullable String shellControlClass, int shellExpected) {
    String basePath = instance.getBaseFolder();
    if (basePath == null || !new File(basePath).isDirectory()) {
        return ContainerUtil.emptyList();
    }
    int expected = type == FrameworkBundleType.SYSTEM ? sysExpected : type == FrameworkBundleType.SHELL ? shellExpected : -1;
    if (expected == 0)
        return ContainerUtil.emptyList();
    Collection<SelectedBundle> bundles = ContainerUtil.newArrayList();
    outer: for (File dir : flattenDirPatterns(basePath, bundleDirs)) {
        File[] files = ObjectUtils.notNull(dir.listFiles(), ArrayUtil.EMPTY_FILE_ARRAY);
        for (File file : files) {
            FrameworkBundleType bundleType = detectType(file, sysNamePattern, sysControlClass, shellNamePattern, shellControlClass);
            if (bundleType == type) {
                SelectedBundle bundle = makeBundle(file);
                bundles.add(bundle);
                if (expected > 0 && bundles.size() == expected) {
                    break outer;
                }
            }
        }
    }
    if (expected > 0 && bundles.size() < expected) {
        return Collections.emptyList();
    }
    return bundles;
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) JarFile(java.util.jar.JarFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with SelectedBundle

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

the class OsgiRunConfiguration method readExternal.

@Override
public void readExternal(final Element element) throws InvalidDataException {
    workingDir = element.getAttributeValue(WORKING_DIR_ATTRIBUTE);
    vmParameters = element.getAttributeValue(VM_PARAMETERS_ATTRIBUTE);
    programParameters = element.getAttributeValue(PROGRAM_PARAMETERS_ATTRIBUTE);
    includeAllBundlesInClassPath = Boolean.valueOf(element.getAttributeValue(INCLUDE_ALL_BUNDLES_IN_CLASS_PATH_ATTRIBUTE, "false"));
    useAlternativeJre = Boolean.valueOf(element.getAttributeValue(USE_ALTERNATIVE_JRE_ATTRIBUTE, "false"));
    alternativeJrePath = element.getAttributeValue(ALTERNATIVE_JRE_PATH, "");
    generateWorkingDir = Boolean.valueOf(element.getAttributeValue(GENERATE_WORKING_DIR_ATTRIBUTE));
    try {
        frameworkStartLevel = Integer.parseInt(element.getAttributeValue(FRAMEWORK_START_LEVEL, "1"));
    } catch (NumberFormatException e) {
        frameworkStartLevel = 1;
    }
    try {
        defaultStartLevel = Integer.parseInt(element.getAttributeValue(DEFAULT_START_LEVEL, "5"));
    } catch (NumberFormatException e) {
        defaultStartLevel = 5;
    }
    List<Element> children = element.getChildren(BUNDLE_ELEMENT);
    bundlesToDeploy.clear();
    for (Element child : children) {
        String name = child.getAttributeValue(NAME_ATTRIBUTE);
        String url = child.getAttributeValue(URL_ATTRIBUTE);
        String startLevel = child.getAttributeValue(START_LEVEL_ATTRIBUTE);
        String typeName = child.getAttributeValue(TYPE_ATTRIBUTE);
        SelectedBundle.BundleType type;
        try {
            type = SelectedBundle.BundleType.valueOf(typeName);
        } catch (IllegalArgumentException e) {
            LOG.error("unexpected bundle type '" + typeName + "'");
            type = SelectedBundle.BundleType.Module;
        }
        String path = url != null ? VfsUtilCore.urlToPath(url) : null;
        SelectedBundle selectedBundle = new SelectedBundle(type, name, path);
        if (startLevel != null) {
            try {
                selectedBundle.setStartLevel(Integer.parseInt(startLevel));
            } catch (NumberFormatException ignored) {
            }
        }
        String startAfterInstallationString = child.getAttributeValue(START_AFTER_INSTALLATION_ATTRIBUTE);
        if (startAfterInstallationString != null) {
            selectedBundle.setStartAfterInstallation(Boolean.parseBoolean(startAfterInstallationString));
        }
        bundlesToDeploy.add(selectedBundle);
    }
    // try to load the framework instance
    Element framework = element.getChild(FRAMEWORK_ELEMENT);
    if (framework != null) {
        String name = framework.getAttributeValue(INSTANCE_ATTRIBUTE);
        if (name != null) {
            ApplicationSettings settings = ServiceManager.getService(ApplicationSettings.class);
            instanceToUse = settings.getFrameworkInstance(name);
        }
    }
    Element additionalProperties = element.getChild(ADDITIONAL_PROPERTIES_ELEMENT);
    if (additionalProperties == null) {
        //noinspection SpellCheckingInspection
        additionalProperties = element.getChild("additinalProperties");
    }
    if (additionalProperties != null) {
        List<Attribute> attributes = additionalProperties.getAttributes();
        for (Attribute attribute : attributes) {
            this.additionalProperties.put(attribute.getName(), attribute.getValue());
        }
    }
    super.readExternal(element);
}
Also used : ApplicationSettings(org.osmorc.settings.ApplicationSettings) SelectedBundle(org.osmorc.run.ui.SelectedBundle) Attribute(org.jdom.Attribute) Element(org.jdom.Element)

Example 14 with SelectedBundle

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

the class OsgiRunConfiguration method writeExternal.

@Override
public void writeExternal(final Element element) throws WriteExternalException {
    // store the vm parameters
    element.setAttribute(VM_PARAMETERS_ATTRIBUTE, vmParameters == null ? "" : vmParameters);
    element.setAttribute(PROGRAM_PARAMETERS_ATTRIBUTE, programParameters == null ? "" : programParameters);
    element.setAttribute(INCLUDE_ALL_BUNDLES_IN_CLASS_PATH_ATTRIBUTE, Boolean.toString(includeAllBundlesInClassPath));
    element.setAttribute(WORKING_DIR_ATTRIBUTE, workingDir == null ? "" : workingDir);
    element.setAttribute(USE_ALTERNATIVE_JRE_ATTRIBUTE, String.valueOf(useAlternativeJre));
    element.setAttribute(ALTERNATIVE_JRE_PATH, alternativeJrePath != null ? alternativeJrePath : "");
    element.setAttribute(FRAMEWORK_START_LEVEL, String.valueOf(frameworkStartLevel));
    element.setAttribute(DEFAULT_START_LEVEL, String.valueOf(defaultStartLevel));
    element.setAttribute(GENERATE_WORKING_DIR_ATTRIBUTE, String.valueOf(generateWorkingDir));
    // all module's names
    for (SelectedBundle selectedBundle : bundlesToDeploy) {
        Element bundle = new Element(BUNDLE_ELEMENT);
        bundle.setAttribute(NAME_ATTRIBUTE, selectedBundle.getName());
        if (!selectedBundle.isModule()) {
            String path = selectedBundle.getBundlePath();
            if (path != null)
                bundle.setAttribute(URL_ATTRIBUTE, VfsUtilCore.pathToUrl(path));
        }
        bundle.setAttribute(START_LEVEL_ATTRIBUTE, String.valueOf(selectedBundle.getStartLevel()));
        bundle.setAttribute(TYPE_ATTRIBUTE, selectedBundle.getBundleType().name());
        bundle.setAttribute(START_AFTER_INSTALLATION_ATTRIBUTE, Boolean.toString(selectedBundle.isStartAfterInstallation()));
        element.addContent(bundle);
    }
    // and the instance to use
    Element framework = new Element(FRAMEWORK_ELEMENT);
    framework.setAttribute(INSTANCE_ATTRIBUTE, instanceToUse != null ? instanceToUse.getName() : "");
    element.addContent(framework);
    Element additionalProperties = new Element(ADDITIONAL_PROPERTIES_ELEMENT);
    for (String additionalPropertyName : this.additionalProperties.keySet()) {
        additionalProperties.setAttribute(additionalPropertyName, this.additionalProperties.get(additionalPropertyName));
    }
    element.addContent(additionalProperties);
    super.writeExternal(element);
}
Also used : SelectedBundle(org.osmorc.run.ui.SelectedBundle) Element(org.jdom.Element)

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