Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error 'Invalid project description' caused by incorrect glob patterns for Windows paths #2911

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Comment on lines +555 to +559
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change is introduced by the cleanup actions.

});
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