private long findMostRecentResetTimestamp(IProfileRegistry registry, IProfile profile) { long[] history = registry.listProfileTimestamps(profile.getProfileId()); int index = history.length - 1; boolean found = false; while (!(found = IProfile.STATE_SHARED_INSTALL_VALUE_BEFOREFLUSH.equals(registry.getProfileStateProperties(profile.getProfileId(), history[index]).get(IProfile.STATE_PROP_SHARED_INSTALL))) && index > 0) { index--; } if (!found) return -1; return history[index]; }
@Override public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { return profile.query(query, monitor); } }
/** * Returns the install folder for the profile, or <code>null</code> * if no install folder is defined. */ public static File getInstallFolder(IProfile profile) { String folder = profile.getProperty(IProfile.PROP_INSTALL_FOLDER); return folder == null ? null : new File(folder); }
@Override public IQueryResult<IInstallableUnit> queryProfile(IProfile profile, IQuery<IInstallableUnit> query, IProgressMonitor monitor) { IProfile sharedProfile = getSharedProfile(profile.getProfileId()); if (sharedProfile == null) return profile.query(query, monitor); // TODO: Should consider using a sequenced iterator here instead of collecting Collector<IInstallableUnit> result = new Collector<>(); result.addAll(sharedProfile.query(query, monitor)); result.addAll(profile.query(query, monitor)); return result; } }
private boolean checkTimestamps(IProfile profile, IProfile internalProfile) { long[] timestamps = listProfileTimestamps(profile.getProfileId()); if (timestamps.length == 0) { if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "check timestamp: expected " + profile.getTimestamp() + " but no profiles were found"); //$NON-NLS-1$ //$NON-NLS-2$ resetProfiles(); return false; } long currentTimestamp = (timestamps.length == 0) ? -1 : timestamps[timestamps.length - 1]; if (profile.getTimestamp() != currentTimestamp) { if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "check timestamp: expected " + profile.getTimestamp() + " but was " + currentTimestamp); //$NON-NLS-1$ //$NON-NLS-2$ if (internalProfile.getTimestamp() != currentTimestamp) resetProfiles(); return false; } return true; }
private static IInstallableUnit createSharedProfileIU(final IProfile sharedProfile) { InstallableUnitDescription iuDescription = new InstallableUnitDescription(); iuDescription.setId("SharedProfile_" + sharedProfile.getProfileId()); //$NON-NLS-1$ iuDescription.setVersion(Version.createOSGi(1, 0, 0, Long.toString(sharedProfile.getTimestamp()))); ArrayList<IProvidedCapability> iuCapabilities = new ArrayList<IProvidedCapability>(); IProvidedCapability selfCapability = MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, iuDescription.getId(), iuDescription.getVersion()); iuCapabilities.add(selfCapability); iuDescription.addProvidedCapabilities(iuCapabilities); ArrayList<IRequirement> iuRequirements = new ArrayList<IRequirement>(); IQueryResult<IInstallableUnit> allIUs = sharedProfile.query(QueryUtil.createIUAnyQuery(), null); for (Iterator<IInstallableUnit> iterator = allIUs.iterator(); iterator.hasNext();) { IInstallableUnit iu = iterator.next(); IMatchExpression<IInstallableUnit> iuMatcher = ExpressionUtil.getFactory().<IInstallableUnit> matchExpression(ExpressionUtil.parse("id == $0 && version == $1"), iu.getId(), iu.getVersion()); //$NON-NLS-1$ iuRequirements.add(MetadataFactory.createRequirement(iuMatcher, null, 0, 1, true)); } iuDescription.addRequirements(iuRequirements); iuDescription.setProperty(IInstallableUnit.PROP_NAME, NLS.bind(Messages.Shared_Profile, null)); IInstallableUnit sharedProfileIU = MetadataFactory.createInstallableUnit(iuDescription); return sharedProfileIU; }
public void writeProfile(IProfile profile) { start(PROFILE_ELEMENT); attribute(ID_ATTRIBUTE, profile.getProfileId()); attribute(TIMESTAMP_ATTRIBUTE, Long.toString(profile.getTimestamp())); writeProperties(profile.getProperties()); ArrayList<IInstallableUnit> ius = new ArrayList<IInstallableUnit>(profile.query(QueryUtil.createIUAnyQuery(), null).toUnmodifiableSet()); Collections.sort(ius, new Comparator<IInstallableUnit>() { public int compare(IInstallableUnit iu1, IInstallableUnit iu2) { int IdCompare = iu1.getId().compareTo(iu2.getId()); if (IdCompare != 0) return IdCompare; return iu1.getVersion().compareTo(iu2.getVersion()); } }); writeInstallableUnits(ius.iterator(), ius.size()); writeInstallableUnitsProperties(ius.iterator(), ius.size(), profile); end(PROFILE_ELEMENT); flush(); }
private Object[] updatePlannerInfo(ProfileChangeRequest profileChangeRequest, ProvisioningContext context) { IQueryResult<IInstallableUnit> alreadyInstalled = profileChangeRequest.getProfile() .query(new IUProfilePropertyQuery(INCLUSION_RULES, IUProfilePropertyQuery.ANY), null); profileChangeRequest.getProfile().getInstallableUnitProperty(iu, INCLUSION_RULES)); gatheredRequirements.addAll(profileChangeRequest.getExtraRequirements()); IInstallableUnit[] existingRoots = profileChangeRequest.getProfile() .query(new IUProfilePropertyQuery(INCLUSION_RULES, IUProfilePropertyQuery.ANY), null) .toArray(IInstallableUnit.class); return new Object[] { createIURepresentingTheProfile(gatheredRequirements), existingRoots };
public ReconcilerProfileChangeRequest createProfileChangeRequest(ProvisioningContext context) { ReconcilerProfileChangeRequest request = new ReconcilerProfileChangeRequest(profile); boolean resolve = Boolean.valueOf(profile.getProperty("org.eclipse.equinox.p2.resolve")).booleanValue(); //$NON-NLS-1$ if (resolve) request.removeProfileProperty("org.eclipse.equinox.p2.resolve"); //$NON-NLS-1$ IQueryResult<IInstallableUnit> dropinIUs = profile.query(new IUProfilePropertyQuery(PROP_FROM_DROPINS, Boolean.TRUE.toString()), null); Set<IInstallableUnit> all = allIUs.toUnmodifiableSet(); for (Iterator<IInstallableUnit> iter = dropinIUs.iterator(); iter.hasNext();) { if ("STRICT".equals(profile.getInstallableUnitProperty(iu, "org.eclipse.equinox.p2.internal.inclusion.rules"))) { //$NON-NLS-1$//$NON-NLS-2$ request.removeInstallableUnitProfileProperty(iu, PROP_FROM_DROPINS); request.removeInstallableUnitProfileProperty(iu, IProfile.PROP_PROFILE_LOCKED_IU);
writer.println(" " + NLS.bind(IDEWorkbenchMessages.ConfigurationLogUpdateSection_lastChangedOn, DateFormat.getDateInstance().format(new Date(profile.getTimestamp())))); //$NON-NLS-1$ writer.println(" " + NLS.bind(IDEWorkbenchMessages.ConfigurationLogUpdateSection_location, profile.getProperty(IProfile.PROP_INSTALL_FOLDER))); //$NON-NLS-1$ writer.println(" " + NLS.bind(IDEWorkbenchMessages.ConfigurationLogUpdateSection_timestamp, Long.toString(profile.getTimestamp()))); //$NON-NLS-1$ writer.println(); IQueryResult result = profile.available(QueryUtil.createIUAnyQuery(), null); SortedSet sorted = new TreeSet(); for (Iterator iter = result.iterator(); iter.hasNext();) {
private static void synchronizeAllIUProperties(IProfileChangeRequest request, IProfile current, IProfile target) { Set<IInstallableUnit> currentIUset = current.query(QueryUtil.createIUAnyQuery(), null).toUnmodifiableSet(); Iterator<IInstallableUnit> targetIUs = target.query(QueryUtil.createIUAnyQuery(), null).iterator(); List<IInstallableUnit> iusToAdd = new ArrayList<>(); List<IInstallableUnit> iusToUpdate = new ArrayList<>(); for (Entry<String, String> entry : target.getInstallableUnitProperties(iu).entrySet()) { request.setInstallableUnitProfileProperty(iu, entry.getKey(), entry.getValue()); Map<String, String> propertiesToSet = new HashMap<>(target.getInstallableUnitProperties(iu)); for (Entry<String, String> entry : current.getInstallableUnitProperties(iu).entrySet()) { String key = entry.getKey(); String newValue = propertiesToSet.get(key);
protected String getProfileProperty(IProfile profile, IInstallableUnit iu, String propertyName) { if (profile == null || iu == null) return null; return profile.getInstallableUnitProperty(iu, propertyName); }
@Override public IQueryResult<IInstallableUnit> available(IQuery<IInstallableUnit> query, IProgressMonitor monitor) { return profile.available(query, monitor); }
@Override public long getTimestamp() { return profile.getTimestamp(); }
@Override public IProvisioningAgent getProvisioningAgent() { return profile.getProvisioningAgent(); }
@Override public Map<String, String> getInstallableUnitProperties(IInstallableUnit iu) { return profile.getInstallableUnitProperties(iu); }
private static IInstallableUnit createSharedProfileIU(final IProfile sharedProfile) { InstallableUnitDescription iuDescription = new InstallableUnitDescription(); iuDescription.setId("SharedProfile_" + sharedProfile.getProfileId()); //$NON-NLS-1$ iuDescription.setVersion(Version.createOSGi(1, 0, 0, Long.toString(sharedProfile.getTimestamp()))); ArrayList<IProvidedCapability> iuCapabilities = new ArrayList<>(); IProvidedCapability selfCapability = MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, iuDescription.getId(), iuDescription.getVersion()); iuCapabilities.add(selfCapability); iuDescription.addProvidedCapabilities(iuCapabilities); ArrayList<IRequirement> iuRequirements = new ArrayList<>(); IQueryResult<IInstallableUnit> allIUs = sharedProfile.query(QueryUtil.createIUAnyQuery(), null); for (Iterator<IInstallableUnit> iterator = allIUs.iterator(); iterator.hasNext();) { IInstallableUnit iu = iterator.next(); IMatchExpression<IInstallableUnit> iuMatcher = ExpressionUtil.getFactory().matchExpression(ExpressionUtil.parse("id == $0 && version == $1"), iu.getId(), iu.getVersion()); //$NON-NLS-1$ iuRequirements.add(MetadataFactory.createRequirement(iuMatcher, null, 0, 1, true)); } iuDescription.addRequirements(iuRequirements); iuDescription.setProperty(IInstallableUnit.PROP_NAME, NLS.bind(Messages.Shared_Profile, null)); IInstallableUnit sharedProfileIU = MetadataFactory.createInstallableUnit(iuDescription); return sharedProfileIU; }
public void writeProfile(IProfile profile) { start(PROFILE_ELEMENT); attribute(ID_ATTRIBUTE, profile.getProfileId()); attribute(TIMESTAMP_ATTRIBUTE, Long.toString(profile.getTimestamp())); writeProperties(profile.getProperties()); ArrayList<IInstallableUnit> ius = new ArrayList<>(profile.query(QueryUtil.createIUAnyQuery(), null).toUnmodifiableSet()); Collections.sort(ius, new Comparator<IInstallableUnit>() { @Override public int compare(IInstallableUnit iu1, IInstallableUnit iu2) { int IdCompare = iu1.getId().compareTo(iu2.getId()); if (IdCompare != 0) return IdCompare; return iu1.getVersion().compareTo(iu2.getVersion()); } }); writeInstallableUnits(ius.iterator(), ius.size()); writeInstallableUnitsProperties(ius.iterator(), ius.size(), profile); end(PROFILE_ELEMENT); flush(); }
private boolean checkTimestamps(IProfile profile, IProfile internalProfile) { long[] timestamps = listProfileTimestamps(profile.getProfileId()); if (timestamps.length == 0) { if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "check timestamp: expected " + profile.getTimestamp() + " but no profiles were found"); //$NON-NLS-1$ //$NON-NLS-2$ resetProfiles(); return false; } long currentTimestamp = (timestamps.length == 0) ? -1 : timestamps[timestamps.length - 1]; if (profile.getTimestamp() != currentTimestamp) { if (DebugHelper.DEBUG_PROFILE_REGISTRY) DebugHelper.debug(PROFILE_REGISTRY, "check timestamp: expected " + profile.getTimestamp() + " but was " + currentTimestamp); //$NON-NLS-1$ //$NON-NLS-2$ if (internalProfile.getTimestamp() != currentTimestamp) resetProfiles(); return false; } return true; }
public IQueryResult<IInstallableUnit> queryProfile(IProfile profile, IQuery<IInstallableUnit> query, IProgressMonitor monitor) { IProfile sharedProfile = getSharedProfile(profile.getProfileId()); if (sharedProfile == null) return profile.query(query, monitor); // TODO: Should consider using a sequenced iterator here instead of collecting Collector<IInstallableUnit> result = new Collector<IInstallableUnit>(); result.addAll(sharedProfile.query(query, monitor)); result.addAll(profile.query(query, monitor)); return result; } }