Skip to content

Commit 54087d5

Browse files
authored
Merge pull request #273 from SeeSharpSoft/master
Release 2.16.1
2 parents 5abf207 + e6930db commit 54087d5

File tree

7 files changed

+88
-5
lines changed

7 files changed

+88
-5
lines changed

.github/workflows/PullRequest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
strategy:
16+
fail-fast: false
1617
matrix:
1718
include:
1819
- ideaVersion: IC-193.5233.102

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.16.1
2+
Apr 20, 2021
3+
4+
FIX: keep existing & correct entries in CSV attributes map
5+
16
2.16.0
27
Apr 18, 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.0'
31+
version '2.16.1'
3232

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

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static String getRelativeFileUrl(Project project, VirtualFile virtualFile
2323
String url = virtualFile.getUserData(RELATIVE_FILE_URL);
2424
if (url == null && project.getBasePath() != null) {
2525
String projectDir = PathUtil.getLocalPath(project.getBasePath());
26-
url = PathUtil.getLocalPath(virtualFile.getPath())
27-
.replaceFirst("^" + Pattern.quote(projectDir), "");
26+
url = Paths.get(PathUtil.getLocalPath(virtualFile.getPath())
27+
.replaceFirst("^" + Pattern.quote(projectDir), "")).toString();
2828
virtualFile.putUserData(RELATIVE_FILE_URL, url);
2929
}
3030
return url;
@@ -34,12 +34,13 @@ public static Path getFilePath(Project project, String fileName) {
3434
if (project == null || fileName == null) {
3535
return null;
3636
}
37-
return Paths.get(project.getBasePath()).resolve(fileName.startsWith(File.separator) ? fileName.substring(1) : fileName);
37+
String formattedFileName = Paths.get(fileName).toString();
38+
return Paths.get(project.getBasePath()).resolve(formattedFileName.startsWith(File.separator) ? formattedFileName.substring(1) : formattedFileName);
3839
}
3940

4041
public static VirtualFile getFileInProject(Project project, String fileName) {
4142
Path filePath = getFilePath(project, fileName);
42-
return VirtualFileManager.getInstance().findFileByUrl(filePath.toAbsolutePath().toString());
43+
return VirtualFileManager.getInstance().findFileByUrl(filePath.toUri().toString());
4344
}
4445

4546
private CsvStorageHelper() {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ NEW: Ability to split on ASCII separator character \x1e #267
5454
NEW: "General" settings group
5555
FIX: Lower annotator severity to not appear as problem
5656
FIX: Prevent non CSV entries in CSV attributes map #268
57+
FIX: keep existing & correct entries in CSV attributes map
5758
</pre>
5859
]]>
5960
</change-notes>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.seesharpsoft.intellij.plugins.csv;
2+
3+
import com.intellij.openapi.vfs.VirtualFile;
4+
import com.intellij.testFramework.fixtures.BasePlatformTestCase;
5+
6+
import java.nio.file.Paths;
7+
8+
public class CsvStorageHelperTest extends BasePlatformTestCase {
9+
10+
@Override
11+
protected void setUp() throws Exception {
12+
super.setUp();
13+
Paths.get(this.getProject().getBasePath()).toFile().mkdirs();
14+
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().createNewFile();
15+
Paths.get(this.getProject().getBasePath(), "test").toFile().mkdir();
16+
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().createNewFile();
17+
}
18+
19+
@Override
20+
protected void tearDown() throws Exception {
21+
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().delete();
22+
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().delete();
23+
Paths.get(this.getProject().getBasePath(), "test").toFile().delete();
24+
super.tearDown();
25+
}
26+
27+
public void testGetFileInProjectExists() {
28+
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/csv_file_test.csv").toString());
29+
assertNotNull(vf);
30+
}
31+
32+
public void testGetFileInProjectDirectory() {
33+
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/test/py_file_test.py").toString());
34+
assertNotNull(vf);
35+
}
36+
37+
public void testGetFileInProjectDoesNotExist() {
38+
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/not_existing_csv_file_test.csv").toString());
39+
assertNull(vf);
40+
}
41+
42+
public void testGetFileInProjectDirectoryDoesNotExist() {
43+
VirtualFile vf = CsvStorageHelper.getFileInProject(this.getProject(), Paths.get("/test2/py_file_test.py").toString());
44+
assertNull(vf);
45+
}
46+
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@
55
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
66
import net.seesharpsoft.intellij.plugins.csv.settings.CsvEditorSettings;
77

8+
import java.nio.file.Paths;
9+
810
public class CsvFileAttributesTest extends BasePlatformTestCase {
911
@Override
1012
protected String getTestDataPath() {
1113
return "./src/test/resources/components";
1214
}
1315

16+
@Override
17+
protected void setUp() throws Exception {
18+
super.setUp();
19+
Paths.get(this.getProject().getBasePath()).toFile().mkdirs();
20+
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().createNewFile();
21+
Paths.get(this.getProject().getBasePath(), "test").toFile().mkdir();
22+
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().createNewFile();
23+
}
24+
1425
@Override
1526
protected void tearDown() throws Exception {
27+
Paths.get(this.getProject().getBasePath(), "test", "py_file_test.py").toFile().delete();
28+
Paths.get(this.getProject().getBasePath(), "test").toFile().delete();
29+
Paths.get(this.getProject().getBasePath(), "csv_file_test.csv").toFile().delete();
30+
1631
CsvFileAttributes.getInstance(this.getProject()).reset();
1732
super.tearDown();
1833
}
@@ -39,4 +54,18 @@ public void testSaveFileEscapeCharacter() {
3954
assertEquals(CsvEscapeCharacter.BACKSLASH, csvFileAttributes.getEscapeCharacter(this.getProject(), myFixture.getFile().getOriginalFile().getVirtualFile()));
4055
}
4156

57+
public void testCleanupAttributeMap() {
58+
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());
62+
63+
assertEquals(3, fileAttributes.attributeMap.size());
64+
65+
fileAttributes.cleanupAttributeMap(this.getProject());
66+
67+
assertEquals(1, fileAttributes.attributeMap.size());
68+
assertNotNull(fileAttributes.attributeMap.get(Paths.get("/csv_file_test.csv").toString()));
69+
}
70+
4271
}

0 commit comments

Comments
 (0)