Skip to content

Commit

Permalink
Fix the error 'Invalid project description' caused by incorrect glob …
Browse files Browse the repository at this point in the history
…patterns for Windows paths (#2911)

Signed-off-by: Jinbo Wang <[email protected]>
  • Loading branch information
testforstephen authored Oct 19, 2023
1 parent a763751 commit fe0ac4c
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ public boolean applies(IProgressMonitor monitor) throws CoreException {
.addExclusions("**/bin");//default Eclipse build dir
for (IProject project : ProjectUtils.getAllProjects(false)) {
File projectFile = project.getLocation().toFile();
eclipseDetector.addExclusions(projectFile.getAbsolutePath());
/**
* The exclusion pattern will be used as a regular expression
* that matches the files or folders to be excluded. On Windows,
* the path separator (\) is a special character in regular
* expressions, so it needs to be escaped with another backslash (\)
* to be treated literally. For example, to exclude the folder
* C:\Users\Hello, the exclusion pattern should be C:\\Users\\Hello.
*/
eclipseDetector.addExclusions(projectFile.getAbsolutePath().replace("\\", "\\\\"));
}
directories = eclipseDetector.scan(monitor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean applies(IProgressMonitor monitor) throws CoreException {
for (IProject project : ProjectUtils.getAllProjects()) {
if (!ProjectUtils.isGradleProject(project)) {
String path = project.getLocation().toOSString();
gradleDetector.addExclusions(path);
gradleDetector.addExclusions(path.replace("\\", "\\\\"));
}
}
directories = gradleDetector.scan(monitor);
Expand Down Expand Up @@ -552,15 +552,11 @@ private static boolean checkGradlePersistence(IProject project, File projectDir)
if (persistentFile.exists()) {
long modified = persistentFile.lastModified();
if (projectDir.exists()) {
File[] files = projectDir.listFiles(new FilenameFilter() {

@Override
public boolean accept(File dir, String name) {
if (name != null && GradleBuildSupport.GRADLE_FILE_EXT.matcher(name).matches()) {
return new File(dir, name).lastModified() > modified;
}
return false;
File[] files = projectDir.listFiles((FilenameFilter) (dir, name) -> {
if (name != null && GradleBuildSupport.GRADLE_FILE_EXT.matcher(name).matches()) {
return new File(dir, name).lastModified() > modified;
}
return false;
});
shouldSynchronize = files != null && files.length > 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
for (IProject project : ProjectUtils.getAllProjects()) {
if (!ProjectUtils.isMavenProject(project)) {
String path = project.getLocation().toOSString();
mavenDetector.addExclusions(path);
mavenDetector.addExclusions(path.replace("\\", "\\\\"));
}
}
directories = mavenDetector.scan(monitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,18 @@ public void testNullAnalysis() throws Exception {
}
}

@Test
public void DoNotDuplicateImportProject() throws Exception {
String name = "hello";
importProjects("eclipse/"+name);
IProject project = getProject(name );
assertIsJavaProject(project);
EclipseProjectImporter importer = new EclipseProjectImporter();
importer.initialize(project.getLocation().toFile());
boolean hasUnimportedProjects = importer.applies(new NullProgressMonitor());
assertFalse(hasUnimportedProjects);
}

@After
public void after() {
importer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,23 @@ public void avoidImportDuplicatedProjects() throws Exception {
}
}

@Test
public void avoidImportDuplicatedProjects2() throws Exception {
try {
this.preferences.setImportGradleEnabled(false);
importProjects("multi-buildtools");
IProject project = getProject("multi-build-tools");
assertIsJavaProject(project);
GradleProjectImporter importer = new GradleProjectImporter();
importer.initialize(project.getLocation().toFile());

this.preferences.setImportGradleEnabled(true);
assertFalse(importer.applies(null));
} finally {
this.preferences.setImportGradleEnabled(true);
}
}

@Test
public void testProtoBufSupport() throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,23 @@ public void avoidImportDuplicatedProjects() throws Exception {
}
}

@Test
public void avoidImportDuplicatedProjects2() throws Exception {
try {
this.preferences.setImportMavenEnabled(false);
importProjects("multi-buildtools");
IProject project = WorkspaceHelper.getProject("multi-buildtools");
assertIsJavaProject(project);
MavenProjectImporter importer = new MavenProjectImporter();
importer.initialize(project.getLocation().toFile());

this.preferences.setImportMavenEnabled(true);
assertFalse(importer.applies(null));
} finally {
this.preferences.setImportMavenEnabled(true);
}
}

// https://github.com/redhat-developer/vscode-java/issues/2712
@Test
public void testNullAnalysisDisabled() throws Exception {
Expand Down

0 comments on commit fe0ac4c

Please sign in to comment.