Skip to content

Commit 9c92cb7

Browse files
authored
Merge pull request #281 from SeeSharpSoft/master
Release 2.16.3
2 parents fb55b45 + 16991c1 commit 9c92cb7

File tree

7 files changed

+78
-46
lines changed

7 files changed

+78
-46
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.16.3
2+
Apr 24, 2021
3+
4+
HOTFIX: Exception in CSV plugin when using with remote SSH host #279
5+
16
2.16.2
27
Apr 21, 2021
38

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jacocoTestReport {
2828
}
2929

3030
group 'net.seesharpsoft.intellij.plugins'
31-
version '2.16.2'
31+
version '2.16.3'
3232

3333
apply plugin: 'java'
3434
project.sourceCompatibility = JavaVersion.VERSION_11

src/main/java/net/seesharpsoft/intellij/plugins/csv/CsvStorageHelper.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,44 @@
22

33
import com.intellij.openapi.project.Project;
44
import com.intellij.openapi.util.Key;
5+
import com.intellij.openapi.util.io.FileUtil;
56
import com.intellij.openapi.vfs.VirtualFile;
6-
import com.intellij.openapi.vfs.VirtualFileManager;
77
import com.intellij.util.PathUtil;
88

9-
import java.io.File;
10-
import java.nio.file.Path;
11-
import java.nio.file.Paths;
129
import java.util.regex.Pattern;
1310

1411
public final class CsvStorageHelper {
1512
public static final String CSV_STATE_STORAGE_FILE = "csv-plugin.xml";
1613

1714
public static final Key<String> RELATIVE_FILE_URL = Key.create("CSV_PLUGIN_RELATIVE_URL");
1815

19-
public static String getRelativeFileUrl(Project project, VirtualFile virtualFile) {
16+
public static String getRelativeFilePath(Project project, VirtualFile virtualFile) {
2017
if (project == null || virtualFile == null) {
2118
return null;
2219
}
23-
String url = virtualFile.getUserData(RELATIVE_FILE_URL);
24-
if (url == null && project.getBasePath() != null) {
20+
String filePath = virtualFile.getUserData(RELATIVE_FILE_URL);
21+
if (filePath == null && project.getBasePath() != null) {
2522
String projectDir = PathUtil.getLocalPath(project.getBasePath());
26-
url = Paths.get(PathUtil.getLocalPath(virtualFile.getPath())
27-
.replaceFirst("^" + Pattern.quote(projectDir), "")).toString();
28-
virtualFile.putUserData(RELATIVE_FILE_URL, url);
23+
filePath = PathUtil.getLocalPath(virtualFile)
24+
.replaceFirst("^" + Pattern.quote(projectDir), "");
25+
virtualFile.putUserData(RELATIVE_FILE_URL, filePath);
2926
}
30-
return url;
27+
return filePath;
3128
}
3229

33-
public static Path getFilePath(Project project, String fileName) {
34-
if (project == null || fileName == null) {
35-
return null;
30+
public static boolean csvFileExists(Project project, String fileName) {
31+
if (fileName == null) {
32+
return false;
3633
}
37-
String formattedFileName = Paths.get(fileName).toString();
38-
return Paths.get(project.getBasePath()).resolve(formattedFileName.startsWith(File.separator) ? formattedFileName.substring(1) : formattedFileName);
39-
}
40-
41-
public static VirtualFile getFileInProject(Project project, String fileName) {
42-
Path filePath = getFilePath(project, fileName);
43-
return VirtualFileManager.getInstance().findFileByUrl(filePath.toUri().toString());
34+
String filePath = PathUtil.getLocalPath(fileName);
35+
if (filePath == null ||
36+
!CsvHelper.isCsvFile(PathUtil.getFileExtension(filePath))) {
37+
return false;
38+
}
39+
if (project != null && FileUtil.exists(PathUtil.getLocalPath(project.getBasePath()) + filePath)) {
40+
return true;
41+
}
42+
return FileUtil.exists(filePath);
4443
}
4544

4645
private CsvStorageHelper() {

src/main/java/net/seesharpsoft/intellij/plugins/csv/components/CsvFileAttributes.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.intellij.openapi.project.Project;
1313
import com.intellij.openapi.vfs.VirtualFile;
1414
import com.intellij.psi.PsiFile;
15+
import com.intellij.util.PathUtil;
1516
import com.intellij.util.xmlb.XmlSerializerUtil;
1617
import com.intellij.util.xmlb.annotations.OptionTag;
1718
import net.seesharpsoft.commons.collection.Pair;
@@ -58,13 +59,10 @@ public void loadState(@NotNull CsvFileAttributes state) {
5859

5960
public void cleanupAttributeMap(@NotNull Project project) {
6061
List<String> faultyFiles = new ArrayList<>();
62+
final String projectBasePath = PathUtil.getLocalPath(project.getBasePath());
6163
attributeMap.forEach((fileName, attribute) -> {
62-
VirtualFile virtualFile = CsvStorageHelper.getFileInProject(project, fileName);
63-
if (virtualFile == null) {
64-
LOG.debug(fileName + " not found");
65-
faultyFiles.add(fileName);
66-
} else if (!CsvHelper.isCsvFile(virtualFile.getExtension())) {
67-
LOG.debug(fileName + " is not a csv file");
64+
if (!CsvStorageHelper.csvFileExists(project, fileName)) {
65+
LOG.debug(fileName + " not found or not CSV file");
6866
faultyFiles.add(fileName);
6967
}
7068
});
@@ -80,7 +78,7 @@ protected String generateMapKey(@NotNull PsiFile psiFile) {
8078
}
8179

8280
protected String generateMapKey(@NotNull Project project, @NotNull VirtualFile virtualFile) {
83-
return CsvStorageHelper.getRelativeFileUrl(project, virtualFile);
81+
return CsvStorageHelper.getRelativeFilePath(project, virtualFile);
8482
}
8583

8684
@Nullable

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ FIX: Lower annotator severity to not appear as problem
5656
FIX: Prevent non CSV entries in CSV attributes map #268
5757
FIX: keep existing & correct entries in CSV attributes map
5858
HOTFIX: Editor complaining about crashes on PyCharm 2021.1 #274
59+
HOTFIX: Exception in CSV plugin when using with remote SSH host #279
5960
</pre>
6061
]]>
6162
</change-notes>
Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package net.seesharpsoft.intellij.plugins.csv;
22

33
import com.intellij.openapi.vfs.VirtualFile;
4+
import com.intellij.testFramework.LightVirtualFile;
45
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
6+
import com.intellij.util.PathUtil;
57

68
import java.nio.file.Paths;
79

@@ -14,33 +16,58 @@ protected void setUp() throws Exception {
1416
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().createNewFile();
1517
Paths.get(this.getProject().getBasePath(), "test").toFile().mkdir();
1618
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().createNewFile();
19+
Paths.get(this.getProject().getBasePath(), "test", "tsv_file_test.tab").toFile().createNewFile();
1720
}
1821

1922
@Override
2023
protected void tearDown() throws Exception {
2124
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().delete();
25+
Paths.get(this.getProject().getBasePath(), "test", "tsv_file_test.tab").toFile().delete();
2226
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().delete();
2327
Paths.get(this.getProject().getBasePath(), "test").toFile().delete();
2428
super.tearDown();
2529
}
2630

27-
public void testGetFileInProjectExists() {
28-
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/csv_file_test.csv").toString());
29-
assertNotNull(vf);
31+
public void testCsvFileExists() {
32+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), Paths.get("/csv_file_test.csv").toString());
33+
assertTrue(exists);
3034
}
3135

32-
public void testGetFileInProjectDirectory() {
33-
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/test/py_file_test.py").toString());
34-
assertNotNull(vf);
36+
public void testCsvFileExistsDirectory() {
37+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), Paths.get("/test/tsv_file_test.tab").toString());
38+
assertTrue(exists);
3539
}
3640

37-
public void testGetFileInProjectDoesNotExist() {
38-
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/not_existing_csv_file_test.csv").toString());
39-
assertNull(vf);
41+
public void testCsvFileExistsPyLanguage() {
42+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), Paths.get("/test/py_file_test.py").toString());
43+
assertFalse(exists);
4044
}
4145

42-
public void testGetFileInProjectDirectoryDoesNotExist() {
43-
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/test2/py_file_test.py").toString());
44-
assertNull(vf);
46+
public void testCsvFileExistsDoesNotExist() {
47+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), Paths.get("/not_existing_csv_file_test.csv").toString());
48+
assertFalse(exists);
4549
}
50+
51+
public void testCsvFileExistsDirectoryDoesNotExist() {
52+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), Paths.get("/test2/py_file_test.csv").toString());
53+
assertFalse(exists);
54+
}
55+
56+
public void testGetFilePathForSSH() {
57+
boolean exists = CsvStorageHelper.csvFileExists(this.getProject(), "<835d7ae1-4344-4666-bc29-31fb457b610e>\\raid/someRemotePath//someFileName.json");
58+
assertFalse(exists);
59+
}
60+
61+
public void testGetRelativeFileUrl() {
62+
VirtualFile vf = new LightVirtualFile("<835d7ae1-4344-4666-bc29-31fb457b610e>\\raid/someRemotePath\\someFileName.json");
63+
String relativePath = CsvStorageHelper.getRelativeFilePath(this.getProject(), vf);
64+
assertEquals(PathUtil.getLocalPath("/<835d7ae1-4344-4666-bc29-31fb457b610e>\\raid\\someRemotePath\\someFileName.json"), relativePath);
65+
}
66+
67+
public void testGetRelativeFileUrlFaulty() {
68+
VirtualFile vf = new LightVirtualFile("/<$.}>^\\ra*id\\someRemote \"Path\\someFileName.csv");
69+
String relativePath = CsvStorageHelper.getRelativeFilePath(this.getProject(), vf);
70+
assertEquals(PathUtil.getLocalPath("\\\\<$.}>^\\ra*id\\someRemote \"Path\\someFileName.csv"), relativePath);
71+
}
72+
4673
}

src/test/java/net/seesharpsoft/intellij/plugins/csv/components/CsvFileAttributesTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,18 @@ public void testSaveFileEscapeCharacter() {
5656

5757
public void testCleanupAttributeMap() {
5858
CsvFileAttributes fileAttributes = CsvFileAttributes.getInstance(this.getProject());
59-
fileAttributes.attributeMap.put(Paths.get("/csv_file_test.csv").toString(), new CsvFileAttributes.Attribute());
60-
fileAttributes.attributeMap.put(Paths.get("/test/py_file_test.py").toString(), new CsvFileAttributes.Attribute());
61-
fileAttributes.attributeMap.put(Paths.get("/not_existing_csv_file_test.csv").toString(), new CsvFileAttributes.Attribute());
59+
fileAttributes.attributeMap.put("/csv_file_test.csv", new CsvFileAttributes.Attribute());
60+
fileAttributes.attributeMap.put("/test/py_file_test.py", new CsvFileAttributes.Attribute());
61+
fileAttributes.attributeMap.put("/not_existing_csv_file_test.csv", new CsvFileAttributes.Attribute());
62+
fileAttributes.attributeMap.put("/<835d7ae1-4344-4666-bc29-31fb457b610e>\\raid\\someRemotePath\\someFileName.csv", new CsvFileAttributes.Attribute());
63+
fileAttributes.attributeMap.put("/<$.}>^\\ra*id\\someRemote \"Path\\someFileName.json", new CsvFileAttributes.Attribute());
6264

63-
assertEquals(3, fileAttributes.attributeMap.size());
65+
assertEquals(5, fileAttributes.attributeMap.size());
6466

6567
fileAttributes.cleanupAttributeMap(this.getProject());
6668

6769
assertEquals(1, fileAttributes.attributeMap.size());
68-
assertNotNull(fileAttributes.attributeMap.get(Paths.get("/csv_file_test.csv").toString()));
70+
assertNotNull(fileAttributes.attributeMap.get("/csv_file_test.csv"));
6971
}
7072

7173
}

0 commit comments

Comments
 (0)