Skip to content

Commit

Permalink
Do not use helper for create memory composite
Browse files Browse the repository at this point in the history
Instead of going through the managers to create a composite repos, just
do it directly and get better error reporting and less disturbing.
  • Loading branch information
laeubi committed Jan 26, 2024
1 parent 5b0707d commit c87e127
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 38 deletions.
6 changes: 6 additions & 0 deletions tools/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions tools/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>tools</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
10 changes: 10 additions & 0 deletions tools/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> filter = options.getFilter();
addFilterForFeatureJARs(filter);
if (filterProperties != null) {
filter.putAll(filterProperties);
}
mirrorApp.setSlicingOptions(options);
LogListener logListener = new LogListener(logger);
mirrorApp.setLog(logListener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -107,7 +107,7 @@ public IArtifactRepository getCompositeArtifactRepository() {
}

@Override
protected Slicer createSlicer(SlicingOptions options) {
protected Slicer createSlicer(SlicingOptions options) throws ProvisionException {
List<Map<String, String>> filters = getContextFilters();
List<IInstallableUnit> selectionContexts = filters.stream().map(InstallableUnit::contextIU).toList();
boolean includeOptionalDependencies = options.includeOptionalDependencies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -249,41 +250,43 @@ 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<IMetadataRepository> 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<IArtifactRepository> 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;
}
return false;
}

public boolean hasMetadataSources() {
public boolean hasMetadataSources() throws ProvisionException {
IMetadataRepository repository = getCompositeMetadataRepository();
if (repository instanceof ICompositeRepository<?> composite) {
return composite.getChildren().size() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private IQueryable<IInstallableUnit> 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());
Expand Down

0 comments on commit c87e127

Please sign in to comment.