-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically discover dependencies from a published product
Currently the publis-products mojo is only fully usable in the eclipse-repository packaging type but there are other use-cases where it becomes interesting to publish the product metadata and further use it, for example in an p2 installed runtime. Even though it works to use the mojos it is quite inconvenient as one has to specify all its requirements manually as extra dependencies. This adds a new PublishProduct P2 unit providers that collect the dependencies from a product and supply them automatically as requirements to the project so the mojo can be used without having missed dependencies from the target.
- Loading branch information
Showing
13 changed files
with
204 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tycho-api/src/main/java/org/eclipse/tycho/UnmodifiableDependencyMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich 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: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import org.eclipse.equinox.p2.metadata.IInstallableUnit; | ||
|
||
public class UnmodifiableDependencyMetadata implements IDependencyMetadata { | ||
|
||
private Set<IInstallableUnit> units; | ||
private DependencyMetadataType dependencyMetadataType; | ||
|
||
public UnmodifiableDependencyMetadata(Set<IInstallableUnit> units, DependencyMetadataType type) { | ||
this.dependencyMetadataType = type; | ||
this.units = Collections.unmodifiableSet(units); | ||
} | ||
|
||
@Override | ||
public Set<IInstallableUnit> getDependencyMetadata(DependencyMetadataType type) { | ||
if (dependencyMetadataType == type) { | ||
return getDependencyMetadata(); | ||
} | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Set<IInstallableUnit> getDependencyMetadata() { | ||
return units; | ||
} | ||
|
||
@Override | ||
public void setDependencyMetadata(DependencyMetadataType type, Collection<IInstallableUnit> units) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...in/java/org/eclipse/tycho/plugins/p2/publisher/PublishProductInstallableUnitProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich 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: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.plugins.p2.publisher; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.model.Plugin; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.component.annotations.Requirement; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.equinox.p2.metadata.IInstallableUnit; | ||
import org.eclipse.equinox.p2.metadata.IRequirement; | ||
import org.eclipse.tycho.core.osgitools.EclipseRepositoryProject; | ||
import org.eclipse.tycho.p2maven.InstallableUnitGenerator; | ||
import org.eclipse.tycho.p2maven.actions.ProductFile2; | ||
import org.eclipse.tycho.resolver.InstallableUnitProvider; | ||
|
||
@Component(role = InstallableUnitProvider.class, hint = PublishProductInstallableUnitProvider.HINT) | ||
public class PublishProductInstallableUnitProvider implements InstallableUnitProvider { | ||
|
||
static final String HINT = "publish-products"; | ||
|
||
@Requirement | ||
private InstallableUnitGenerator installableUnitGenerator; | ||
|
||
@Override | ||
public Collection<IInstallableUnit> getInstallableUnits(MavenProject project, MavenSession session) | ||
throws CoreException { | ||
return getProductUnits(installableUnitGenerator, project); | ||
} | ||
|
||
static Set<IInstallableUnit> getProductUnits(InstallableUnitGenerator installableUnitGenerator, | ||
MavenProject project) { | ||
Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-p2-publisher-plugin"); | ||
if (plugin == null || plugin.getExecutions().isEmpty()) { | ||
return Set.of(); | ||
} | ||
List<File> productFiles = EclipseRepositoryProject.getProductFiles(project.getBasedir()); | ||
if (productFiles.isEmpty()) { | ||
return Set.of(); | ||
} | ||
List<IRequirement> requirements = new ArrayList<>(); | ||
for (File file : productFiles) { | ||
try { | ||
Collection<IInstallableUnit> units = installableUnitGenerator | ||
.getInstallableUnits(new ProductFile2(file)); | ||
for (IInstallableUnit unit : units) { | ||
requirements.addAll(unit.getRequirements()); | ||
} | ||
} catch (CoreException e) { | ||
} catch (Exception e) { | ||
} | ||
} | ||
if (requirements.isEmpty()) { | ||
return Set.of(); | ||
} | ||
return new HashSet<>(InstallableUnitProvider.createIU(requirements, HINT)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
.../src/main/java/org/eclipse/tycho/plugins/p2/publisher/PublishProductMetadataProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.eclipse.tycho.plugins.p2.publisher; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.component.annotations.Requirement; | ||
import org.eclipse.equinox.p2.metadata.IInstallableUnit; | ||
import org.eclipse.tycho.IDependencyMetadata; | ||
import org.eclipse.tycho.IDependencyMetadata.DependencyMetadataType; | ||
import org.eclipse.tycho.OptionalResolutionAction; | ||
import org.eclipse.tycho.TargetEnvironment; | ||
import org.eclipse.tycho.UnmodifiableDependencyMetadata; | ||
import org.eclipse.tycho.p2maven.InstallableUnitGenerator; | ||
import org.eclipse.tycho.resolver.P2MetadataProvider; | ||
|
||
@Component(role = P2MetadataProvider.class, hint = PublishProductInstallableUnitProvider.HINT) | ||
public class PublishProductMetadataProvider implements P2MetadataProvider { | ||
|
||
@Requirement | ||
private InstallableUnitGenerator installableUnitGenerator; | ||
|
||
@Override | ||
public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession session, MavenProject project, | ||
List<TargetEnvironment> environments, OptionalResolutionAction optionalAction) { | ||
|
||
Set<IInstallableUnit> productUnits = PublishProductInstallableUnitProvider | ||
.getProductUnits(installableUnitGenerator, project); | ||
if (productUnits.isEmpty()) { | ||
return Map.of(); | ||
} | ||
return Map.of(PublishProductInstallableUnitProvider.HINT, | ||
new UnmodifiableDependencyMetadata(productUnits, DependencyMetadataType.ADDITIONAL)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters