Skip to content

Commit

Permalink
Provide RepositoryHelper.getSharedBundlePools()
Browse files Browse the repository at this point in the history
This returns shared bundle pools as used by the Eclipse Installer.

#373
  • Loading branch information
merks committed Nov 5, 2023
1 parent df5d137 commit 3734726
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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",
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.
*/
@SuppressWarnings("nls")
public static List<Path> getSharedBundlePools() throws IOException {
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();
}
}
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();
}

}

0 comments on commit 3734726

Please sign in to comment.