Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport target resolve #3283

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.tycho.IRepositoryIdManager;
import org.eclipse.tycho.version.TychoVersion;

@Component(role = IAgentServiceFactory.class, hint = "org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager")
public class RemoteArtifactRepositoryManagerAgentFactory implements IAgentServiceFactory {

@Requirement
@Requirement
Logger logger;

@Requirement
Expand All @@ -33,26 +34,25 @@ public class RemoteArtifactRepositoryManagerAgentFactory implements IAgentServic
@Requirement
MavenAuthenticator authenticator;

@Override
public Object createService(IProvisioningAgent agent) {
IArtifactRepositoryManager plainRepoManager = (IArtifactRepositoryManager) new ArtifactRepositoryComponent()
.createService(agent);
if (getDisableP2MirrorsConfiguration()) {
plainRepoManager = new P2MirrorDisablingArtifactRepositoryManager(plainRepoManager,
logger);
}
@Override
public Object createService(IProvisioningAgent agent) {
IArtifactRepositoryManager plainRepoManager = (IArtifactRepositoryManager) new ArtifactRepositoryComponent()
.createService(agent);
if (getDisableP2MirrorsConfiguration()) {
plainRepoManager = new P2MirrorDisablingArtifactRepositoryManager(plainRepoManager, logger);
}
return new RemoteArtifactRepositoryManager(plainRepoManager, repositoryIdManager, authenticator);
}
}

private boolean getDisableP2MirrorsConfiguration() {
String key = "tycho.disableP2Mirrors";
private boolean getDisableP2MirrorsConfiguration() {
String key = "tycho.disableP2Mirrors";
String value = System.getProperty(key);

boolean disableP2Mirrors = Boolean.parseBoolean(value);
if (disableP2Mirrors && logger.isDebugEnabled()) {
String message = key + "=" + value + " -> ignoring mirrors specified in p2 artifact repositories";
logger.debug(message);
}
return disableP2Mirrors;
}
if (value != null) {
logger.info("Using " + key
+ " to disable P2 mirrors is deprecated, use the property eclipse.p2.mirrors instead, see https://tycho.eclipseprojects.io/doc/"
+ TychoVersion.getTychoVersion() + "/SystemProperties.html for details.");
return Boolean.parseBoolean(value);
}
return false;
}
}
9 changes: 9 additions & 0 deletions src/site/markdown/SystemProperties.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ Name | Value | Default | Documentation
--- | --- | ---
tycho.comparator.showDiff | true / false | false | If set to true if text-like files show a unified diff of possible differences in files
tycho.comparator.threshold | bytes | 5242880 (~5MB) | gives the number of bytes for content to be compared semantically, larger files will only be compared byte-by-byte

### P2

These properties control the behaviour of P2 used by Tycho

Name | Value | Default | Documentation
--- | --- | ---
eclipse.p2.mirrors | true / false | true | Each p2 site can define a list of artifact repository mirrors, this controls if P2 mirrors should be used. This is independent from configuring mirrors in the maven configuration to be used by Tycho!

4 changes: 4 additions & 0 deletions tycho-api/src/main/java/org/eclipse/tycho/TargetPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public interface TargetPlatform {
* Key under which the final target platform is stored in the reactor project instances.
*/
String FINAL_TARGET_PLATFORM_KEY = "org.eclipse.tycho.core.TychoConstants/targetPlatform";

/**
* Key under which the preliminary target platform is stored in the reactor project instances.
*/
String PRELIMINARY_TARGET_PLATFORM_KEY = "org.eclipse.tycho.core.TychoConstants/dependencyOnlyTargetPlatform";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface DependencyResolver {

PomDependencyCollector resolvePomDependencies(MavenSession session, MavenProject project);

public TargetPlatform computePreliminaryTargetPlatform(MavenSession session, MavenProject project);
public TargetPlatform getPreliminaryTargetPlatform(MavenSession session, MavenProject project);

/**
* @param targetPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public DependencyArtifacts getDependencyArtifacts(ReactorProject reactorProject)
}
MavenSession mavenSession = getMavenSession(reactorProject);
MavenProject mavenProject = getMavenProject(reactorProject);
TargetPlatform preliminaryTargetPlatform = dependencyResolver.computePreliminaryTargetPlatform(mavenSession,
TargetPlatform preliminaryTargetPlatform = dependencyResolver.getPreliminaryTargetPlatform(mavenSession,
mavenProject);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(mavenProject);
DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ public Collection<IRequirement> getAdditionalRequirements() {
return resolverConfiguration.getAdditionalRequirements();
}
};
TargetPlatform preliminaryTargetPlatform = dependencyResolver.computePreliminaryTargetPlatform(mavenSession,
TargetPlatform preliminaryTargetPlatform = dependencyResolver.getPreliminaryTargetPlatform(mavenSession,
mavenProject);
return dependencyResolver.resolveDependencies(mavenSession, mavenProject, preliminaryTargetPlatform,
testResolverConfiguration, configuration.getEnvironments());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* 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.osgitools;

import java.io.File;
import java.util.List;
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.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.DefaultArtifactKey;
import org.eclipse.tycho.DependencyArtifacts;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.ArtifactDependencyVisitor;
import org.eclipse.tycho.core.ArtifactDependencyWalker;
import org.eclipse.tycho.core.TychoProject;
import org.eclipse.tycho.core.osgitools.targetplatform.DefaultDependencyArtifacts;
import org.eclipse.tycho.core.resolver.target.ArtifactTypeHelper;
import org.eclipse.tycho.model.Feature;
import org.eclipse.tycho.model.ProductConfiguration;
import org.eclipse.tycho.model.UpdateSite;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

@Component(role = TychoProject.class, hint = PackagingType.TYPE_ECLIPSE_TARGET_DEFINITION)
public class TargetPlatformProject extends AbstractTychoProject {

@Override
public ArtifactDependencyWalker getDependencyWalker(ReactorProject project) {
return new ArtifactDependencyWalker() {

@Override
public void walk(ArtifactDependencyVisitor visitor) {

}

@Override
public void traverseUpdateSite(UpdateSite site, ArtifactDependencyVisitor visitor) {

}

@Override
public void traverseProduct(ProductConfiguration productConfiguration, ArtifactDependencyVisitor visitor) {

}

@Override
public void traverseFeature(File location, Feature feature, ArtifactDependencyVisitor visitor) {

}
};
}

@Override
public ArtifactKey getArtifactKey(ReactorProject project) {
return new DefaultArtifactKey("target", project.getArtifactId(), project.getVersion());
}

@Override
public DependencyArtifacts getDependencyArtifacts(ReactorProject reactorProject) {
return reactorProject.computeContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS, () -> {
DefaultDependencyArtifacts artifacts = new DefaultDependencyArtifacts(reactorProject);
MavenSession mavenSession = getMavenSession(reactorProject);
MavenProject mavenProject = getMavenProject(reactorProject);
TargetPlatform targetPlatform = dependencyResolver.getPreliminaryTargetPlatform(mavenSession,
mavenProject);
if (targetPlatform instanceof P2TargetPlatform p2) {
Set<IInstallableUnit> installableUnits = p2.getInstallableUnits();
for (IInstallableUnit iu : installableUnits) {
for (IArtifactKey key : iu.getArtifacts()) {
ArtifactKey artifactKey = ArtifactTypeHelper.toTychoArtifactKey(iu, key);
artifacts.addArtifactFile(artifactKey, () -> targetPlatform.getArtifactLocation(artifactKey),
List.of(iu));
}
}
}
return artifacts;
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
Expand All @@ -27,20 +28,27 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.tycho.ArtifactKey;
import org.eclipse.tycho.DependencyResolutionException;
import org.eclipse.tycho.IllegalArtifactReferenceException;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.ReactorProjectIdentities;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.TargetPlatformService;
import org.eclipse.tycho.TychoConstants;
import org.eclipse.tycho.core.DependencyResolver;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.core.resolver.target.SupplierMetadataRepository;
import org.eclipse.tycho.p2.repository.GAV;
import org.eclipse.tycho.p2.repository.PublishingRepository;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;
import org.eclipse.tycho.p2resolver.PreliminaryTargetPlatformImpl;
import org.eclipse.tycho.repository.registry.facade.ReactorRepositoryManager;
import org.eclipse.tycho.targetplatform.P2TargetPlatform;

@Component(role = TargetPlatformService.class)
public class DefaultTargetPlatformService implements TargetPlatformService {
Expand All @@ -63,6 +71,9 @@ public class DefaultTargetPlatformService implements TargetPlatformService {
@Requirement
private TargetPlatformFactory tpFactory;

@Requirement
private IProvisioningAgent agent;

@Override
public Optional<TargetPlatform> getTargetPlatform() throws DependencyResolutionException {
MavenSession session = legacySupport.getSession();
Expand All @@ -78,61 +89,67 @@ public Optional<TargetPlatform> getTargetPlatform() throws DependencyResolutionE

@Override
public Optional<TargetPlatform> getTargetPlatform(ReactorProject project) throws DependencyResolutionException {
synchronized (project) {
Object contextValue = project.getContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY);
if (contextValue instanceof TargetPlatform) {
return Optional.of((TargetPlatform) contextValue);
}
MavenSession session = legacySupport.getSession();
if (repositoryManager == null || session == null) {
return Optional.empty();
}
List<ReactorProjectIdentities> upstreamProjects = getReferencedTychoProjects(project);
PomDependencyCollector pomDependenciesCollector = dependencyResolver.resolvePomDependencies(session,
project.adapt(MavenProject.class));
TargetPlatform finalTargetPlatform = computeFinalTargetPlatform(project, upstreamProjects,
pomDependenciesCollector);
return Optional.ofNullable(finalTargetPlatform);
Object contextValue = project.getContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY);
if (contextValue instanceof TargetPlatform) {
return Optional.of((TargetPlatform) contextValue);
}
if (repositoryManager == null || project.adapt(MavenSession.class) == null) {
return Optional.empty();
}
return Optional.ofNullable(computeFinalTargetPlatform(project));
}

/**
* Computes the (immutable) target platform with final p2 metadata and attaches it to the given
* project.
*
* @param project
* the reactor project to compute the target platform for.
* @param upstreamProjects
* Other projects in the reactor which have already been built and may be referenced
* by the given project.
*/
private TargetPlatform computeFinalTargetPlatform(ReactorProject project,
List<? extends ReactorProjectIdentities> upstreamProjects, PomDependencyCollector pomDependencyCollector) {
synchronized (project) {
PreliminaryTargetPlatformImpl preliminaryTargetPlatform = getRegisteredPreliminaryTargetPlatform(project);
if (preliminaryTargetPlatform == null) {
MavenSession session = project.adapt(MavenSession.class);
if (session == null) {
session = legacySupport.getSession();
if (session == null) {
return null;
}
private TargetPlatform computeFinalTargetPlatform(ReactorProject project) {
return project.computeContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY, () -> {
MavenProject mavenProject = project.adapt(MavenProject.class);
MavenSession mavenSession = project.adapt(MavenSession.class);
TargetPlatform preliminaryTargetPlatform = dependencyResolver.getPreliminaryTargetPlatform(mavenSession,
mavenProject);
if (PackagingType.TYPE_ECLIPSE_TARGET_DEFINITION.equals(mavenProject.getPackaging())) {
IMetadataRepository metadataRepository;
if (preliminaryTargetPlatform instanceof P2TargetPlatform p2) {
metadataRepository = new SupplierMetadataRepository(agent,
() -> p2.getInstallableUnits().iterator());
} else {
metadataRepository = new SupplierMetadataRepository(agent, () -> Collections.emptyIterator());
}
MavenProject mavenProject = project.adapt(MavenProject.class);
if (mavenProject == null) {
return null;
}
preliminaryTargetPlatform = (PreliminaryTargetPlatformImpl) dependencyResolver
.computePreliminaryTargetPlatform(session, mavenProject);
return new TargetPlatform() {

}
List<PublishingRepository> upstreamProjectResults = getBuildResults(upstreamProjects);
TargetPlatform result = tpFactory.createTargetPlatformWithUpdatedReactorContent(preliminaryTargetPlatform,
upstreamProjectResults, pomDependencyCollector);
@Override
public ArtifactKey resolveArtifact(String type, String id, String versionRef)
throws IllegalArtifactReferenceException, DependencyResolutionException {
return preliminaryTargetPlatform.resolveArtifact(type, id, versionRef);
}

project.setContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY, result);
return result;
}
@Override
public boolean isFileAlreadyAvailable(ArtifactKey artifactKey) {
return preliminaryTargetPlatform.isFileAlreadyAvailable(artifactKey);
}

@Override
public IMetadataRepository getMetadataRepository() {
return metadataRepository;
}

@Override
public IArtifactRepository getArtifactRepository() {
return preliminaryTargetPlatform.getArtifactRepository();
}

@Override
public File getArtifactLocation(ArtifactKey artifact) {
return preliminaryTargetPlatform.getArtifactLocation(artifact);
}
};
} else {
List<ReactorProjectIdentities> upstreamProjects = getReferencedTychoProjects(project);
PomDependencyCollector pomDependenciesCollector = dependencyResolver
.resolvePomDependencies(mavenSession, project.adapt(MavenProject.class));
List<PublishingRepository> upstreamProjectResults = getBuildResults(upstreamProjects);
return tpFactory.createTargetPlatformWithUpdatedReactorContent(preliminaryTargetPlatform,
upstreamProjectResults, pomDependenciesCollector);
}
});
}

private List<PublishingRepository> getBuildResults(List<? extends ReactorProjectIdentities> projects) {
Expand All @@ -143,13 +160,6 @@ private List<PublishingRepository> getBuildResults(List<? extends ReactorProject
return results;
}

private PreliminaryTargetPlatformImpl getRegisteredPreliminaryTargetPlatform(ReactorProject project) {
return project.getContextValue(
TargetPlatform.PRELIMINARY_TARGET_PLATFORM_KEY) instanceof PreliminaryTargetPlatformImpl preliminaryTargetPlatformImpl
? preliminaryTargetPlatformImpl
: null;
}

private List<ReactorProjectIdentities> getReferencedTychoProjects(ReactorProject reactorProject)
throws DependencyResolutionException {
List<ReactorProjectIdentities> result = new ArrayList<>();
Expand Down
Loading
Loading