Skip to content

Commit

Permalink
Improve RepositoryHelper.getSharedBundlePools to load all agent pools
Browse files Browse the repository at this point in the history
Oomph has moved the encoding.info to be in the same folder as the
agents.info which lists all the agent locations (rather than in the
folder of the default agent's location). The agents.info file can be
loaded to determine the location of the pools.info of each agent. This
refined approach covers the full generality of Oomph's shared agent
manager allows all pools of all agents to be located with no assumptions
about defaults.

#373
  • Loading branch information
merks committed Nov 10, 2023
1 parent c7470b4 commit eb2cae8
Showing 1 changed file with 24 additions and 9 deletions.
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,36 @@ 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(poolLocation -> Path.of(poolLocation, "artifacts.xml"))
.filter(Files::isRegularFile).map(Path::getParent).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

0 comments on commit eb2cae8

Please sign in to comment.