tycho icon indicating copy to clipboard operation
tycho copied to clipboard

Migrate Plexus @Component annotations to JSR330 in 9 modules (excluding tycho-core, demo, tycho-its, p2-maven-plugin, tycho-packaging-plugin, tycho-versions-plugin)

Open Copilot opened this issue 2 months ago • 2 comments

This PR migrates org.codehaus.plexus.component.annotations.Component annotated classes to JSR330 annotations (javax.inject.*), following the deprecation of Plexus annotations in favor of JSR330 as documented in the Plexus to JSR330 migration guide.

Scope

This migration covers 20 production Java files across 9 modules, excluding tycho-core, demo, tycho-its, p2-maven-plugin, tycho-packaging-plugin, and tycho-versions-plugin which will be handled separately:

  • tycho-build (3 files)
  • tycho-source-plugin (3 files)
  • tycho-apitools-plugin (2 files)
  • tycho-baseline-plugin (2 files)
  • tycho-bnd-plugin (3 files)
  • tycho-eclipse-plugin (1 file)
  • tycho-p2-publisher-plugin (2 files)
  • tycho-repository-plugin (2 files)
  • tycho-sbom (2 files)

Changes

Annotation Replacements

  1. @Component → @Named + @Singleton

    // Before
    @Component(role = SomeService.class, hint = "default")
    public class DefaultSomeService implements SomeService { }
    
    // After
    @Named("default")
    @Singleton
    public class DefaultSomeService implements SomeService { }
    
  2. @Requirement → @Inject

    // Before
    @Requirement
    private Logger logger;
    
    // After
    @Inject
    private Logger logger;
    
  3. @Requirement(hint="x") → @Inject + @Named("x")

    // Before
    @Requirement(hint = "custom")
    private SomeService service;
    
    // After
    @Inject
    @Named("custom")
    private SomeService service;
    
  4. Per-lookup components (omit @Singleton for non-singleton lifecycle)

    // Before
    @Component(role = X.class, instantiationStrategy = "per-lookup")
    
    // After
    @Named
    

Build Configuration

Added sisu-maven-plugin to 7 affected pom.xml files to generate the required META-INF/sisu/javax.inject.Named index files for component discovery.

Testing

  • ✅ Full build succeeds: mvn clean install -T1C -DskipTests
  • ✅ All META-INF/sisu/javax.inject.Named files generated correctly
  • ✅ No compilation errors across all migrated modules
  • ✅ Existing tests cover the migrated code (no new tests required)

Notes

  • Formatting changes kept minimal to reduce diff size
  • Existing @SessionScoped annotations preserved where present
  • Test files intentionally not migrated as they don't affect production behavior
  • p2-maven-plugin, tycho-packaging-plugin, and tycho-versions-plugin excluded from this PR to keep the workload manageable and will be handled separately
  • This PR contributes to #1494 but does not close it, as tycho-core, demo, tycho-its, and the excluded modules require separate handling

Relates to #1494

Original prompt

Migrate all remaining org.codehaus.plexus.component.annotations.Component annotated classes except in in tycho-core, the demo or tycho-its to JSR330 annotations

Plexus @Component annotations are deprecated replaced by plain JSR 330 components see https://github.com/eclipse/sisu.plexus/wiki/Plexus-to-JSR330

For this we want:

  1. Migrate any currently @Component annotated components to JSR330
  2. if a component currently does not implement an interface extract an intermediate interface and rename the previous one to Default<NameOfClass>
  3. Make sure @Named is always added to all components as it is required by maven, and @Singelton when it is a component that do not uses per-lookup strategy
  4. Keep formatting of the source files as close as possible to have smaller diffs
  5. We do not need any tests for this change as existing test will cover the case
  6. Make sure everything compile using mvn clean install -T1C -DskipTests in the root of the repository (skips all tests and integration test for fast verification)
  7. Add a reference to https://github.com/eclipse-tycho/tycho/issues/1494 to link the PR with the ongoing effort but not close it.
  8. Make sure the sisu-maven-plugin is activated in the pom.xml to generate the file target/classes/META-INF/sisu/javax.inject.Named
  9. Use @PreDestroy on method where Disposable was previously implemented
  10. If a component is using a base class and that baseclass has fields that are injected with @Requirement this baseclass and all its extensions need to be converted as well
  11. tycho-core, demo and tycho-its should be ommited from this search as we need to handle them seperatly

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Oct 23 '25 08:10 Copilot

@copilot we exclude p2-maven-plugin (41 files), tycho-packaging-plugin (10 files) and tycho-versions-plugin (12 files) for now to keep the workload managable here!

laeubi avatar Oct 23 '25 08:10 laeubi

@copilot we exclude p2-maven-plugin (41 files), tycho-packaging-plugin (10 files) and tycho-versions-plugin (12 files) for now to keep the workload managable here!

Reverted the changes for p2-maven-plugin (41 files), tycho-packaging-plugin (10 files), and tycho-versions-plugin (12 files) in commit ab9131d. The PR now migrates only 20 files across 9 modules.

Copilot avatar Oct 23 '25 08:10 Copilot