[ 
https://issues.apache.org/jira/browse/KARAF-957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13133822#comment-13133822
 ] 

Raman Gupta edited comment on KARAF-957 at 10/24/11 4:26 AM:
-------------------------------------------------------------

Well, it doesn't seem to work anyway when using systemPackages(...), probably 
because of a bug in the ancient version of Pax-Exam that is being used by the 
Karaf tooling.

However, the fix for this issue will still be useful since a work-around for 
the pax-exam bug is to use:

{code}systemProperty("org.osgi.framework.system.packages.extra").value("...");{code}

but that does not work unless this issue is resolved, since Pax-Exam adds the 
new system property before the VMOptions defined by karaf, and therefore the 
Karaf empty value for the same property overrides it.

The work-around to THAT is to use this little chunk of code instead of 
Helper.getDefaultOptions() directly (this assumes the value for 
org.osgi.framework.system.packages.extra is empty, which it is by default):

{code}
Option[] karafHelperOptions = Helper.getDefaultOptions();
List<Option> karafOptions = new ArrayList<Option>(karafHelperOptions.length);

for(Option o : karafHelperOptions) {
    if(o instanceof VMOption) {
        String oldVmOption = ((VMOption)o).getOption();
        StringBuilder builder = new StringBuilder(oldVmOption.length());
        final String extraStr = "-Dorg.osgi.framework.system.packages.extra=";
        final int startExtra = oldVmOption.indexOf(extraStr);
        builder
            .append(oldVmOption.substring(0, startExtra))
            .append(oldVmOption.substring(startExtra + extraStr.length() + 1));
        VMOption newVmOption = new VMOption(builder.toString());
        karafOptions.add(newVmOption);
    } else {
        karafOptions.add(o);
    }
}

return combine(
    // Default karaf environment
    /*Helper.getDefaultOptions()*/ karafOptions.toArray(new 
Option[karafOptions.size()]),
    ...
{code}
                
      was (Author: rocketraman):
    Well, it doesn't seem to work anyway when using systemPackages(...), 
probably because of a bug in the ancient version of Pax-Exam that is being used 
by the Karaf tooling.

However, the fix for this issue will still be useful since a work-around for 
the pax-exam bug is to use:

{code}systemProperty("org.osgi.framework.system.packages.extra").value("...");{code}

but that does not work unless this issue is resolved, since Pax-Exam adds the 
new system property before the VMOptions defined by karaf, and therefore the 
Karaf empty value for the same property overrides it.

The work-around to THAT is to use this little chunk of code instead of 
Helper.getDefaultOptions() directly (this assumes the value for 
org.osgi.framework.system.packages.extra is empty, which it is by default):

{code}
Option[] karafHelperOptions = Helper.getDefaultOptions();
List<Option> karafOptions = new ArrayList<Option>(karafHelperOptions.length);

for(Option o : karafHelperOptions) {
    if(o instanceof VMOption) {
        String oldVmOption = ((VMOption)o).getOption();
        StringBuilder builder = new StringBuilder(oldVmOption.length());
        final String extraStr = "-Dorg.osgi.framework.system.packages.extra=";
        final int startExtra = oldVmOption.indexOf(extraStr);
        builder
            .append(oldVmOption.substring(0, startExtra))
            .append(oldVmOption.substring(startExtra + extraStr.length() + 1));
        VMOption newVmOption = new VMOption(builder.toString());
        karafOptions.add(newVmOption);
    } else {
        karafOptions.add(o);
    }
}
{code}
                  
> Cannot specify systemPackage options when using karaf.testing.Helper
> --------------------------------------------------------------------
>
>                 Key: KARAF-957
>                 URL: https://issues.apache.org/jira/browse/KARAF-957
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf-tooling
>    Affects Versions: 2.2.4
>            Reporter: Raman Gupta
>
> When using the karaf.testing.Helper, it pre-sets the 
> "org.osgi.framework.system.packages.extra" property to an empty value. Then, 
> when using pax-exam systemPackages(...) option to add system packages to the 
> list, it does not work since org.osgi.framework.system.packages.extra already 
> exists in the option list.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to