Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tycho-p2-director-plugin / director: Cannot invoke "org.osgi.framework.BundleContext.getProperty(String)" because the return value of "org.eclipse.equinox.internal.p2.engine.EngineActivator.getContext()" is null #3437

Closed
sratz opened this issue Jan 30, 2024 · 9 comments · Fixed by #3438

Comments

@sratz
Copy link
Contributor

sratz commented Jan 30, 2024

I am trying to use the new director mojo of tycho-p2-director-plugin that was backported to 4.0.5 in #3411, but this runs into the following exception:

java.lang.NullPointerException: Cannot invoke "org.osgi.framework.BundleContext.getProperty(String)" because the return value of "org.eclipse.equinox.internal.p2.engine.EngineActivator.getContext()" is null
    at org.eclipse.equinox.p2.engine.PhaseSetFactory.<clinit> (PhaseSetFactory.java:26)
    at org.eclipse.equinox.internal.p2.engine.phases.Collect.<init> (Collect.java:41)
    at org.eclipse.tycho.p2tools.copiedfromp2.PhaseSetFactory.createPhaseSetIncluding (PhaseSetFactory.java:119)
    at org.eclipse.tycho.p2tools.copiedfromp2.PhaseSetFactory.createDefaultPhaseSetExcluding (PhaseSetFactory.java:101)
    at org.eclipse.tycho.plugins.p2.director.DirectorMojo.execute (DirectorMojo.java:401)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:568)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

My plugin config looks like this:

          <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-p2-director-plugin</artifactId>
            <version>4.0.5</version>
            <executions>
              <execution>
                <id>run-director</id>
                <goals>
                  <goal>director</goal>
                </goals>
                <phase>package</phase>
                <configuration>
                  <repositories>${director.repo}</repositories>
                  <installIUs>${director.installIU}</installIUs>
                  <destination>${director.destination}</destination>
                  <profile>${director.profile}</profile>
                  <installFeatures>true</installFeatures>
                  <roaming>true</roaming>
                  <p2os>${director.os}</p2os>
                  <p2ws>${director.ws}</p2ws>
                  <p2arch>${director.arch}</p2arch>
                </configuration>
              </execution>
            </executions>
          </plugin>

In
5b0707d#diff-75e34d80e724a1b1c5162508b06dfb539324b39bf97c008a0f8c43d5a86b2873R40
there was a change from EngineActivator.getContext().getProperty() to System.getProperty() in the copiedfromp2 code, seemingly for a similar reason, but there appears to be still code assuming to be running in an OSGI context.

Am I missing something here?

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

Can you provide an integration-test to demonstrate the issue in more context?

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

By the way here is where the mojo is used as part of the test:

https://github.com/eclipse-tycho/tycho/tree/main/tycho-its/projects/surefire.p2InstalledRuntime/extProductTestDirector

@sratz
Copy link
Contributor Author

sratz commented Jan 30, 2024

Can you provide an integration-test to demonstrate the issue in more context?

Here's a minimal pom.xm showing the exception (providing a real integration test that does something meaningful would be a bit more work):

<project
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>bar</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-p2-director-plugin</artifactId>
        <version>4.0.5</version>
        <executions>
          <execution>
            <id>run-director</id>
            <goals>
              <goal>director</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <repositories>a</repositories>
              <installIUs>b</installIUs>
              <destination>c</destination>
              <profile>d</profile>
              <installFeatures>true</installFeatures>
              <roaming>true</roaming>
              <p2os>win32</p2os>
              <p2ws>win32</p2ws>
              <p2arch>x86_64</p2arch>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

And this is the result:

$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------< foo:bar >-------------------------------
[INFO] Building bar 0.1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- tycho-p2-director:4.0.5:director (run-director) @ bar ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.698 s
[INFO] Finished at: 2024-01-30T13:57:15+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-director-plugin:4.0.5:director (run-director) on project bar: Execution run-director of goal org.eclipse.tycho:tycho-p2-director-plugin:4.0.5:director failed: An API incompatibility was encountered while executing org.eclipse.tycho:tycho-p2-director-plugin:4.0.5:director: java.lang.ExceptionInInitializerError: null
...
[ERROR] : Cannot invoke "org.osgi.framework.BundleContext.getProperty(String)" because the return value of "org.eclipse.equinox.internal.p2.engine.EngineActivator.getContext()" is null
...

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

@sratz can you try if adding the tycho-maven-plugin as an extension works?

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

okay the problem is that org.eclipse.equinox.internal.p2.engine.phases.Collect.Collect(int) calls PhaseSetFactory.PHASE_COLLECT what was not copied and for some reason it is not discovered here... what a mess!

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

Even worse Actually all phases do so and as these "constants" are not constant but compile time changeable the compiler need to instantiate the class and can't inline it :-\

@laeubi
Copy link
Member

laeubi commented Jan 30, 2024

@sratz I now used your example for a first attempt to create a PR here, of course this would probably always fail so testcase needs to be enhanced together with the fix:

github-actions bot pushed a commit that referenced this issue Jan 30, 2024
laeubi added a commit that referenced this issue Jan 31, 2024
@laeubi
Copy link
Member

laeubi commented Jan 31, 2024

You can try out the current tycho snapshot build if it fixes the issue for you!

@sratz
Copy link
Contributor Author

sratz commented Jan 31, 2024

You can try out the current tycho snapshot build if it fixes the issue for you!

It's working fine with the new snapshot. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants