Skip to content

Commit

Permalink
Use the TargetPlatformService in the PackageFeatureMojo
Browse files Browse the repository at this point in the history
 and reset the TargetPlatfrom if TargetPlatformMojo is called twice

Fix #1411
  • Loading branch information
laeubi authored and Christoph Läubrich committed Sep 24, 2022
1 parent f7b1413 commit 7493b25
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
Expand Up @@ -20,11 +20,15 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetPlatformService;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;

@Mojo(name = "target-platform", threadSafe = true)
public class TargetPlatformMojo extends AbstractMojo {

private static final String TARGET_PLATFORM_MOJO_EXECUTED = "TargetPlatformMojo.executed";

// TODO site doc (including steps & parameters handled in afterProjectsRead?)
@Parameter(property = "project", readonly = true)
private MavenProject project;
Expand All @@ -34,8 +38,17 @@ public class TargetPlatformMojo extends AbstractMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

ReactorProject reactorProject = DefaultReactorProject.adapt(project);
Object executed = reactorProject.getContextValue(TARGET_PLATFORM_MOJO_EXECUTED);
if (executed != null) {
//second execution should force recomputation
platformService.clearTargetPlatform(reactorProject);
} else {
reactorProject.setContextValue(TARGET_PLATFORM_MOJO_EXECUTED, Boolean.TRUE);
}
//trigger target platform resoloution....
platformService.getTargetPlatform(DefaultReactorProject.adapt(project));
platformService.getTargetPlatform(reactorProject);
}

}
Expand Up @@ -31,4 +31,12 @@ public interface TargetPlatformService {
* when the target platform for the project can not be resolved
*/
Optional<TargetPlatform> getTargetPlatform(ReactorProject project) throws DependencyResolutionException;

/**
* Clears the given target platform for this project
*
* @param reactorProject
* the project for what the {@link TargetPlatform} should be cleared
*/
void clearTargetPlatform(ReactorProject reactorProject);
}
Expand Up @@ -171,4 +171,12 @@ private static void verifyFilePresenceInTargetFolder(ReactorProject project, Str
"Unexpected build result of " + project + ": File \"" + expectedLocation + "\" is missing");
}
}

@Override
public void clearTargetPlatform(ReactorProject project) {
synchronized (project) {
project.setContextValue(TargetPlatform.FINAL_TARGET_PLATFORM_KEY, null);
}

}
}
Expand Up @@ -41,8 +41,8 @@
import org.eclipse.tycho.BuildProperties;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TargetPlatform;
import org.eclipse.tycho.TargetPlatformService;
import org.eclipse.tycho.core.osgitools.DefaultReactorProject;
import org.eclipse.tycho.core.utils.TychoProjectUtils;
import org.eclipse.tycho.model.Feature;

@Mojo(name = "package-feature", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
Expand Down Expand Up @@ -107,6 +107,9 @@ public class PackageFeatureMojo extends AbstractTychoPackagingMojo {
@Component
private LicenseFeatureHelper licenseFeatureHelper;

@Component
private TargetPlatformService platformService;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
synchronized (LOCK) {
Expand Down Expand Up @@ -248,13 +251,13 @@ private void expandVersionQualifiers(Feature feature) throws MojoFailureExceptio
ReactorProject reactorProject = DefaultReactorProject.adapt(project);
feature.setVersion(reactorProject.getExpandedVersion());

TargetPlatform targetPlatform = TychoProjectUtils.getTargetPlatformIfAvailable(reactorProject);
if (targetPlatform == null) {
getLog().warn(
TargetPlatform targetPlatform = platformService.getTargetPlatform(reactorProject).orElse(null);
if (targetPlatform == null) {
getLog().warn(
"Skipping version reference expansion in eclipse-feature project using the deprecated -Dtycho.targetPlatform configuration");
return;
}
featureXmlTransformer.expandReferences(feature, targetPlatform);
return;
}
featureXmlTransformer.expandReferences(feature, targetPlatform);
}

private JarArchiver getJarArchiver() throws MojoExecutionException {
Expand Down

0 comments on commit 7493b25

Please sign in to comment.