tycho icon indicating copy to clipboard operation
tycho copied to clipboard

Migrate tycho-source-plugin to JSR330 annotations

Open Copilot opened this issue 4 months ago • 0 comments

Migrates tycho-source-plugin from deprecated Plexus @Component annotations to JSR330 (@Named, @Inject, @Singleton). Part of the ongoing effort tracked in #1494.

Changes

Component providers (3 files):

  • SourceFeatureP2MetadataProvider, SourceInstallableUnitProvider, SourcesP2MetadataProvider
  • Replaced @Component(role=..., hint=...) with @Named("...") + @Singleton
  • Replaced @Requirement with @Inject, using @Named for hint-based dependencies
  • Removed Initializable lifecycle interface and empty initialize() methods
  • Replaced Plexus Logger with org.slf4j.Logger

Mojo classes (3 files):

  • AbstractSourceJarMojo, OsgiSourceMojo, SourceFeatureMojo
  • Replaced @Component field injections with @Inject
  • Added @Named("jar") qualifier for JarArchiver injection

Build configuration:

  • Added sisu-maven-plugin to generate META-INF/sisu/javax.inject.Named index

Example migration

// Before
@Component(role = P2MetadataProvider.class, hint = "SourcesP2MetadataProvider")
public class SourcesP2MetadataProvider implements P2MetadataProvider, Initializable {
    @Requirement(hint = DependencyMetadataGenerator.SOURCE_BUNDLE)
    private DependencyMetadataGenerator sourcesGenerator;
    
    @Override
    public void initialize() throws InitializationException {
    }
}

// After
@Named("SourcesP2MetadataProvider")
@Singleton
public class SourcesP2MetadataProvider implements P2MetadataProvider {
    @Inject
    @Named(DependencyMetadataGenerator.SOURCE_BUNDLE)
    private DependencyMetadataGenerator sourcesGenerator;
}

No new interfaces required—components already implement P2MetadataProvider or InstallableUnitProvider. Mojos remain per-execution instances without @Singleton.

Original prompt

Migrate all @Component annotated classes in tycho-source-plugin 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. A class can't use @Singleton and @SessionScoped at the same time, don't add @Singleton if it already uses @SessionScoped in that case.

✨ 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 25 '25 16:10 Copilot