-
Notifications
You must be signed in to change notification settings - Fork 41
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation looks wrong here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks strange