Skip to content

Commit

Permalink
Cleanup the DependencyResolver interface and remove obsolete params
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Dec 16, 2023
1 parent e09e8f0 commit 70da154
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ public interface DependencyResolver {

PomDependencyCollector resolvePomDependencies(MavenSession session, MavenProject project);

public TargetPlatform computePreliminaryTargetPlatform(MavenSession session, MavenProject project,
List<ReactorProject> reactorProjects);
public TargetPlatform computePreliminaryTargetPlatform(MavenSession session, MavenProject project);

/**
* @param targetPlatform
* The candidate artifacts which may be used to resolve dependencies. If
* <code>null</code>, the final target platform of the project will be used.
*/
public DependencyArtifacts resolveDependencies(MavenSession session, MavenProject project,
TargetPlatform targetPlatform, List<ReactorProject> reactorProjects,
DependencyResolverConfiguration resolverConfiguration, List<TargetEnvironment> environments);
TargetPlatform targetPlatform, DependencyResolverConfiguration resolverConfiguration,
List<TargetEnvironment> environments);

public void injectDependenciesIntoMavenModel(MavenProject project, TychoProject projectType,
DependencyArtifacts resolvedDependencies, DependencyArtifacts testDepedencyArtifacts, Logger logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,12 @@ public DependencyArtifacts getDependencyArtifacts(ReactorProject reactorProject)
}
MavenSession mavenSession = getMavenSession(reactorProject);
MavenProject mavenProject = getMavenProject(reactorProject);
List<ReactorProject> reactorProjects = DefaultReactorProject.adapt(mavenSession);
TargetPlatform preliminaryTargetPlatform = dependencyResolver.computePreliminaryTargetPlatform(mavenSession,
mavenProject, reactorProjects);
mavenProject);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(mavenProject);
DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
DependencyArtifacts dependencyArtifacts = dependencyResolver.resolveDependencies(mavenSession, mavenProject,
preliminaryTargetPlatform, reactorProjects, resolverConfiguration, configuration.getEnvironments());
preliminaryTargetPlatform, resolverConfiguration, configuration.getEnvironments());
if (logger != null) {
if (logger.isDebugEnabled() && DebugUtils.isDebugEnabled(mavenSession, mavenProject)) {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@ public DependencyArtifacts getTestDependencyArtifacts(ReactorProject reactorProj
logger.info("Resolving test dependencies of " + reactorProject);
MavenSession mavenSession = getMavenSession(reactorProject);
MavenProject mavenProject = getMavenProject(reactorProject);
List<ReactorProject> reactorProjects = DefaultReactorProject.adapt(mavenSession);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(mavenProject);
DependencyResolverConfiguration resolverConfiguration = configuration.getDependencyResolverConfiguration();
DependencyResolverConfiguration testResolverConfiguration = new DependencyResolverConfiguration() {
Expand All @@ -713,9 +712,9 @@ public Collection<IRequirement> getAdditionalRequirements() {
}
};
TargetPlatform preliminaryTargetPlatform = dependencyResolver.computePreliminaryTargetPlatform(mavenSession,
mavenProject, reactorProjects);
mavenProject);
return dependencyResolver.resolveDependencies(mavenSession, mavenProject, preliminaryTargetPlatform,
reactorProjects, testResolverConfiguration, configuration.getEnvironments());
testResolverConfiguration, configuration.getEnvironments());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private TargetPlatform computeFinalTargetPlatform(ReactorProject project,
return null;
}
preliminaryTargetPlatform = (PreliminaryTargetPlatformImpl) dependencyResolver
.computePreliminaryTargetPlatform(session, mavenProject, DefaultReactorProject.adapt(session));
.computePreliminaryTargetPlatform(session, mavenProject);

}
List<PublishingRepository> upstreamProjectResults = getBuildResults(upstreamProjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Function;
Expand Down Expand Up @@ -83,7 +84,6 @@
import org.eclipse.tycho.core.resolver.P2Resolver;
import org.eclipse.tycho.core.resolver.P2ResolverFactory;
import org.eclipse.tycho.core.resolver.shared.PomDependencies;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.helper.PluginRealmHelper;
import org.eclipse.tycho.p2.metadata.DependencyMetadataGenerator;
import org.eclipse.tycho.p2.metadata.PublisherOptions;
Expand Down Expand Up @@ -196,16 +196,16 @@ protected Collection<IDependencyMetadata> getDependencyMetadata(final MavenSessi
}

@Override
public TargetPlatform computePreliminaryTargetPlatform(MavenSession session, MavenProject project,
List<ReactorProject> reactorProjects) {
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
public TargetPlatform computePreliminaryTargetPlatform(MavenSession mavenSession, MavenProject mavenProject) {
ReactorProject reactorProject = DefaultReactorProject.adapt(mavenProject);
return reactorProject.computeContextValue(TargetPlatform.PRELIMINARY_TARGET_PLATFORM_KEY, () -> {
logger.debug("Computing preliminary target platform for " + project);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(project);
ExecutionEnvironmentConfiguration ee = projectManager.getExecutionEnvironmentConfiguration(project);
logger.debug("Computing preliminary target platform for " + mavenProject);
List<ReactorProject> reactorProjects = DefaultReactorProject.adapt(mavenSession);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(mavenProject);
ExecutionEnvironmentConfiguration ee = projectManager.getExecutionEnvironmentConfiguration(mavenProject);

TargetPlatformConfigurationStub tpConfiguration = new TargetPlatformConfigurationStub();
for (ArtifactRepository repository : project.getRemoteArtifactRepositories()) {
for (ArtifactRepository repository : mavenProject.getRemoteArtifactRepositories()) {
addEntireP2RepositoryToTargetPlatform(repository, tpConfiguration);
}

Expand Down Expand Up @@ -296,19 +296,13 @@ private void addEntireP2RepositoryToTargetPlatform(ArtifactRepository repository

@Override
public DependencyArtifacts resolveDependencies(final MavenSession session, final MavenProject project,
TargetPlatform targetPlatform, List<ReactorProject> reactorProjects,
DependencyResolverConfiguration resolverConfiguration, List<TargetEnvironment> environments) {
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
if (targetPlatform == null) {
targetPlatform = TychoProjectUtils.getTargetPlatform(reactorProject);
}

// TODO 364134 For compatibility reasons, target-platform-configuration includes settings for the dependency resolution
// --> split this information logically, e.g. through two distinct interfaces
TargetPlatform targetPlatform, DependencyResolverConfiguration resolverConfiguration,
List<TargetEnvironment> environments) {
Objects.requireNonNull(targetPlatform);
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(project);

P2Resolver osgiResolverImpl = resolverFactory.createResolver(environments);

List<ReactorProject> reactorProjects = DefaultReactorProject.adapt(session);
return doResolveDependencies(session, project, reactorProjects, resolverConfiguration, targetPlatform,
osgiResolverImpl, configuration);
}
Expand Down Expand Up @@ -431,4 +425,5 @@ private MavenDependencyDescriptor resolveDescriptorWithValidation(MavenProject p
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.tycho.core.DependencyResolverConfiguration;
import org.eclipse.tycho.core.TargetPlatformConfiguration;
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.p2.repository.RepositoryBlackboardKey;
import org.eclipse.tycho.p2.tools.RepositoryReferences;

Expand Down Expand Up @@ -122,8 +121,7 @@ private void addTargetPlatformRepository(RepositoryReferences sources, MavenSess
.getDependencyResolverConfiguration();

DependencyArtifacts dependencyArtifacts = dependencyResolver.resolveDependencies(session, project,
targetPlatform, DefaultReactorProject.adapt(session), resolverConfiguration,
configuration.getEnvironments());
targetPlatform, resolverConfiguration, configuration.getEnvironments());
dependencyArtifacts.getArtifacts().forEach(artifact -> artifact.getLocation(true)); // ensure artifacts are available locally

// this contains dependency-only metadata for 'this' project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public Collection<IRequirement> getAdditionalRequirements() {
DependencyArtifacts testRuntimeArtifacts = dependencyResolver.resolveDependencies(session, project,
projectManager.getTargetPlatform(project)
.orElseThrow(() -> new MojoExecutionException(TychoConstants.TYCHO_NOT_CONFIGURED + project)),
getReactorProjects(), resolverConfiguration, getTestTargetEnvironments());
resolverConfiguration, getTestTargetEnvironments());
if (testRuntimeArtifacts == null) {
throw new MojoExecutionException(
"Cannot determinate build target platform location -- not executing tests");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,6 @@ protected ReactorProject getReactorProject() {
return DefaultReactorProject.adapt(project);
}

protected List<ReactorProject> getReactorProjects() {
return DefaultReactorProject.adapt(session);
}

/**
* This generates a bundle that is a fragment to the host that enhances the original bundle by
* the following items:
Expand Down

0 comments on commit 70da154

Please sign in to comment.