Skip to content

Commit

Permalink
Prevent execution of the Java Resource Import Configurator #1288 (#1293)
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 authored Jan 15, 2024
1 parent 0800e1c commit 548ec8d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.eclipse.buildship.ui.test/src\/main\/groovy"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit5"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_ATTR_USE_ARGFILE" value="false"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
Expand Down
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 548ec8d

Please sign in to comment.