Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/GP-1-dragonmacher-help-build-fix'
Browse files Browse the repository at this point in the history
(Closes #6265)
  • Loading branch information
ryanmkurtz committed Mar 1, 2024
2 parents 1988e53 + 89f9e6f commit 317a881
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 62 deletions.
65 changes: 65 additions & 0 deletions Ghidra/Framework/Help/src/main/java/help/PathKey.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, AnchorDefinition> anchorsByHelpPath =
new HashMap<String, AnchorDefinition>();
private Map<PathKey, AnchorDefinition> anchorsByHelpPath =
new HashMap<>();
private Map<String, AnchorDefinition> anchorsById = new HashMap<String, AnchorDefinition>();
private Map<String, AnchorDefinition> anchorsByName = new HashMap<String, AnchorDefinition>();
private Map<String, List<AnchorDefinition>> duplicateAnchorsById =
Expand All @@ -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();
Expand All @@ -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);
}
Expand All @@ -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<String, AnchorDefinition> getAnchorsByHelpPath() {
public Map<PathKey, AnchorDefinition> getAnchorsByHelpPath() {
return anchorsByHelpPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <b>input</b> directory and 0 or more
Expand Down Expand Up @@ -353,48 +373,4 @@ private Collection<HREF> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -74,9 +80,10 @@ public Map<String, List<AnchorDefinition>> getDuplicateAnchorsByID() {
return anchorManager.getDuplicateAnchorsByID();
}

public AnchorDefinition getAnchorDefinition(Path helpPath) {
Map<String, AnchorDefinition> anchorsByHelpPath = anchorManager.getAnchorsByHelpPath();
return anchorsByHelpPath.get(helpPath.toString());
public AnchorDefinition getAnchorDefinition(Path helpPath) {
Map<PathKey, AnchorDefinition> anchorsByHelpPath = anchorManager.getAnchorsByHelpPath();
AnchorDefinition def = anchorsByHelpPath.get(new PathKey(helpPath));
return def;
}

public Collection<AnchorDefinition> getAllAnchorDefinitions() {
Expand Down

0 comments on commit 317a881

Please sign in to comment.