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

When a cpp plugin is applied, set cpp module type #95

Closed
wants to merge 1 commit into from
Closed
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 @@ -12,6 +12,9 @@
import org.gradle.api.artifacts.result.ResolvedDependencyResult;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.PluginContainer;
import org.gradle.language.cpp.plugins.CppApplicationPlugin;
import org.gradle.language.cpp.plugins.CppLibraryPlugin;
import org.jfrog.build.api.builder.ModuleType;
import org.jfrog.build.api.util.FileChecksumCalculator;
import org.jfrog.build.extractor.ModuleExtractor;
Expand Down Expand Up @@ -79,7 +82,7 @@ private ModuleBuilder getModuleBuilder(Project project, Set<GradleDeployDetails>
.findAny()
.orElse("");
ModuleBuilder builder = new ModuleBuilder()
.type(ModuleType.GRADLE)
.type(getModuleType(project))
.id(moduleId)
.repository(repo);
try {
Expand All @@ -99,6 +102,21 @@ private ModuleBuilder getModuleBuilder(Project project, Set<GradleDeployDetails>
return builder;
}

/**
* Get the module type to publish.
*
* @param project - Project to extract the module type
* @return the module type.
*/
private ModuleType getModuleType(Project project) {
PluginContainer plugins = project.getPlugins();
if (!plugins.withType(CppApplicationPlugin.class).isEmpty() ||
!plugins.withType(CppLibraryPlugin.class).isEmpty()) {
Comment on lines +113 to +114
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be an AND condition instead of OR?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. We need one of the plugin lists to be not empty.
In other words -
The cpp-application plugin or the cpp-library plugin should be applied.

Copy link

Choose a reason for hiding this comment

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

Actually, you maybe better off using NativeBasePlugin.class here instead. We provide our own CppLibrary/CppApplication plugins w/a custom CppBasePlugin (possible alternative to NativeBasePlugin.class). However, if you do use NativeBasePlugin.class, this change would also capture e.g. swift projects (which is really just a C++ extension provided by Apple if you ask me).

Copy link

Choose a reason for hiding this comment

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

Add the following import statement, and remove the ones related to the CppApplication and CppLibrary plugins

import org.gradle.language.plugins.NativeBasePlugin;

Then add:

     private ModuleType getModuleType(Project project) {
         PluginContainer plugins = project.getPlugins();
         if (!plugins.withType(NativeBasePlugin.class).isEmpty()) {
             return ModuleType.CPP;
         }
         return ModuleType.GRADLE;
     }

Sorry it took me so long to get that tested. I had to fix up the build to publish to mavenLocal and then re-run my separate build using that. In addition, the ModuleType.CPP change wasn't in the build-info-api yet so I had to additionally publish that locally too.

But the above works, it fills in the module with a type="cpp" field, and any dependencies under it seem to inherit it (despite being empty in the build-info.json file) when published to artifactory. They do show up as CPP type for X-Ray / Build SBOM and the dependencies are correctly being tracked there.

return ModuleType.CPP;
}
return ModuleType.GRADLE;
}

/**
* Extract Artifacts from the given deploy details
*/
Expand Down
Loading