Skip to content

Commit

Permalink
Introduce "Include references" for TPs
Browse files Browse the repository at this point in the history
  • Loading branch information
tivervac committed Apr 25, 2024
1 parent 4b7b7a1 commit 3586229
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ <h1>Software Site Location Wizard</h1>

<p><strong>Include configure phase</strong> is an advanced option to control whether the configure phase of the download operation will be run. The configure phase allows downloaded software to run additional operations. If this causes problems for your software site, this option can be turned off.</p>

<p>The <strong>Include references</strong> option will search repository references defined in your software sites. Disabling it in essence forces your software to become self-contained.</p>

<h3 class="related">Related references</h3>
<a href="./edit_target_locations_tab.htm">Location Tab</a><br>
<a href="./edit_target_wizard.htm">Edit Target Wizard</a><br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ public class IUBundleContainer extends AbstractBundleContainer {
*/
public static final int INCLUDE_CONFIGURE_PHASE = 1 << 3;


/**
* Whether this container should consider repository references.
*/
public static final int INCLUDE_REFERENCES = 1 << 4;

/**
* IU identifiers.
*/
Expand Down Expand Up @@ -152,10 +158,20 @@ public class IUBundleContainer extends AbstractBundleContainer {
/**
* Constructs a installable unit bundle container for the specified units.
*
* @param ids IU identifiers
* @param versions IU versions
* @param repositories metadata repositories used to search for IU's or <code>null</code> for default set
* @param resolutionFlags bitmask of flags to control IU resolution, possible flags are {@link IUBundleContainer#INCLUDE_ALL_ENVIRONMENTS}, {@link IUBundleContainer#INCLUDE_REQUIRED}, {@link IUBundleContainer#INCLUDE_SOURCE}, {@link IUBundleContainer#INCLUDE_CONFIGURE_PHASE}
* @param ids
* IU identifiers
* @param versions
* IU versions
* @param repositories
* metadata repositories used to search for IU's or
* <code>null</code> for default set
* @param resolutionFlags
* bitmask of flags to control IU resolution, possible flags are
* {@link IUBundleContainer#INCLUDE_ALL_ENVIRONMENTS},
* {@link IUBundleContainer#INCLUDE_REQUIRED},
* {@link IUBundleContainer#INCLUDE_SOURCE},
* {@link IUBundleContainer#INCLUDE_CONFIGURE_PHASE},
* {@link IUBundleContainer#INCLUDE_REFERENCES}
*/
IUBundleContainer(String[] ids, Version[] versions, URI[] repositories, int resolutionFlags) {
fIds = ids;
Expand Down Expand Up @@ -368,7 +384,8 @@ void synchronizerChanged(ITargetDefinition target) {
public synchronized IUBundleContainer update(Set<String> toUpdate, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 100);
URI[] updateRepos = fRepos == null ? null : fRepos.clone();
IQueryable<IInstallableUnit> source = P2TargetUtils.getQueryableMetadata(updateRepos, progress.split(30));
IQueryable<IInstallableUnit> source = P2TargetUtils.getQueryableMetadata(updateRepos, getIncludeReferences(),
progress.split(30));
boolean updated = false;
String[] updateIDs = fIds.clone();
Version[] updateVersions = fVersions.clone();
Expand Down Expand Up @@ -550,7 +567,7 @@ public synchronized void removeInstallableUnit(IInstallableUnit unit) {
public boolean getIncludeAllRequired() {
// if this container has not been associated with a container, return its own value
if (fSynchronizer == null) {
return (fFlags & INCLUDE_REQUIRED) == INCLUDE_REQUIRED;
return (fFlags & INCLUDE_REQUIRED) != 0;
}
return fSynchronizer.getIncludeAllRequired();
}
Expand All @@ -566,7 +583,7 @@ public boolean getIncludeAllRequired() {
public boolean getIncludeAllEnvironments() {
// if this container has not been associated with a container, return its own value
if (fSynchronizer == null) {
return (fFlags & INCLUDE_ALL_ENVIRONMENTS) == INCLUDE_ALL_ENVIRONMENTS;
return (fFlags & INCLUDE_ALL_ENVIRONMENTS) != 0;
}
return fSynchronizer.getIncludeAllEnvironments();
}
Expand All @@ -580,7 +597,7 @@ public boolean getIncludeAllEnvironments() {
public boolean getIncludeSource() {
// if this container has not been associated with a container, return its own value
if (fSynchronizer == null) {
return (fFlags & INCLUDE_SOURCE) == INCLUDE_SOURCE;
return (fFlags & INCLUDE_SOURCE) != 0;
}
return fSynchronizer.getIncludeSource();
}
Expand All @@ -593,11 +610,25 @@ public boolean getIncludeSource() {
public boolean getIncludeConfigurePhase() {
// if this container has not been associated with a container, return its own value
if (fSynchronizer == null) {
return (fFlags & INCLUDE_CONFIGURE_PHASE) == INCLUDE_CONFIGURE_PHASE;
return (fFlags & INCLUDE_CONFIGURE_PHASE) != 0;
}
return fSynchronizer.getIncludeConfigurePhase();
}

/**
* Returns whether or not repository references should be considered
*
* @return whether or not repository references should be considered
*/
public boolean getIncludeReferences() {
// if this container has not been associated with a container, return
// its own value
if (fSynchronizer == null) {
return (fFlags & INCLUDE_REFERENCES) != 0;
}
return fSynchronizer.getIncludeReferences();
}

/**
* Returns the installable units defined by this container
*
Expand Down Expand Up @@ -663,6 +694,7 @@ protected void associateWithTarget(ITargetDefinition target) {
fSynchronizer.setIncludeAllEnvironments((fFlags & INCLUDE_ALL_ENVIRONMENTS) == INCLUDE_ALL_ENVIRONMENTS);
fSynchronizer.setIncludeSource((fFlags & INCLUDE_SOURCE) == INCLUDE_SOURCE);
fSynchronizer.setIncludeConfigurePhase((fFlags & INCLUDE_CONFIGURE_PHASE) == INCLUDE_CONFIGURE_PHASE);
fSynchronizer.setIncludeReferences((fFlags & INCLUDE_REFERENCES) == INCLUDE_REFERENCES);
}

@Override
Expand All @@ -684,6 +716,7 @@ public String serialize() {
containerElement.setAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_ALL_PLATFORMS, Boolean.toString(getIncludeAllEnvironments()));
containerElement.setAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_SOURCE, Boolean.toString(getIncludeSource()));
containerElement.setAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_CONFIGURE_PHASE, Boolean.toString(getIncludeConfigurePhase()));
containerElement.setAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_REFERENCES, Boolean.toString(getIncludeReferences()));
URI[] repositories = getRepositories();
if (repositories != null) {
Arrays.sort(repositories);
Expand Down Expand Up @@ -739,7 +772,8 @@ private int[] getPredictableOrder(String[] ids, Version[] versions) {
}

IInstallableUnit[] getRootIUs(ITargetDefinition definition, IProgressMonitor monitor) throws CoreException {
IQueryable<IInstallableUnit> repos = P2TargetUtils.getQueryableMetadata(getRepositories(), monitor);
IQueryable<IInstallableUnit> repos = P2TargetUtils.getQueryableMetadata(getRepositories(),
getIncludeReferences(), monitor);
MultiStatus status = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null);
List<IInstallableUnit> result = new ArrayList<>();
for (int j = 0; j < fIds.length; j++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public ITargetLocation getTargetLocation(String type, String serializedXML) thro
String includeAllPlatforms = location.getAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_ALL_PLATFORMS);
String includeSource = location.getAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_SOURCE);
String includeConfigurePhase = location.getAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_CONFIGURE_PHASE);
String includeReferences = location.getAttribute(TargetDefinitionPersistenceHelper.ATTR_INCLUDE_REFERENCES);

NodeList list = location.getChildNodes();
List<String> ids = new ArrayList<>();
Expand Down Expand Up @@ -101,6 +102,13 @@ public ITargetLocation getTargetLocation(String type, String serializedXML) thro
flags |= Boolean.parseBoolean(includeAllPlatforms) ? IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS : 0;
flags |= Boolean.parseBoolean(includeSource) ? IUBundleContainer.INCLUDE_SOURCE : 0;
flags |= Boolean.parseBoolean(includeConfigurePhase) ? IUBundleContainer.INCLUDE_CONFIGURE_PHASE : 0;
// For backwards compatibility, includeReferences should be true
// when it's absent
if (includeReferences.isEmpty()) {
flags |= IUBundleContainer.INCLUDE_REFERENCES;
} else {
flags |= Boolean.parseBoolean(includeReferences) ? IUBundleContainer.INCLUDE_REFERENCES : 0;
}
return TargetPlatformService.getDefault().newIULocation(iuIDs, iuVer, uris,
flags);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,19 @@ public class P2TargetUtils {
private boolean fIncludeConfigurePhase = false;

/**
* Deletes any profiles associated with target definitions that no longer exist
* and returns a list of profile identifiers that were deleted.
* Whether repository references should be resolved. If this option is
* false, references will be skipped entirely. In essence, this forces
* repositories to be self-contained.
*
* <p>
* <code>true</code> by default
* </p>
*/
private boolean fIncludeReferences = true;

/**
* Deletes any profiles associated with target definitions that no longer
* exist and returns a list of profile identifiers that were deleted.
*/
public static List<String> cleanOrphanedTargetDefinitionProfiles() throws CoreException {
List<String> list = new ArrayList<>();
Expand Down Expand Up @@ -703,6 +714,26 @@ public boolean getIncludeConfigurePhase() {
return fIncludeConfigurePhase;
}


/**
* Set whether or not repository references should be considered
*
* @param value whether or not repository references should be considered
*/
public void setIncludeReferences(boolean value) {
fIncludeReferences = value;
}


/**
* Return whether or not repository references should be considered
*
* @return whether or not repository references should be considered
*/
public boolean getIncludeReferences() {
return fIncludeReferences;
}

/**
* Return whether or not the given target has a matching profile that is in sync
* @param target the target to check
Expand Down Expand Up @@ -1004,11 +1035,12 @@ public static IMetadataRepositoryManager getRepoManager() throws CoreException {
* Return a queryable on the metadata defined in the given repo locations
*
* @param repos the repos to lookup
* @param includeReferences whether to consider repository references
* @param monitor the progress monitor
* @return the set of metadata repositories found
* @throws CoreException if there is a problem getting the repositories
*/
static IQueryable<IInstallableUnit> getQueryableMetadata(URI[] repos, IProgressMonitor monitor) throws CoreException {
static IQueryable<IInstallableUnit> getQueryableMetadata(URI[] repos, boolean includeReferences, IProgressMonitor monitor) throws CoreException {
IMetadataRepositoryManager manager = getRepoManager();
if (repos == null) {
repos = manager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
Expand All @@ -1017,15 +1049,16 @@ static IQueryable<IInstallableUnit> getQueryableMetadata(URI[] repos, IProgressM
int repoCount = repos.length;
SubMonitor subMonitor = SubMonitor.convert(monitor, repoCount * 2);

Set<IRepositoryReference> seen = new HashSet<>();
List<IMetadataRepository> result = new ArrayList<>(repoCount);
List<IMetadataRepository> additional = new ArrayList<>();
MultiStatus repoStatus = new MultiStatus(PDECore.PLUGIN_ID, 0, Messages.IUBundleContainer_ProblemsLoadingRepositories, null);
for (int i = 0; i < repoCount; ++i) {
try {
IMetadataRepository repository = manager.loadRepository(repos[i], subMonitor.split(1));
result.add(repository);
addReferences(repository, additional, seen, manager, subMonitor.split(1));
if (includeReferences) {
addReferences(repository, additional, new HashSet<>(), manager, subMonitor.split(1));
}
} catch (ProvisionException e) {
repoStatus.add(e.getStatus());
}
Expand All @@ -1046,8 +1079,7 @@ private static void addReferences(IMetadataRepository repository, List<IMetadata
Collection<IRepositoryReference> references = repository.getReferences();
SubMonitor subMonitor = SubMonitor.convert(monitor, references.size() * 2);
for (IRepositoryReference reference : references) {
if (reference.getType() == IRepository.TYPE_METADATA && reference.getOptions() == IRepository.ENABLED
&& seen.add(reference)) {
if (reference.getType() == IRepository.TYPE_METADATA && reference.isEnabled() && seen.add(reference)) {
try {
IMetadataRepository referencedRepository = manager.loadRepository(reference.getLocation(),
subMonitor.split(1));
Expand Down Expand Up @@ -1103,7 +1135,8 @@ public IQueryable<IInstallableUnit> getMetadata(IProgressMonitor monitor) {
QueryUtil.compoundQueryable(extraMetadataRepositories));
}
};
context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(true));
context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(getIncludeReferences()));
context.setProperty(ProvisioningContext.FOLLOW_ARTIFACT_REPOSITORY_REFERENCES, Boolean.toString(getIncludeReferences()));
context.setMetadataRepositories(getMetadataRepositories(target).toArray(URI[]::new));
context.setArtifactRepositories(getArtifactRepositories(target).toArray(URI[]::new));

Expand Down Expand Up @@ -1302,7 +1335,8 @@ private void resolveWithSlicer(ITargetDefinition target, IProfile profile, IProg
return;
}
URI[] uris = repositories.toArray(URI[]::new);
IQueryable<IInstallableUnit> allMetadata = getQueryableMetadata(uris, subMonitor.split(5));
IQueryable<IInstallableUnit> allMetadata = getQueryableMetadata(uris, getIncludeReferences(),
subMonitor.split(5));

// do an initial slice to add everything the user requested
IQueryResult<IInstallableUnit> queryResult = slice(units, allMetadata, target, subMonitor.split(5));
Expand All @@ -1329,7 +1363,8 @@ private void resolveWithSlicer(ITargetDefinition target, IProfile profile, IProg
ProvisioningContext context = new ProvisioningContext(getAgent());
context.setMetadataRepositories(uris);
context.setArtifactRepositories(getArtifactRepositories(target).toArray(URI[]::new));
context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(true));
context.setProperty(ProvisioningContext.FOLLOW_REPOSITORY_REFERENCES, Boolean.toString(getIncludeReferences()));
context.setProperty(ProvisioningContext.FOLLOW_ARTIFACT_REPOSITORY_REFERENCES, Boolean.toString(getIncludeReferences()));
IProvisioningPlan plan = engine.createPlan(profile, context);
setPlanProperties(plan, target, TargetDefinitionPersistenceHelper.MODE_SLICER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class TargetDefinitionPersistenceHelper {
static final String ATTR_INCLUDE_ALL_PLATFORMS = "includeAllPlatforms"; //$NON-NLS-1$
static final String ATTR_INCLUDE_SOURCE = "includeSource"; //$NON-NLS-1$
static final String ATTR_INCLUDE_CONFIGURE_PHASE = "includeConfigurePhase"; //$NON-NLS-1$
static final String ATTR_INCLUDE_REFERENCES = "includeReferences"; //$NON-NLS-1$
static final String ATTR_VERSION = "version"; //$NON-NLS-1$
static final String ATTR_CONFIGURATION = "configuration"; //$NON-NLS-1$
static final String ATTR_SEQUENCE_NUMBER = "sequenceNumber"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class EditIUContainerPage extends WizardPage implements IEditBundleContai
private Button fAllPlatformsButton;
private Button fIncludeSourceButton;
private Button fConfigurePhaseButton;
private Button fIncludeReferencesButton;
private Text fDetailsText;
private final ProvisioningUI profileUI;
private Thread refreshThread;
Expand Down Expand Up @@ -154,6 +155,7 @@ public ITargetLocation getBundleContainer() {
flags |= fAllPlatformsButton.getSelection() ? IUBundleContainer.INCLUDE_ALL_ENVIRONMENTS : 0;
flags |= fIncludeSourceButton.getSelection() ? IUBundleContainer.INCLUDE_SOURCE : 0;
flags |= fConfigurePhaseButton.getSelection() ? IUBundleContainer.INCLUDE_CONFIGURE_PHASE : 0;
flags |= fIncludeReferencesButton.getSelection() ? IUBundleContainer.INCLUDE_REFERENCES : 0;
IUBundleContainer container = (IUBundleContainer) service.newIULocation(fAvailableIUGroup.getCheckedLeafIUs(), fRepoLocation != null ? new URI[] {fRepoLocation} : null, flags);
return container;
}
Expand Down Expand Up @@ -409,6 +411,8 @@ private void createCheckboxArea(Composite parent) {
fIncludeSourceButton.addSelectionListener(widgetSelectedAdapter(e -> warnIfGlobalSettingChanged()));
fConfigurePhaseButton = SWTFactory.createCheckButton(slicerGroup, Messages.EditIUContainerPage_IncludeConfigurePhase, null, true, 1);
fConfigurePhaseButton.addSelectionListener(widgetSelectedAdapter(e -> warnIfGlobalSettingChanged()));
fIncludeReferencesButton = SWTFactory.createCheckButton(slicerGroup, Messages.EditIUContainerPage_17, null, true, 1);
fIncludeReferencesButton.addSelectionListener(widgetSelectedAdapter(e -> warnIfGlobalSettingChanged()));

}

Expand All @@ -431,6 +435,7 @@ private void warnIfGlobalSettingChanged() {
noChange &= fAllPlatformsButton.getSelection() == iuContainer.getIncludeAllEnvironments();
noChange &= fIncludeSourceButton.getSelection() == iuContainer.getIncludeSource();
noChange &= fConfigurePhaseButton.getSelection() == iuContainer.getIncludeConfigurePhase();
noChange &= fIncludeReferencesButton.getSelection() == iuContainer.getIncludeReferences();
}
}
if (noChange) {
Expand Down Expand Up @@ -575,6 +580,7 @@ private void restoreWidgetState() {
fAllPlatformsButton.setSelection(fEditContainer.getIncludeAllEnvironments());
fIncludeSourceButton.setSelection(fEditContainer.getIncludeSource());
fConfigurePhaseButton.setSelection(fEditContainer.getIncludeConfigurePhase());
fIncludeReferencesButton.setSelection(fEditContainer.getIncludeReferences());
} else {
// If we are creating a new container, but there is an existing iu container we should use it's settings (otherwise we overwrite them)
ITargetLocation[] knownContainers = fTarget.getTargetLocations();
Expand All @@ -585,6 +591,7 @@ private void restoreWidgetState() {
fAllPlatformsButton.setSelection(((IUBundleContainer) knownContainer).getIncludeAllEnvironments());
fIncludeSourceButton.setSelection(((IUBundleContainer) knownContainer).getIncludeSource());
fConfigurePhaseButton.setSelection(((IUBundleContainer) knownContainer).getIncludeConfigurePhase());
fIncludeReferencesButton.setSelection(((IUBundleContainer) knownContainer).getIncludeReferences());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class Messages extends NLS {
public static String EditIUContainerPage_14;
public static String EditIUContainerPage_15;
public static String EditIUContainerPage_16;
public static String EditIUContainerPage_17;
public static String EditIUContainerPage_2;
public static String EditIUContainerPage_3;
public static String EditIUContainerPage_4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ EditIUContainerPage_13=&Properties...
EditIUContainerPage_14=&Group by Category
EditIUContainerPage_15=Show only the latest &version
EditIUContainerPage_16=Include source if available
EditIUContainerPage_17=Include repository references
EditIUContainerPage_2=By default, all required software is added to the target based on its environment settings. Turning this option off allows software to be added with missing requirements and multiple environments. This setting applies to the entire target definition.
EditIUContainerPage_3=Include required software
EditIUContainerPage_4=Changing the included software settings will affect all sites in your target definition
Expand Down

0 comments on commit 3586229

Please sign in to comment.