Skip to content

Commit

Permalink
[TP-Editor] Adapt content-assist to support of version-ranges/no-version
Browse files Browse the repository at this point in the history
- Remove 'version' attribute from 'unit' proposal
Now that PDE supports no versions in unit declarations it does not have
to be proposed for all cases.

- Skip units with version-range in the 'UpdateUnitVersions' action from
the context menu in the Source tab.
  • Loading branch information
HannesWell committed Oct 16, 2024
1 parent 459a095 commit d5a771f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
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

0 comments on commit d5a771f

Please sign in to comment.