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

feat: Support import according to given configuration files #1432

Merged
merged 1 commit into from
Oct 25, 2023
Merged
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 @@ -68,6 +68,15 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
return false;
}

// if the current root already contains Gradle Java project
// imported by Buildship, skip the build server importer.
for (IProject project : ProjectUtils.getGradleProjects()) {
if (ProjectUtils.isJavaProject(project)
&& project.getLocation().toFile().toPath().startsWith(rootFolder.toPath())) {
return false;
}
}

if (directories == null) {
BasicFileDetector gradleDetector = new BasicFileDetector(rootFolder.toPath(), BUILD_GRADLE_DESCRIPTOR,
SETTINGS_GRADLE_DESCRIPTOR, BUILD_GRADLE_KTS_DESCRIPTOR, SETTINGS_GRADLE_KTS_DESCRIPTOR)
Expand All @@ -77,6 +86,10 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
directories = gradleDetector.scan(monitor);
}

if (directories.isEmpty()) {
return false;
}

for (java.nio.file.Path directory : directories) {
// we don't support android
BasicFileDetector androidDetector = new BasicFileDetector(directory, ANDROID_MANIFEST)
Expand All @@ -90,17 +103,35 @@ public boolean applies(IProgressMonitor monitor) throws OperationCanceledExcepti
telemetry);
return false;
}
}

IProject project = ProjectUtils.getProjectFromUri(directory.toUri().toString());
// skip this importer if any of the project in workspace is already
// imported by other importers.
if (project != null && (!Utils.isGradleBuildServerProject(project)
&& ProjectUtils.isJavaProject(project))) {
return false;
}
return true;
}

@Override
public boolean applies(Collection<IPath> projectConfigurations, IProgressMonitor monitor)
throws OperationCanceledException, CoreException {
if (rootFolder == null) {
return false;
}


if (!Utils.isBuildServerEnabled(getPreferences())) {
return false;
}

return !directories.isEmpty();
Collection<java.nio.file.Path> directories = findProjectPathByConfigurationName(
projectConfigurations,
Arrays.asList(
BUILD_GRADLE_DESCRIPTOR,
SETTINGS_GRADLE_DESCRIPTOR,
BUILD_GRADLE_KTS_DESCRIPTOR,
SETTINGS_GRADLE_KTS_DESCRIPTOR
),
false /*includeNested*/
);

return !directories.isEmpty() && !importedByOtherImporters(directories);
}

@Override
Expand Down Expand Up @@ -200,6 +231,18 @@ public static boolean updateConfigurationDigest(IProject project) {
return result;
}

/**
* Return false if any of the input folder has already been imported as a
* Java project by other importer.
*/
private boolean importedByOtherImporters(Collection<java.nio.file.Path> directories) {
return directories.stream()
.map(directory -> ProjectUtils.getProjectFromUri(directory.toUri().toString()))
.anyMatch(project -> !Utils.isGradleBuildServerProject(project) &&
ProjectUtils.isJavaProject(project)
);
}

/**
* Import the projects according to the available build targets. If a build target
* maps to a project that is already imported by other importer
Expand Down
Loading