diff --git a/Ghidra/Framework/Help/src/main/java/help/PathKey.java b/Ghidra/Framework/Help/src/main/java/help/PathKey.java new file mode 100644 index 00000000000..0896a22b8c9 --- /dev/null +++ b/Ghidra/Framework/Help/src/main/java/help/PathKey.java @@ -0,0 +1,65 @@ +/* ### + * IP: GHIDRA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package help; + +import java.nio.file.Path; +import java.util.Objects; + + +/** A class that wraps a Path and allows map lookup for paths from different file systems */ +public class PathKey { + private String path; + + public PathKey(Path p) { + if (p == null) { + Objects.requireNonNull(p, "Path cannot be null"); + } + this.path = p.toString().replace('\\', '/'); + } + + public PathKey(String path) { + Objects.requireNonNull(path, "Path cannot be null");; + this.path = path.replace('\\', '/'); + } + + @Override + public int hashCode() { + return path.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + PathKey other = (PathKey) obj; + + boolean result = path.equals(other.path); + return result; + } + + @Override + public String toString() { + return path.toString(); + } +} diff --git a/Ghidra/Framework/Help/src/main/java/help/validator/AnchorManager.java b/Ghidra/Framework/Help/src/main/java/help/validator/AnchorManager.java index 7de88f0ead0..30e68968c60 100644 --- a/Ghidra/Framework/Help/src/main/java/help/validator/AnchorManager.java +++ b/Ghidra/Framework/Help/src/main/java/help/validator/AnchorManager.java @@ -15,15 +15,24 @@ */ package help.validator; -import help.validator.model.*; - import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import help.PathKey; +import help.validator.model.AnchorDefinition; +import help.validator.model.HREF; +import help.validator.model.IMG; public class AnchorManager { - private Map anchorsByHelpPath = - new HashMap(); + private Map anchorsByHelpPath = + new HashMap<>(); private Map anchorsById = new HashMap(); private Map anchorsByName = new HashMap(); private Map> duplicateAnchorsById = @@ -35,7 +44,7 @@ public class AnchorManager { public AnchorManager() { } - public void addAnchor(Path file, String anchorName, int srcLineNo) { + public void addAnchor(Path file, String anchorName, int srcLineNo) { AnchorDefinition anchor = new AnchorDefinition(file, anchorName, srcLineNo); String id = anchor.getId(); @@ -45,8 +54,8 @@ public void addAnchor(Path file, String anchorName, int srcLineNo) { } anchorsById.put(id, anchor); - anchorsByHelpPath.put(anchor.getHelpPath(), anchor); - + anchorsByHelpPath.put(new PathKey(anchor.getHelpPath()), anchor); + if (anchorName != null) { anchorsByName.put(anchorName, anchor); } @@ -71,11 +80,11 @@ private void addDuplicateAnchor(String anchorName, AnchorDefinition anchor, Stri if (!anchorsByName.containsKey(anchorName)) { anchorsByName.put(anchorName, anchor); - anchorsByHelpPath.put(anchor.getHelpPath(), anchor); + anchorsByHelpPath.put(new PathKey(anchor.getHelpPath()), anchor); } } - public Map getAnchorsByHelpPath() { + public Map getAnchorsByHelpPath() { return anchorsByHelpPath; } diff --git a/Ghidra/Framework/Help/src/main/java/help/validator/location/HelpModuleCollection.java b/Ghidra/Framework/Help/src/main/java/help/validator/location/HelpModuleCollection.java index a3efa33bdd9..8489df7b285 100644 --- a/Ghidra/Framework/Help/src/main/java/help/validator/location/HelpModuleCollection.java +++ b/Ghidra/Framework/Help/src/main/java/help/validator/location/HelpModuleCollection.java @@ -16,10 +16,21 @@ package help.validator.location; import java.io.File; -import java.net.*; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import javax.help.HelpSet; @@ -29,8 +40,17 @@ import help.CustomTOCView.CustomTreeItemDecorator; import help.HelpBuildUtils; +import help.PathKey; import help.TOCItemProvider; -import help.validator.model.*; +import help.validator.model.AnchorDefinition; +import help.validator.model.GhidraTOCFile; +import help.validator.model.HREF; +import help.validator.model.HelpFile; +import help.validator.model.HelpTopic; +import help.validator.model.IMG; +import help.validator.model.TOCItem; +import help.validator.model.TOCItemDefinition; +import help.validator.model.TOCItemExternal; /** * A class that is meant to hold a single help input directory and 0 or more @@ -353,48 +373,4 @@ private Collection getTOC_HREFs(GhidraTOCFile file) { public String toString() { return helpLocations.toString(); } - -//================================================================================================== -// Inner Classes -//================================================================================================== - - /** A class that wraps a Path and allows map lookup for paths from different file systems */ - private class PathKey { - private String path; - - PathKey(Path p) { - if (p == null) { - throw new IllegalArgumentException("Path cannot be null"); - } - this.path = p.toString().replace('\\', '/'); - } - - @Override - public int hashCode() { - return path.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - - PathKey other = (PathKey) obj; - - boolean result = path.equals(other.path); - return result; - } - - @Override - public String toString() { - return path.toString(); - } - } } diff --git a/Ghidra/Framework/Help/src/main/java/help/validator/model/HelpFile.java b/Ghidra/Framework/Help/src/main/java/help/validator/model/HelpFile.java index 374df0bf16b..e3fbc280eac 100644 --- a/Ghidra/Framework/Help/src/main/java/help/validator/model/HelpFile.java +++ b/Ghidra/Framework/Help/src/main/java/help/validator/model/HelpFile.java @@ -17,11 +17,17 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; import ghidra.util.exception.AssertException; import help.HelpBuildUtils; -import help.validator.*; +import help.PathKey; +import help.validator.AnchorManager; +import help.validator.HTMLFileParser; +import help.validator.ReferenceTagProcessor; +import help.validator.TagProcessor; import help.validator.location.HelpModuleLocation; public class HelpFile { @@ -74,9 +80,10 @@ public Map> getDuplicateAnchorsByID() { return anchorManager.getDuplicateAnchorsByID(); } - public AnchorDefinition getAnchorDefinition(Path helpPath) { - Map anchorsByHelpPath = anchorManager.getAnchorsByHelpPath(); - return anchorsByHelpPath.get(helpPath.toString()); + public AnchorDefinition getAnchorDefinition(Path helpPath) { + Map anchorsByHelpPath = anchorManager.getAnchorsByHelpPath(); + AnchorDefinition def = anchorsByHelpPath.get(new PathKey(helpPath)); + return def; } public Collection getAllAnchorDefinitions() {