Skip to content

Commit

Permalink
Add support for resolving target platform projects
Browse files Browse the repository at this point in the history
Currently target-platform projects do not have any resolved
dependencies, this has a few disadvantages:

- if one want to see the dependency tree it is empty
- if one wants to mirror a target platform this can't be performed

This adds support for target platform projects to resolve and have their
dependencies injected to support such advanced use-cases.
  • Loading branch information
laeubi committed Dec 17, 2023
1 parent 77acf50 commit 41b1b4f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* 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 org.codehaus.plexus.component.annotations.Component;
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.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.model.Feature;
import org.eclipse.tycho.model.ProductConfiguration;
import org.eclipse.tycho.model.UpdateSite;

@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 project) {
synchronized (project) {
DependencyArtifacts resolvedDependencies = (DependencyArtifacts) project
.getContextValue(TychoConstants.CTX_DEPENDENCY_ARTIFACTS);
if (resolvedDependencies != null) {
return resolvedDependencies;
}
DefaultDependencyArtifacts artifacts = new DefaultDependencyArtifacts(project);
return artifacts;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.eclipse.tycho.MavenDependencyDescriptor;
import org.eclipse.tycho.MavenRepositoryLocation;
import org.eclipse.tycho.OptionalResolutionAction;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetEnvironment;
import org.eclipse.tycho.TargetPlatform;
Expand Down Expand Up @@ -149,22 +150,26 @@ public class P2DependencyResolver implements DependencyResolver, Initializable {
@Override
public void setupProjects(final MavenSession session, final MavenProject project,
final ReactorProject reactorProject) {
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(project);
List<TargetEnvironment> environments = configuration.getEnvironments();
Collection<IDependencyMetadata> metadataMap = getDependencyMetadata(session, project, environments,
OptionalResolutionAction.OPTIONAL);
Map<DependencyMetadataType, Set<IInstallableUnit>> typeMap = new TreeMap<>();
for (DependencyMetadataType type : DependencyMetadataType.values()) {
typeMap.put(type, new LinkedHashSet<>());
}
for (IDependencyMetadata metadata : metadataMap) {
typeMap.forEach((key, value) -> value.addAll(metadata.getDependencyMetadata(key)));
}
Set<IInstallableUnit> initial = new HashSet<>();
typeMap.forEach((key, value) -> {
reactorProject.setDependencyMetadata(key, value);
initial.addAll(value);
});
if (PackagingType.TYPE_ECLIPSE_TARGET_DEFINITION.equals(project.getPackaging())) {
//Target projects do not have any (initial) dependency metadata
} else {
TargetPlatformConfiguration configuration = projectManager.getTargetPlatformConfiguration(project);
List<TargetEnvironment> environments = configuration.getEnvironments();
Collection<IDependencyMetadata> metadataMap = getDependencyMetadata(session, project, environments,
OptionalResolutionAction.OPTIONAL);
Map<DependencyMetadataType, Set<IInstallableUnit>> typeMap = new TreeMap<>();
for (DependencyMetadataType type : DependencyMetadataType.values()) {
typeMap.put(type, new LinkedHashSet<>());
}
for (IDependencyMetadata metadata : metadataMap) {
typeMap.forEach((key, value) -> value.addAll(metadata.getDependencyMetadata(key)));
}
typeMap.forEach((key, value) -> {
reactorProject.setDependencyMetadata(key, value);
initial.addAll(value);
});
}
reactorProject.setDependencyMetadata(DependencyMetadataType.INITIAL, initial);
}

Expand Down

0 comments on commit 41b1b4f

Please sign in to comment.