Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide RepositoryHelper.getSharedBundlePools() #377

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Export-Package: org.eclipse.equinox.internal.p2.persistence;
org.eclipse.equinox.p2.publisher,
org.eclipse.equinox.p2.repository.tools,
org.eclipse.equinox.p2.ui,
org.eclipse.equinox.p2.updatesite",
org.eclipse.equinox.p2.updatesite,
org.eclipse.pde.core",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks strange

org.eclipse.equinox.internal.provisional.p2.repository,
org.eclipse.equinox.p2.repository;version="2.1.0",
org.eclipse.equinox.p2.repository.artifact;version="2.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
package org.eclipse.equinox.internal.p2.repository.helpers;

import java.io.File;
import java.io.IOException;
import java.net.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.repository.Activator;
Expand Down Expand Up @@ -138,4 +144,36 @@ public static <T> IRepository<T> createMemoryComposite(IProvisioningAgent agent,
return null;
}

/**
* Returns an unmodifiable list of global shared bundle pools, e.g., as used by
* the Eclipse Installer.
*
* @return an unmodifiable list of global shared bundle pools.
*
* @throws IOException if there are problems loading the pool information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the long term I think we might simply return an empty list in such case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wondered too about guarding all exceptions within the method....

*/
@SuppressWarnings("nls")
public static List<Path> getSharedBundlePools() throws IOException {
Path bundlePools = Path.of(System.getProperty("user.home"), ".p2/pools.info");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks wrong here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to improve things. This often happens because only touched lines are formatted, and I removed the if guard. Sorry about that.

if (Files.isRegularFile(bundlePools)) {
try (Stream<String> lines = Files.lines(bundlePools, getSharedBundlePoolEncoding())) {
return lines.map(Path::of).filter(Files::isDirectory).toList();
}
}
return List.of();
}

@SuppressWarnings("nls")
private static Charset getSharedBundlePoolEncoding() {
Path encodingInfo = Path.of(System.getProperty("user.home"), ".p2/encoding.info");
if (Files.isRegularFile(encodingInfo)) {
try {
return Charset.forName(Files.readString(encodingInfo).trim());
} catch (Exception e) {
//$FALL-THROUGH$
}
}
return Charset.defaultCharset();
}

}
Loading