From f963c10a5ea4d961cd1ad08f6bdfd96256b5f608 Mon Sep 17 00:00:00 2001
From: Hannes Wellmann
Date: Wed, 30 Aug 2023 23:54:11 +0200
Subject: [PATCH] Minor code enhancements in p2-repository assembling code
---
.../core/TargetPlatformConfiguration.java | 7 +-
.../DestinationRepositoryDescriptor.java | 12 +-
.../p2tools/MirrorApplicationServiceImpl.java | 5 +-
.../tycho/p2tools/TychoMirrorApplication.java | 158 +++++++++---------
.../tycho/plugins/p2/extras/MirrorMojo.java | 3 +-
.../p2/repository/AssembleRepositoryMojo.java | 98 +++++------
.../FixArtifactsMetadataMetadataMojo.java | 4 +-
7 files changed, 136 insertions(+), 151 deletions(-)
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..a70ea329e3 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;
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-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 3a52ed3b0e..2d4dcbdfe7 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;
@@ -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,13 @@
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();
+ /**
+ * The list of location patterns that includes only matching repository references (if this
+ * list is not empty).
+ */
+ List include = List.of();
}
private static final Object LOCK = new Object();
@@ -214,16 +216,16 @@ 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;
/**
@@ -258,14 +260,14 @@ public static class RepositoryReferenceFilter {
*
*/
@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,31 +312,21 @@ 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,
!createArtifactRepository, true, extraArtifactRepositoryProperties, repositoryReferences);
@@ -345,20 +337,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);
@@ -369,11 +359,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);
}
@@ -402,16 +389,13 @@ 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);
- }
+ if (!repositoryReferenceFilter.include.isEmpty()) {
+ MatchPatterns inclusionPattern = MatchPatterns.from(repositoryReferenceFilter.include);
+ filter = l -> inclusionPattern.matches(l, true);
+ }
+ if (!repositoryReferenceFilter.exclude.isEmpty()) {
+ MatchPatterns exclusionPattern = MatchPatterns.from(repositoryReferenceFilter.exclude);
+ filter = filter.and(l -> !exclusionPattern.matches(l, true));
}
return filter;
}
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);