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

Prevent execution of the Java Resource Import Configurator #1288 #1293

Merged
merged 2 commits into from
Jan 15, 2024
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 @@ -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