getTargetRepositories(MavenProject currentProject) {
return Collections.unmodifiableList(p2repositories);
}
+
+ /**
+ * The is created lazily based on the plugin configuration of this SBOM project.
+ * If is converter is used outside a project, a default configuration is
+ * returned. If no configuration has been created for the current project, a new
+ * instance is created and stored as context value, which is then returned on
+ * successive calls.
+ *
+ * @return The SBOM configuration of the current project. Never {@code null}.
+ */
+ private synchronized TychoSBOMConfiguration getOrCreateCurrentProjectConfiguration() {
+ MavenProject currentProject = legacySupport.getSession().getCurrentProject();
+ if (currentProject == null) {
+ return new TychoSBOMConfiguration();
+ }
+ TychoSBOMConfiguration projectConfig = (TychoSBOMConfiguration) currentProject.getContextValue(KEY_CONTEXT);
+ if (projectConfig == null) {
+ projectConfig = new TychoSBOMConfiguration(currentProject);
+ currentProject.setContextValue(KEY_CONTEXT, projectConfig);
+ }
+ return projectConfig;
+ }
}
diff --git a/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoSBOMConfiguration.java b/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoSBOMConfiguration.java
new file mode 100644
index 0000000000..664174c61c
--- /dev/null
+++ b/tycho-sbom/src/main/java/org/eclipse/tycho/sbom/TychoSBOMConfiguration.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2024 Patrick Ziegler and others.
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Patrick Ziegler - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.tycho.sbom;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.tycho.PackagingType;
+
+/**
+ * Configuration of the {@code tycho-sbom} plugin to configure the packaging
+ * types for which the {@link TychoModelConverter} is used. By default only
+ * plug-ins and features are supported, but user may include additional types
+ * using this class. Example:
+ *
+ *
+ * <configuration>
+ * <includes>
+ * <include>eclipse-plugin</include>
+ * <include>eclipse-feature</include>
+ * <include>eclipse-repository</include>
+ * </includes>
+ * </configuration>>
+ *
+ */
+public class TychoSBOMConfiguration {
+ private static final Set DEFAULT_TYPES = Set.of(PackagingType.TYPE_ECLIPSE_FEATURE,
+ PackagingType.TYPE_ECLIPSE_PLUGIN);
+ private static final String KEY_INCLUDES = "includes";
+ /**
+ * Contains all packaging types for which the {@link TychoModelConverter} should
+ * be used. Initialized with {@link #DEFAULT_TYPES} if no other configuration is
+ * specified.
+ */
+ private Set includes = DEFAULT_TYPES;
+
+ /**
+ * A default implementation that is used when used outside of a Maven project.
+ */
+ public TychoSBOMConfiguration() {
+ // no-op
+ }
+
+ /**
+ * Initializes the configuration based on the configuration of the
+ * {@code tycho-sbom} plugin. If no configuration exists, this configuration is
+ * initialized with its default values.
+ */
+ public TychoSBOMConfiguration(MavenProject currentProject) {
+ Plugin plugin = currentProject.getPlugin("org.eclipse.tycho:tycho-sbom");
+ if (plugin != null && plugin.getConfiguration() instanceof Xpp3Dom root) {
+ readIncludes(root.getChild(KEY_INCLUDES));
+ }
+ }
+
+ private void readIncludes(Xpp3Dom parent) {
+ if (parent == null) {
+ return;
+ }
+ // Overwrite default configuration
+ includes = Arrays.stream(parent.getChildren()) //
+ .map(Xpp3Dom::getValue) //
+ .collect(Collectors.toUnmodifiableSet());
+ }
+
+ /**
+ * Returns all packaging types for which the {@link TychoModelConverter} should
+ * be used.
+ *
+ * @return An unmodifiable list of {@link String}s.
+ */
+ public Set getIncludedPackagingTypes() {
+ // Set is already immutable
+ return includes;
+ }
+}