Skip to content

Commit

Permalink
Prevent execution of the Java Resource Import Configurator #1288
Browse files Browse the repository at this point in the history
When importing Gradle projects from a folder with the generic project
configurator, other configurators like the
ProjectWithJavaResourcesImportConfigurator must not run. Otherwise
resources in subprojects could be imported twice.

To prevent the execution of secondary configurators the method
shouldBeAnEclipseProject(...) has to return true for the root of Gradle
projects.
  • Loading branch information
oleosterhagen committed Jan 14, 2024
1 parent 6418500 commit 78419df
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ package org.eclipse.buildship.ui.internal.wizard.project

import org.eclipse.core.resources.IProject
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.core.runtime.jobs.Job
import org.eclipse.jdt.core.JavaCore
import org.eclipse.jface.dialogs.IDialogConstants
import org.eclipse.swtbot.eclipse.finder.waits.Conditions
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell
Expand Down Expand Up @@ -72,6 +74,28 @@ class ProjectImportWizardUiTest extends SwtBotSpecification {
bot.button("Cancel").click()
}

def "import project from folder does not include Java resources of subprojects in the root project"() {
given:
def rootDir = dir('rootProject') {
file 'settings.gradle', 'include "subProject"'
dir('subProject') {
file 'build.gradle', 'plugins { id "java-library" }'
dir('src/main/java') {
file 'Foobar.java', 'class Foobar { }'
}
}
}

when:
importProjectFromFolder rootDir
waitForImportJobsToFinish()
waitForGradleJobsToFinish()

then:
findProject('rootProject').hasNature(JavaCore.NATURE_ID) == false
findProject('subProject').hasNature(JavaCore.NATURE_ID) == true
}

private static SWTBotShell openGradleImportWizard() {
bot.menu("File").menu("Import...").click()
SWTBotShell shell = bot.shell("Import")
Expand All @@ -82,6 +106,21 @@ class ProjectImportWizardUiTest extends SwtBotSpecification {
bot.shell(ProjectWizardMessages.Title_GradleProjectWizardPage)
}

private void importProjectFromFolder(File projectDir) {
bot.menu("File").menu("Import...").click()
bot.shell("Import").activate()
bot.waitUntil(Conditions.shellIsActive("Import"))
bot.tree().expandNode("General").select("Projects from Folder or Archive")
bot.button("Next >").click()
bot.comboBoxWithLabel("Import source:").setText(projectDir.canonicalPath)
bot.button(IDialogConstants.FINISH_LABEL).click()
}

private void waitForImportJobsToFinish() {
def jobFamily = Class.forName("org.eclipse.ui.internal.wizards.datatransfer.SmartImportJob")
Job.getJobManager().join(jobFamily, null)
}

class FaultyWorkspaceOperations {
@Delegate WorkspaceOperations delegate = CorePlugin.workspaceOperations()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private boolean isGradleRoot(File root) {

@Override
public boolean shouldBeAnEclipseProject(IContainer container, IProgressMonitor monitor) {
return false;
IPath location = container.getLocation();
return location != null && isGradleRoot(location.toFile());
}

@Override
Expand All @@ -88,11 +89,7 @@ public Set<IFolder> getFoldersToIgnore(IProject project, IProgressMonitor monito

@Override
public boolean canConfigure(IProject project, Set<IPath> ignoredPaths, IProgressMonitor monitor) {
IPath location = project.getLocation();
if(location != null) {
return isGradleRoot(location.toFile());
}
return false;
return shouldBeAnEclipseProject(project, monitor);
}

@Override
Expand Down

0 comments on commit 78419df

Please sign in to comment.