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

[tycho-4.0.x] Register TargetPlatformFactory as a component #3226

Closed
wants to merge 1 commit into from
Closed
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 @@ -55,10 +55,12 @@ public class DefaultTargetPlatformService implements TargetPlatformService {
private DependencyResolver dependencyResolver;

@Requirement
ReactorRepositoryManager repositoryManager;
private ReactorRepositoryManager repositoryManager;

@Requirement
private P2ResolverFactory p2ResolverFactory;

@Requirement
P2ResolverFactory p2ResolverFactory;
private TargetPlatformFactory tpFactory;

@Override
Expand Down Expand Up @@ -125,8 +127,8 @@ private TargetPlatform computeFinalTargetPlatform(ReactorProject project,

}
List<PublishingRepository> upstreamProjectResults = getBuildResults(upstreamProjects);
TargetPlatform result = getTpFactory().createTargetPlatformWithUpdatedReactorContent(
preliminaryTargetPlatform, upstreamProjectResults, pomDependencyCollector);
TargetPlatform result = tpFactory.createTargetPlatformWithUpdatedReactorContent(preliminaryTargetPlatform,
upstreamProjectResults, pomDependencyCollector);

project.setContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY, result);
return result;
Expand All @@ -141,13 +143,6 @@ private List<PublishingRepository> getBuildResults(List<? extends ReactorProject
return results;
}

public synchronized TargetPlatformFactory getTpFactory() {
if (tpFactory == null) {
tpFactory = p2ResolverFactory.getTargetPlatformFactory();
}
return tpFactory;
}

private PreliminaryTargetPlatformImpl getRegisteredPreliminaryTargetPlatform(ReactorProject project) {
return project.getContextValue(
TargetPlatform.PRELIMINARY_TARGET_PLATFORM_KEY) instanceof PreliminaryTargetPlatformImpl preliminaryTargetPlatformImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;

public interface P2ResolverFactory {

Expand All @@ -31,9 +30,6 @@ public interface P2ResolverFactory {
// TODO move to a PomDependencyCollectorFactory interface?
public PomDependencyCollector newPomDependencyCollector(ReactorProject project);

// TODO directly register as service
public TargetPlatformFactory getTargetPlatformFactory();

/**
* Create a resolver for the given environments
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.tycho.core.resolver.P2ResolverFactory;
import org.eclipse.tycho.core.resolver.shared.IncludeSourceMode;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;

/**
* Component that resolves all the bundles that make up an Eclipse Application to run from a given
Expand All @@ -51,6 +52,9 @@ public class EclipseApplicationFactory {
@Requirement
private P2ResolverFactory resolverFactory;

@Requirement
private TargetPlatformFactory platformFactory;

@Requirement
private Logger logger;

Expand Down Expand Up @@ -88,8 +92,7 @@ public TargetPlatform createTargetPlatform(Collection<MavenRepositoryLocation> l
ExecutionEnvironmentConfiguration eeConfiguration = new ExecutionEnvironmentConfigurationImpl(logger, false,
toolchainManager, mavenSession);
eeConfiguration.setProfileConfiguration("JavaSE-" + javaVersion, "tycho-eclipse-application-resolver");
TargetPlatform targetPlatform = resolverFactory.getTargetPlatformFactory().createTargetPlatform(tpConfiguration,
eeConfiguration, null);
TargetPlatform targetPlatform = platformFactory.createTargetPlatform(tpConfiguration, eeConfiguration, null);
return targetPlatform;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*******************************************************************************
* Copyright (c) 2008, 2023 Sonatype Inc. 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:
* Sonatype Inc. - initial API and implementation
* Christoph Läubrich - Bug 567098 - pomDependencies=consider should wrap non-osgi jars
* Issue #443 - Use regular Maven coordinates -when possible- for dependencies
* Issue #822 - If multiple fragments match a bundle all items are added to the classpath while only the one with the highest version should match
* Extracted into DefaultTargetPlatformFactory
*******************************************************************************/
package org.eclipse.tycho.p2resolver;

import java.io.File;
import java.util.List;

import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.tycho.ExecutionEnvironmentConfiguration;
import org.eclipse.tycho.IRepositoryIdManager;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.core.osgitools.MavenBundleResolver;
import org.eclipse.tycho.core.shared.MavenContext;
import org.eclipse.tycho.p2.repository.LocalArtifactRepository;
import org.eclipse.tycho.p2.repository.LocalMetadataRepository;
import org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices;
import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
import org.eclipse.tycho.p2.repository.RepositoryReader;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformConfigurationStub;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;

@Component(role = TargetPlatformFactory.class)
public class DefaultTargetPlatformFactory implements TargetPlatformFactory {

// TODO cache these instances in an p2 agent, and not here
private LocalMetadataRepository localMetadataRepository;
private LocalArtifactRepository localArtifactRepository;

@Requirement
private IProvisioningAgent agent;

@Requirement
private MavenContext mavenContext;

@Requirement
private LocalRepositoryP2Indices localRepoIndices;

@Requirement
private IRepositoryIdManager repositoryIdManager;

@Requirement
private MavenBundleResolver bundleResolver;

@Requirement
private TychoProjectManager projectManager;

@Requirement
private TargetDefinitionResolverService targetDefinitionResolverService;
private TargetPlatformFactoryImpl impl;

@Override
public TargetPlatform createTargetPlatform(TargetPlatformConfigurationStub tpConfiguration,
ExecutionEnvironmentConfiguration eeConfiguration, List<ReactorProject> reactorProjects,
ReactorProject project) {
return getImpl().createTargetPlatform(tpConfiguration, eeConfiguration, reactorProjects, project);
}

@Override
public TargetPlatform createTargetPlatformWithUpdatedReactorContent(TargetPlatform baseTargetPlatform,
List<?> upstreamProjectResults, PomDependencyCollector pomDependencies) {
return getImpl().createTargetPlatformWithUpdatedReactorContent(baseTargetPlatform, upstreamProjectResults,
pomDependencies);
}

private TargetPlatformFactory getImpl() {
if (impl == null) {
// TODO should be plexus-components!
LocalMetadataRepository localMetadataRepo = getLocalMetadataRepository(mavenContext, localRepoIndices);
LocalArtifactRepository localArtifactRepo = getLocalArtifactRepository(mavenContext, localRepoIndices);
//TODO merge the impl here...
impl = new TargetPlatformFactoryImpl(mavenContext, agent, localArtifactRepo, localMetadataRepo,
targetDefinitionResolverService, repositoryIdManager, projectManager, bundleResolver);
}
return impl;
}

private synchronized LocalMetadataRepository getLocalMetadataRepository(MavenContext context,
LocalRepositoryP2Indices localRepoIndices) {
if (localMetadataRepository == null) {
File localMavenRepoRoot = context.getLocalRepositoryRoot();
RepositoryReader contentLocator = new LocalRepositoryReader(context);
localMetadataRepository = new LocalMetadataRepository(getAgent(), localMavenRepoRoot.toURI(),
localRepoIndices.getMetadataIndex(), contentLocator);

}
return localMetadataRepository;
}

private synchronized LocalArtifactRepository getLocalArtifactRepository(MavenContext mavenContext,
LocalRepositoryP2Indices localRepoIndices) {
if (localArtifactRepository == null) {
RepositoryReader contentLocator = new LocalRepositoryReader(mavenContext);
localArtifactRepository = new LocalArtifactRepository(getAgent(), localRepoIndices, contentLocator);
}
return localArtifactRepository;
}

private IProvisioningAgent getAgent() {
//force triggering service loads... just in case not initialized yet ...
agent.getService(IArtifactRepositoryManager.class);
return agent;
}
}
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 @@ -140,6 +141,7 @@ public class P2DependencyResolver implements DependencyResolver, Initializable {
@Requirement
private MavenDependenciesResolver dependenciesResolver;

@Requirement
private TargetPlatformFactory tpFactory;

@Requirement
Expand Down Expand Up @@ -218,19 +220,12 @@ public TargetPlatform computePreliminaryTargetPlatform(MavenSession session, Mav
tpConfiguration
.setIgnoreLocalArtifacts(configuration.getIgnoreLocalArtifacts() == LocalArtifactHandling.ignore);
tpConfiguration.setReferencedRepositoryMode(configuration.getReferencedRepositoryMode());
TargetPlatform result = getTpFactory().createTargetPlatform(tpConfiguration, ee, reactorProjects,
TargetPlatform result = tpFactory.createTargetPlatform(tpConfiguration, ee, reactorProjects,
reactorProject);
return result;
});
}

private synchronized TargetPlatformFactory getTpFactory() {
if (tpFactory == null) {
tpFactory = resolverFactory.getTargetPlatformFactory();
}
return tpFactory;
}

private ReactorProject getThisReactorProject(MavenSession session, MavenProject project,
TargetPlatformConfiguration configuration) {
// 'this' project should obey optionalDependencies configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*******************************************************************************/
package org.eclipse.tycho.p2resolver;

import java.io.File;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -53,20 +52,13 @@
import org.eclipse.tycho.core.resolver.P2ResolverFactory;
import org.eclipse.tycho.core.shared.MavenContext;
import org.eclipse.tycho.core.shared.MavenLogger;
import org.eclipse.tycho.p2.repository.LocalArtifactRepository;
import org.eclipse.tycho.p2.repository.LocalMetadataRepository;
import org.eclipse.tycho.p2.repository.LocalRepositoryP2Indices;
import org.eclipse.tycho.p2.repository.LocalRepositoryReader;
import org.eclipse.tycho.p2.repository.RepositoryReader;
import org.eclipse.tycho.p2.target.facade.PomDependencyCollector;
import org.eclipse.tycho.p2.target.facade.TargetPlatformFactory;

@Component(role = P2ResolverFactory.class)
public class P2ResolverFactoryImpl implements P2ResolverFactory {

// TODO cache these instances in an p2 agent, and not here
private LocalMetadataRepository localMetadataRepository;
private LocalArtifactRepository localArtifactRepository;

@Requirement
IProvisioningAgent agent;

Expand All @@ -93,26 +85,8 @@ public class P2ResolverFactoryImpl implements P2ResolverFactory {
@Requirement
private MavenBundleResolver bundleResolver;

private synchronized LocalMetadataRepository getLocalMetadataRepository(MavenContext context,
LocalRepositoryP2Indices localRepoIndices) {
if (localMetadataRepository == null) {
File localMavenRepoRoot = context.getLocalRepositoryRoot();
RepositoryReader contentLocator = new LocalRepositoryReader(context);
localMetadataRepository = new LocalMetadataRepository(getAgent(), localMavenRepoRoot.toURI(),
localRepoIndices.getMetadataIndex(), contentLocator);

}
return localMetadataRepository;
}

private synchronized LocalArtifactRepository getLocalArtifactRepository(MavenContext mavenContext,
LocalRepositoryP2Indices localRepoIndices) {
if (localArtifactRepository == null) {
RepositoryReader contentLocator = new LocalRepositoryReader(mavenContext);
localArtifactRepository = new LocalArtifactRepository(getAgent(), localRepoIndices, contentLocator);
}
return localArtifactRepository;
}
@Requirement
private TargetPlatformFactory targetPlatformFactory;

private IProvisioningAgent getAgent() {
//force triggering service loads... just in case not initialized yet ...
Expand All @@ -129,18 +103,9 @@ public PomDependencyCollector newPomDependencyCollector(ReactorProject project)
return new PomDependencyCollectorImpl(logger, project, getAgent());
}

@Override
public TargetPlatformFactoryImpl getTargetPlatformFactory() {
// TODO should be plexus-components!
LocalMetadataRepository localMetadataRepo = getLocalMetadataRepository(mavenContext, localRepoIndices);
LocalArtifactRepository localArtifactRepo = getLocalArtifactRepository(mavenContext, localRepoIndices);
return new TargetPlatformFactoryImpl(mavenContext, agent, localArtifactRepo, localMetadataRepo,
targetDefinitionResolverService, repositoryIdManager, projectManager, bundleResolver);
}

@Override
public P2Resolver createResolver(Collection<TargetEnvironment> environments) {
return new P2ResolverImpl(getTargetPlatformFactory(), this, mavenContext.getLogger(), environments);
return new P2ResolverImpl(targetPlatformFactory, this, mavenContext.getLogger(), environments);
}

public Set<IInstallableUnit> calculateDependencyFragments(ResolutionData data,
Expand Down
Loading
Loading