Skip to content

Commit

Permalink
Allow to specify additional update sites to install items in p2 mode
Browse files Browse the repository at this point in the history
Currently only the project target platform items can be selected if a
p2installed runtime is used.

This now adds a new option to specify additional repositories in
p2installed mode.
  • Loading branch information
laeubi committed Feb 10, 2024
1 parent b0d1fc3 commit 3879d6e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public void addMetadataRepository(URI metadataRepository) {
metadataRepos.add(metadataRepository);
}

/**
* Adds a co-located metadata/artifact repository at the given location.
*
* @param repository
* A URL pointing to a p2 repository
*/
public void addRepository(URI repository) {
addArtifactRepository(repository);
addMetadataRepository(repository);
}

/**
* Adds the artifact repository at the given location.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -44,6 +46,7 @@
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Repository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
Expand Down Expand Up @@ -527,6 +530,22 @@ public abstract class AbstractEclipseTestMojo extends AbstractTestMojo {
@Parameter
private List<IU> install;

/**
* Additional repositories used to install units from, only relevant if {@link #testRuntime} is
* <code>p2Installed</code>.
*
* <pre>
* &lt;repositories&gt;
* &lt;repository&gt;
* &lt;url&gt;...another repository...&lt;/url&gt;
* &lt;/repository&gt;
* &lt;/repositories&gt;
* </pre>
*
*/
@Parameter(name = "repositories")
private List<Repository> repositories;

/**
* p2 <a href=
* "https://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_director.html"
Expand Down Expand Up @@ -653,6 +672,17 @@ private EquinoxInstallation createProvisionedInstallation() throws MojoExecution
}
RepositoryReferences sources = repositoryReferenceTool.getVisibleRepositories(project, session,
RepositoryReferenceTool.REPOSITORIES_INCLUDE_CURRENT_MODULE);
if (repositories != null) {
for (Repository repository : repositories) {
String url = repository.getUrl();
if (url == null || url.isBlank()) {
throw new MojoExecutionException("Repository url can't be empty!");
}
URI uri = new URI(url);
getLog().info("Adding repository " + uri + "...");
sources.addRepository(uri);
}
}
installationBuilder.addMetadataRepositories(sources.getMetadataRepositories());
installationBuilder.addArtifactRepositories(sources.getArtifactRepositories());
installationBuilder.setProfileName(profileName);
Expand Down Expand Up @@ -680,8 +710,14 @@ private EquinoxInstallation createProvisionedInstallation() throws MojoExecution
getLog().info("Provisioning with environment " + testEnvironment + "...");
return installationBuilder.install(testEnvironment);
}
} catch (Exception ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (MojoExecutionException e) {
throw e;
} catch (MojoFailureException e) {
throw e;
} catch (URISyntaxException e) {
throw new MojoExecutionException(e.getInput() + " is not a valid URI", e);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void executeDirector(TargetEnvironment env) throws MojoFailureException
command.setProfileName(profileName);
command.setInstallFeatures(installFeatures);
command.setEnvironment(env);
log.info("Installing IUs " + ius + " to " + effectiveDestination);
log.info("Installing IUs " + ius + " to " + effectiveDestination + " using " + command.getProfileProperties());
try {
command.execute();
} catch (DirectorCommandException e) {
Expand Down

0 comments on commit 3879d6e

Please sign in to comment.