Skip to content

Commit

Permalink
Merge pull request #8191 from mbien/stabilize-groovyparsertest
Browse files Browse the repository at this point in the history
GroovyParserTest: don't clear workdir while indexer is active
  • Loading branch information
mbien authored Feb 7, 2025
2 parents 12ad0e7 + 85194dd commit bbdcc25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ protected void setUp() throws Exception {
Logger.getLogger(org.netbeans.modules.groovy.editor.api.parser.GroovyParser.class.getName())
.setLevel(Level.FINEST);
}


@Override
protected void tearDown() throws Exception {
// remove the static stuff
parserUnit = null;
Expand All @@ -76,7 +77,10 @@ protected void tearDown() throws Exception {
enabledForUnit = null;
GroovyTestTransformer.parserCompUnit = null;

clearWorkDir();
// TODO cancel indexing?
// don't clear since indexer might be still active; setUp() clears on reruns
// clearWorkDir();

URL u = URLMapper.findURL(FileUtil.getConfigRoot(), URLMapper.EXTERNAL);
if (u != null) {
Path p = Paths.get(u.toURI());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.netbeans.modules.groovy.editor.test;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -30,7 +28,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.editor.BaseDocument;
Expand All @@ -46,7 +43,6 @@
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.Utilities;

/**
* In order to be able to run tests using java.source on Mac, you need to apply patch
Expand Down Expand Up @@ -80,6 +76,14 @@ protected void setUp() throws Exception {
testFO = workDir.createData("Test.groovy");
}

@Override
protected void tearDown() throws Exception {
if (testFO != null) {
testFO.delete();
}
super.tearDown();
}

@Override
protected DefaultLanguageConfig getPreferredLanguage() {
return new GroovyLanguage();
Expand Down
11 changes: 8 additions & 3 deletions harness/nbjunit/src/org/netbeans/junit/NbTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.SimpleFileVisitor;
Expand Down Expand Up @@ -994,7 +995,7 @@ public File getWorkDir() throws IOException {
}

// private method for deleting a file/directory (and all its subdirectories/files)
private static void deleteFile(File file) throws IOException {
private static void deleteRecursive(File file) throws IOException {
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<java.nio.file.Path>() {
@Override
public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes attrs) throws IOException {
Expand All @@ -1003,7 +1004,11 @@ public FileVisitResult visitFile(java.nio.file.Path file, BasicFileAttributes at
}
@Override
public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
Files.delete(dir);
try {
Files.delete(dir);
} catch (DirectoryNotEmptyException ex) {
throw new IOException("concurrent write detected, folder no longer empty:\n" + Arrays.asList(dir.toFile().list()), ex);
}
return FileVisitResult.CONTINUE;
}
});
Expand All @@ -1014,7 +1019,7 @@ static void deleteSubFiles(File file) throws IOException {
File files[] = file.getCanonicalFile().listFiles();
if (files != null) {
for (File f : files) {
deleteFile(f);
deleteRecursive(f);
}
} else {
// probably do nothing - file is not a directory
Expand Down

0 comments on commit bbdcc25

Please sign in to comment.