Skip to content

Commit

Permalink
java.lang.AssertionError: Need to normalize ..., when there is a colo…
Browse files Browse the repository at this point in the history
…n in the string #19
  • Loading branch information
markiewb committed Apr 12, 2016
1 parent a6ddb31 commit 4a6e0ab
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

nb-resource-hyperlink-at-cursor
===============================
This plugin adds hyperlinks to filenames within String literals of Java sources. If you click the hyperlink, then the file will be opened in the NetBeans editor.

Download at http://plugins.netbeans.org/plugin/52349/?show=true

Expand All @@ -30,6 +29,7 @@ Features:
<h2>Updates in 1.3.2:</h2>
<ul>
<li>[<a href="https://github.com/markiewb/nb-resource-hyperlink-at-cursor/issues/3">Issue 3</a>]: Fixed freeze</li>
<li>[<a href="https://github.com/markiewb/nb-resource-hyperlink-at-cursor/issues/19">Issue 19</a>]: Fixed java.lang.AssertionError: Need to normalize ..., when there is a colon in the string #19</li>
</ul>

<h2>Updates in 1.3.1:</h2>
Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@
<version>RELEASE721</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -188,6 +200,7 @@ Features:
&lt;h2&gt;Updates in 1.3.2:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;[&lt;a href="https://github.com/markiewb/nb-resource-hyperlink-at-cursor/issues/3"&gt;Issue 3&lt;/a&gt;]: Fixed freeze&lt;/li&gt;
&lt;li&gt;[&lt;a href="https://github.com/markiewb/nb-resource-hyperlink-at-cursor/issues/19"&gt;Issue 19&lt;/a&gt;]: Fixed java.lang.AssertionError: Need to normalize ..., when there is a colon in the string #19&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Updates in 1.3.1:&lt;/h2&gt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private Set<FileObject> findFiles(Document doc, String path) {
FileObject projectDirectory = project.getProjectDirectory();
if (null != projectDirectory) {
//exact matches
FileObject fileObjectAtProjectRoot = projectDirectory.getFileObject(path);
FileObject fileObjectAtProjectRoot = getFileObjectInASafeManner(projectDirectory, path);
if (fileObjectAtProjectRoot != null && !fileObjectAtProjectRoot.isFolder()) {
result.add(fileObjectAtProjectRoot);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ private List<FileObject> getMatchingFilesFromSourceRoots(Project p, String searc
foundMatches.addAll(partialMatches);

//exact matches, relative path
FileObject fileObject = sourceGroup.getRootFolder().getFileObject(searchToken);
FileObject fileObject = getFileObjectInASafeManner(sourceGroup.getRootFolder(), searchToken);
if (fileObject != null && !fileObject.isFolder()) {
foundMatches.add(fileObject);
}
Expand Down Expand Up @@ -319,7 +319,7 @@ private FileObject getMatchingFileInCurrentDirectory(Document doc, String path)
if (null == currentDir) {
return null;
}
final FileObject fileObject = currentDir.getFileObject(path);
final FileObject fileObject = getFileObjectInASafeManner(currentDir, path);
if (null != fileObject && !fileObject.isFolder()) {
return fileObject;
} else {
Expand Down Expand Up @@ -535,7 +535,7 @@ private Collection<? extends FileObject> getMatchingFilesFromOtherSourceRootsBut
continue;
}
//-> c:/myprojects/project/src/test/java/com/foo
final FileObject packageInSourceRoot = rootFolder.getFileObject(packageName);
final FileObject packageInSourceRoot = getFileObjectInASafeManner(rootFolder, packageName);
if (null == packageInSourceRoot) {
continue;
}
Expand All @@ -560,6 +560,28 @@ private List<SourceGroup> getAllSourceGroups(Project p) {
list.addAll(Arrays.asList(sources.getSourceGroups(MAVEN_TYPE_TEST_OTHER)));
return list;
}

/**
* Try to catch
* https://github.com/markiewb/nb-resource-hyperlink-at-cursor/issues/19
* "java.lang.AssertionError: Need to normalize ..., when there is a colon
* in the string"
*
* @param parent
* @param relativePath
* @return
*/
private FileObject getFileObjectInASafeManner(FileObject parent, String relativePath) {
if (null != parent) {
try {
FileObject result = parent.getFileObject(relativePath);
return result;
} catch (AssertionError e) {
return null;
}
}
return null;
}

private String getPathOrDefault(FileObject fo) {
if (null == fo) {
Expand Down
51 changes: 26 additions & 25 deletions src/test/java/NewMain.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import java.math.BigDecimal;

public class NewMain {

public static void main(String[] args) {
System.out.println("filename = "
+ "com/toy/anagrams/lib/WordLibrary.java");
System.out.println("filename = " + "WordLibrary.java");
System.out.println("Hyper");
System.out.println("./src\\test\\java\\foo\\NewMain.java");
System.out.println(".\\src\\test\\java\\foo\\NewMain.java");
//link to src/main/nbm
System.out.println("manifest.mf");
//link to src/main/resources
System.out.println("de/markiewb/netbeans/plugins/resourcehyperlink/options/Bundle.properties");
//link to src/test/resources
System.out.println("TestResource.txt");
System.out.println("de.markiewb.netbeans.plugins.resourcehyperlink.ResourceHyperlinkProvider");
System.out.println("de.markiewb.netbeans.plugins.resourcehyperlink.ResourceHyperlinkProvider");
System.out.println("D:\\ws\\nb-resource-hyperlink-at-cursor\\doc\\screenshot-1.0.0.png");
System.out.println("D:/ws/nb-resource-hyperlink-at-cursor/doc/screenshot-1.0.0.png");
System.out.println("filename = " + 1 + "help.png"
+ new BigDecimal("0"));
}
}
import java.math.BigDecimal;

public class NewMain {

public static void main(String[] args) {
System.out.println("filename = "
+ "com/toy/anagrams/lib/WordLibrary.java");
System.out.println("filename = " + "WordLibrary.java");
System.out.println("Hyper");
System.out.println("file:asdsdf.....");
System.out.println("./src\\test\\java\\foo\\NewMain.java");
System.out.println(".\\src\\test\\java\\foo\\NewMain.java");
//link to src/main/nbm
System.out.println("manifest.mf");
//link to src/main/resources
System.out.println("de/markiewb/netbeans/plugins/resourcehyperlink/options/Bundle.properties");
//link to src/test/resources
System.out.println("TestResource.txt");
System.out.println("de.markiewb.netbeans.plugins.resourcehyperlink.ResourceHyperlinkProvider");
System.out.println("de.markiewb.netbeans.plugins.resourcehyperlink.ResourceHyperlinkProvider");
System.out.println("D:\\ws\\nb-resource-hyperlink-at-cursor\\doc\\screenshot-1.0.0.png");
System.out.println("D:/ws/nb-resource-hyperlink-at-cursor/doc/screenshot-1.0.0.png");
System.out.println("filename = " + 1 + "help.png"
+ new BigDecimal("0"));
}
}

0 comments on commit 4a6e0ab

Please sign in to comment.