Migrate tycho-source-plugin to JSR330 annotations
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
@Requirementwith@Inject, using@Namedfor hint-based dependencies - Removed
Initializablelifecycle interface and emptyinitialize()methods - Replaced Plexus
Loggerwithorg.slf4j.Logger
Mojo classes (3 files):
-
AbstractSourceJarMojo,OsgiSourceMojo,SourceFeatureMojo - Replaced
@Componentfield injections with@Inject - Added
@Named("jar")qualifier forJarArchiverinjection
Build configuration:
- Added
sisu-maven-pluginto generateMETA-INF/sisu/javax.inject.Namedindex
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
@Componentannotated classes in tycho-source-plugin to JSR330 annotationsPlexus
@Componentannotations are deprecated replaced by plain JSR 330 components see https://github.com/eclipse/sisu.plexus/wiki/Plexus-to-JSR330For this we want:
- Migrate any currently
@Componentannotated components to JSR330- if a component currently does not implement an interface extract an intermediate interface and rename the previous one to
Default<NameOfClass>- Make sure
@Namedis always added to all components as it is required by maven, and@Singeltonwhen it is a component that do not uses per-lookup strategy- Keep formatting of the source files as close as possible to have smaller diffs
- We do not need any tests for this change as existing test will cover the case
- Make sure everything compile using
mvn clean install -T1C -DskipTestsin the root of the repository (skips all tests and integration test for fast verification)- Add a reference to https://github.com/eclipse-tycho/tycho/issues/1494 to link the PR with the ongoing effort but not close it.
- Make sure the
sisu-maven-pluginis activated in thepom.xmlto generate the filetarget/classes/META-INF/sisu/javax.inject.Named- Use
@PreDestroyon method whereDisposablewas previously implemented- If a component is using a base class and that baseclass has fields that are injected with
@Requirementthis baseclass and all its extensions need to be converted as well- A class can't use
@Singletonand@SessionScopedat the same time, don't add@Singletonif it already uses@SessionScopedin 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.