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

[TP-Editor] Adapt content-assist to support of version-ranges/no-version #1445

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
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.genericeditor.extension;singleton:=true
Bundle-Version: 1.2.400.qualifier
Bundle-Version: 1.2.500.qualifier
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.jface.text,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Red Hat Inc. and others
* Copyright (c) 2018, 2024 Red Hat Inc. and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -39,8 +39,7 @@ public class TagCompletionProposal extends TargetCompletionProposal {
new Attribute(ITargetConstants.LOCATION_PATH_ATTR, null),
new Attribute(ITargetConstants.LOCATION_TYPE_ATTR, ITargetConstants.LOCATION_TYPE_ATTR_VALUE_PROFILE) });
tagStartingAttributesAndValues.put(ITargetConstants.UNIT_TAG, new Attribute[] {
new Attribute(ITargetConstants.UNIT_ID_ATTR, null),
new Attribute(ITargetConstants.UNIT_VERSION_ATTR, ITargetConstants.UNIT_VERSION_ATTR_GENERIC) });
new Attribute(ITargetConstants.UNIT_ID_ATTR, null) });
tagStartingAttributesAndValues.put(ITargetConstants.REPOSITORY_TAG, new Attribute[] {
new Attribute(ITargetConstants.REPOSITORY_LOCATION_ATTR, null) });
tagStartingAttributesAndValues.put(ITargetConstants.TARGET_JRE_TAG, new Attribute[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2022 Red Hat Inc. and others
* Copyright (c) 2018, 2024 Red Hat Inc. and others
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -87,6 +87,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
List<UnitNode> repositoryUnits = cache.fetchP2UnitsFromRepo(repositoryLocation, false);
for (Node n2 : locationNode.getChildNodesByTag(ITargetConstants.UNIT_TAG)) {
UnitNode unitNode = ((UnitNode) n2);
String declaredVersion = unitNode.getVersion();

@SuppressWarnings("restriction")
// if not ok, probably a version range
boolean isValidExplicitVersion = org.eclipse.pde.internal.core.util.VersionUtil
.validateVersion(declaredVersion).isOK();
if (declaredVersion == null || !isValidExplicitVersion) {
continue;
}
List<String> versions = null;
for (UnitNode unit : repositoryUnits) {
if (unit.getId().equals(unitNode.getId())) {
Expand All @@ -99,20 +108,19 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
}
Collections.sort(versions, (v1, v2) -> (new Version(v2)).compareTo(new Version(v1)));
String version = versions.get(0);
if (version == null || version.isEmpty() || unitNode.getVersion() == null
|| version.equals(unitNode.getVersion())) {
if (version == null || version.isEmpty() || version.equals(declaredVersion)) {
continue;
}

String nodeString = documentText.substring(unitNode.getOffsetStart() + offsetChange,
unitNode.getOffsetEnd() + offsetChange);

nodeString = nodeString.replaceFirst("version=\"" + unitNode.getVersion() + "\"",
nodeString = nodeString.replaceFirst("version=\"" + declaredVersion + "\"",
"version=\"" + version + "\"");
documentText = documentText.substring(0, unitNode.getOffsetStart() + offsetChange) + nodeString
+ documentText.substring(unitNode.getOffsetEnd() + offsetChange, documentText.length());

offsetChange += version.length() - unitNode.getVersion().length();
offsetChange += version.length() - declaredVersion.length();
}
}
if (document.get().equals(documentText)) {
Expand Down
Loading