Skip to content

Commit

Permalink
[backport] Support repository references
Browse files Browse the repository at this point in the history
Currently Tycho ignores repository references when resolving IU
locations and P2 repositories.

This now adds support for referenced repositories so Tycho can resolve
from there as well.
  • Loading branch information
laeubi committed Jul 31, 2023
1 parent 84c6cb1 commit 0699e2f
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 104 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
This page describes the noteworthy improvements provided by each release of Eclipse Tycho.

## 4.0.2
-
- new option to include referenced repositories when resolving the target platform
- Add dummy parameter to prevent warnings with jgit as timestamp provider

## 4.0.1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.ICompositeRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
Expand All @@ -57,8 +58,8 @@ public class ListCompositeArtifactRepository extends AbstractArtifactRepository

public final List<IArtifactRepository> artifactRepositories;

public ListCompositeArtifactRepository(IProvisioningAgent agent,
List<? extends IArtifactRepository> artifactRepositories) {
public ListCompositeArtifactRepository(List<? extends IArtifactRepository> artifactRepositories,
IProvisioningAgent agent) {
super(agent, null, IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null, null, null, null, null);
try {
setLocation(new URI("list:" + UUID.randomUUID()));
Expand All @@ -74,12 +75,7 @@ public IQueryResult<IArtifactKey> query(IQuery<IArtifactKey> query, IProgressMon
if (size == 1) {
return artifactRepositories.get(0).query(query, monitor);
}
Collector<IArtifactKey> collector = new Collector<>();
SubMonitor subMonitor = SubMonitor.convert(monitor, size);
for (IArtifactRepository repository : artifactRepositories) {
collector.addAll(repository.query(query, subMonitor.split(1)));
}
return collector;
return QueryUtil.compoundQueryable(artifactRepositories).query(query, IProgressMonitor.nullSafe(monitor));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public IArtifactRepository getCompositeArtifactRepository(Collection<Repository>
for (Repository repository : repositories) {
childs.add(getArtifactRepository(repository));
}
return new ListCompositeArtifactRepository(agent, childs);
return new ListCompositeArtifactRepository(childs, agent);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.tycho.core.resolver.DefaultTargetPlatformConfigurationReader;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
import org.eclipse.tycho.core.resolver.shared.PomDependencies;
import org.eclipse.tycho.core.resolver.shared.ReferencedRepositoryMode;
import org.eclipse.tycho.targetplatform.TargetPlatformFilter.CapabilityPattern;

/**
Expand All @@ -45,11 +46,11 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
* List of .target artifacts to use for dependency resolution.<br>
* Could either be
* <ul>
* <li><code>&lt;artifact></code> to define a target GAV (either local to the reactor or a remote
* one)</li>
* <li><code>&lt;artifact></code> to define a target GAV (either local to the reactor or a
* remote one)</li>
* <li><code>&lt;file></code> to define a file local to the build</li>
* <li><code>&lt;uri></code> to define a (remote) URI that specifies a target, currently only URIs
* that can be converted to URLs are supported (e.g. file:/.... http://..., )</li>
* <li><code>&lt;uri></code> to define a (remote) URI that specifies a target, currently only
* URIs that can be converted to URLs are supported (e.g. file:/.... http://..., )</li>
* </ul>
*/
@Parameter(name = DefaultTargetPlatformConfigurationReader.TARGET)
Expand All @@ -60,21 +61,21 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
* <p>
* If <code>consider</code> or <code>wrapAsBundle</code>, the effect is:
* <ul>
* <li>First, Maven resolves the GAV dependencies according to the normal Maven rules. This results
* in a list of artifacts consisting of the specified artifacts and their transitive Maven
* dependencies.</li>
* <li>Tycho then checks each of these artifacts, and if the artifact is an OSGi bundle, it is added
* to the target platform. Other artifacts are ignored in case of <code>consider</code>, or get some
* OSGi metadata generated and an OSGi bundle created from them.</li>
* <li>First, Maven resolves the GAV dependencies according to the normal Maven rules. This
* results in a list of artifacts consisting of the specified artifacts and their transitive
* Maven dependencies.</li>
* <li>Tycho then checks each of these artifacts, and if the artifact is an OSGi bundle, it is
* added to the target platform. Other artifacts are ignored in case of <code>consider</code>,
* or get some OSGi metadata generated and an OSGi bundle created from them.</li>
* <li>OSGi bundles which become part of the target platform in this way are then available to
* resolve the project's OSGi dependencies.</li>
* </ul>
* </p>
* <p>
* 📝 Tycho always attempts to resolve transitive dependencies, so if you need a POM dependency in
* the target platform of one module, you will also need it in all downstream modules. Therefore the
* POM dependencies (and the pomDependencies=consider configuration) typically need to be added in
* the parent POM.
* 📝 Tycho always attempts to resolve transitive dependencies, so if you need a POM dependency
* in the target platform of one module, you will also need it in all downstream modules.
* Therefore the POM dependencies (and the pomDependencies=consider configuration) typically
* need to be added in the parent POM.
* </p>
* <p>
* If no explicit value is configured Tycho uses {@link PomDependencies#ignore} if eager
Expand All @@ -85,8 +86,8 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
private PomDependencies pomDependencies;

/**
* Force an execution environment for dependency resolution. If unset, use the default JRE of your
* computer.
* Force an execution environment for dependency resolution. If unset, use the default JRE of
* your computer.
* <p>
* Set to <code>none</code> to force the resolution to happen <b>without</b> any execution
* environment, typically when the module is supposed to use system packages coming from some
Expand Down Expand Up @@ -122,15 +123,15 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
/**
* Selectively remove content from the target platform.
* <p>
* This for example allows to restrict the version of a bundle, or to select one particular provider
* for a package. Filtering is done as last step in the target platform computation, so the filters
* apply to all sources listed above.
* This for example allows to restrict the version of a bundle, or to select one particular
* provider for a package. Filtering is done as last step in the target platform computation, so
* the filters apply to all sources listed above.
* </p>
* <p>
* The filters will only remove content from the target platform; they will not add new content.
* {@code dependency-resolution} should be used for addition of extra content. If you specify a
* restriction that is not fulfilled by any of the units from the target platform sources, all units
* that the filter applies to (i.e. units that match the filter.type, filter.id, and
* restriction that is not fulfilled by any of the units from the target platform sources, all
* units that the filter applies to (i.e. units that match the filter.type, filter.id, and
* filter.version/versionRange criteria) will be removed from the target platform.
* </p>
* <p>
Expand Down Expand Up @@ -169,10 +170,10 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
private List<CapabilityPattern> filters;

/**
* Exclusions could be used together with {@link #pomDependencies} setting to exclude certain maven
* dependencies from being considered. This is useful for example if there is an offending
* (transitive) dependency needed for compilation but not for the runtime that would cause problems
* otherwise.
* Exclusions could be used together with {@link #pomDependencies} setting to exclude certain
* maven dependencies from being considered. This is useful for example if there is an offending
* (transitive) dependency needed for compilation but not for the runtime that would cause
* problems otherwise.
*/
@Parameter(name = DefaultTargetPlatformConfigurationReader.EXCLUSIONS)
private List<Exclusion> exclusions;
Expand Down Expand Up @@ -206,6 +207,12 @@ public class TargetPlatformConfigurationMojo extends AbstractMojo {
@Parameter(name = DefaultTargetPlatformConfigurationReader.TARGET_DEFINITION_INCLUDE_SOURCE)
private IncludeSourceMode targetDefinionIncludeSource;

/**
* Configures if referenced repositories should be included in when fetching repositories.
*/
@Parameter(name = DefaultTargetPlatformConfigurationReader.REFERENCED_REPOSITORY_MODE)
private ReferencedRepositoryMode referencedRepositoryMode;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoFailureException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
import org.eclipse.tycho.core.resolver.shared.PomDependencies;
import org.eclipse.tycho.core.resolver.shared.ReferencedRepositoryMode;
import org.eclipse.tycho.targetplatform.TargetDefinitionFile;
import org.eclipse.tycho.targetplatform.TargetPlatformFilter;

Expand Down Expand Up @@ -118,6 +119,8 @@ public enum InjectP2MavenMetadataHandling {

private InjectP2MavenMetadataHandling p2MavenMetadataHandling;

private ReferencedRepositoryMode referencedRepositoryMode = ReferencedRepositoryMode.ignore;

/**
* Returns the list of configured target environments, or the running environment if no
* environments have been specified explicitly.
Expand Down Expand Up @@ -311,4 +314,12 @@ public void setLocalArtifactHandling(LocalArtifactHandling localArtifactHandling
this.localArtifactHandling = localArtifactHandling;
}

public ReferencedRepositoryMode getReferencedRepositoryMode() {
return referencedRepositoryMode;
}

public void setReferencedRepositoryMode(ReferencedRepositoryMode referencedRepositoryMode) {
this.referencedRepositoryMode = referencedRepositoryMode;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
import org.eclipse.tycho.core.resolver.shared.PomDependencies;
import org.eclipse.tycho.core.resolver.shared.ReferencedRepositoryMode;
import org.eclipse.tycho.p2resolver.TargetDefinitionResolver;
import org.eclipse.tycho.targetplatform.TargetDefinitionFile;
import org.eclipse.tycho.targetplatform.TargetPlatformArtifactResolver;
Expand All @@ -59,6 +60,7 @@
@Component(role = DefaultTargetPlatformConfigurationReader.class)
public class DefaultTargetPlatformConfigurationReader {
public static final String TARGET_DEFINITION_INCLUDE_SOURCE = "targetDefinitionIncludeSource";
public static final String REFERENCED_REPOSITORY_MODE = "referencedRepositoryMode";
public static final String DEPENDENCY_RESOLUTION = "dependency-resolution";
public static final String OPTIONAL_DEPENDENCIES = "optionalDependencies";
public static final String LOCAL_ARTIFACTS = "localArtifacts";
Expand Down Expand Up @@ -137,6 +139,7 @@ public TargetPlatformConfiguration getTargetPlatformConfiguration(MavenSession s
readDependencyResolutionConfiguration(result, configuration, session);

setTargetDefinitionIncludeSources(result, configuration);
setReferencedRepositoryMode(result, configuration);
}
}
//consider items set in the pom repositories
Expand Down Expand Up @@ -191,6 +194,20 @@ private void setTargetDefinitionIncludeSources(TargetPlatformConfiguration resul
}
}

private void setReferencedRepositoryMode(TargetPlatformConfiguration result, Xpp3Dom configuration)
throws BuildFailureException {
String value = getStringValue(configuration.getChild(REFERENCED_REPOSITORY_MODE));
if (value == null) {
return;
}
try {
result.setReferencedRepositoryMode(ReferencedRepositoryMode.valueOf(value));
} catch (IllegalArgumentException e) {
throw new BuildFailureException("Illegal value of <" + REFERENCED_REPOSITORY_MODE
+ "> target platform configuration parameter: " + value, e);
}
}

protected void readDependencyResolutionConfiguration(TargetPlatformConfiguration result, Xpp3Dom configuration,
MavenSession mavenSession) {
Xpp3Dom resolverDom = configuration.getChild(DEPENDENCY_RESOLUTION);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2023 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.core.resolver.shared;

public enum ReferencedRepositoryMode {

/**
* Repository references are ignored
*/
ignore,
/**
* Repository references are included
*/
include;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.UUID;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.query.Collector;
import org.eclipse.equinox.p2.query.IQuery;
import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.ICompositeRepository;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
Expand Down Expand Up @@ -61,12 +61,7 @@ public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IPro
if (size == 1) {
return metadataRepositories.get(0).query(query, monitor);
}
Collector<IInstallableUnit> collector = new Collector<>();
SubMonitor subMonitor = SubMonitor.convert(monitor, size);
for (IMetadataRepository repository : metadataRepositories) {
collector.addAll(repository.query(query, subMonitor.split(1)));
}
return collector;
return QueryUtil.compoundQueryable(metadataRepositories).query(query, IProgressMonitor.nullSafe(monitor));
}

@Override
Expand Down
Loading

0 comments on commit 0699e2f

Please sign in to comment.