Skip to content
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

Use a digest to generate the API baseline target location #1545

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF
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.pde.api.tools;singleton:=true
Bundle-Version: 1.3.600.qualifier
Bundle-Version: 1.3.700.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package org.eclipse.pde.api.tools.internal.model;

import java.io.File;
import java.io.OutputStream;
import java.net.URI;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -42,7 +45,7 @@
import org.eclipse.pde.core.target.ITargetPlatformService;
import org.eclipse.pde.core.target.TargetBundle;
import org.eclipse.pde.internal.core.target.ExternalFileTargetHandle;
import org.eclipse.pde.internal.core.target.TargetDefinition;
import org.eclipse.pde.internal.core.target.TargetDefinitionPersistenceHelper;
import org.eclipse.pde.internal.core.target.WorkspaceFileTargetHandle;

/**
Expand Down Expand Up @@ -340,7 +343,7 @@ public static IApiBaseline newApiBaselineFromTarget(String name, ITargetDefiniti

/**
* Create predictable location description for a target definition. Form is
* <code>target:/targetSeq/definitionLocation</code>. A location must be
* <code>target:/[target hashcode}/definitionLocation</code>. A location must be
* compatible with {@link IPath#fromPortableString(String)}.
*
* @param definition the target platform definition
Expand All @@ -351,8 +354,16 @@ public static IApiBaseline newApiBaselineFromTarget(String name, ITargetDefiniti
private static String generateTargetLocation(ITargetDefinition definition) {
StringBuilder sb = new StringBuilder(TARGET_PREFIX);
sb.append(IPath.SEPARATOR);
if (definition instanceof TargetDefinition target) {
sb.append(target.getSequenceNumber());
try {
MessageDigest digest = MessageDigest.getInstance("SHA-1"); //$NON-NLS-1$
try (DigestOutputStream output = new DigestOutputStream(OutputStream.nullOutputStream(), digest)) {
TargetDefinitionPersistenceHelper.persistXML(definition, output);
}
for (byte b : digest.digest()) {
sb.append(Integer.toHexString(b & 0xFF));
}
} catch (Exception e) {
// can't record a hashcode then...
}
sb.append(IPath.SEPARATOR);
sb.append(getDefinitionIdentifier(definition));
Expand Down
Loading