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

Improve RepositoryHelper.getSharedBundlePools to load all agent pools #384

Merged
merged 1 commit into from
Nov 11, 2023
Merged
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 @@ -19,8 +19,7 @@
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.*;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import org.eclipse.core.runtime.*;
Expand Down Expand Up @@ -151,20 +150,37 @@ public static <T> IRepository<T> createMemoryComposite(IProvisioningAgent agent,
*/
@SuppressWarnings("nls")
public static List<Path> getSharedBundlePools() {
Path bundlePools = Path.of(System.getProperty("user.home"), ".p2/pools.info");
if (Files.isRegularFile(bundlePools)) {
try (Stream<String> lines = Files.lines(bundlePools, getSharedBundlePoolEncoding())) {
return lines.map(Path::of).filter(Files::isDirectory).toList();
Path agentsInfoLocation = getAgentManagerLocation().resolve("agents.info");
if (Files.isRegularFile(agentsInfoLocation)) {
Charset encoding = getSharedAgentEncoding();
try (Stream<String> agentLocations = Files.lines(agentsInfoLocation, encoding)) {
List<Path> result = new ArrayList<>();
agentLocations.map(agentLocation -> Path.of(agentLocation, "pools.info")).filter(Files::isRegularFile)
.forEach(poolsInfoLocation -> {
try (Stream<String> poolLocations = Files.lines(poolsInfoLocation, encoding)) {
poolLocations.map(Path::of)
.filter(poolLocation -> Files.exists(poolLocation.resolve("artifacts.xml")))
.forEach(result::add);
} catch (Exception ex) {
LogHelper.log(Status.warning("The bundle pools load failed: " + poolsInfoLocation, ex));
}
});
return result;
} catch (Exception ex) {
LogHelper.log(Status.warning("The bundle pool load failed: " + bundlePools, ex));
LogHelper.log(Status.warning("The agents load failed: " + agentsInfoLocation, ex));
}
}
return List.of();
}

@SuppressWarnings("nls")
private static Charset getSharedBundlePoolEncoding() {
Path encodingInfo = Path.of(System.getProperty("user.home"), ".p2/encoding.info");
private static Path getAgentManagerLocation() {
return Path.of(System.getProperty("user.home"), ".eclipse/org.eclipse.oomph.p2");
}

@SuppressWarnings("nls")
private static Charset getSharedAgentEncoding() {
Path encodingInfo = getAgentManagerLocation().resolve("encoding.info");
if (Files.isRegularFile(encodingInfo)) {
try {
return Charset.forName(Files.readString(encodingInfo).trim());
Expand Down
Loading