Skip to content

Commit

Permalink
Add option to p2installed runtime to select additional root IUs
Browse files Browse the repository at this point in the history
Currently one can specify additional IUs only through target extra
dependencies, but in some cases it is useful to install additional root
IUs (e.g these are user visible and can be updated).

This adds a new option to the test mojo that allows to specify
additional units to be installed.

(cherry picked from commit b0d1fc3)
  • Loading branch information
laeubi committed Feb 10, 2024
1 parent 6689723 commit 6905732
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.StringJoiner;
Expand Down Expand Up @@ -429,9 +430,9 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
* when installing products under test (see below).
* <ul>
* <li>In <code>default</code> mode, all necessary files to define the test runtime like
* <code>config.ini</code> are generated by tycho. This installation mode has the advantage that the
* test runtime is minimal (defined by the transitive dependencies of the test bundle plus and
* the test harness) and existing bundle jars are referenced rather than copied for the
* <code>config.ini</code> are generated by tycho. This installation mode has the advantage that
* the test runtime is minimal (defined by the transitive dependencies of the test bundle plus
* and the test harness) and existing bundle jars are referenced rather than copied for the
* installation</li>
* <li>In <code>p2Installed</code> mode, use p2 director to install test bundle, test harness
* bundles and respective dependencies. This installation mode can be used for integration tests
Expand Down Expand Up @@ -510,6 +511,22 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
@Parameter
private Dependency[] dependencies;

/**
* Additional root IUs to install, only relevant if {@link #testRuntime} is
* <code>p2Installed</code>.
*
* <pre>
* &lt;install&gt;
* &lt;iu&gt;
* &lt;id&gt;...&lt;/id&gt;
* &lt;version&gt;...optional version...&lt;/id&gt;
* &lt;feature&gt;true/false&lt;/feature&gt; &lt;!-- optional if true .feature.group is automatically added to the id --&gt;
* &lt;/install&gt;
* </pre>
*/
@Parameter
private List<IU> install;

/**
* p2 <a href=
* "https://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_director.html"
Expand Down Expand Up @@ -678,6 +695,14 @@ private List<String> getIUsToInstall(Set<Artifact> testHarnessArtifacts) {
LinkedHashSet<ArtifactKey> extraDependencies = new LinkedHashSet<>(
projectManager.getTargetPlatformConfiguration(project).getAdditionalArtifacts());
extraDependencies.addAll(osgiBundle.getExtraTestRequirements(getReactorProject()));
// 4. mojo specified extras
if (this.install != null) {
for (IU iu : this.install) {
extraDependencies.add(new DefaultArtifactKey(
iu.feature ? ArtifactType.TYPE_ECLIPSE_FEATURE : ArtifactType.TYPE_ECLIPSE_PLUGIN, iu.id,
Objects.requireNonNullElse(iu.version, "0.0.0")));
}
}
for (ArtifactKey extraDependency : extraDependencies) {
String type = extraDependency.getType();
if (ArtifactType.TYPE_ECLIPSE_PLUGIN.equals(type) || ArtifactType.TYPE_INSTALLABLE_UNIT.equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* 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.surefire;

public final class IU {
String id;
String version;
boolean feature;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
* runtime" consists of the bundle built in this project and its transitive dependencies, plus some
* Equinox and test harness bundles. The bundles are resolved from the target platform of the
* project. Note that the test runtime does typically <em>not</em> contain the entire target
* platform. If there are implicitly required bundles (e.g. <code>org.apache.felix.scr</code> to make
* declarative services work), they need to be added manually through an <code>extraRequirements</code>
* configuration on the <code>target-platform-configuration</code> plugin.
* platform. If there are implicitly required bundles (e.g. <code>org.apache.felix.scr</code> to
* make declarative services work), they need to be added manually through an
* <code>extraRequirements</code> configuration on the <code>target-platform-configuration</code>
* plugin.
* </p>
*/
@Mojo(name = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
Expand All @@ -62,6 +63,9 @@ public class TestPluginMojo extends AbstractEclipseTestMojo {
@Parameter(property = "maven.test.failure.ignore", defaultValue = "false")
private boolean testFailureIgnore;

@Parameter
private boolean quiet;

/**
* Configures the packaging type where this mojos applies, would normally be one of
* eclipse-test-plugin or eclipse-plugin.
Expand All @@ -81,15 +85,19 @@ protected File getReportsDirectory() {

@Override
protected void handleSuccess() {
getLog().info("All tests passed");
if (!quiet) {
getLog().info("All tests passed");
}
}

@Override
protected void handleTestFailures() throws MojoFailureException {
String errorMessage = "There are test failures.\n\nPlease refer to " + reportsDirectory
+ " for the individual test results.";
+ " for the individual test results.\n\n";
if (testFailureIgnore) {
getLog().error(errorMessage);
if (!quiet) {
getLog().error(errorMessage);
}
} else {
throw new MojoFailureException(errorMessage);
}
Expand Down

0 comments on commit 6905732

Please sign in to comment.