From c87e1273bee3d229a6ae4d20e7af2046a4e52d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 26 Jan 2024 05:11:43 +0100 Subject: [PATCH] Do not use helper for create memory composite Instead of going through the managers to create a composite repos, just do it directly and get better error reporting and less disturbing. --- tools/.classpath | 6 +++ tools/.project | 17 ++++++++ tools/.settings/org.eclipse.jdt.core.prefs | 10 +++++ .../p2tools/MirrorApplicationServiceImpl.java | 32 +++++++-------- .../tycho/p2tools/TychoMirrorApplication.java | 4 +- .../copiedfromp2/AbstractApplication.java | 41 ++++++++++--------- .../copiedfromp2/MirrorApplication.java | 2 +- 7 files changed, 74 insertions(+), 38 deletions(-) create mode 100644 tools/.classpath create mode 100644 tools/.project create mode 100644 tools/.settings/org.eclipse.jdt.core.prefs diff --git a/tools/.classpath b/tools/.classpath new file mode 100644 index 0000000000..919ff1e8dd --- /dev/null +++ b/tools/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/tools/.project b/tools/.project new file mode 100644 index 0000000000..00f1c58da8 --- /dev/null +++ b/tools/.project @@ -0,0 +1,17 @@ + + + tools + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/tools/.settings/org.eclipse.jdt.core.prefs b/tools/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..d4540a53f9 --- /dev/null +++ b/tools/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 +org.eclipse.jdt.core.compiler.compliance=17 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=17 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 3d12db47b3..8481a0e76c 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 @@ -179,23 +179,23 @@ public void mirrorReactor(RepositoryReferences sources, DestinationRepositoryDes final TychoMirrorApplication mirrorApp = createMirrorApplication(sources, destination, agent); // mirror scope: seed units... - mirrorApp - .setSourceIUs(toInstallableUnitList(projectSeeds, mirrorApp.getCompositeMetadataRepository(), sources)); - mirrorApp.setIncludeSources(includeAllSource, sources.getTargetPlatform()); - mirrorApp.setIncludeRequiredBundles(includeRequiredBundles); - mirrorApp.setIncludeRequiredFeatures(includeRequiredFeatures); - mirrorApp.setFilterProvided(filterProvided); - mirrorApp.setAddOnlyProvidingRepoReferences(addOnlyProvidingRepoReferences); - mirrorApp.setEnvironments(context.getEnvironments()); - SlicingOptions options = new SlicingOptions(); - options.considerStrictDependencyOnly(!includeAllDependencies); - Map filter = options.getFilter(); - addFilterForFeatureJARs(filter); - if (filterProperties != null) { - filter.putAll(filterProperties); - } - mirrorApp.setSlicingOptions(options); try { + mirrorApp.setSourceIUs( + toInstallableUnitList(projectSeeds, mirrorApp.getCompositeMetadataRepository(), sources)); + mirrorApp.setIncludeSources(includeAllSource, sources.getTargetPlatform()); + mirrorApp.setIncludeRequiredBundles(includeRequiredBundles); + mirrorApp.setIncludeRequiredFeatures(includeRequiredFeatures); + mirrorApp.setFilterProvided(filterProvided); + mirrorApp.setAddOnlyProvidingRepoReferences(addOnlyProvidingRepoReferences); + mirrorApp.setEnvironments(context.getEnvironments()); + SlicingOptions options = new SlicingOptions(); + options.considerStrictDependencyOnly(!includeAllDependencies); + Map filter = options.getFilter(); + addFilterForFeatureJARs(filter); + if (filterProperties != null) { + filter.putAll(filterProperties); + } + mirrorApp.setSlicingOptions(options); LogListener logListener = new LogListener(logger); mirrorApp.setLog(logListener); 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 950681489a..9df6fd2983 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 @@ -97,7 +97,7 @@ protected IArtifactRepository initializeDestination(RepositoryDescriptor toInit, } @Override - public IArtifactRepository getCompositeArtifactRepository() { + public IArtifactRepository getCompositeArtifactRepository() throws ProvisionException { IArtifactRepository repository = super.getCompositeArtifactRepository(); if (targetPlatform != null) { return new ListCompositeArtifactRepository(List.of(repository, targetPlatform.getArtifactRepository()), @@ -107,7 +107,7 @@ public IArtifactRepository getCompositeArtifactRepository() { } @Override - protected Slicer createSlicer(SlicingOptions options) { + protected Slicer createSlicer(SlicingOptions options) throws ProvisionException { List> filters = getContextFilters(); List selectionContexts = filters.stream().map(InstallableUnit::contextIU).toList(); boolean includeOptionalDependencies = options.includeOptionalDependencies(); diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java index 23d790ce4c..1b310ff279 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/AbstractApplication.java @@ -21,8 +21,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; -import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; +import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.core.ProvisionException; @@ -36,6 +35,8 @@ import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.util.NLS; +import org.eclipse.tycho.p2.repository.ListCompositeMetadataRepository; +import org.eclipse.tycho.p2maven.ListCompositeArtifactRepository; public abstract class AbstractApplication { protected boolean removeAddedRepositories = true; @@ -49,8 +50,8 @@ public abstract class AbstractApplication { protected IArtifactRepository destinationArtifactRepository = null; protected IMetadataRepository destinationMetadataRepository = null; - private CompositeMetadataRepository compositeMetadataRepository = null; - private CompositeArtifactRepository compositeArtifactRepository = null; + private IMetadataRepository compositeMetadataRepository = null; + private IArtifactRepository compositeArtifactRepository = null; protected IProvisioningAgent agent; @@ -249,33 +250,35 @@ else if (repository instanceof IArtifactRepository && !descriptor.isAppend()) return false; } - public IMetadataRepository getCompositeMetadataRepository() { + public synchronized IMetadataRepository getCompositeMetadataRepository() throws ProvisionException { if (compositeMetadataRepository == null) { - compositeMetadataRepository = CompositeMetadataRepository.createMemoryComposite(agent); - if (compositeMetadataRepository != null) { - for (RepositoryDescriptor repo : sourceRepositories) { - if (repo.isMetadata()) - compositeMetadataRepository.addChild(repo.getRepoLocation()); - } + IMetadataRepositoryManager repositoryManager = agent.getService(IMetadataRepositoryManager.class); + List loadedRepository = new ArrayList<>(); + for (RepositoryDescriptor repo : sourceRepositories) { + loadedRepository + .add(repositoryManager.loadRepository(repo.getRepoLocation(), new NullProgressMonitor())); } + compositeMetadataRepository = new ListCompositeMetadataRepository(loadedRepository, agent); } return compositeMetadataRepository; } - public IArtifactRepository getCompositeArtifactRepository() { + public synchronized IArtifactRepository getCompositeArtifactRepository() throws ProvisionException { if (compositeArtifactRepository == null) { - compositeArtifactRepository = CompositeArtifactRepository.createMemoryComposite(agent); - if (compositeArtifactRepository != null) { - for (RepositoryDescriptor repo : sourceRepositories) { - if (repo.isArtifact()) - compositeArtifactRepository.addChild(repo.getRepoLocation()); + IArtifactRepositoryManager repositoryManager = agent.getService(IArtifactRepositoryManager.class); + List loadedRepository = new ArrayList<>(); + for (RepositoryDescriptor repo : sourceRepositories) { + if (repo.isArtifact()) { + loadedRepository + .add(repositoryManager.loadRepository(repo.getRepoLocation(), new NullProgressMonitor())); } } + compositeArtifactRepository = new ListCompositeArtifactRepository(loadedRepository, agent); } return compositeArtifactRepository; } - public boolean hasArtifactSources() { + public boolean hasArtifactSources() throws ProvisionException { IArtifactRepository repository = getCompositeArtifactRepository(); if (repository instanceof ICompositeRepository composite) { return composite.getChildren().size() > 0; @@ -283,7 +286,7 @@ public boolean hasArtifactSources() { return false; } - public boolean hasMetadataSources() { + public boolean hasMetadataSources() throws ProvisionException { IMetadataRepository repository = getCompositeMetadataRepository(); if (repository instanceof ICompositeRepository composite) { return composite.getChildren().size() > 0; diff --git a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java index 308d313817..a129082da2 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/p2tools/copiedfromp2/MirrorApplication.java @@ -475,7 +475,7 @@ private IQueryable slice(IProgressMonitor monitor) throws Prov return slice; } - protected Slicer createSlicer(SlicingOptions options) { + protected Slicer createSlicer(SlicingOptions options) throws ProvisionException { PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), options.getFilter(), options.includeOptionalDependencies(), options.isEverythingGreedy(), options.forceFilterTo(), options.considerStrictDependencyOnly(), options.followOnlyFilteredRequirements());