diff --git a/plugins/buildsystem/build.gradle b/plugins/buildsystem/build.gradle index 769d1def..c077a405 100644 --- a/plugins/buildsystem/build.gradle +++ b/plugins/buildsystem/build.gradle @@ -10,7 +10,7 @@ plugins { } group 'com.microsoft.identity' -version '0.2.2' +version '0.3.0' pluginBundle { @@ -45,6 +45,10 @@ dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.ext.kotlinVersion}" testImplementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${rootProject.ext.kotlinVersion}" testImplementation "org.jetbrains.kotlin:kotlin-test:${rootProject.ext.kotlinVersion}" + + compileOnly "org.projectlombok:lombok:$rootProject.ext.lombokVersion" + annotationProcessor "org.projectlombok:lombok:$rootProject.ext.lombokVersion" + implementation "com.google.code.gson:gson:$rootProject.ext.gsonVersion" } test { diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPlugin.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPlugin.java index 32216c28..2fea5c60 100644 --- a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPlugin.java +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/BuildPlugin.java @@ -23,10 +23,20 @@ package com.microsoft.identity.buildsystem; import com.android.build.gradle.LibraryExtension; +import com.microsoft.identity.buildsystem.rendering.ConsoleGradleDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.IMavenDependencyFormatter; +import com.microsoft.identity.buildsystem.rendering.SimpleMavenDependencyFormatter; +import com.microsoft.identity.buildsystem.rendering.cgmanifest.CGManifestGradleDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettingsAdapter; +import com.microsoft.identity.buildsystem.rendering.settings.DependencyRendererSettingsExtension; +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; +import com.microsoft.identity.buildsystem.rendering.settings.IDependencyRendererSettingsAdapter; + import com.microsoft.identity.buildsystem.codecov.CodeCoverage; import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.tasks.diagnostics.DependencyReportTask; public class BuildPlugin implements Plugin { @@ -42,14 +52,34 @@ public void apply(final Project project) { final BuildPluginExtension config = project.getExtensions() .create("buildSystem", BuildPluginExtension.class); - project.afterEvaluate(project1 -> { - if(config.getDesugar().get()) { - project1.getLogger().warn("DESUGARING ENABLED"); - applyDesugaringToAndroidProject(project1); - applyJava8ToJavaProject(project1); - }else{ - project1.getLogger().warn("DESUGARING DISABLED"); + final DependencyRendererSettingsExtension dependencyRendererSettingsExtension = + project.getExtensions().create("dependencyRendering", DependencyRendererSettingsExtension.class); + + project.afterEvaluate(evaluatedProject -> { + if (config.getDesugar().get()) { + evaluatedProject.getLogger().warn("DESUGARING ENABLED"); + applyDesugaringToAndroidProject(evaluatedProject); + applyJava8ToJavaProject(evaluatedProject); + } else { + evaluatedProject.getLogger().warn("DESUGARING DISABLED"); } + + final IDependencyRendererSettingsAdapter mDependencyRendererSettingsAdapter = + new DependencyRendererSettingsAdapter(evaluatedProject); + + final GradleDependencyRendererSettings gradleDependencyRendererSettings = + mDependencyRendererSettingsAdapter.adapt(dependencyRendererSettingsExtension); + + // generate gradle task to print dependencies to console + final DependencyReportTask consoleTask = project.getTasks().create("printDependenciesToConsole", DependencyReportTask.class); + final IMavenDependencyFormatter dependencyFormatter = new SimpleMavenDependencyFormatter(); + consoleTask.setRenderer(new ConsoleGradleDependencyRenderer( + gradleDependencyRendererSettings, dependencyFormatter + )); + + // generate gradle task to create CG Manifest + final DependencyReportTask cgManifestTask = project.getTasks().create("createDependenciesCgManifest", DependencyReportTask.class); + cgManifestTask.setRenderer(new CGManifestGradleDependencyRenderer(gradleDependencyRendererSettings)); }); SpotBugs.applySpotBugsPlugin(project); @@ -57,7 +87,7 @@ public void apply(final Project project) { CodeCoverage.applyCodeCoveragePlugin(project); } - private void applyDesugaringToAndroidProject(final Project project){ + private void applyDesugaringToAndroidProject(final Project project) { project.getPluginManager().withPlugin(ANDROID_LIBRARY_PLUGIN_ID, appliedPlugin -> { LibraryExtension libraryExtension = project.getExtensions().findByType(LibraryExtension.class); diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java new file mode 100644 index 00000000..0c59c8a7 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/AbstractGradleDependencyRenderer.java @@ -0,0 +1,273 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.component.ProjectComponentIdentifier; +import org.gradle.api.artifacts.result.DependencyResult; +import org.gradle.api.artifacts.result.ResolutionResult; +import org.gradle.api.artifacts.result.ResolvedComponentResult; +import org.gradle.api.tasks.diagnostics.internal.DependencyReportRenderer; +import org.gradle.api.tasks.diagnostics.internal.TextReportRenderer; +import org.gradle.internal.deprecation.DeprecatableConfiguration; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.experimental.Accessors; + +/** + * An abstract implementation of {@link DependencyReportRenderer} that uses the settings provided by + * the {@link GradleDependencyRendererSettings} and renders the dependencies as specified by the + * implementation of the {@link AbstractGradleDependencyRenderer#render(GradleDependency)} and + * {@link AbstractGradleDependencyRenderer#complete(Project, Collection)} methods. + */ +@AllArgsConstructor +@Accessors(prefix = "m") +public abstract class AbstractGradleDependencyRenderer extends TextReportRenderer implements DependencyReportRenderer { + + /** + * Settings that govern some of the behavior while rendering the dependencies. + *

+ * We are making this field available to children of this class so they can also take action on + * these settings as applicable. + */ + protected final GradleDependencyRendererSettings mGradleDependencyRendererSettings; + + private static final IMavenDependencyAdapter sMavenDependencyAdapter = new MavenDependencyAdapter(); + + private static final IDependencyTypeAdapter sConfigurationAdapter = new DependencyTypeAdapter(); + + /** + * Renders a {@link GradleDependency} somewhere as indicated by the implementation of this + * method. + * + * @param gradleDependency the {@link GradleDependency} to render + */ + public abstract void render(@NonNull final GradleDependency gradleDependency); + + /** + * Complete the rendering of all the {@link GradleDependency} dependencies in a {@link Project}. + * + * @param project the {@link Project} for which to complete the rendering + * @param gradleDependencies the list of {@link GradleDependency} in this project + */ + public abstract void complete(@NonNull final Project project, + @NonNull final Collection gradleDependencies); + + /** + * Keeps track of which dependencies have already been rendered. + */ + private final Map mRenderedDepMap = new HashMap<>(); + + @Override + public void startConfiguration(Configuration configuration) { + // We don't need to do anything here by default + // but let's just print configuration name + System.out.println("Starting configuration: " + configuration.getName()); + } + + @Override + public void completeProject(Project project) { + // let's just call our own complete method here and delegate the actual work to that + // method's implementation + complete(project, mRenderedDepMap.values()); + } + + + @Override + public void render(Configuration configuration) { + // If we want to render transitive dependencies and we can resolve them then let's render + // them + if (mGradleDependencyRendererSettings.isRenderTransitiveDependencies() && canBeResolved(configuration)) { + // First resolve the configuration + final ResolutionResult result = configuration.getIncoming().getResolutionResult(); + // now render all dependencies in this configuration + result.allDependencies(dependencyResult -> renderDependencyResult(configuration, dependencyResult)); + } else { + // The configuration couldn't be resolved..let's just render the direct dependencies + System.out.println("Unable to resolve configuration: " + configuration.getName()); + final DependencySet dependencies = configuration.getDependencies(); + renderDependencySet(configuration, dependencies); + } + } + + @Override + public void completeConfiguration(Configuration configuration) { + // We don't need to do anything here by default + } + + /** + * Render each dependency in a Dependency Set. + * + * @param configuration the {@link Configuration} for which we are rendering dependencies + * @param dependencies the {@link DependencySet} that contains a set of dependencies + */ + private void renderDependencySet(@NonNull final Configuration configuration, + @NonNull final DependencySet dependencies) { + dependencies.iterator().forEachRemaining( + dependency -> renderDependency(configuration, dependency) + ); + } + + /** + * Render the dependency represented by a {@link DependencyResult} object. + * + * @param configuration the {@link Configuration} for which we are rendering the dependency + * @param dependencyResult the {@link DependencyResult} that needs to be rendered + */ + private void renderDependencyResult(@NonNull final Configuration configuration, + @NonNull final DependencyResult dependencyResult) { + // first convert the internal dependency result into our custom IMavenDependency object + final IMavenDependency depToRender = sMavenDependencyAdapter.adapt(dependencyResult); + + // Get the root dependency that brought in this dependency + final ResolvedComponentResult rootResult = dependencyResult.getFrom(); + + // If the dependency is not null then we can render it + if (depToRender != null) { + IMavenDependency depRoot; + + // if the root is a Project and we've decided to NOT to render Projects, then let's skip + if (rootResult.getId() instanceof ProjectComponentIdentifier && !mGradleDependencyRendererSettings.isRenderProjectDependency()) { + depRoot = null; + } else { + // the root was NOT a project so we should proceed to render it anyway + // take the root and convert that into our own custom IMavenDependency object + depRoot = sMavenDependencyAdapter.adapt( + rootResult.getModuleVersion() + ); + } + + // Now render the dependency that we received + renderInternal(configuration, depToRender, depRoot); + } else { + System.out.println("Weird. The dependency was null for " + dependencyResult.toString()); + } + } + + /** + * Render the dependency represented by a {@link Dependency} object. + * + * @param configuration the {@link Configuration} for which we are rendering the dependency + * @param dependency the {@link Dependency} that needs to be rendered + */ + private void renderDependency(@NonNull final Configuration configuration, + @NonNull final Dependency dependency) { + if (shouldRender(dependency)) { + renderInternal(configuration, sMavenDependencyAdapter.adapt(dependency), null); + } + } + + /** + * Determines if we should render a dependency represented by the {@link Dependency} object. + * + * @param dependency the {@link Dependency} for which we need to decide if we want to render it + * @return a boolean that indicates whether the dependency should be rendered + */ + private boolean shouldRender(@NonNull final Dependency dependency) { + return !(dependency instanceof ProjectDependency) || + mGradleDependencyRendererSettings.isRenderProjectDependency(); + } + + /** + * Determines whether a gradle dependency configuration can be resolved. + * + * @param configuration the {@link Configuration} for which we need to decide if it can be + * resolved + * @return a boolean that indicates whether the configuration can be resolved + */ + private boolean canBeResolved(Configuration configuration) { + boolean isDeprecatedForResolving = ((DeprecatableConfiguration) configuration).getResolutionAlternatives() != null; + return configuration.isCanBeResolved() && !isDeprecatedForResolving; + } + + /** + * An internal method that will take the dependency information supplied to it, convert it into + * a {@link GradleDependency} representation and delegate the actual rendering to the + * implementation of {@link AbstractGradleDependencyRenderer#render(GradleDependency)} method. + * + * @param configuration the {@link Configuration} for which we are rendering the dependency + * @param mavenDependency the {@link IMavenDependency} that needs to be rendered + * @param depRoot the {@link IMavenDependency} root of the dependency that we need to render + */ + private void renderInternal(@NonNull final Configuration configuration, + @NonNull final IMavenDependency mavenDependency, + @Nullable final IMavenDependency depRoot) { + // Take the configuration and adapt that into an internal dependency type + final DependencyType incomingDependencyType = sConfigurationAdapter.adapt(configuration); + + // check if we already received (rendered) this dependency + GradleDependency gradleDependency = mRenderedDepMap.get(mavenDependency.toString()); + + // we have not seen this dependency yet + if (gradleDependency == null) { + final Set depRoots = new HashSet<>(); + + // we also have root dependency so let's add that to roots + if (depRoot != null) { + depRoots.add(depRoot); + } + + // Create a GradleDependency object from the information we have + gradleDependency = new GradleDependency( + incomingDependencyType, + mavenDependency, + depRoots + ); + } else { + // we have already seen this dependency + // so now we just need to update the roots because the root we received this time + // might not have been recorded yet + if (depRoot != null) { + gradleDependency.addRootDependency(depRoot); + } + + // We would also update dependency type. + // It is possible that when we saw this dep earlier we got in a compile only classpath + // so if we got runtime now then we would overwrite the dependency type + if (incomingDependencyType == DependencyType.RUNTIME) { + gradleDependency.setDependencyType(incomingDependencyType); + } + } + + // Now actually render this dependency + // or do whatever the render method does ;) + render(gradleDependency); + + // we rendered it...save it into the Map + mRenderedDepMap.put(mavenDependency.toString(), gradleDependency); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java new file mode 100644 index 00000000..ab5f8656 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/ConsoleGradleDependencyRenderer.java @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; + +import org.gradle.api.Project; + +import java.util.Collection; + +import lombok.NonNull; + +/** + * An implementation of {@link AbstractGradleDependencyRenderer} that will use the provided + * {@link IMavenDependencyFormatter} to format dependency into a String and render them to console. + */ +public class ConsoleGradleDependencyRenderer extends AbstractGradleDependencyRenderer { + + private final IMavenDependencyFormatter mDependencyFormatter; + + public ConsoleGradleDependencyRenderer(@NonNull final GradleDependencyRendererSettings gradleDependencyRendererSettings, + @NonNull final IMavenDependencyFormatter dependencyFormatter) { + super(gradleDependencyRendererSettings); + mDependencyFormatter = dependencyFormatter; + } + + @Override + public void render(@NonNull final GradleDependency gradleDependency) { + render(mDependencyFormatter.formatDependency(gradleDependency.getMavenDependency())); + } + + @Override + public void complete(@NonNull final Project project, + @NonNull final Collection gradleDependencies) { + // don't do anything + System.out.println("Rendering all now.."); + gradleDependencies.iterator().forEachRemaining(gradleDependency -> + System.out.println(gradleDependency.toString()) + ); + } + + private void render(@NonNull final String formattedDependency) { + System.out.println(formattedDependency); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyType.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyType.java new file mode 100644 index 00000000..b812baa3 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyType.java @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +/** + * Determines the type of a dependency i.e. whether it used in development vs production code. + */ +public enum DependencyType { + DEVELOPMENT, + RUNTIME; +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java new file mode 100644 index 00000000..6bf7f348 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/DependencyTypeAdapter.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Configuration; + +import lombok.NonNull; + +/** + * An implementation of the {@link IDependencyTypeAdapter}. + */ +public class DependencyTypeAdapter implements IDependencyTypeAdapter { + @Override + public DependencyType adapt(Configuration configuration) { + if (isRuntimeConfiguration(configuration.getName())) { + return DependencyType.RUNTIME; + } else { + return DependencyType.DEVELOPMENT; + } + } + + /** + * Determines if the supplied {@link Configuration} translates to dependencies appearing on the + * runtime classpath or not. + * + * @param configurationName the name of the configuration to render + * @return a boolean that indicates if the configuration is runtime or not + */ + private boolean isRuntimeConfiguration(@NonNull final String configurationName) { + switch (configurationName) { + case "runtimeClasspath": + case "implementation": + return true; + default: + return false; + } + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/GradleDependency.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/GradleDependency.java new file mode 100644 index 00000000..3dbd97a3 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/GradleDependency.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import java.util.Set; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.experimental.Accessors; + +/** + * Represents a Gradle Dependency. + */ +@AllArgsConstructor +@Getter +@Accessors(prefix = "m") +@EqualsAndHashCode +public class GradleDependency { + private DependencyType mDependencyType; + private final IMavenDependency mMavenDependency; + private final Set mDependencyRoots; + + /** + * Add a root dependency to this gradle dependency. + * + * @param mavenDependency the {@link IMavenDependency} that needs to be added as a root this + * gradle dependency + */ + public void addRootDependency(@NonNull final IMavenDependency mavenDependency) { + mDependencyRoots.add(mavenDependency); + } + + /** + * Set the dependency type of this gradle dependency. + * + * @param dependencyType the {@link DependencyType} + */ + public void setDependencyType(@NonNull final DependencyType dependencyType) { + mDependencyType = dependencyType; + } + + @Override + public String toString() { + return "dep = " + mMavenDependency.toString() + " scope = " + mDependencyType.name() + + " roots = " + mDependencyRoots.toString(); + + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java new file mode 100644 index 00000000..99e15647 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IDependencyTypeAdapter.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Configuration; + +/** + * An adapter that convert a Gradle dependency {@link Configuration} into a {@link DependencyType} + * object. + */ +public interface IDependencyTypeAdapter { + + /** + * Convert the supplied the {@link Configuration} into a {@link DependencyType} object. + * + * @param configuration the {@link Configuration} that needs to be adapted + * @return a {@link DependencyType} object + */ + DependencyType adapt(Configuration configuration); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependency.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependency.java new file mode 100644 index 00000000..0fb39a72 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependency.java @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +/** + * Describes a maven dependency. + */ +public interface IMavenDependency { + + /** + * Returns the group of this dependency. The group is often required to find the artifacts of a dependency in a + * repository. For example, the group name corresponds to a directory name in a Maven like repository. Might return + * null. + */ + String getGroup(); + + /** + * Returns the name of this dependency. The name is almost always required to find the artifacts of a dependency in + * a repository. Never returns null. + */ + String getName(); + + /** + * Returns the version of this dependency. The version is often required to find the artifacts of a dependency in a + * repository. For example the version name corresponds to a directory name in a Maven like repository. Might return + * null. + */ + String getVersion(); + +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java new file mode 100644 index 00000000..a3b296ab --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyAdapter.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.ModuleVersionIdentifier; +import org.gradle.api.artifacts.result.DependencyResult; + +/** + * An adapter to convert different types of internal Gradle dependency objects into a customized + * {@link IMavenDependency} type. + */ +public interface IMavenDependencyAdapter { + + /** + * Convert a {@link Dependency} into a {@link IMavenDependency}. + * + * @param dependency the {@link Dependency} to convert + * @return an {@link IMavenDependency} representation of the provided dep + */ + IMavenDependency adapt(Dependency dependency); + + /** + * Convert a {@link DependencyResult} into a {@link IMavenDependency}. + * + * @param dependencyResult the {@link DependencyResult} to convert + * @return an {@link IMavenDependency} representation of the provided dep + */ + IMavenDependency adapt(DependencyResult dependencyResult); + + /** + * Convert a {@link ModuleVersionIdentifier} into a {@link IMavenDependency}. + * + * @param moduleVersionIdentifier the {@link ModuleVersionIdentifier} to convert + * @return an {@link IMavenDependency} representation of the provided dep + */ + IMavenDependency adapt(ModuleVersionIdentifier moduleVersionIdentifier); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java new file mode 100644 index 00000000..79ca53be --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/IMavenDependencyFormatter.java @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +/** + * An interface to format a dependency into a simple String. + */ +public interface IMavenDependencyFormatter { + + /** + * Formats a {@link IMavenDependency} into a easily readable String representation. + * + * @param dependency the dependency to format + * @return a String representation of the dependency + */ + String formatDependency(IMavenDependency dependency); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependency.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependency.java new file mode 100644 index 00000000..18ac36f6 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependency.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.experimental.Accessors; + +/** + * An implementation of {@link IMavenDependency}. + */ +@AllArgsConstructor +@Getter +@Accessors(prefix = "m") +@EqualsAndHashCode +public class MavenDependency implements IMavenDependency { + + private static final IMavenDependencyFormatter sDependencyFormatter = new SimpleMavenDependencyFormatter(); + + private final String mGroup; + private final String mName; + private final String mVersion; + + @Override + public String toString() { + return sDependencyFormatter.formatDependency(this); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependencyAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependencyAdapter.java new file mode 100644 index 00000000..b5080628 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/MavenDependencyAdapter.java @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +import org.gradle.api.artifacts.Dependency; +import org.gradle.api.artifacts.ModuleVersionIdentifier; +import org.gradle.api.artifacts.result.DependencyResult; +import org.gradle.api.artifacts.result.ResolvedDependencyResult; + +import javax.annotation.Nullable; + +import lombok.NonNull; + +/** + * An implementation of the {@link IMavenDependencyAdapter}. + */ +public class MavenDependencyAdapter implements IMavenDependencyAdapter { + @Override + public IMavenDependency adapt(@NonNull final Dependency dependency) { + final String group = dependency.getGroup(); + final String name = dependency.getName(); + final String version = dependency.getVersion(); + + return new MavenDependency(group, name, version); + } + + @Nullable + @Override + public IMavenDependency adapt(@NonNull final DependencyResult dependencyResult) { + if (dependencyResult instanceof ResolvedDependencyResult) { + return adapt((ResolvedDependencyResult) dependencyResult); + } else { + return null; + } + } + + @Override + public IMavenDependency adapt(@NonNull final ModuleVersionIdentifier moduleVersionIdentifier) { + final String group = moduleVersionIdentifier.getGroup(); + final String name = moduleVersionIdentifier.getName(); + final String version = moduleVersionIdentifier.getVersion(); + + return new MavenDependency(group, name, version); + } + + private IMavenDependency adapt(ResolvedDependencyResult resolvedDependencyResult) { + final ModuleVersionIdentifier selectedModuleVersion = + resolvedDependencyResult.getSelected().getModuleVersion(); + + if (selectedModuleVersion == null) { + return null; + } + + return adapt(selectedModuleVersion); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java new file mode 100644 index 00000000..367009e2 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/SimpleMavenDependencyFormatter.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering; + +/** + * An implementation of {@link IMavenDependencyFormatter} that formats the dependency into a simple + * string as follows: + * + * :: + */ +public class SimpleMavenDependencyFormatter implements IMavenDependencyFormatter { + + private static final String SEPARATOR = ":"; + + @Override + public String formatDependency(IMavenDependency dependency) { + return dependency.getGroup() + + SEPARATOR + dependency.getName() + + SEPARATOR + dependency.getVersion(); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java new file mode 100644 index 00000000..0e93dab4 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CGManifestGradleDependencyRenderer.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; +import com.microsoft.identity.buildsystem.rendering.AbstractGradleDependencyRenderer; +import com.microsoft.identity.buildsystem.rendering.DependencyType; +import com.microsoft.identity.buildsystem.rendering.GradleDependency; +import com.microsoft.identity.buildsystem.rendering.IMavenDependency; +import com.microsoft.identity.buildsystem.rendering.settings.GradleDependencyRendererSettings; + +import org.gradle.api.Project; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import lombok.NonNull; + +/** + * An implementation of {@link AbstractGradleDependencyRenderer} to render dependencies in a + * {@link CgManifest} format and also write them to the cgmanifest.json file. + *

+ * The renderer will create the CG Manifest file in the location provided to the + * {@link GradleDependencyRendererSettings} object. + */ +public class CGManifestGradleDependencyRenderer extends AbstractGradleDependencyRenderer { + + private static final String CG_MANIFEST_FILE_NAME = "cgmanifest.json"; + + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private static final JsonParser JSON_PARSER = new JsonParser(); + + private final IComponentAdapter mDependencyComponentAdapter = new ComponentAdapter(); + + public CGManifestGradleDependencyRenderer(GradleDependencyRendererSettings gradleDependencyRendererSettings) { + super(gradleDependencyRendererSettings); + } + + @Override + public void render(@NonNull GradleDependency gradleDependency) { + // we could do something here...but let's just take the final result from the complete + // method + } + + @Override + public void complete(@NonNull final Project project, + @NonNull Collection gradleDependencies) { + // create CG Manifest object from these dependencies + final CgManifest cgManifest = createCgManifest(gradleDependencies); + + // convert it to JSON representation + final String cgManifestJson = GSON.toJson(cgManifest); + + // let's get a pretty representation of it + final JsonElement cgManifestJsonElement = JSON_PARSER.parse(cgManifestJson); + + // and now convert to JSON again so that the string is in the pretty format + final String cgManifestPrettyJson = GSON.toJson(cgManifestJsonElement); + + // log the JSON to console + System.out.println(cgManifestPrettyJson); + + // and also dump it into the cgmanifest file i.e. cgmanifest.json + dumpToCgManifestJsonFile( + mGradleDependencyRendererSettings.getCgManifestReportDirectory(), cgManifestPrettyJson + ); + } + + @Override + public void completeProject(Project project) { + super.completeProject(project); + } + + private CgManifest createCgManifest(@NonNull final Collection gradleDependencies) { + final CgManifest cgManifest = new CgManifest(); + + // iterate over all the gradle dependencies that we have received + for (final GradleDependency gradleDependency : gradleDependencies) { + final IMavenDependency mavenDependency = gradleDependency.getMavenDependency(); + final DependencyType dependencyType = gradleDependency.getDependencyType(); + final Set rootDeps = gradleDependency.getDependencyRoots(); + + // take the maven dependency that we got and convert that into a MavenComponent + // MavenComponent is type that we need for the CG Manifest + final MavenComponent mavenComponent = mDependencyComponentAdapter.adapt( + mavenDependency + ); + + final Set rootComponents = new HashSet<>(); + + // for each root dependency of the dependency we received..we would also convert these + // to a CG Manifest Maven Component and add it as the root components + rootDeps.iterator().forEachRemaining(mavenDep -> rootComponents.add(mDependencyComponentAdapter.adapt(mavenDep))); + + // Create a Registration object out of the data we have for this dependency and add it + // to the CG Manifest. Each Dependency object essentially translates to a Registration + // object in the CG Manifest. + // + // Just look at the Registration.java class to understand what all is in there + // or just read the docs here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + cgManifest.addRegistration(new Registration( + mavenComponent, + dependencyType == DependencyType.DEVELOPMENT, + rootComponents + )); + } + + return cgManifest; + } + + private void dumpToCgManifestJsonFile(@NonNull final File rootDir, @NonNull final String text) { + try { + final File cgManifestFile = new File(rootDir, CG_MANIFEST_FILE_NAME); + System.out.println("Writing cg manifest to file: " + cgManifestFile.getAbsolutePath()); + final FileWriter fileWriter = new FileWriter(cgManifestFile); + PrintWriter printWriter = new PrintWriter(fileWriter); + printWriter.print(text); + printWriter.close(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CgManifest.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CgManifest.java new file mode 100644 index 00000000..f6f02c13 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/CgManifest.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import java.util.HashSet; +import java.util.Set; + +import lombok.EqualsAndHashCode; +import lombok.NonNull; + +/** + * Describes a CG Manifest that is used to report dependencies to Microsoft Component Governance. + *

+ * More information is located here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + */ +@EqualsAndHashCode +public class CgManifest { + + @SerializedName(SerializedNames.REGISTRATIONS) + private final Set mRegistrations = new HashSet<>(); + + public void addRegistration(@NonNull final Registration registration) { + mRegistrations.add(registration); + } + + public Set getRegistrations() { + return mRegistrations; + } + + private static class SerializedNames { + private static final String REGISTRATIONS = "Registrations"; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Component.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Component.java new file mode 100644 index 00000000..4d540db2 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Component.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; + +/** + * Represents a component in a {@link Registration}. + *

+ * For more info read the docs here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + */ +@EqualsAndHashCode +@AllArgsConstructor +public abstract class Component { + + @SerializedName(SerializedNames.TYPE) + private final String mType; + + private static class SerializedNames { + private static final String TYPE = "Type"; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java new file mode 100644 index 00000000..71a9fb01 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/ComponentAdapter.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.microsoft.identity.buildsystem.rendering.IMavenDependency; + +import lombok.NonNull; + +/** + * An implementation of {@link IComponentAdapter} that converts the provided dependency + * into a {@link MavenComponent}. + */ +public class ComponentAdapter implements IComponentAdapter { + @NonNull + @Override + public MavenComponent adapt(@NonNull final IMavenDependency dependency) { + final MavenComponentInfo mavenComponentInfo = new MavenComponentInfo( + dependency.getGroup(), + dependency.getName(), + dependency.getVersion() + ); + + return new MavenComponent(mavenComponentInfo); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java new file mode 100644 index 00000000..b12d9d1c --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/IComponentAdapter.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.microsoft.identity.buildsystem.rendering.IMavenDependency; + +/** + * Converts an internal dependency into a {@link Component}. + */ +public interface IComponentAdapter { + + /** + * Converts a {@link IMavenDependency} into a {@link MavenComponent}. + * + * @param dependency the {@link IMavenDependency} dependency that needs to be converted to a + * component + * @return a {@link MavenComponent} representation of the {@link IMavenDependency} + */ + MavenComponent adapt(IMavenDependency dependency); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponent.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponent.java new file mode 100644 index 00000000..a92b4603 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponent.java @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.experimental.Accessors; + +/** + * Represents a Maven Component i.e. a {@link Component} of the Maven type in a {@link Registration} + * in the CG Manifest. + *

+ * For more information, read the docs here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + */ +@EqualsAndHashCode(callSuper = true) +@Getter +@Accessors(prefix = "m") +public class MavenComponent extends Component { + + private static final String MAVEN_COMPONENT_TYPE_NAME = "Maven"; + + @SerializedName(MAVEN_COMPONENT_TYPE_NAME) + private final MavenComponentInfo mMavenComponentInfo; + + public MavenComponent(@NonNull final MavenComponentInfo mavenComponentInfo) { + super(MAVEN_COMPONENT_TYPE_NAME); + this.mMavenComponentInfo = mavenComponentInfo; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentInfo.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentInfo.java new file mode 100644 index 00000000..93131752 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/MavenComponentInfo.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.experimental.Accessors; + +/** + * Provides information about a {@link MavenComponent}. + *

+ * For more information, read the docs here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + */ +@Getter +@AllArgsConstructor +@Accessors(prefix = "m") +public class MavenComponentInfo { + + @SerializedName(SerializedNames.GROUP_ID) + private final String mGroupId; + + @SerializedName(SerializedNames.ARTIFACT_ID) + private final String mArtifactId; + + @SerializedName(SerializedNames.VERSION) + private final String mVersion; + + private static class SerializedNames { + private static final String GROUP_ID = "GroupId"; + private static final String ARTIFACT_ID = "ArtifactId"; + private static final String VERSION = "Version"; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Registration.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Registration.java new file mode 100644 index 00000000..40ccca39 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/cgmanifest/Registration.java @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.cgmanifest; + +import com.google.gson.annotations.SerializedName; + +import java.util.Set; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.experimental.Accessors; + +/** + * Represents the Registration of a dependency in the {@link CgManifest}. + *

+ * For more information, read the docs here: https://docs.opensource.microsoft.com/tools/cg/features/cgmanifest/ + */ +@EqualsAndHashCode() +@AllArgsConstructor +@Getter +@Accessors(prefix = "m") +public class Registration { + + @SerializedName(SerializedNames.COMPONENT) + private final Component mComponent; + + @SerializedName(SerializedNames.DEVELOPMENT_DEPENDENCY) + private final boolean mDevelopmentDependency; + + @SerializedName(SerializedNames.DEPENDENCY_ROOTS) + private final Set mDependencyRoots; + + private static class SerializedNames { + private static final String COMPONENT = "Component"; + private static final String DEVELOPMENT_DEPENDENCY = "DevelopmentDependency"; + private static final String DEPENDENCY_ROOTS = "DependencyRoots"; + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsAdapter.java new file mode 100644 index 00000000..b85cee4e --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsAdapter.java @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.settings; + +import org.gradle.api.Project; +import org.gradle.api.provider.Property; + +import java.io.File; + +import javax.annotation.Nullable; + +import lombok.AllArgsConstructor; + +/** + * An implementation of the {@link IDependencyRendererSettingsAdapter}. + */ +@AllArgsConstructor +public class DependencyRendererSettingsAdapter implements IDependencyRendererSettingsAdapter { + + private final Project mProject; + + @Override + public GradleDependencyRendererSettings adapt(@Nullable final DependencyRendererSettingsExtension extension) { + final GradleDependencyRendererSettings.GradleDependencyRendererSettingsBuilder builder = + GradleDependencyRendererSettings.builder(); + + if (extension == null) { + return builder.build(); + } + + final Property renderProjectDependency = extension.getRenderProjectDependency(); + if (renderProjectDependency != null && renderProjectDependency.isPresent()) { + builder.renderProjectDependency(renderProjectDependency.get()); + } + + final Property renderTransitiveDependencies = extension.getRenderTransitiveDependencies(); + if (renderTransitiveDependencies != null && renderTransitiveDependencies.isPresent()) { + builder.renderTransitiveDependencies(renderTransitiveDependencies.get()); + } + + final Property cgManifestReportDirectory = extension.getCgManifestReportDirectory(); + if (cgManifestReportDirectory != null && cgManifestReportDirectory.isPresent()) { + builder.cgManifestReportDirectory(cgManifestReportDirectory.get()); + } else { + // project.getBuildDir is the default if a File location is not project + builder.cgManifestReportDirectory(mProject.getBuildDir()); + } + + return builder.build(); + } +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java new file mode 100644 index 00000000..47e3dbf2 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/DependencyRendererSettingsExtension.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.settings; + +import org.gradle.api.provider.Property; + +import java.io.File; + +/** + * Gradle Build Extension to provide dependency rendering configuration to our + * {@link com.microsoft.identity.buildsystem.BuildPlugin}. + */ +public abstract class DependencyRendererSettingsExtension { + + /** + * Get the property that indicates if project dependencies should be rendered by the build + * plugin. + * + * @return a {@link Property} that indicates if project dependencies should be rendered + */ + abstract public Property getRenderProjectDependency(); + + /** + * Get the property that indicates if transitive dependencies should be rendered by the build + * plugin. + * + * @return a {@link Property} that indicates if transitive dependencies should be + * rendered + */ + abstract public Property getRenderTransitiveDependencies(); + + /** + * Get the property that indicates the directory where the + * {@link com.microsoft.identity.buildsystem.rendering.cgmanifest.CgManifest} file should be + * created. + * + * @return a {@link Property} that indicates the directory of the cg manifest file + */ + abstract public Property getCgManifestReportDirectory(); +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java new file mode 100644 index 00000000..c5459316 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/GradleDependencyRendererSettings.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.settings; + +import java.io.File; + +import lombok.Builder; +import lombok.Getter; +import lombok.NonNull; +import lombok.experimental.Accessors; + +/** + * Represents the settings that control some of the rendering of the dependencies in the + * {@link com.microsoft.identity.buildsystem.rendering.AbstractGradleDependencyRenderer}. + */ +@Builder +@Getter +@Accessors(prefix = "m") +public class GradleDependencyRendererSettings { + + /** + * Indicates whether project dependencies should be rendered. + *

+ * These are basically when we do things like "implementation project(":projectName")" + */ + @Builder.Default + private final boolean mRenderProjectDependency = false; + + /** + * Indicates whether transitive dependencies of a dependency should be rendered. + */ + @Builder.Default + private final boolean mRenderTransitiveDependencies = true; + + /** + * Indicates the directory on the machine where the CG Manifest should be created. + */ + @NonNull + private final File mCgManifestReportDirectory; +} diff --git a/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/IDependencyRendererSettingsAdapter.java b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/IDependencyRendererSettingsAdapter.java new file mode 100644 index 00000000..617d89f3 --- /dev/null +++ b/plugins/buildsystem/src/main/java/com/microsoft/identity/buildsystem/rendering/settings/IDependencyRendererSettingsAdapter.java @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +package com.microsoft.identity.buildsystem.rendering.settings; + +/** + * Describes an adapter that can convert a {@link DependencyRendererSettingsExtension} into a + * {@link GradleDependencyRendererSettings} object. + */ +public interface IDependencyRendererSettingsAdapter { + + /** + * Converts the provided {@link DependencyRendererSettingsExtension} object into the internal + * {@link GradleDependencyRendererSettings} object. + * + * @param dependencyRendererSettingsExtension the {@link DependencyRendererSettingsExtension} + * object that needs to be converted + * @return a {@link GradleDependencyRendererSettings} object derived from the supplied extension + */ + GradleDependencyRendererSettings adapt( + DependencyRendererSettingsExtension dependencyRendererSettingsExtension + ); + +} diff --git a/settings.gradle b/settings.gradle index eda09826..3d06c213 100644 --- a/settings.gradle +++ b/settings.gradle @@ -76,8 +76,8 @@ project(':labapi').projectDir = new File('common/labapi') include(":keyvault") project(':keyvault').projectDir = new File('common/keyvault') -include(":AcaPlugin") -project(':AcaPlugin').projectDir = new File('plugins/buildsystem') +include(":buildsystem") +project(':buildsystem').projectDir = new File('plugins/buildsystem') include(":broker4j") project(':broker4j').projectDir = new File('broker/broker4j')