Skip to content

Commit

Permalink
Add isEnabled on IRepositoryReference
Browse files Browse the repository at this point in the history
This abstracts the bit flag checking for repository
references.
  • Loading branch information
tivervac authored and laeubi committed Apr 25, 2024
1 parent d70cc78 commit 4426f86
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.p2.metadata.expression;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.metadata.index;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.query;version="[2.1.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.2.0,3.0.0)",
org.eclipse.equinox.p2.repository.artifact;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.artifact.spi;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ private void loadMetadataRepository(IMetadataRepositoryManager manager, URI loca
// If the manager does not know about the repo, consider the reference enablement state
@SuppressWarnings("rawtypes")
private boolean isEnabled(IRepositoryManager manager, IRepositoryReference reference) {
return (manager.contains(reference.getLocation()) && manager.isEnabled(reference.getLocation())) || ((!manager.contains(reference.getLocation())) && ((reference.getOptions() & IRepository.ENABLED) == IRepository.ENABLED));
return (manager.contains(reference.getLocation()) && manager.isEnabled(reference.getLocation()))
|| ((!manager.contains(reference.getLocation())) && reference.isEnabled());
}

private boolean shouldFollowReferences() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Import-Package: javax.xml.parsers,
org.eclipse.equinox.p2.metadata.expression;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.metadata.index;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.query;version="[2.1.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.2.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata.spi;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.spi;version="[2.0.0,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ public void publishRepositoryReferences() {

List<IRepositoryReference> repositoriesSnapshot = createRepositoriesSnapshot();
for (IRepositoryReference reference : repositoriesSnapshot) {
boolean isEnabled = (reference.getOptions() & IRepository.ENABLED) != 0;
bus.publishEvent(new RepositoryEvent(reference.getLocation(), reference.getType(), RepositoryEvent.DISCOVERED, isEnabled));
bus.publishEvent(new RepositoryEvent(reference.getLocation(), reference.getType(),
RepositoryEvent.DISCOVERED, reference.isEnabled()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Import-Package: org.eclipse.equinox.app;version="[1.0.0,2.0.0)",
org.eclipse.equinox.p2.publisher,
org.eclipse.equinox.p2.publisher.actions,
org.eclipse.equinox.p2.query;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository;version="[2.2.0,3.0.0)",
org.eclipse.equinox.p2.repository.artifact;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.artifact.spi;version="[2.0.0,3.0.0)",
org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescription;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
import org.eclipse.osgi.util.ManifestElement;
Expand Down Expand Up @@ -275,7 +274,7 @@ protected String[] getConfigurationStrings(Collection<IConfigAdvice> configAdvic
if (repo.getNickname() != null) {
parameters.put("name", repo.getNickname()); //$NON-NLS-1$
}
parameters.put("enabled", Boolean.toString((repo.getOptions() & IRepository.ENABLED) == IRepository.ENABLED)); //$NON-NLS-1$
parameters.put("enabled", Boolean.toString(repo.isEnabled())); //$NON-NLS-1$
configurationData += TouchpointInstruction.encodeAction("addRepository", parameters); //$NON-NLS-1$
parameters.remove("enabled"); //$NON-NLS-1$
unconfigurationData += TouchpointInstruction.encodeAction("removeRepository", parameters);//$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.equinox.p2.repository;singleton:=true
Bundle-Version: 2.8.200.qualifier
Bundle-Version: 2.9.100.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.repository.Activator
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down Expand Up @@ -34,7 +34,7 @@ Export-Package: org.eclipse.equinox.internal.p2.persistence;
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;version="2.2.0",
org.eclipse.equinox.p2.repository.artifact;version="2.3.0",
org.eclipse.equinox.p2.repository.artifact.spi;version="2.0.0",
org.eclipse.equinox.p2.repository.metadata;version="2.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
* Cloudsmith Inc - public API
Expand Down Expand Up @@ -36,7 +36,7 @@ public interface IRepositoryReference {
int getType();

/**
* Returns bit-wise or of option constants (currently either
* Returns bit-wise or of option constants (currently either
* {@link IRepository#ENABLED} or {@link IRepository#NONE}).
* @return bit-wise or of option constants
*/
Expand All @@ -47,4 +47,15 @@ public interface IRepositoryReference {
* @return The nickname or <code>null</code>
*/
String getNickname();

/**
* Returns whether this reference is enabled or not
*
* @see IRepository#ENABLED
* @return whether this reference is enabled or not
* @since 2.9
*/
default boolean isEnabled() {
return (getOptions() & IRepository.ENABLED) != 0;
}
}

0 comments on commit 4426f86

Please sign in to comment.