diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index e2d57446eb..3cc8f7fafc 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -18,9 +18,9 @@ can now be filtered by their location using exclusion and inclusion patterns and
https://foo.bar.org/hidden/**
- https://foo.bar.org/secret/**
+ %regex[http(s)?:\/\/foo\.bar\.org\/secret\/.*]
+ ![https://foo.bar.org/**]
- %regex[http(s)?:\/\/foo\.bar\.org\/.*]
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/TargetPlatformConfiguration.java b/tycho-core/src/main/java/org/eclipse/tycho/core/TargetPlatformConfiguration.java
index 46cad2dcc0..e8393a80a0 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/core/TargetPlatformConfiguration.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/core/TargetPlatformConfiguration.java
@@ -111,7 +111,7 @@ public enum InjectP2MavenMetadataHandling {
private Map resolverProfileProperties = new HashMap<>();
- List> lazyTargetFiles = new ArrayList<>();
+ private final List> lazyTargetFiles = new ArrayList<>();
private LocalArtifactHandling localArtifactHandling;
@@ -240,10 +240,7 @@ public void setFilters(List filters) {
}
public List getFilters() {
- if (filters == null)
- return Collections.emptyList();
- else
- return filters;
+ return filters == null ? Collections.emptyList() : filters;
}
public DependencyResolverConfiguration getDependencyResolverConfiguration() {
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/DestinationRepositoryDescriptor.java b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/DestinationRepositoryDescriptor.java
index a27d78cc46..c434eefc7e 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/DestinationRepositoryDescriptor.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/p2/tools/DestinationRepositoryDescriptor.java
@@ -19,8 +19,8 @@
public class DestinationRepositoryDescriptor {
- final File location;
- final String name;
+ private final File location;
+ private final String name;
private final boolean compress;
private final boolean xzCompress;
private final boolean keepNonXzIndexFiles;
@@ -43,8 +43,14 @@ public DestinationRepositoryDescriptor(File location, String name, boolean compr
this.repositoryReferences = repositoryReferences;
}
+ public DestinationRepositoryDescriptor(File location, String name, boolean compress, boolean xzCompress,
+ boolean keepNonXzIndexFiles, boolean metaDataOnly, boolean append) {
+ this(location, name, compress, xzCompress, keepNonXzIndexFiles, metaDataOnly, append, Collections.emptyMap(),
+ Collections.emptyList());
+ }
+
public DestinationRepositoryDescriptor(File location, String name) {
- this(location, name, true, true, false, false, true, Collections.emptyMap(), Collections.emptyList());
+ this(location, name, true, true, false, false, true);
}
public File getLocation() {
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java
index b68face24c..cc249ffaf9 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/MirrorApplicationServiceImpl.java
@@ -236,8 +236,7 @@ public void recreateArtifactRepository(DestinationRepositoryDescriptor destinati
private static TychoMirrorApplication createMirrorApplication(RepositoryReferences sources,
DestinationRepositoryDescriptor destination, IProvisioningAgent agent) {
- final TychoMirrorApplication mirrorApp = new TychoMirrorApplication(agent,
- destination.getExtraArtifactRepositoryProperties(), destination.getRepositoryReferences());
+ final TychoMirrorApplication mirrorApp = new TychoMirrorApplication(agent, destination);
mirrorApp.setRaw(false);
List sourceDescriptors = createSourceDescriptors(sources);
@@ -438,7 +437,7 @@ public void addMavenMappingRules(File repository, URI[] mavenRepositories) throw
repo.save();
DestinationRepositoryDescriptor desc = new DestinationRepositoryDescriptor(repository, repo.getName(),
new File(repository, "artifacts.xml.xz").exists(), new File(repository, "artifacts.xml.xz").exists(),
- true, false, false, Collections.emptyMap(), Collections.emptyList());
+ true, false, false);
xzCompress(desc);
}
}
diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java
index becbe1c044..78e8d2a996 100644
--- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java
+++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/TychoMirrorApplication.java
@@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.tycho.p2tools;
+import static java.util.stream.Collectors.groupingBy;
+
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -20,7 +22,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -41,12 +42,13 @@
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.repository.IRepository;
-import org.eclipse.equinox.p2.repository.IRepositoryReference;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.tycho.TargetPlatform;
+import org.eclipse.tycho.p2.tools.DestinationRepositoryDescriptor;
import org.eclipse.tycho.p2.tools.RepositoryReference;
public class TychoMirrorApplication extends org.eclipse.tycho.p2tools.copiedfromp2.MirrorApplication {
@@ -58,14 +60,13 @@ public class TychoMirrorApplication extends org.eclipse.tycho.p2tools.copiedfrom
private boolean includeAllSource;
private boolean includeRequiredBundles;
private boolean includeRequiredFeatures;
- private TargetPlatform targetPlatform;
private boolean filterProvided;
+ private TargetPlatform targetPlatform;
- public TychoMirrorApplication(IProvisioningAgent agent, Map extraArtifactRepositoryProperties,
- List repositoryReferences) {
+ public TychoMirrorApplication(IProvisioningAgent agent, DestinationRepositoryDescriptor destination) {
super(agent);
- this.extraArtifactRepositoryProperties = extraArtifactRepositoryProperties;
- this.repositoryReferences = repositoryReferences;
+ this.extraArtifactRepositoryProperties = destination.getExtraArtifactRepositoryProperties();
+ this.repositoryReferences = destination.getRepositoryReferences();
this.removeAddedRepositories = false;
}
@@ -75,8 +76,7 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit,
IArtifactRepository result = super.initializeDestination(toInit, mgr);
// simple.SimpleArtifactRepository.PUBLISH_PACK_FILES_AS_SIBLINGS is not public
result.setProperty("publishPackFilesAsSiblings", "true");
- extraArtifactRepositoryProperties.entrySet()
- .forEach(entry -> result.setProperty(entry.getKey(), entry.getValue()));
+ extraArtifactRepositoryProperties.forEach(result::setProperty);
return result;
}
@@ -85,38 +85,25 @@ protected Slicer createSlicer(SlicingOptions options) {
Map context = options.getFilter();
boolean includeOptionalDependencies = options.includeOptionalDependencies();
boolean onlyFilteredRequirements = options.followOnlyFilteredRequirements();
- boolean considerFilter = (context != null && context.size() > 1) ? true : false;
+ boolean considerFilter = context != null && context.size() > 1;
IMetadataRepository repository = getCompositeMetadataRepository();
return new PermissiveSlicer(repository, context, includeOptionalDependencies, options.isEverythingGreedy(),
options.forceFilterTo(), options.considerStrictDependencyOnly(), onlyFilteredRequirements) {
@Override
protected boolean isApplicable(IInstallableUnit iu, IRequirement req) {
- if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu)) {
- if (req instanceof IRequiredCapability capability) {
- if (IInstallableUnit.NAMESPACE_IU_ID.equals(capability.getNamespace())) {
- boolean isFeature = capability.getName().endsWith(FEATURE_GROUP);
- if ((isFeature && includeRequiredFeatures) || (!isFeature && includeRequiredBundles)) {
- if (!includeOptionalDependencies) {
- if (req.getMin() == 0) {
- return false;
- }
- }
- IMatchExpression filter = req.getFilter();
- if (considerFilter) {
- if (onlyFilteredRequirements && filter == null) {
- return false;
- }
- boolean filterMatches = filter == null || filter.isMatch(selectionContext);
- if (filterMatches) {
- }
- return filterMatches;
- }
- if (filter == null && onlyFilteredRequirements) {
- return false;
- }
- return true;
- }
+ if ((includeRequiredBundles || includeRequiredFeatures) && QueryUtil.isGroup(iu)
+ && req instanceof IRequiredCapability capability
+ && IInstallableUnit.NAMESPACE_IU_ID.equals(capability.getNamespace())) {
+ boolean isFeature = capability.getName().endsWith(FEATURE_GROUP);
+ if ((isFeature && includeRequiredFeatures) || (!isFeature && includeRequiredBundles)) {
+ if (!includeOptionalDependencies && req.getMin() == 0) {
+ return false;
}
+ IMatchExpression filter = req.getFilter();
+ if (onlyFilteredRequirements && filter == null) {
+ return false;
+ }
+ return !considerFilter || filter == null || filter.isMatch(selectionContext);
}
}
return super.isApplicable(req);
@@ -133,11 +120,10 @@ public IQueryable slice(IInstallableUnit[] ius, IProgressMonit
if (includeAllSource && targetPlatform != null) {
Set collected = slice.query(QueryUtil.ALL_UNITS, null).toSet();
Set result = new HashSet<>(collected);
- IQueryResult query = targetPlatform.getMetadataRepository()
- .query(QueryUtil.ALL_UNITS, null);
- Map> sourceIus = StreamSupport.stream(query.spliterator(), false)
+ var allUnits = targetPlatform.getMetadataRepository().query(QueryUtil.ALL_UNITS, null);
+ Map> sourceIus = stream(allUnits)
.filter(iu -> iu.getId().endsWith(SOURCE_SUFFIX))
- .collect(Collectors.groupingBy(IInstallableUnit::getId));
+ .collect(groupingBy(IInstallableUnit::getId));
for (IInstallableUnit iu : collected) {
String id = iu.getId();
String sourceId = id.endsWith(FEATURE_GROUP)
@@ -161,22 +147,18 @@ public IQueryable slice(IInstallableUnit[] ius, IProgressMonit
protected IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr)
throws ProvisionException {
IMetadataRepository result = super.initializeDestination(toInit, mgr);
- List extends IRepositoryReference> iRepoRefs = repositoryReferences.stream()
- .flatMap(TychoMirrorApplication::toSpiRepositoryReferences).toList();
- result.addReferences(iRepoRefs);
+ var refs = repositoryReferences.stream().flatMap(TychoMirrorApplication::toSpiRepositoryReferences).toList();
+ result.addReferences(refs);
return result;
}
private static Stream toSpiRepositoryReferences(
RepositoryReference rr) {
- return Stream.of(toSpiRepositoryReference(rr, IRepository.TYPE_METADATA),
- toSpiRepositoryReference(rr, IRepository.TYPE_ARTIFACT));
- }
-
- private static org.eclipse.equinox.p2.repository.spi.RepositoryReference toSpiRepositoryReference(
- RepositoryReference rr, int type) {
- return new org.eclipse.equinox.p2.repository.spi.RepositoryReference(URI.create(rr.getLocation()), rr.getName(),
- type, rr.isEnable() ? IRepository.ENABLED : IRepository.NONE);
+ return Stream.of(IRepository.TYPE_METADATA, IRepository.TYPE_ARTIFACT).map(type -> {
+ URI location = URI.create(rr.getLocation());
+ int options = rr.isEnable() ? IRepository.ENABLED : IRepository.NONE;
+ return new org.eclipse.equinox.p2.repository.spi.RepositoryReference(location, rr.getName(), type, options);
+ });
}
@Override
@@ -184,47 +166,67 @@ protected List collectArtifactKeys(Collection iu
throws ProvisionException {
List keys = super.collectArtifactKeys(ius, monitor);
if (isFilterProvidedItems()) {
- List referencedRepositories = new ArrayList<>();
- for (RepositoryReference reference : repositoryReferences) {
- String location = reference.getLocation();
- try {
- referencedRepositories
- .add(getArtifactRepositoryManager().loadRepository(new URI(location), monitor));
- } catch (URISyntaxException e) {
- throw new ProvisionException("Can't parse referenced URI!", e);
- }
- }
- keys.removeIf(key -> referencedRepositories.stream().anyMatch(repo -> repo.contains(key)));
+ removeProvidedItems(keys, getArtifactRepositoryManager(), monitor);
}
return keys;
}
- private boolean isFilterProvidedItems() {
- return filterProvided && !repositoryReferences.isEmpty();
- }
-
@Override
protected Set collectUnits(IQueryable slice, IProgressMonitor monitor)
throws ProvisionException {
Set units = super.collectUnits(slice, monitor);
if (isFilterProvidedItems()) {
- List referencedRepositories = new ArrayList<>();
- for (RepositoryReference reference : repositoryReferences) {
- String location = reference.getLocation();
- try {
- referencedRepositories
- .add(getMetadataRepositoryManager().loadRepository(new URI(location), monitor));
- } catch (URISyntaxException e) {
- throw new ProvisionException("Can't parse referenced URI!", e);
- }
- }
- units.removeIf(unit -> referencedRepositories.stream().anyMatch(repo -> {
- return !repo.query(QueryUtil.createIUQuery(unit.getId(), unit.getVersion()), monitor).isEmpty();
- }));
+ removeProvidedItems(units, getMetadataRepositoryManager(), monitor);
}
return units;
}
+ private boolean isFilterProvidedItems() {
+ return filterProvided && !repositoryReferences.isEmpty();
+ }
+
+ private void removeProvidedItems(Collection allElements, IRepositoryManager repoManager,
+ IProgressMonitor monitor) throws ProvisionException {
+ List> referencedRepositories = new ArrayList<>();
+ for (RepositoryReference reference : repositoryReferences) {
+ try {
+ URI location = new URI(reference.getLocation());
+ IRepository repository = loadRepository(repoManager, location, monitor);
+ referencedRepositories.add(repository);
+ } catch (URISyntaxException e) {
+ throw new ProvisionException("Can't parse referenced URI!", e);
+ }
+ }
+ allElements.removeIf(e -> referencedRepositories.stream().anyMatch(repo -> contains(repo, e)));
+ }
+
+ //TODO: just call IRepositoryManager.loadRepository() once available: https://github.com/eclipse-equinox/p2/pull/311
+ @SuppressWarnings("unchecked")
+ private static IRepository loadRepository(IRepositoryManager mgr, URI location, IProgressMonitor monitor)
+ throws ProvisionException {
+ if (mgr instanceof IArtifactRepositoryManager artifactRepoManager) {
+ return (IRepository) artifactRepoManager.loadRepository(location, monitor);
+ } else if (mgr instanceof IMetadataRepositoryManager metadataMangager) {
+ return (IRepository) metadataMangager.loadRepository(location, monitor);
+ }
+ throw new AssertionError("Unsupported IRepositoryManager type" + mgr.getClass());
+ }
+
+ //TODO: just call IRepositoryManager.contains() once available: https://github.com/eclipse-equinox/p2/pull/314
+ private static boolean contains(IRepository repository, T element) {
+ if (repository instanceof IArtifactRepository artifactRepository) {
+ return artifactRepository.contains((IArtifactKey) element);
+ } else if (repository instanceof IMetadataRepository metadataRepository) {
+ return !metadataRepository.query(QueryUtil.createIUQuery((IInstallableUnit) element), null).isEmpty();
+ }
+ throw new AssertionError("Unsupported IRepository type" + repository.getClass());
+ }
+
+ //TODO: use query.stream() once available: https://github.com/eclipse-equinox/p2/pull/312 is available
+ private static Stream stream(IQueryResult result) {
+ return StreamSupport.stream(result.spliterator(), false);
+ }
+
public void setIncludeSources(boolean includeAllSource, TargetPlatform targetPlatform) {
this.includeAllSource = includeAllSource;
this.targetPlatform = targetPlatform;
@@ -234,12 +236,12 @@ public void setIncludeRequiredBundles(boolean includeRequiredBundles) {
this.includeRequiredBundles = includeRequiredBundles;
}
- public void setFilterProvided(boolean filterProvided) {
- this.filterProvided = filterProvided;
- }
-
public void setIncludeRequiredFeatures(boolean includeRequiredFeatures) {
this.includeRequiredFeatures = includeRequiredFeatures;
}
+ public void setFilterProvided(boolean filterProvided) {
+ this.filterProvided = filterProvided;
+ }
+
}
diff --git a/tycho-extras/tycho-p2-extras-plugin/src/main/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojo.java b/tycho-extras/tycho-p2-extras-plugin/src/main/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojo.java
index 8730e41df7..b1e9f9864a 100644
--- a/tycho-extras/tycho-p2-extras-plugin/src/main/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojo.java
+++ b/tycho-extras/tycho-p2-extras-plugin/src/main/java/org/eclipse/tycho/plugins/p2/extras/MirrorMojo.java
@@ -246,8 +246,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
name = "";
}
final DestinationRepositoryDescriptor destinationDescriptor = new DestinationRepositoryDescriptor(destination,
- name, compress, xzCompress, keepNonXzIndexFiles, mirrorMetadataOnly, append, Collections.emptyMap(),
- Collections.emptyList());
+ name, compress, xzCompress, keepNonXzIndexFiles, mirrorMetadataOnly, append);
getLog().info("Mirroring to " + destination);
try {
mirrorService.mirrorStandalone(sourceDescriptor, destinationDescriptor, createIUDescriptions(),
diff --git a/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml b/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
index 33764661d8..09dddecfff 100644
--- a/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
+++ b/tycho-its/projects/p2Repository.repositoryRef.filter/pom.xml
@@ -45,8 +45,8 @@
https://download.eclipse.org/lsp4e/**
https://download.eclipse.org/lsp4j/**
+ ![%regex[http(s)?:\/\/download\.eclipse\.org\/.*]]
- %regex[http(s)?:\/\/download\.eclipse\.org\/.*]
diff --git a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
index c3160e3cd2..6461550af3 100644
--- a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
+++ b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/AssembleRepositoryMojo.java
@@ -23,7 +23,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-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;
@@ -31,7 +30,7 @@
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.MatchPatterns;
+import org.codehaus.plexus.util.MatchPattern;
import org.eclipse.tycho.PackagingType;
import org.eclipse.tycho.ReactorProject;
import org.eclipse.tycho.TychoConstants;
@@ -48,8 +47,6 @@
import org.eclipse.tycho.p2.tools.mirroring.facade.MirrorApplicationService;
import org.eclipse.tycho.p2tools.RepositoryReferenceTool;
import org.eclipse.tycho.targetplatform.TargetDefinition.InstallableUnitLocation;
-import org.eclipse.tycho.targetplatform.TargetDefinition.Location;
-import org.eclipse.tycho.targetplatform.TargetDefinitionFile;
import aQute.bnd.osgi.repository.XMLResourceGenerator;
import aQute.bnd.repository.fileset.FileSetRepository;
@@ -78,8 +75,8 @@
public class AssembleRepositoryMojo extends AbstractRepositoryMojo {
public static class RepositoryReferenceFilter {
- List exclude;
- List include;
+ /** The list of location patterns that exclude matching repository references. */
+ List exclude = List.of();
}
private static final Object LOCK = new Object();
@@ -214,58 +211,66 @@ public static class RepositoryReferenceFilter {
private Map extraArtifactRepositoryProperties;
/**
- * if enabled all P2 repositories referenced in the pom are added as referenced sites
+ * If enabled all P2-repositories referenced in the pom are added as referenced repositories.
*/
- @Parameter()
+ @Parameter
private boolean addPomRepositoryReferences;
/**
- * if enabled all P2 repositories referenced in the IU location type of target-files are added
- * as referenced sites
+ * If enabled all P2 repositories referenced in {@code InstallableUnit}-type locations of the
+ * active target-file are added as referenced repositories.
*/
- @Parameter()
+ @Parameter
private boolean addIUTargetRepositoryReferences;
/**
- * A list of patterns to filter the automatically derived repository references by including or
- * excluding their location to control if they are eventually added to the assembled repository.
+ * A list of patterns to exclude automatically derived repository references from being added to
+ * the assembled repository.
*
- * Each pattern is either an inclusion or exclusion and an arbitrary number of
- * each can be specified. The location of a repository reference must match at least one
- * inclusion-pattern (if any is specified) and must not be match by any
- * exclusion-pattern, in order to be eventually added to the assembled repository.
+ * The location of a reference must not be matched by any pattern, in order to be eventually
+ * added to the assembled repository. An arbitrary number of patterns can be specified.
* The specified filters are only applied to those repository references derived from the
* target-definition or pom file, when {@link #addIUTargetRepositoryReferences} respectively
* {@link #addPomRepositoryReferences} is set to {@code true}.
*
*
- * Configuration example
+ * Configuration example 1
+ *
+ *
+ * <repositoryReferenceFilter>
+ * <exclude>https://foo.bar.org/hidden/**</exclude>
+ * </repositoryReferenceFilter>
+ *
+ *
+ * Configuration example 2
*
*
* <repositoryReferenceFilter>
* <exclude>
* <location>https://foo.bar.org/hidden/**</location>
- * <location>https://foo.bar.org/secret/**</location>
+ * <location>%regex[http(s)?:\/\/foo\.bar\.org\/secret\/.*]</location>
+ * <location>![https://foo.bar.org/**]</location>
* </exclude>
- * <include>%regex[http(s)?:\/\/foo\.bar\.org\/.*]</include>
* </repositoryReferenceFilter>
*
*
- * It contains two exclusion patterns using {@code ANT}-style syntax and one
- * inclusion using a {@code Java RegEx} {@link Pattern} (enclosed in
- * {@code %regex[]}). The inclusion pattern uses the shorthand
- * notation for singleton lists.
+ * In the second example the first of the three patterns uses {@code ANT}-style syntax, the
+ * second one uses a {@code Java RegEx} {@link Pattern} (enclosed in
+ * {@code %regex[]}).
+ * The third pattern is a negated (enclosed in {@code ![]}), which
+ * effectively makes it an inclusion pattern that all references must match in order to
+ * be added.
*
*/
@Parameter
- private RepositoryReferenceFilter repositoryReferenceFilter = null;
+ private RepositoryReferenceFilter repositoryReferenceFilter = new RepositoryReferenceFilter();
/**
* If enabled, an
* OSGi
* Repository is generated out of the content of the P2 repository.
*/
- @Parameter()
+ @Parameter
private boolean generateOSGiRepository;
/**
@@ -310,29 +315,20 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.collect(Collectors.toCollection(ArrayList::new));
Predicate autoReferencesFilter = buildRepositoryReferenceLocationFilter();
if (addPomRepositoryReferences) {
- for (Repository pomRepo : getProject().getRepositories()) {
- if ("p2".equals(pomRepo.getLayout())) {
- String locationURL = pomRepo.getUrl();
- if (autoReferencesFilter.test(locationURL)) {
- repositoryReferences.add(new RepositoryReference(pomRepo.getName(), locationURL, true));
- }
- }
- }
+ getProject().getRepositories().stream() //
+ .filter(pomRepo -> "p2".equals(pomRepo.getLayout()))
+ .filter(pomRepo -> autoReferencesFilter.test(pomRepo.getUrl()))
+ .map(pomRepo -> new RepositoryReference(pomRepo.getName(), pomRepo.getUrl(), true))
+ .forEach(repositoryReferences::add);
}
if (addIUTargetRepositoryReferences) {
- for (TargetDefinitionFile targetDefinitionFile : projectManager
- .getTargetPlatformConfiguration(getProject()).getTargets()) {
- for (Location location : targetDefinitionFile.getLocations()) {
- if (location instanceof InstallableUnitLocation iu) {
- for (var iuRepo : iu.getRepositories()) {
- String locationURL = iuRepo.getLocation();
- if (autoReferencesFilter.test(locationURL)) {
- repositoryReferences.add(new RepositoryReference(null, locationURL, true));
- }
- }
- }
- }
- }
+ projectManager.getTargetPlatformConfiguration(getProject()).getTargets().stream()
+ .flatMap(tpFile -> tpFile.getLocations().stream())
+ .filter(InstallableUnitLocation.class::isInstance).map(InstallableUnitLocation.class::cast)
+ .flatMap(iu -> iu.getRepositories().stream())
+ .filter(iuRepo -> autoReferencesFilter.test(iuRepo.getLocation()))
+ .map(iuRepo -> new RepositoryReference(null, iuRepo.getLocation(), true))
+ .forEach(repositoryReferences::add);
}
DestinationRepositoryDescriptor destinationRepoDescriptor = new DestinationRepositoryDescriptor(
destination, repositoryName, compress, xzCompress, keepNonXzIndexFiles,
@@ -344,20 +340,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
XMLResourceGenerator resourceGenerator = new XMLResourceGenerator();
resourceGenerator.name(repositoryName);
resourceGenerator.base(destination.toURI());
- File pluginsResult = new File(destination, "plugins");
- if (pluginsResult.isDirectory()) {
- File[] files = pluginsResult
- .listFiles(pathname -> pathname.isFile() && pathname.getName().endsWith(".jar"));
+ File plugins = new File(destination, "plugins");
+ if (plugins.isDirectory()) {
+ File[] files = plugins.listFiles(path -> path.getName().endsWith(".jar") && path.isFile());
try {
resourceGenerator.repository(new FileSetRepository("plugins", Arrays.asList(files)));
} catch (Exception e) {
throw new MojoExecutionException("Could not read p2 repository plugins", e);
}
}
- File featureResult = new File(destination, "features");
- if (featureResult.isDirectory()) {
- File[] files = featureResult
- .listFiles(pathname -> pathname.isFile() && pathname.getName().endsWith(".jar"));
+ File features = new File(destination, "features");
+ if (features.isDirectory()) {
+ File[] files = features.listFiles(path -> path.getName().endsWith(".jar") && path.isFile());
for (File featureFile : files) {
try {
Feature feature = Feature.readJar(featureFile);
@@ -368,11 +362,8 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
try {
- if (compress) {
- resourceGenerator.save(new File(destination, repositoryFileName + ".gz"));
- } else {
- resourceGenerator.save(new File(destination, repositoryFileName));
- }
+ String filename = compress ? repositoryFileName + ".gz" : repositoryFileName;
+ resourceGenerator.save(new File(destination, filename));
} catch (IOException e) {
throw new MojoExecutionException("Could not write OSGi Repository!", e);
}
@@ -400,19 +391,17 @@ private List getCategories(final File categoriesDirectory) {
}
private Predicate buildRepositoryReferenceLocationFilter() {
- Predicate filter = l -> true;
- if (repositoryReferenceFilter != null) {
- if (repositoryReferenceFilter.include != null && !repositoryReferenceFilter.include.isEmpty()) {
- MatchPatterns inclusionPattern = MatchPatterns.from(repositoryReferenceFilter.include);
- filter = l -> inclusionPattern.matches(l, true);
- }
- if (repositoryReferenceFilter.exclude != null && !repositoryReferenceFilter.exclude.isEmpty()) {
- MatchPatterns exclusionPattern = MatchPatterns.from(repositoryReferenceFilter.exclude);
- Predicate exclusionFilter = l -> !exclusionPattern.matches(l, true);
- filter = filter.and(exclusionFilter);
- }
- }
- return filter;
+ List> filters = repositoryReferenceFilter.exclude.stream()
+ .> map(exclusionPattern -> {
+ boolean isNegated = false;
+ if (exclusionPattern.startsWith("![") && exclusionPattern.endsWith("]")) {
+ exclusionPattern = exclusionPattern.substring(2, exclusionPattern.length() - 1);
+ isNegated = true;
+ }
+ MatchPattern pattern = MatchPattern.fromString(exclusionPattern);
+ return isNegated ? ref -> !pattern.matchPath(ref, true) : ref -> pattern.matchPath(ref, true);
+ }).toList();
+ return ref -> filters.stream().noneMatch(f -> f.test(ref));
}
}
diff --git a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/FixArtifactsMetadataMetadataMojo.java b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/FixArtifactsMetadataMetadataMojo.java
index f803f7e1c3..b63d97b0df 100644
--- a/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/FixArtifactsMetadataMetadataMojo.java
+++ b/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/FixArtifactsMetadataMetadataMojo.java
@@ -13,7 +13,6 @@
package org.eclipse.tycho.plugins.p2.repository;
import java.io.File;
-import java.util.Collections;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -73,8 +72,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
"Could not update p2 repository, directory does not exist: " + destination);
}
DestinationRepositoryDescriptor destinationRepoDescriptor = new DestinationRepositoryDescriptor(
- destination, repositoryName, true, xzCompress, keepNonXzIndexFiles, false, true,
- Collections.emptyMap(), Collections.emptyList());
+ destination, repositoryName, true, xzCompress, keepNonXzIndexFiles, false, true);
mirrorApp.recreateArtifactRepository(destinationRepoDescriptor);
} catch (FacadeException e) {
throw new MojoExecutionException("Could not update p2 repository", e);