Skip to content

Commit

Permalink
Make checks for 'feature-source'/'p2-metadata' executions more precise
Browse files Browse the repository at this point in the history
Using an execution's goal and not its id as criteria to check for its
presence is more precise. The id can be chosen arbitrarily and requiring
a specific id can easily lead to false positive and false negative
results.
  • Loading branch information
HannesWell authored and laeubi committed Apr 24, 2022
1 parent 9a88e29 commit 16cb813
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@
/**
* Goal to create a JAR-package containing all the source files of a osgi project.
*/
@Mojo(name = "plugin-source", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true)
@Mojo(name = OsgiSourceMojo.GOAL, defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true)
public class OsgiSourceMojo extends AbstractSourceJarMojo {

private static final String GOAL = "plugin-source";
static final String GOAL = "plugin-source";

static final String MANIFEST_HEADER_ECLIPSE_SOURCE_BUNDLE = "Eclipse-SourceBundle";
private static final String MANIFEST_BUNDLE_LOCALIZATION_BASENAME = BUNDLE_LOCALIZATION_DEFAULT_BASENAME + "-src";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -90,9 +89,11 @@
* <code>&lt;originalFeature&gt;/feature.properties</code>.
*
*/
@Mojo(name = "feature-source", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
@Mojo(name = SourceFeatureMojo.GOAL, defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
public class SourceFeatureMojo extends AbstractMojo {

static final String GOAL = "feature-source";

public enum MissingSourcesAction {
FAIL, WARN;
}
Expand Down Expand Up @@ -257,7 +258,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
projectHelper.attachArtifact(project, outputJarFile, SOURCES_FEATURE_CLASSIFIER);
if (!isP2GenerationEnabled()) {
logger.warn(
"org.eclipse.tycho:tycho-p2-plugin seems not to be enabled but will be required if the generated feature is used in an update-site. You can add the following snippet to your pom: \n" //
"org.eclipse.tycho:tycho-p2-plugin seems not to be enabled but will be required if the generated source-feature is used in an update-site or another feature. You can add the following snippet to your pom: \n" //
+ " <plugin>\n"
+ " <groupId>org.eclipse.tycho</groupId>\n" //
+ " <artifactId>tycho-p2-plugin</artifactId>\n" //
Expand All @@ -282,13 +283,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

protected boolean isP2GenerationEnabled() {
Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-p2-plugin");
if (plugin != null) {
PluginExecution execution = plugin.getExecutionsAsMap().get("attach-p2-metadata");
if (execution != null) {
return execution.getGoals().contains("p2-metadata");
}
}
return false;
return plugin != null && plugin.getExecutions().stream().anyMatch(e -> e.getGoals().contains("p2-metadata"));
}

static File getSourcesFeatureOutputDir(MavenProject project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public Map<String, IDependencyMetadata> getDependencyMetadata(MavenSession sessi
}
Plugin plugin = project.getPlugin("org.eclipse.tycho:tycho-source-plugin");
if (plugin != null) {
PluginExecution execution = plugin.getExecutionsAsMap().get("feature-source");
PluginExecution execution = plugin.getExecutions().stream()
.filter(e -> e.getGoals().contains(SourceFeatureMojo.GOAL)).findFirst().orElse(null);
if (execution == null) {
return null;
}
Expand Down

0 comments on commit 16cb813

Please sign in to comment.